[PATCH v3] libio: Fix race in _IO_new_file_init_internal initialization order [BZ #33785]

Florian Weimer fweimer@redhat.com
Wed May 13 05:53:00 GMT 2026


* Shamil Abdulaev:

> _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>
> ---
>
> Notes:
>     Changes since v2: Fix copyright header in libio/tst-file-init-race.c to use 'Copyright The GNU Toolchain Authors.' for DCO submission (suggested by Florian Weimer).

This version looks okay to me, thanks.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

I'm going to push it for you.

Florian



More information about the Libc-alpha mailing list