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

Florian Weimer fweimer@redhat.com
Wed May 6 19:20:47 GMT 2026


* Florian Weimer:

> * 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>
>> ---
>> Changes since v1:
>>  - Apply the same _fileno/_IO_link_in reordering to libio/oldfileops.c
>>    (suggested by Florian Weimer).
>>  - tst-file-init-race: treat fopen/fclose failures as test failures via
>>    FAIL_EXIT1 instead of silently ignoring them (suggested by Florian
>>    Weimer).
>
> This version looks okay to me.
>
> Reviewed-by: Florian Weimer <fweimer@redhat.com>
>
> I'll do a final round of testing and will push it for you afterwards.

Sorry, something else has come up.  You submitted this under DCO:

> Signed-off-by: Shamil Abdulaev <ashamil435@gmail.com>

And yet the new file you added says:

> +   Copyright (C) 2026 Free Software Foundation, Inc.

For DCO submissions, it should be

+   Copyright The GNU Toolchain Authors.

Would you please submit a v3 with this fixed?  I don't feel quite
comfortable editing copyright notices before pushing, but I suppose I
could do it for you if explicitly told. 8-)

Thanks,
Florian



More information about the Libc-alpha mailing list