[{"id":3683898,"web_url":"http://patchwork.ozlabs.org/comment/3683898/","msgid":"<lhuqznyuq37.fsf@oldenburg.str.redhat.com>","list_archive_url":null,"date":"2026-04-29T08:29:32","subject":"Re: [PATCH] libio: Fix race in _IO_new_file_init_internal\n initialization order [BZ #33785]","submitter":{"id":14312,"url":"http://patchwork.ozlabs.org/api/people/14312/","name":"Florian Weimer","email":"fweimer@redhat.com"},"content":"* Shamil Abdulaev:\n\n> _IO_new_file_init_internal linked the new stream into _IO_list_all\n> before setting fp->_fileno to -1.  A concurrent thread that walks\n> _IO_list_all (for example via fflush (NULL)) could observe the stream\n> with an uninitialized _fileno before initialization completed.\n>\n> Set _fileno = -1 before _IO_link_in so the stream is fully\n> initialized when it becomes visible in the global list.\n>\n> This is the residual concurrency defect noted at the end of commit\n> b657f72fa3 (\"libio: Fix deadlock between freopen, fflush (NULL) and\n> fclose (bug 24963)\").\n>\n> Add libio/tst-file-init-race exercising concurrent fopen/fclose and\n> fflush (NULL) to detect regressions.\n>\n> Signed-off-by: Shamil Abdulaev <ashamil435@gmail.com>\n> ---\n>  libio/Makefile             |  3 ++\n>  libio/fileops.c            |  2 +-\n>  libio/tst-file-init-race.c | 66 ++++++++++++++++++++++++++++++++++++++\n>  3 files changed, 70 insertions(+), 1 deletion(-)\n>  create mode 100644 libio/tst-file-init-race.c\n>\n> diff --git a/libio/Makefile b/libio/Makefile\n> index 93656466df..7e448295e3 100644\n> --- a/libio/Makefile\n> +++ b/libio/Makefile\n> @@ -107,6 +107,7 @@ tests = \\\n>    tst-fgetc-after-eof \\\n>    tst-fgetwc \\\n>    tst-fgetws \\\n> +  tst-file-init-race \\\n>    tst-fopenloc2 \\\n>    tst-fputws \\\n>    tst-freopen \\\n> @@ -160,6 +161,8 @@ tests-static += \\\n>  \n>  $(objpfx)tst-popen-fork: $(shared-thread-library)\n>  \n> +$(objpfx)tst-file-init-race: $(shared-thread-library)\n> +\n>  tests-internal = tst-vtables tst-vtables-interposed\n>  \n>  ifeq (yes,$(build-shared))\n> diff --git a/libio/fileops.c b/libio/fileops.c\n> index 8067c0a9cf..9348d7c3a1 100644\n> --- a/libio/fileops.c\n> +++ b/libio/fileops.c\n> @@ -111,8 +111,8 @@ _IO_new_file_init_internal (struct _IO_FILE_plus *fp)\n>    fp->file._offset = _IO_pos_BAD;\n>    fp->file._flags |= CLOSED_FILEBUF_FLAGS;\n>  \n> -  _IO_link_in (fp);\n>    fp->file._fileno = -1;\n> +  _IO_link_in (fp);\n>  }\n\nThanks for investigating this and fixing it.\n\nWould you please apply the parallel change to libio/oldfileops.c?  It\nlooks like it has the same bug.\n\nFlorian","headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=M3IkDXe1;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=M3IkDXe1","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g59Tj4Wf0z1yHv\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 18:30:01 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 93EEF4BA23D3\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 08:29:59 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 569DA4BA2E36\n for <libc-alpha@sourceware.org>; Wed, 29 Apr 2026 08:29:39 +0000 (GMT)","from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-47-BSG3vdarNNmtw7FNYgb0XQ-1; Wed,\n 29 Apr 2026 04:29:37 -0400","from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 1BCD41800609; Wed, 29 Apr 2026 08:29:36 +0000 (UTC)","from fweimer-oldenburg.csb.redhat.com (unknown [10.44.48.4])\n by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 150F81800446; Wed, 29 Apr 2026 08:29:34 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 93EEF4BA23D3","OpenDKIM Filter v2.11.0 sourceware.org 569DA4BA2E36"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 569DA4BA2E36","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 569DA4BA2E36","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777451379; cv=none;\n b=CDhFVaEowBxWb3lG5lFInSiSyvf720MTpOpKpwLeuWGkQQ9VOmlQ9w5HAnFZ8IbndZuUgZt6aBZjz0zONfiORtAyPXIediv9o70kCA9zT0C/1UIhNXTKB3fCcMrV6qnLg/HXS3nAMGt+nPso82Os3DXkF0+IMJZiNq/YSd+hqJw=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777451379; c=relaxed/simple;\n bh=LFP9gU0J7g171WXFWfAnorkNgOXpQBuXhgPPZ0DspP4=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=plvA0AsePTQfBOnxx0iBD0KVYkwaJgU8RWLHQRS82fZjUTzhpmzSg05EI/1PPItm0DWPQlvoMSFcXQoGeekauhfWFMU2c9U15lQ68SAhGkS6zjwyQgMR/iX7Xh7mGxhu6GJFFkKy68ZEvXbUs30D6Zzc1xW0axWmY9eyG1w0nX8=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1777451378;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=NKbxt8OPRcV5mWd/eMVfjtA/TQDsc+maNBctl1XMPQo=;\n b=M3IkDXe1zW/r0lBUzhu2aJXiXVY0ERJ11wStKg4lFEzWdnyc6ibKWXv7tS45aTuJqO6G4Q\n 2H4t/42LiDcbryTndJQRS8xTE62XEx3Lofuq0XxMD0m4GMA5foCqvrw9aWnjhbZg8rnL8s\n jc4nP6gFzwqO6a15yTCTfzIvK5dvLvs=","X-MC-Unique":"BSG3vdarNNmtw7FNYgb0XQ-1","X-Mimecast-MFC-AGG-ID":"BSG3vdarNNmtw7FNYgb0XQ_1777451376","From":"Florian Weimer <fweimer@redhat.com>","To":"Shamil Abdulaev <ashamil435@gmail.com>","Cc":"libc-alpha@sourceware.org","Subject":"Re: [PATCH] libio: Fix race in _IO_new_file_init_internal\n initialization order [BZ #33785]","In-Reply-To":"\n <94933ea56cf84f067c5e7bb7a67eb39f9d9384c0.1777424201.git.ashamil435@gmail.com>\n (Shamil Abdulaev's message of \"Wed, 29 Apr 2026 03:58:12 +0300\")","References":"\n <94933ea56cf84f067c5e7bb7a67eb39f9d9384c0.1777424201.git.ashamil435@gmail.com>","Date":"Wed, 29 Apr 2026 10:29:32 +0200","Message-ID":"<lhuqznyuq37.fsf@oldenburg.str.redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.111","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"t1pEHfF39EL68nOvTKeF-pKeGAHshZXapILcnhcKJ-8_1777451376","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"}},{"id":3683902,"web_url":"http://patchwork.ozlabs.org/comment/3683902/","msgid":"<lhumrymupvk.fsf@oldenburg.str.redhat.com>","list_archive_url":null,"date":"2026-04-29T08:34:07","subject":"Re: [PATCH] libio: Fix race in _IO_new_file_init_internal\n initialization order [BZ #33785]","submitter":{"id":14312,"url":"http://patchwork.ozlabs.org/api/people/14312/","name":"Florian Weimer","email":"fweimer@redhat.com"},"content":"* Shamil Abdulaev:\n\n> +  while (!atomic_load_explicit (&stop, memory_order_acquire))\n> +    {\n> +      FILE *fp = fopen (\"/dev/null\", \"r\");\n> +      if (fp != NULL)\n> +        fclose (fp);\n> +    }\n\nSorry, missed this: Is there any reason not to treat fopen failure as a\ntest failure?  You could perhaps use xfopen/xfclose, but some of us\nprefer not to use error-checking wrappers for functions under test.\n\nThanks,\nFlorian","headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=e8tu6j13;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=e8tu6j13","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g59b03ftXz1yHX\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 18:34:36 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 7FAEE4B9208E\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 08:34:34 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id B28864B99F6D\n for <libc-alpha@sourceware.org>; Wed, 29 Apr 2026 08:34:14 +0000 (GMT)","from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-HNtDpH_7PhmCUl-WjHxgLQ-1; Wed,\n 29 Apr 2026 04:34:12 -0400","from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 9DD851800347; Wed, 29 Apr 2026 08:34:11 +0000 (UTC)","from fweimer-oldenburg.csb.redhat.com (unknown [10.44.48.4])\n by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 96E6D195608E; Wed, 29 Apr 2026 08:34:10 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 7FAEE4B9208E","OpenDKIM Filter v2.11.0 sourceware.org B28864B99F6D"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org B28864B99F6D","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org B28864B99F6D","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777451654; cv=none;\n b=alUhdbh2lc5aybfY5IzO69S/ypPQ01R4iDGb1F0nSSJ2d+lb1ZZExOKfS/H20kyluqr2fNH2g738rI+PSNqgeGzx1QE1fUmMqzZ5OChEbjobEKsoO+BOoYYNrgAm5F1keNCpF4gWiXAUaURgSjyiIu9ufPPvQJb/c/q/TgivYKI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777451654; c=relaxed/simple;\n bh=7SXJ2ZMbdTU1h+wXaWY4N2XFjBA1g2yrSx0n2WJhG5s=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=qUaLdylRjkvIlDLqEe2FzHcB5tn4uvZe2KYf/dPHOSS+P51KJhhbH7qUHbo5jnJmnzHzrw9z54iHCmVQkRIvqJZ+bAwDEqTVEEcfqmU/qSCZK5flIhVlqCWDD1SWc8faX9KadmvcSfkHX4mhnyQPgBadqSTzyo3FaWmZHTCx2kE=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1777451654;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=iAf588VPomYxgp69ybmRyHFyDsXu3XlpwdX4ST0jHDw=;\n b=e8tu6j13V1D4eok1cKW7psUwfbMkDiVNFFB37lUF6o9k0VYDJ9fyg+MwFoPsQ1aNPBIBzR\n u83ItEoRJvjrvZKYW8pTvQAxo9Zbq137BJPCMl6VhKviYJ+b898KfDm2sdZGC6ytA015h7\n 7SzD1BYdnm6mvVZnFuuST/fQYKhN2v0=","X-MC-Unique":"HNtDpH_7PhmCUl-WjHxgLQ-1","X-Mimecast-MFC-AGG-ID":"HNtDpH_7PhmCUl-WjHxgLQ_1777451652","From":"Florian Weimer <fweimer@redhat.com>","To":"Shamil Abdulaev <ashamil435@gmail.com>","Cc":"libc-alpha@sourceware.org","Subject":"Re: [PATCH] libio: Fix race in _IO_new_file_init_internal\n initialization order [BZ #33785]","In-Reply-To":"\n <94933ea56cf84f067c5e7bb7a67eb39f9d9384c0.1777424201.git.ashamil435@gmail.com>\n (Shamil Abdulaev's message of \"Wed, 29 Apr 2026 03:58:12 +0300\")","References":"\n <94933ea56cf84f067c5e7bb7a67eb39f9d9384c0.1777424201.git.ashamil435@gmail.com>","Date":"Wed, 29 Apr 2026 10:34:07 +0200","Message-ID":"<lhumrymupvk.fsf@oldenburg.str.redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.17","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"1rtUNxuHbfsgNYTDOsHLoZ_plRW3hBij0kdhr8vYBLU_1777451652","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"}}]