Skip to content

bpo-35214: Initial clang MemorySanitizer support #10479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 12, 2018

Conversation

gpshead
Copy link
Member

@gpshead gpshead commented Nov 12, 2018

Adds a convenient configure flags for --with-memory-sanitizer and --with-undefined-behavior-sanitizer.

Fixes up the CPython code base to be mostly memory sanitizer clean. These changes come from patches we've been using at Google.

https://bugs.python.org/issue35214

This makes it easier to enable clang's memory and undefined behavior
sanitizers on a build without manually setting CFLAGS and LDFLAGS.

This also encodes the detail that address sanitizer and memory sanitizer
should disable pymalloc.
This allows code to easily take conditional action when in an msan
build.  Usually used for telling msan things it can't otherwise
figure out such as syscall, asm behavior, or about libc functions
it isn't yet aware of.
These teach MSan about syscalls, asm behavior, or otherwise address
clang memory sanitizer flagged issues.
@gpshead
Copy link
Member Author

gpshead commented Nov 12, 2018

A news entry will come. I put the PR up to see what the CI thinks of this on various platforms.

I run the current undefined behavior sanitizer buildbot and am setting up a memory sanitizer buildbot. This is a prerequisite for that to be useful.

@gpshead gpshead merged commit 1584a00 into python:master Nov 12, 2018
@miss-islington
Copy link
Contributor

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @gpshead, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 1584a0081500d35dc93ff88e5836df35faf3e3e2 3.7

@miss-islington
Copy link
Contributor

Sorry, @gpshead, I could not cleanly backport this to 3.6 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 1584a0081500d35dc93ff88e5836df35faf3e3e2 3.6

gpshead added a commit to gpshead/cpython that referenced this pull request Nov 12, 2018
Adds configure flags for msan and ubsan builds to make it easier to enable.
These also encode the detail that address sanitizer and memory sanitizer
should disable pymalloc.

Define MEMORY_SANITIZER when appropriate at build time and adds workarounds
to existing code to mark things as initialized where the sanitizer is otherwise unable to
determine that.  This lets our build succeed under the memory sanitizer.  not all tests
pass without sanitizer failures yet but we're in pretty good shape after this.

(cherry picked from commit 1584a00)
gpshead added a commit to gpshead/cpython that referenced this pull request Nov 12, 2018
Adds configure flags for msan and ubsan builds to make it easier to enable.
These also encode the detail that address sanitizer and memory sanitizer
should disable pymalloc.

Define MEMORY_SANITIZER when appropriate at build time and adds workarounds
to existing code to mark things as initialized where the sanitizer is otherwise unable to
determine that.  This lets our build succeed under the memory sanitizer.  not all tests
pass without sanitizer failures yet but we're in pretty good shape after this..
(cherry picked from commit 1584a00)

Co-authored-by: Gregory P. Smith <[email protected]>
@bedevere-bot
Copy link

GH-10492 is a backport of this pull request to the 3.7 branch.

gpshead added a commit that referenced this pull request Nov 12, 2018
…-10492)

Adds configure flags for msan and ubsan builds to make it easier to enable.
These also encode the detail that address sanitizer and memory sanitizer
should disable pymalloc.

Define MEMORY_SANITIZER when appropriate at build time and adds workarounds
to existing code to mark things as initialized where the sanitizer is otherwise unable to
determine that.  This lets our build succeed under the memory sanitizer.  not all tests
pass without sanitizer failures yet but we're in pretty good shape after this.

(cherry picked from commit 1584a00)

Co-authored-by: Gregory P. Smith <[email protected]> [Google LLC]
gpshead added a commit to gpshead/cpython that referenced this pull request Nov 12, 2018
Adds configure flags for msan and ubsan builds to make it easier to enable.
These also encode the detail that address sanitizer and memory sanitizer
should disable pymalloc.

Define MEMORY_SANITIZER when appropriate at build time and adds workarounds
to existing code to mark things as initialized where the sanitizer is otherwise unable to
determine that.  This lets our build succeed under the memory sanitizer.  not all tests
pass without sanitizer failures yet but we're in pretty good shape after this.

(cherry picked from commit 1584a00)

Contributed by Gregory P. Smith [Google LLC]
gpshead added a commit to gpshead/cpython that referenced this pull request Nov 12, 2018
Adds configure flags for msan and ubsan builds to make it easier to enable.
These also encode the detail that address sanitizer and memory sanitizer
should disable pymalloc.

Define MEMORY_SANITIZER when appropriate at build time and adds workarounds
to existing code to mark things as initialized where the sanitizer is otherwise unable to
determine that.  This lets our build succeed under the memory sanitizer.  not all tests
pass without sanitizer failures yet but we're in pretty good shape after this..
(cherry picked from commit 1584a00)

Co-authored-by: Gregory P. Smith <[email protected]>
@bedevere-bot
Copy link

GH-10493 is a backport of this pull request to the 3.6 branch.

@gpshead gpshead deleted the initial-msan-fixes branch November 12, 2018 22:11
gpshead added a commit that referenced this pull request Nov 13, 2018
…-10493)

Adds configure flags for msan and ubsan builds to make it easier to enable.
These also encode the detail that address sanitizer and memory sanitizer
should disable pymalloc.

Define MEMORY_SANITIZER when appropriate at build time and adds workarounds
to existing code to mark things as initialized where the sanitizer is otherwise unable to
determine that.  This lets our build succeed under the memory sanitizer.  not all tests
pass without sanitizer failures yet but we're in pretty good shape after this.

(cherry picked from commit 1584a00)

Contributed by Gregory P. Smith [Google LLC]

Also includes a whitespace fix from make patchcheck to _posixsubprocess.c - unrelated to the main change that makes the CI happy so I'm just doing it now rather than creating a separate PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants