]> sourceware.org Git - glibc.git/commit
libio: Fix a deadlock after fork in popen
authorArjun Shankar <arjun@redhat.com>
Fri, 18 Oct 2024 14:03:25 +0000 (16:03 +0200)
committerArjun Shankar <arjun@redhat.com>
Wed, 23 Oct 2024 11:40:16 +0000 (13:40 +0200)
commit9f0d2c0ee6c728643fcf9a4879e9f20f5e45ce5f
tree86cff8d63944f5a0e573b1d0a72d3a669c4f124d
parent81439a116cf48583127ddf1f09809440aa40969a
libio: Fix a deadlock after fork in popen

popen modifies its file handler book-keeping under a lock that wasn't
being taken during fork.  This meant that a concurrent popen and fork
could end up copying the lock in a "locked" state into the fork child,
where subsequently calling popen would lead to a deadlock due to the
already (spuriously) held lock.

This commit fixes the deadlock by appropriately taking the lock before
fork, and releasing/resetting it in the parent/child after the fork.

A new test for concurrent popen and fork is also added.  It consistently
hangs (and therefore fails via timeout) without the fix applied.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
libio/Makefile
libio/iopopen.c
libio/libioP.h
libio/tst-popen-fork.c [new file with mode: 0644]
posix/fork.c
This page took 0.033707 seconds and 5 git commands to generate.