Page MenuHomePhabricator

[ASan] Add interceptor for printf_chk
ClosedPublic

Authored by denis13 on Dec 7 2017, 5:20 AM.

Details

Summary

Could be a situation when a specific DSO was built with FORTIFY_SOURCE option. In case asan-ed binary link against that DSO, libasan can't handle the possible memory error because does not have interceptors for spinrtf_chk, snprintf_chk, vprintf_chk, vsnprintf_chk, __fprintf_chk functions.

Diff Detail

Event Timeline

denis13 created this revision.Dec 7 2017, 5:20 AM
alekseyshl added inline comments.Dec 7 2017, 12:59 PM
lib/sanitizer_common/sanitizer_platform_interceptors.h
167

Why #ifndef here?

168

Shouldn't it be (SANITIZER_INTERCEPT_PRINTF && SI_LINUX_NOT_ANDROID)?

vitalybuka added inline comments.Dec 7 2017, 2:33 PM
test/asan/TestCases/Linux/printf-fortify-2.c
13

Maybe just:

char write_buffer[1];
snprintf(write_buffer, 2, "%s_%s", "one", "two");

denis13 added inline comments.Dec 8 2017, 3:06 AM
lib/sanitizer_common/sanitizer_platform_interceptors.h
168

Thanks, I've fixed that.

test/asan/TestCases/Linux/printf-fortify-2.c
13

IMHO, in this test case the DSO is building without ASan's instrumentation, therefore the memory on the stack could not be "poisoned" with "redzones", in this case ASan could not handle the error. Sorry if I miss something, please correct me if I'm wrong. Thanks.

denis13 updated this revision to Diff 126111.Dec 8 2017, 3:08 AM

Fixed the "define" issue

vitalybuka accepted this revision.Dec 8 2017, 3:55 PM
This revision is now accepted and ready to land.Dec 8 2017, 3:55 PM
Closed by commit rCRT320990: [asan] Add interceptor for printf_chk (authored by chefmax, committed by ). · Explain WhyDec 18 2017, 7:32 AM
This revision was automatically updated to reflect the committed changes.
Herald added subscribers: Restricted Project, llvm-commits. · View Herald TranscriptDec 18 2017, 7:32 AM

Hi, I've committed this on behalf of Denis. @denis13 Will ping you if some buildbots complain about this change.