]> git.ipfire.org Git - thirdparty/glibc.git/commit
libio: Fix race in _IO_new_file_init_internal initialization order [BZ #33785]
authorShamil Abdulaev <ashamil435@gmail.com>
Wed, 13 May 2026 05:52:40 +0000 (07:52 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 13 May 2026 05:52:40 +0000 (07:52 +0200)
commit389ecf52bc75e6378b2881415b03f3c00a3ef891
treeb08e630e6072d48ff3408a849cd53f672898e262
parent1cc165baed20b6589ef2f2c8c0e0415139bbb151
libio: Fix race in _IO_new_file_init_internal initialization order [BZ #33785]

_IO_new_file_init_internal linked the new stream into _IO_list_all
before setting fp->_fileno to -1.  A concurrent thread that walks
_IO_list_all (for example via fflush (NULL)) could observe the stream
with an uninitialized _fileno before initialization completed.

Set _fileno = -1 before _IO_link_in so the stream is fully
initialized when it becomes visible in the global list.

This is the residual concurrency defect noted at the end of commit
b657f72fa3 ("libio: Fix deadlock between freopen, fflush (NULL) and
fclose (bug 24963)").

Add libio/tst-file-init-race exercising concurrent fopen/fclose and
fflush (NULL) to detect regressions.

Signed-off-by: Shamil Abdulaev <ashamil435@gmail.com>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
libio/Makefile
libio/fileops.c
libio/oldfileops.c
libio/tst-file-init-race.c [new file with mode: 0644]