]> git.ipfire.org Git - thirdparty/glibc.git/commit
libio: Fix deadlock between freopen, fflush (NULL) and fclose (bug 24963)
authorFlorian Weimer <fweimer@redhat.com>
Mon, 23 Feb 2026 13:19:38 +0000 (14:19 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Mon, 23 Feb 2026 13:19:38 +0000 (14:19 +0100)
commitb657f72fa34192b9afdd4cfab7fcf8e039d8888c
tree214b1c21b559023fc7e0f20465fa560b9f06c352
parent9af18a94e051fce513972254bf97c12ae563841e
libio: Fix deadlock between freopen, fflush (NULL) and fclose (bug 24963)

The canonical lock ordering for stream list processing is
locking list_all_lock first, then individual streams as needed.
The fclose implementation reversed that, and the freopen
implementation performed list operations under the reverse order,
too.

Unlinking in fclose was already unconditional, and the early unlinking
looks unnecessary: _IO_file_close_it would call it even for
!_IO_IS_FILEBUF streams.

There is still a remaining concurrency defect because
_IO_new_file_init_internal links in the stream before it is
fully initialized, and it is not locked at this point.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
libio/fileops.c
libio/freopen.c
libio/freopen64.c
libio/genops.c
libio/iofclose.c
libio/libio.h
libio/libioP.h
sysdeps/pthread/Makefile
sysdeps/pthread/tst-bug24963.c [new file with mode: 0644]