This is an archive of the discontinued LLVM Phabricator instance.

[MSAN] add interceptor for timer_create, timer_settime, timer_gettime
ClosedPublic

Authored by kda on Feb 25 2022, 6:17 PM.

Diff Detail

Event Timeline

kda requested review of this revision.Feb 25 2022, 6:17 PM
kda created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2022, 6:17 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
kda added inline comments.Feb 25 2022, 6:28 PM
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
515

lint is insisting on these spaces.
They seem wrong.
How do I bypass the linter here?

vitalybuka accepted this revision.Feb 28 2022, 4:30 PM

for sanitizer_common interceptors we usually add trivial lit test just to make sure that it does not crash with any sanitizers
so LGTM with test/sanitizer_common

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
10222

man says timerid us not NULL pointer

10224

we don't use {} for one liners

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
515

insisting to add spaces or to remove?

This revision is now accepted and ready to land.Feb 28 2022, 4:30 PM
kda updated this revision to Diff 411949.Feb 28 2022, 7:42 PM
kda marked 2 inline comments as done.

remove spacing noise

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
10224

I stole this from getitimer, which does.

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
515

The linter is insisting on ADDING the spaces.
I don't think they belong there and want to remove them.

kda retitled this revision from [WIP] [MSAN] add interceptor for timer_create to [MSAN] add interceptor for timer_create.Feb 28 2022, 7:44 PM
vitalybuka added inline comments.Mar 1 2022, 11:58 PM
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
515

it's find, there is a setting in clang-format to add these spaces, we have it ON.
Still some files are not reformated yet.
Either way is fine, we can reformat in a separate patch.

Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2022, 11:58 PM
kda updated this revision to Diff 412495.Mar 2 2022, 11:19 AM

add interceptors for timer_settime and timer_gettime

kda retitled this revision from [MSAN] add interceptor for timer_create to [MSAN] add interceptor for timer_create, timer_settime, timer_gettime.Mar 2 2022, 11:19 AM
vitalybuka added inline comments.Mar 2 2022, 11:29 AM
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
10222

btw we need COMMON_INTERCEPTOR_READ_RANGE for sevp

10240

COMMON_INTERCEPTOR_READ_RANGE for new_value?
before REAL()?

kda updated this revision to Diff 412595.Mar 2 2022, 8:29 PM

add sanitizer_common test, and UMR checks.

vitalybuka accepted this revision.Mar 2 2022, 11:39 PM
vitalybuka added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
10215

Can you please clang format it?

10219

Sorry, I guess my suggestion does not work here.
sigevent is complex structure, and it contains unions.
It's not required to be initialized fully. We need to check field by field according to the spec if the functions.
Let's just skip it for now.

10239

Sorry, I've read the man page and similar story:

If either field in new_value.it_value is nonzero, then the timer

is armed to initially expire at the specified time.  If both
fields in new_value.it_value are zero, then the timer is
disarmed.

The new_value.it_interval field specifies the new interval for
the timer; if both of its subfields are zero, the timer is
single-shot.

So we don't READ new_value.it_interval if new_value.it_value is ZERO.
I propose just drop it for to avoid introducing struct __sanitizer_itimerval

compiler-rt/test/sanitizer_common/TestCases/Linux/timer.cpp
1–40 ↗(On Diff #412595)
kda updated this revision to Diff 412728.Mar 3 2022, 8:04 AM
kda marked 3 inline comments as done.

remove read checks and format

kda updated this revision to Diff 412729.Mar 3 2022, 8:05 AM
kda marked an inline comment as not done.

remove FileCheck from timer.cpp

kda marked an inline comment as done.Mar 3 2022, 8:06 AM
kda updated this revision to Diff 413169.Mar 4 2022, 5:01 PM

move timer.cpp from Linux to Posix.

vitalybuka accepted this revision.Mar 4 2022, 5:08 PM
vitalybuka added inline comments.Mar 4 2022, 7:40 PM
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
591–593

OSX does not support it

also single define maybe is enough?

compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
512

we need to make this timer_create, #define SANITIZER_INTERCEPT_TIMER_CREATE SI_POSIX
#define SANITIZER_INTERCEPT_TIMER_SETTIME SI_POSIX
#define SANITIZER_INTERCEPT_TIMER_GETTIME SI_POSIX and
TestCases/Posix/ or TestCases/Linux/
and
TEST(MemorySanitizer, timer_create) { ....
consistent

Looks like OSX does not support this functions

we need this for other platforms:
search all "typedef.*__sanitizer_clockid_t"

compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp
2 ↗(On Diff #413169)

// UNSUPPORTED: darwin

kda updated this revision to Diff 413256.Mar 5 2022, 2:34 PM
kda marked an inline comment as done.

going with LINUX

kda added inline comments.Mar 5 2022, 2:35 PM
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
512

I'm leaving this as is. I'm choosing LINUX.

kda updated this revision to Diff 413932.Mar 8 2022, 2:13 PM

move test back to Posix, add typedef to solaris, freebsd, netbsd.

vitalybuka accepted this revision.Mar 8 2022, 3:11 PM
vitalybuka added inline comments.
compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp
1 ↗(On Diff #413932)
kda updated this revision to Diff 413955.Mar 8 2022, 3:17 PM

add UNSUPPORTED: darwin to test

kda marked an inline comment as done.Mar 8 2022, 3:17 PM
vitalybuka accepted this revision.Mar 8 2022, 3:30 PM
This revision was landed with ongoing or failed builds.Mar 8 2022, 4:59 PM
This revision was automatically updated to reflect the committed changes.
phosek added a subscriber: phosek.Mar 8 2022, 7:36 PM

The new test is failing on our builders with what appears to be a leak:

Script:
--
: 'RUN: at line 1';      /opt/s/w/ir/x/w/staging/llvm_build/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=leak  --unwindlib=libunwind -static-libgcc -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta  -funwind-tables --sysroot=/opt/s/w/ir/x/w/cipd/linux  -ldl -O0 -g /opt/s/w/ir/x/w/llvm-llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp -o /opt/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/sanitizer_common/lsan-aarch64-Linux/Posix/Output/timer.cpp.tmp &&  /opt/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/sanitizer_common/lsan-aarch64-Linux/Posix/Output/timer.cpp.tmp
--
Exit Code: 23

Command Output (stderr):
--

=================================================================
==16730==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x2510e0 in malloc ../staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/../staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/lib/lsan/lsan_interceptors.cpp:75:3
    #1 0xffff819feb50 in timer_create (/lib/aarch64-linux-gnu/librt.so.1+0x3b50) (BuildId: 1aba141af4fa49c86298936e700aa7fd865f5518)
    #2 0x253838 in main /opt/s/w/ir/x/w/llvm-llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp:13:3
    #3 0xffff818c26dc in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x206dc) (BuildId: 53f40c1d2f3739ae017dcdcef1a17314786e3709)
    #4 0x2281d4 in _start (/opt/s/w/ir/x/w/staging/llvm_build/runtimes/runtimes-aarch64-unknown-linux-gnu-bins/compiler-rt/test/sanitizer_common/lsan-aarch64-Linux/Posix/Output/timer.cpp.tmp+0x2281d4) (BuildId: a7e4b66ead191fc7)

SUMMARY: LeakSanitizer: 8 byte(s) leaked in 1 allocation(s).

--

Would it be possible to take a look and revert the change if necessary?

This commit also causes our bots fail https://lab.llvm.org/buildbot/#/builders/105/builds/22623

******************** TEST 'SanitizerCommon-lsan-powerpc64le-Linux :: Posix/timer.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';      /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=leak  -m64 -fno-function-sections -funwind-tables  -ldl -O0 -g /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp -o /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/lsan-powerpc64le-Linux/Posix/Output/timer.cpp.tmp &&  /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/lsan-powerpc64le-Linux/Posix/Output/timer.cpp.tmp
--
Exit Code: 23
Command Output (stderr):
--
=================================================================
==151261==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x1005410c in __interceptor_malloc.part.10 /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/lib/lsan/lsan_interceptors.cpp:75:3
    #1 0x7fff81a649a8 in .annobin_timer_create.c timer_create.c
    #2 0x10058c24 in main /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp:13:3
    #3 0x7fff818249f4 in .annobin_libc_start.c libc-start.c
    #4 0x7fff81824be0 in __libc_start_main (/lib64/libc.so.6+0x24be0) (BuildId: 3f510e433e7682fc2680148fe7836ab789f8084b)
SUMMARY: LeakSanitizer: 8 byte(s) leaked in 1 allocation(s).
******************** TEST 'SanitizerCommon-lsan-powerpc64le-Linux :: Posix/timer.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';      /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=leak  -m64 -fno-function-sections -funwind-tables  -ldl -O0 -g /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp -o /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/lsan-powerpc64le-Linux/Posix/Output/timer.cpp.tmp &&  /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/lsan-powerpc64le-Linux/Posix/Output/timer.cpp.tmp
--
Exit Code: 23
Command Output (stderr):
--
=================================================================
==151261==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x1005410c in __interceptor_malloc.part.10 /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/lib/lsan/lsan_interceptors.cpp:75:3
    #1 0x7fff81a649a8 in .annobin_timer_create.c timer_create.c
    #2 0x10058c24 in main /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp:13:3
    #3 0x7fff818249f4 in .annobin_libc_start.c libc-start.c
    #4 0x7fff81824be0 in __libc_start_main (/lib64/libc.so.6+0x24be0) (BuildId: 3f510e433e7682fc2680148fe7836ab789f8084b)
SUMMARY: LeakSanitizer: 8 byte(s) leaked in 1 allocation(s).
lei added a subscriber: lei.Mar 9 2022, 4:37 AM

This also failing on all our bots:
https://lab.llvm.org/buildbot/#/builders/105/builds/22623
https://lab.llvm.org/buildbot/#/builders/100/builds/13530

******************** TEST 'SanitizerCommon-lsan-powerpc64le-Linux :: Posix/timer.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';      /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=leak  -m64 -fno-function-sections -funwind-tables  -ldl -O0 -g /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp -o /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/lsan-powerpc64le-Linux/Posix/Output/timer.cpp.tmp &&  /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/lsan-powerpc64le-Linux/Posix/Output/timer.cpp.tmp
--
Exit Code: 23
Command Output (stderr):
--
=================================================================
==151261==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x1005410c in __interceptor_malloc.part.10 /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/lib/lsan/lsan_interceptors.cpp:75:3
    #1 0x7fff81a649a8 in .annobin_timer_create.c timer_create.c
    #2 0x10058c24 in main /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp:13:3
    #3 0x7fff818249f4 in .annobin_libc_start.c libc-start.c
    #4 0x7fff81824be0 in __libc_start_main (/lib64/libc.so.6+0x24be0) (BuildId: 3f510e433e7682fc2680148fe7836ab789f8084b)
SUMMARY: LeakSanitizer: 8 byte(s) leaked in 1 allocation(s).
--
********************
******************** TEST 'SanitizerCommon-asan-powerpc64le-Linux :: Posix/timer.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';      /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=address  -m64 -fno-function-sections -funwind-tables  -ldl -O0 -g /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp -o /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/asan-powerpc64le-Linux/Posix/Output/timer.cpp.tmp &&  /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/projects/compiler-rt/test/sanitizer_common/asan-powerpc64le-Linux/Posix/Output/timer.cpp.tmp
--
Exit Code: 1
Command Output (stderr):
--
=================================================================
==151451==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x100e7e84 in __interceptor_malloc.part.10 /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/lib/asan/asan_malloc_linux.cpp:69:3
    #1 0x7ffff7b649a8 in .annobin_timer_create.c timer_create.c
    #2 0x1007075c in __interceptor_timer_create.part.331 /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:10222:31
    #3 0x10151d68 in main /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp:13:3
    #4 0x7ffff79249f4 in .annobin_libc_start.c libc-start.c
    #5 0x7ffff7924be0 in __libc_start_main (/lib64/libc.so.6+0x24be0) (BuildId: 3f510e433e7682fc2680148fe7836ab789f8084b)
SUMMARY: AddressSanitizer: 8 byte(s) leaked in 1 allocation(s).
--
********************

The test is failing on s390x as well:

******************** TEST 'SanitizerCommon-asan-s390x-Linux :: Posix/timer.cpp' FAILED ********************
Script:
--
: 'RUN: at line 1';      /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=address  -funwind-tables  -ldl -O0 -g /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/projects/compiler-rt/test/sanitizer_common/asan-s390x-Linux/Posix/Output/timer.cpp.tmp &&  /home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/projects/compiler-rt/test/sanitizer_common/asan-s390x-Linux/Posix/Output/timer.cpp.tmp
--
Exit Code: 1
Command Output (stderr):
--
AddressSanitizer:DEADLYSIGNAL
=================================================================
==3181575==ERROR: AddressSanitizer: SEGV on unknown address 0x0403cb561000 (pc 0x03ff88104914 bp 0x000000000000 sp 0x03fffd7fe028 T0)
==3181575==The signal is caused by a UNKNOWN memory access.
    #0 0x3ff88104914 in timer_settime /build/glibc-8YaO6T/glibc-2.31/rt/../sysdeps/unix/sysv/linux/x86_64/timer_settime.c:41:10
    #1 0x10436a7 in timer_settime /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:10235:32
    #2 0x1110fbb in main /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/timer.cpp:21:3
    #3 0x3ff87ea4409 in __libc_start_main /build/glibc-8YaO6T/glibc-2.31/csu/libc-start.c:308:16
    #4 0x1022173 in _start (/home/uweigand/sandbox/buildbot/clang-s390x-linux/stage1/projects/compiler-rt/test/sanitizer_common/asan-s390x-Linux/Posix/Output/timer.cpp.tmp+0x1022173)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /build/glibc-8YaO6T/glibc-2.31/rt/../sysdeps/unix/sysv/linux/x86_64/timer_settime.c:41:10 in timer_settime
==3181575==ABORTING
--
********************
kda reopened this revision.Mar 9 2022, 11:04 AM
This revision is now accepted and ready to land.Mar 9 2022, 11:04 AM
kda updated this revision to Diff 414164.Mar 9 2022, 11:20 AM

fix memory leak and SEGV in timer.cpp

This revision was landed with ongoing or failed builds.Mar 9 2022, 11:21 AM
This revision was automatically updated to reflect the committed changes.