0006-libsanitizer-enable-swapcontext-interceptor-on-uClibc.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. libsanitizer: enable swapcontext/makecontext interceptor on uClibc-ng
  2. The swapcontext/makecontext ASan interceptor is gated on
  3. ASAN_INTERCEPT_SWAPCONTEXT, which until now was only enabled for
  4. SANITIZER_GLIBC || SANITIZER_SOLARIS. Since 0001-libsanitizer-do-not-
  5. treat-uClibc-ng-as-glibc.patch forces SANITIZER_GLIBC=0 on uClibc-ng,
  6. the interceptor is silently dropped on our toolchain. Two consequences:
  7. 1. asan_interceptors.cpp:399 (INTERCEPTOR(swapcontext, ...)) is not
  8. compiled, so the runtime never emits the documented
  9. "WARNING: ASan doesn't fully support makecontext/swapcontext
  10. functions and may produce false positives in some cases!"
  11. and the GCC testsuite case c-c++-common/asan/swapcontext-test-1.c
  12. hits "output pattern test FAIL" for the first dg-output regex.
  13. 2. ClearShadowMemoryForContextStack() is never called around a
  14. ucontext switch, so stack bytes that were poisoned by ASan in
  15. one context stay poisoned after we resume on another stack.
  16. This is a real runtime bug, not just a missing print:
  17. coroutine code that touches a previously-poisoned region will
  18. trip false-positive use-after-scope / stack-use-after-return
  19. reports.
  20. The gated code in asan_interceptors.cpp:339-428 and asan_linux.cpp:
  21. 201-226 only uses the POSIX surface (stack_t::ss_sp, ss_size, ss_flags,
  22. swapcontext(), makecontext()) plus the libsanitizer-internal INTERCEPTOR
  23. machinery, none of which is glibc-specific. uClibc-ng provides all of
  24. these (ss_flags has existed in uClibc since the initial ucontext port,
  25. swapcontext()/makecontext() are now correct after the 0004-arm-ucontext-
  26. fix-vfp-save-restore-area.patch in patches/uClibc-ng/), so it is safe
  27. to flip the gate on for SANITIZER_UCLIBC as well.
  28. This is the natural follow-up to 0001 once swapcontext on uClibc-ng
  29. actually works.
  30. Signed-off-by: Ramin Moussavi <ramin.moussavi@yacoub.de>
  31. ---
  32. --- a/libsanitizer/asan/asan_interceptors.h
  33. +++ b/libsanitizer/asan/asan_interceptors.h
  34. @@ -50,7 +50,11 @@
  35. # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0
  36. #endif
  37. -#if SANITIZER_GLIBC || SANITIZER_SOLARIS
  38. +/* uClibc-ng provides swapcontext()/makecontext() and the standard
  39. + stack_t layout, and our 0004-arm-ucontext-fix-vfp-save-restore-area
  40. + patch in patches/uClibc-ng/ makes context switching actually work,
  41. + so enable the swapcontext interceptor on uClibc as well. */
  42. +#if SANITIZER_GLIBC || SANITIZER_SOLARIS || SANITIZER_UCLIBC
  43. # define ASAN_INTERCEPT_SWAPCONTEXT 1
  44. #else
  45. # define ASAN_INTERCEPT_SWAPCONTEXT 0