llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

msan: incorrect origin for stack variables

Open KernelAddress opened this issue 8 years ago • 1 comments

Bugzilla Link 37206
Version unspecified
OS Linux
CC @dwblaikie,@eugenis,@ramosian-glider,@kcc,@vitalybuka

Extended Description

#include <stdio.h>

int main() { volatile char a, b, c, d, e, f, g, h; volatile char x, y; c = x; d = y; if (c) printf("here\n"); return 0; }

$ clang -v clang version 7.0.0 (trunk 326052) $ clang test.c -fsanitize=memory -fsanitize-memory-track-origins -g $ ./a.out

==259013==WARNING: MemorySanitizer: use-of-uninitialized-value #​0 0x49a1a6 in main test.c:9:6 #​1 0x7f8dd562a2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0) #​2 0x41d5f9 in _start (a.out+0x41d5f9)

Uninitialized value was stored to memory at #​0 0x49a116 in main test.c:8:4 #​1 0x7f8dd562a2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

Uninitialized value was created by an allocation of 'y' in the stack frame of function 'main' #​0 0x499b10 in main test.c:4

SUMMARY: MemorySanitizer: use-of-uninitialized-value test.c:9:6 in main

Uninit values is created by variable 'x', not 'y'.

MSAN should align local variables to origin granularity.

KernelAddress avatar Apr 23 '18 07:04 KernelAddress

Agreed. This should not be too expensive compared to the rest of MSan instrumentation.

eugenis avatar Apr 23 '18 19:04 eugenis