Page MenuHomePhabricator

Bypass potential libc's sysconf wrappers for sysconf(_SC_PAGESIZE) call

Authored by alekseyshl on Mar 17 2017, 11:44 AM.



sysconf(_SC_PAGESIZE) is called very early, during sanitizer init and
any instrumented code (a wrapper/interceptor will likely be instrumented)
calling back to sanitizer before init is done will most surely crash.

Diff Detail


Event Timeline

alekseyshl created this revision.Mar 17 2017, 11:44 AM

So is this to avoid potential future crashes when sysconf gets an interceptor? Can we instead call REAL(sysconf)?

No, it's intended to bypass interceptors defined in other libraries. REAL(sysconf) bypasses our own interceptor and REAL(...) functions are not ready yet at the moment we call sysconf(_SC_PAGESIZE) first time anyway.

If that something that sanitizers need to protect against, then it sounds like we should do a direct syscall instead. Dlsym is also a complicated thing and it can call other possibly-intercepted functions, e.g. malloc or pthread_mutex_lock, IIRC.

Anyway, I'm not opposing this change, I was just curious why we need it.

eugenis edited edge metadata.Mar 17 2017, 1:52 PM

sysconf for the page size is not a syscall on most platforms.
On linux it reads auxv, which could also be done through getauxval() on glibc and bionic, and, it appears, freebsd. But in bionic it is broken.

  • Do not call sysconf() during init at all.

It appears that dlsym() also cannot be used during init stage, this code path calls into instrumented code as well under some sanitizers. PTAL.


18 ↗(On Diff #92357)

Does the test fail w/o this change?
AFAIK CHECK-NOT should go both before and after the CHECK: Passed line.

alekseyshl updated this revision to Diff 92380.Mar 20 2017, 1:58 PM
  • Add forgotten CHECK-NOT.
alekseyshl marked an inline comment as done.Mar 20 2017, 1:58 PM
This revision was automatically updated to reflect the committed changes.