-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[msan] Mark allocator padding as uninitialized, with new origin tag #157187
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
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ed47840
[msan] Mark allocator padding as uninitialized, with new origin tag
thurstond 1b1e1b8
Update comment
thurstond 7105241
Remove poison_in_calloc, add poison_in_padding (shared between calloc…
thurstond ff736b1
Add description to flags
thurstond 6fc1378
Tweak wording
thurstond dea7c28
Address Vitaly's feedback
thurstond 7b98f59
Change message to "Uninitialized value is outside of heap allocation"
thurstond 69bf311
Use ALLOC tag instead of ALLOC_PADDING when track_origins() == 1
thurstond aad1b12
clang-format
thurstond cf66f50
Test track-origins=1 for zero_alloc.cpp
thurstond 322586b
reinterpret_cast<Florian>
thurstond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // *** malloc: all bytes are uninitialized | ||
| // * malloc byte 0 | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 0 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 0 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC | ||
| // | ||
| // * malloc byte 6 | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 6 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 6 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC | ||
| // | ||
| // This test assumes the allocator allocates 16 bytes for malloc(7). Bytes | ||
| // 7-15 are padding. | ||
| // | ||
| // * malloc byte 7 | ||
| // Edge case: when the origin granularity spans both ALLOC and ALLOC_PADDING, | ||
| // ALLOC always takes precedence. | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 7 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 7 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC | ||
| // | ||
| // Bytes 8-15 are padding | ||
| // For track-origins=1, ALLOC is used instead of ALLOC_PADDING. | ||
| // | ||
| // * malloc byte 8 | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 8 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 8 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING | ||
| // | ||
| // * malloc byte 15 | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 15 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 15 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING | ||
|
|
||
| // *** calloc | ||
| // Bytes 0-6 are fully initialized, so no MSan report should happen. | ||
| // | ||
| // * calloc byte 0 | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=1 -DUSE_CALLOC %s -o %t && %run %t 0 2>&1 | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=2 -DUSE_CALLOC %s -o %t && %run %t 0 2>&1 | ||
| // | ||
| // * calloc byte 6 | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=1 -DUSE_CALLOC %s -o %t && %run %t 6 2>&1 | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=2 -DUSE_CALLOC %s -o %t && %run %t 6 2>&1 | ||
| // | ||
| // * calloc byte 7 | ||
| // Byte 7 is uninitialized. Unlike malloc, this is tagged as ALLOC_PADDING | ||
| // (since the origin does not need to track bytes 4-6). | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=1 -DUSE_CALLOC %s -o %t && not %run %t 7 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=2 -DUSE_CALLOC %s -o %t && not %run %t 7 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING | ||
| // | ||
| // * calloc byte 8 | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=1 -DUSE_CALLOC %s -o %t && not %run %t 8 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=2 -DUSE_CALLOC %s -o %t && not %run %t 8 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING | ||
| // | ||
| // * calloc byte 15 | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=1 -DUSE_CALLOC %s -o %t && not %run %t 15 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING | ||
| // RUN: %clang_msan -fsanitize-memory-track-origins=2 -DUSE_CALLOC %s -o %t && not %run %t 15 2>&1 \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING | ||
|
|
||
| #include <assert.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| int main(int argc, char **argv) { | ||
| #ifdef USE_CALLOC | ||
| char *p = (char *)calloc(7, 1); | ||
| #else | ||
| char *p = (char *)malloc(7); | ||
| #endif | ||
|
|
||
| if (argc == 2) { | ||
| int index = atoi(argv[1]); | ||
|
|
||
| printf("p[%d] = %d\n", index, p[index]); | ||
| // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value | ||
| // CHECK: {{#0 0x.* in main .*allocator_padding.cpp:}}[[@LINE-2]] | ||
| // ORIGIN-ALLOC: Uninitialized value was created by a heap allocation | ||
| // ORIGIN-ALLOC-PADDING: Uninitialized value is outside of heap allocation | ||
| free(p); | ||
| } | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.