]> git.ipfire.org Git - thirdparty/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, 30 Apr 2025 10:57:55 +0000 (12:57 +0200)
commit33b33e9dd0ff26158b1b83cc4347a39c073e490e
tree1a202721cf9e7238daa65ef1c16c46ef0dac5b3c
parent8d3dd23e3de8b4c6e4b94f8bbfab971c3b8a55be
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>
(cherry picked from commit 9f0d2c0ee6c728643fcf9a4879e9f20f5e45ce5f)
libio/Makefile
libio/iopopen.c
libio/libioP.h
libio/tst-popen-fork.c [new file with mode: 0644]
posix/fork.c