Skip to content

CI should run Undefined Behavior Sanitizer (UBSAN), as already done for ASAN #111758

Closed

Description

@thesamesam

Feature or enhancement

Proposal:

cpython's CI should run Undefined Behavior Sanitizer (UBSAN), like it already does for Address Sanitizer (ASAN).

It already has support in configure for this with ./configure --with-undefined-behavior-sanitizer.

This is important for portability, future proofing (keeping CPython working with a range of compilers), and avoiding confusing bug reports later when UB manifests.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. thesamesam commented on Nov 5, 2023

    @thesamesam
    ContributorAuthor

    Note that --with-undefined-behavior-sanitizer does not set export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 right now.

    By default, UBSAN will not abort on errors, which might mean errors are being missed by the fuzzer right now which does seem to use UBSAN? Not sure how the configuration works for that job:

    $ grep -rsin undefined .github/
    .github/workflows/build.yml:467:        sanitizer: [address, undefined, memory]
    
  2. thesamesam commented on Nov 5, 2023

    @thesamesam
    ContributorAuthor

    cc @gpshead as we've discussed build issues before and this feels like it's in your wheelhouse

  3. gpshead commented on Nov 5, 2023

    @gpshead
    Member

    Overall in favor. Doing this in CI is predicated on if we actually pass UBSAN today and which things we need to categorize and disable in order to do so.

  4. gpshead commented on Nov 5, 2023

    @gpshead
    Member

    Note that there have been some UB reports in the past that may be technically correct from a C++ compiler spec perspective (read: clang, and note that C and C++ have different defined behavior definitions) but not actually undefined from a "giant swath of C code in the world has depended on the implemented behavior for 30+ years" perspective so the implemented behavior won't actually ever be changed. (see us passing -fwrapv to the compiler all over the place? defining that behavior in our build is one reason why)

    Work to be done there (if any) is mostly around categorization and how to tell UBSAN which things we know and are okay with, the goal being not to introduce more.

  5. gpshead commented on Nov 5, 2023

    @gpshead
    Member

    For example, clang 17 ubsan gives triggers a build failure trying to run _freeze_module:

    ../cpython/Objects/object.c:2858:5: runtime error: call to function list_dealloc through pointer to incorrect function type 'void (*)(struct _o
    bject *)'
    ../cpython/Objects/listobject.c:347: note: list_dealloc defined here
    

    (*)(PyObject *) vs (*)(PyListObject *) is "undefined"? CPython casts things to PyObject* all over the place as a standard practice by design as a common C idiom for structure extension.

  6. thesamesam commented on Nov 5, 2023

    @thesamesam
    ContributorAuthor

    Yeah, see #111178 for that one. I'm not sure that this use as it stands is compatible with CFI which is a useful exploit mitigation.

    But yeah, categorising existing errors sounds fine, sorting them into "things we should fix" and "things we want to make defined in CPython".

  7. encukou commented on Jun 16, 2025

    @encukou
    Member

    Undefined behavior is now gone (#111178, #133157), thanks to @picnixz and many others.

  8. added a commit that references this issue on Jun 19, 2025
  9. encukou commented on Jun 19, 2025

    @encukou
    Member

    The CI run is in. But, as Hugo pointed out, the workflow definitions are now somewhat repetitive.

    I'll watch the job for about a week before consolidating.

  10. added
    infraCI, GitHub Actions, buildbots, Dependabot, etc.
    on Jun 19, 2025
  11. added a commit that references this issue on Jun 19, 2025
  12. added a commit that references this issue on Jul 12, 2025
  13. webknjaz commented on Jul 20, 2025

    @webknjaz
    Member

    I'll watch the job for about a week before consolidating.

    Now that it's passed, #136820 does this thanks to the EuroPython collab ;)

  14. thesamesam commented on Jul 20, 2025

    @thesamesam
    ContributorAuthor

    Thanks for the efforts on this, all.

  15. added a commit that references this issue on Jul 20, 2025
  16. added a commit that references this issue on Jul 20, 2025
  17. added a commit that references this issue on Jul 20, 2025
  18. webknjaz commented on Jul 22, 2025

    @webknjaz
    Member

    @thesamesam I think this issue can be considered resolved.

  19. thesamesam commented on Jul 22, 2025

    @thesamesam
    ContributorAuthor

    Indeed.

  20. added 2 commits that reference this issue on Jul 23, 2025
  21. added a commit that references this issue on Aug 1, 2025
  22. added 2 commits that reference this issue on Aug 4, 2025
  23. added 2 commits that reference this issue on Aug 19, 2025
  24. added a commit that references this issue on Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildThe build process and cross-buildinfraCI, GitHub Actions, buildbots, Dependabot, etc.type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions