This is an archive of the discontinued LLVM Phabricator instance.

[msan] Add interceptors for Linux 64-bit stat variants
ClosedPublic

Authored by manojgupta on Mar 14 2022, 4:54 PM.

Details

Summary

glibc >= 2.33 uses shared functions for stat family functions.
D111984 added support for non-64 bit variants but they
do not appear to be enough as we have been noticing msan
errors on 64-bit stat variants on Chrome OS.

Diff Detail

Event Timeline

manojgupta created this revision.Mar 14 2022, 4:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2022, 4:54 PM
manojgupta requested review of this revision.Mar 14 2022, 4:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2022, 4:54 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript

I am noticing a unit tests error with this change for glob_altdirfunc.cpp file but not sure how to resolve it.

MemorySanitizer:DEADLYSIGNAL
==3854677==ERROR: MemorySanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000000000 bp 0x7ffeeab8eb60 sp 0x7ffeeab8eb28 T3854677)
==3854677==Hint: pc points to the zero page.
==3854677==The signal is caused by a READ memory access.
==3854677==Hint: address points to the zero page.

    #0 0x0  (<unknown module>)
    #1 0x449cef  (compiler-rt/test/msan/X86_64/Linux/Output/glob_altdirfunc.cpp.tmp+0x449cef)
    #2 0x4433e5  (compiler-rt/test/msan/X86_64/Linux/Output/glob_altdirfunc.cpp.tmp+0x4433e5)
    #3 0x44370a  (/compiler-rt/test/msan/X86_64/Linux/Output/glob_altdirfunc.cpp.tmp+0x44370a)
    #4 0x7f0f777021ff  (/lib/x86_64-linux-gnu/libpthread.so.0+0x131ff) (BuildId: 54322f9a621b22e9ea3a4a96b6692f7a0f931b2d)

to avoid crash you need:
INIT_STAT64;
INIT_LSTAT64;
around sanitizer_common_interceptors.inc:10554

can you please add corresponding tests similar to
llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/lstat.cpp
llvm-project/compiler-rt/test/msan/fstat.cpp

I am noticing a unit tests error with this change for glob_altdirfunc.cpp file but not sure how to resolve it.

MemorySanitizer:DEADLYSIGNAL
==3854677==ERROR: MemorySanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000000000 bp 0x7ffeeab8eb60 sp 0x7ffeeab8eb28 T3854677)
==3854677==Hint: pc points to the zero page.
==3854677==The signal is caused by a READ memory access.
==3854677==Hint: address points to the zero page.

    #0 0x0  (<unknown module>)
    #1 0x449cef  (compiler-rt/test/msan/X86_64/Linux/Output/glob_altdirfunc.cpp.tmp+0x449cef)
    #2 0x4433e5  (compiler-rt/test/msan/X86_64/Linux/Output/glob_altdirfunc.cpp.tmp+0x4433e5)
    #3 0x44370a  (/compiler-rt/test/msan/X86_64/Linux/Output/glob_altdirfunc.cpp.tmp+0x44370a)
    #4 0x7f0f777021ff  (/lib/x86_64-linux-gnu/libpthread.so.0+0x131ff) (BuildId: 54322f9a621b22e9ea3a4a96b6692f7a0f931b2d)
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
468–471

Just SANITIZER_INTERCEPT_STAT64 should be enough for now

Fixed crash and added suggested tests.

manojgupta marked an inline comment as done.Mar 14 2022, 9:44 PM

to avoid crash you need:
INIT_STAT64;
INIT_LSTAT64;
around sanitizer_common_interceptors.inc:10554

can you please add corresponding tests similar to
llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/lstat.cpp
llvm-project/compiler-rt/test/msan/fstat.cpp

Done

vitalybuka added inline comments.Mar 14 2022, 9:50 PM
compiler-rt/lib/msan/msan_interceptors.cpp
670

also fstat?

682

I guess we can do now SANITIZER_GLIBC && !__GLIBC_PREREQ(2, 33))
but let keep it as-is for compatibility (to let runtime built with 2.33 work with 2.32 glibc if needed)

721

also fstatat

vitalybuka added inline comments.Mar 14 2022, 9:54 PM
compiler-rt/test/msan/fstat64.cpp
9 ↗(On Diff #415315)

for all new interceptors please, unless it's already there

compiler-rt/test/sanitizer_common/TestCases/Posix/lstat64.cpp
10 ↗(On Diff #415315)

what is about test for stat64?

manojgupta added inline comments.Mar 14 2022, 9:55 PM
compiler-rt/lib/msan/msan_interceptors.cpp
670

fstat is handled right above under the condition SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_STAT_LINUX .

Do I need to do anything special for fstat?

compiler-rt/test/sanitizer_common/TestCases/Posix/lstat64.cpp
10 ↗(On Diff #415315)

Suer, will add tests for others.

vitalybuka accepted this revision.Mar 14 2022, 10:47 PM

LGTM with more tests
Thanks!

compiler-rt/lib/msan/msan_interceptors.cpp
670

Sorry, my mistake.

721

same, nothing needs to be done

This revision is now accepted and ready to land.Mar 14 2022, 10:47 PM

Added tests for stat64 and fstatat64

manojgupta marked 2 inline comments as done.Mar 15 2022, 7:13 PM

Replaced uses of /dev/stdin by /dev/null and added asserts.

This revision was automatically updated to reflect the committed changes.