This is an archive of the discontinued LLVM Phabricator instance.

[ASAN] fix startup crash in dlsym for long paths since glibc 2.27
ClosedPublic

Authored by Lekensteyn on Jun 10 2018, 1:40 PM.

Details

Summary

Error messages for dlsym used to be stored on the stack, but since
commit 2449ae7b ("ld.so: Introduce struct dl_exception") in glibc 2.27
these are now stored on the heap (and thus use the dlsym alloc pool).

Messages look like "undefined symbol: __isoc99_printf\0/path/to/a.out".
With many missing library functions and long object paths, the pool is
quickly exhausted. Implement a simple mechanism to return freed memory
to the pool (clear it in case it is used for calloc).

Fixes https://github.com/google/sanitizers/issues/957

Diff Detail

Repository
rL LLVM

Event Timeline

Lekensteyn created this revision.Jun 10 2018, 1:40 PM
Herald added subscribers: Restricted Project, llvm-commits, kubamracek. · View Herald TranscriptJun 10 2018, 1:40 PM
vitalybuka accepted this revision.Jun 13 2018, 4:49 PM
This revision is now accepted and ready to land.Jun 13 2018, 4:49 PM
vitalybuka added inline comments.Jun 13 2018, 4:52 PM
lib/asan/asan_malloc_linux.cc
58 ↗(On Diff #150661)

Alternative, more general solution is to have some bitmap which tells if byte is allocated. And then trim the tail on each free.

This revision was automatically updated to reflect the committed changes.
Lekensteyn added inline comments.Jun 14 2018, 3:48 AM
lib/asan/asan_malloc_linux.cc
58 ↗(On Diff #150661)

A bitmap before (or after) an allocation increases memory consumption (by a tiny amount). It would only be beneficial in the following pattern:

p = malloc(a); q = malloc(b);
free(q); free(p); // currently does not release "p"
// or:
//free(p); free(q); // currently does not release "p" and "q"

however as I have not observed these patterns and its implementation is more complex, I decided to take the current, simpler approach.

delcypher added inline comments.Jun 14 2018, 4:15 AM
compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
53

Typo? s/dlsym longer/dlsym no longer/

54

Typo. s/use/uses/

Lekensteyn marked 2 inline comments as done.Jun 14 2018, 8:20 AM

Thanks for the reviews, I fixed both typos in r334719 and disabled the test due to a lit problem on Windows. I'll be looking at supporting glob patterns for commands in general or just the "cd" builtin.

Failing test: http://lab.llvm.org:8011/builders/sanitizer-windows/builds/30093

******************** TEST 'AddressSanitizer-i386-windows :: TestCases/long-object-path.cc' FAILED ********************
Exception during script execution:
Traceback (most recent call last):
  File "C:/b/slave/sanitizer-windows/llvm\utils\lit\lit\run.py", line 202, in _execute_test_impl
    result = test.config.test_format.execute(test, lit_config)
  File "C:/b/slave/sanitizer-windows/llvm\utils\lit\lit\formats\shtest.py", line 25, in execute
    self.execute_external)
  File "C:/b/slave/sanitizer-windows/llvm\utils\lit\lit\TestRunner.py", line 1576, in executeShTest
    res = _runShTest(test, litConfig, useExternalSh, script, tmpBase)
  File "C:/b/slave/sanitizer-windows/llvm\utils\lit\lit\TestRunner.py", line 1524, in _runShTest
    res = executeScriptInternal(test, litConfig, tmpBase, script, execdir)
  File "C:/b/slave/sanitizer-windows/llvm\utils\lit\lit\TestRunner.py", line 1019, in executeScriptInternal
    exitCode, timeoutInfo = executeShCmd(cmd, shenv, results, timeout=litConfig.maxIndividualTestTime)
  File "C:/b/slave/sanitizer-windows/llvm\utils\lit\lit\TestRunner.py", line 163, in executeShCmd
    finalExitCode = _executeShCmd(cmd, shenv, results, timeoutHelper)
  File "C:/b/slave/sanitizer-windows/llvm\utils\lit\lit\TestRunner.py", line 738, in _executeShCmd
    res = _executeShCmd(cmd.rhs, shenv, results, timeoutHelper)
  File "C:/b/slave/sanitizer-windows/llvm\utils\lit\lit\TestRunner.py", line 721, in _executeShCmd
    return _executeShCmd(cmd.rhs, shenv, results, timeoutHelper)
  File "C:/b/slave/sanitizer-windows/llvm\utils\lit\lit\TestRunner.py", line 852, in _executeShCmd
    is_builtin_cmd = args[0] in builtin_commands;
TypeError: unhashable instance

Reproducible on Linux with the environment variable LIT_USE_INTERNAL_SHELL=1 set.