This is an archive of the discontinued LLVM Phabricator instance.

[RFC] Fix ASan interceptors for __pthread_mutex_lock|unlock
AbandonedPublic

Authored by azat on Jan 1 2023, 12:05 PM.

Details

Reviewers
None
Summary

In glibc 2.36 the behaviour of RTLD_NEXT had been changed after [1]
patch:

#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>

int main()
{
    void *p = dlsym(RTLD_NEXT, "__pthread_mutex_lock");
    printf("__pthread_mutex_lock: %p (via RTLD_NEXT)\n", p);
    return 0;
}

Results:

libc 2.35: __pthread_mutex_lock: 0x7ffff7e27f70 (via RTLD_NEXT)
libc 2.36: __pthread_mutex_lock: (nil) (via RTLD_NEXT)

[1]: https://sourceware.org/git/?p=glibc.git;a=commit;h=efa7936e4c91b1c260d03614bb26858fbb8a0204

The problem is that now RTLD_NEXT does not return symbols that had been
marked as internal (like pthread_mutex_lock/pthread_mutex_unlock).

And so if you will use it in your program and try to build it with ASan
it will lead to NULL dereference.

And this is indeed what happened in case of ClickHouse. And even though
the fix is simple [2], looks like it is still worth to fix it in llvm
too (since it can take sometime to find this).

[2]: https://github.com/ClickHouse/ClickHouse/pull/44811

Diff Detail

Event Timeline

azat created this revision.Jan 1 2023, 12:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 1 2023, 12:05 PM
Herald added a subscriber: Enna1. · View Herald Transcript
azat requested review of this revision.Jan 1 2023, 12:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 1 2023, 12:05 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
azat edited the summary of this revision. (Show Details)Jan 1 2023, 12:06 PM
azat retitled this revision from Fix ASan interceptors for __pthread_mutex_lock|unlock to [RFC] Fix ASan interceptors for __pthread_mutex_lock|unlock.
azat added a comment.Jan 3 2023, 9:00 AM

Can someone elaborate, does my changes breaks CI? Does not looks like this is so.

https://buildkite.com/llvm-project/premerge-checks/builds/128429#01856ef2-9265-4964-99aa-7dd490f8ebcb

llvm-lit: /var/lib/buildkite-agent/builds/llvm-project/llvm/utils/lit/lit/llvm/subst.py:122: note: Did not find llvm-debuginfod in /var/lib/buildkite-agent/builds/llvm-project/build/bin
ERROR git-clang-format returned an non-zero exit code 1

azat added a comment.Jan 4 2023, 1:27 AM

Closed in favor of D140957

azat abandoned this revision.Jan 4 2023, 1:28 AM