Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link libpthread into the spawn_worker trampoline #452

Merged
merged 1 commit into from
May 24, 2024
Merged

Conversation

bwoebi
Copy link
Contributor

@bwoebi bwoebi commented May 24, 2024

It apparently leads to race conditions if libpthread and libc aren't loaded at the same time. In this case a library linking against libpthread is dlopen()'ed dynamically from the trampoline.

It led to interesting libc memory corruptions, like in getaddrinfo:

#2  0x00007fe45328df67 in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7fe4533a05d0 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:196
#3  0x00007fe453296329 in malloc_printerr (ar_ptr=0x7fe4535dc760 <main_arena>, ptr=<optimized out>, str=0x7fe4533a06d8 "double free or corruption (out)", action=3) at malloc.c:4967
#4  _int_free (av=0x7fe4535dc760 <main_arena>, p=<optimized out>, have_lock=0) at malloc.c:3843
#5  0x00007fe453283247 in _IO_new_fclose (fp=0x7fe448001d20) at iofclose.c:84

etc. on older glibc versions.

@bwoebi bwoebi requested a review from a team as a code owner May 24, 2024 17:33
It apparently leads to race conditions if libpthread and libc aren't loaded at the same time.
In this case a library linking against libpthread is dlopen()'ed dynamically from the trampoline.

It led to interesting libc memory corruptions, like in getaddrinfo:

#2  0x00007fe45328df67 in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7fe4533a05d0 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:196
#3  0x00007fe453296329 in malloc_printerr (ar_ptr=0x7fe4535dc760 <main_arena>, ptr=<optimized out>, str=0x7fe4533a06d8 "double free or corruption (out)", action=3) at malloc.c:4967
#4  _int_free (av=0x7fe4535dc760 <main_arena>, p=<optimized out>, have_lock=0) at malloc.c:3843
#5  0x00007fe453283247 in _IO_new_fclose (fp=0x7fe448001d20) at iofclose.c:84

etc. on older glibc versions.

Signed-off-by: Bob Weinand <[email protected]>
@bwoebi bwoebi force-pushed the bob/link_pthread branch from c61afef to 5321f68 Compare May 24, 2024 17:35
@codecov-commenter
Copy link

codecov-commenter commented May 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.76%. Comparing base (f63cff5) to head (5321f68).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #452   +/-   ##
=======================================
  Coverage   67.76%   67.76%           
=======================================
  Files         193      193           
  Lines       24476    24476           
=======================================
  Hits        16585    16585           
  Misses       7891     7891           
Components Coverage Δ
crashtracker 19.34% <ø> (ø)
datadog-alloc 98.76% <ø> (ø)
data-pipeline 51.45% <ø> (ø)
data-pipeline-ffi 0.00% <ø> (ø)
ddcommon 85.24% <ø> (ø)
ddcommon-ffi 74.93% <ø> (ø)
ddtelemetry 56.09% <ø> (ø)
ipc 81.27% <ø> (ø)
profiling 78.09% <ø> (ø)
profiling-ffi 60.05% <ø> (ø)
serverless 0.00% <ø> (ø)
sidecar 36.58% <ø> (ø)
sidecar-ffi 0.00% <ø> (ø)
spawn-worker 54.98% <ø> (ø)
trace-mini-agent 69.12% <ø> (ø)
trace-normalization 97.79% <ø> (ø)
trace-obfuscation 95.74% <ø> (ø)
trace-protobuf 30.76% <ø> (ø)
trace-utils 78.29% <ø> (ø)

@bwoebi bwoebi merged commit 347df21 into main May 24, 2024
26 checks passed
@bwoebi bwoebi deleted the bob/link_pthread branch May 24, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants