From: Al Viro <viro@zeniv.linux.org.uk>
To: Alexander Monakov <amonakov@ispras.ru>
Cc: linux-fsdevel@vger.kernel.org,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
linux-kernel@vger.kernel.org
Subject: Re: ETXTBSY window in __fput
Date: Tue, 26 Aug 2025 23:00:33 +0100 [thread overview]
Message-ID: <20250826220033.GW39973@ZenIV> (raw)
In-Reply-To: <6e60aa72-94ef-9de2-a54c-ffd91fcc4711@ispras.ru>
On Wed, Aug 27, 2025 at 12:05:38AM +0300, Alexander Monakov wrote:
> Dear fs hackers,
>
> I suspect there's an unfortunate race window in __fput where file locks are
> dropped (locks_remove_file) prior to decreasing writer refcount
> (put_file_access). If I'm not mistaken, this window is observable and it
> breaks a solution to ETXTBSY problem on exec'ing a just-written file, explained
> in more detail below.
>
> The program demonstrating the problem is attached (a slightly modified version
> of the demo given by Russ Cox on the Go issue tracker, see URL in first line).
> It makes 20 threads, each executing an infinite loop doing the following:
>
> 1) open an fd for writing with O_CLOEXEC
> 2) write executable code into it
> 3) close it
> 4) fork
> 5) in the child, attempt to execve the just-written file
>
> If you compile it with -DNOWAIT, you'll see that execve often fails with
> ETXTBSY. This happens if another thread forked while we were holding an open fd
> between steps 1 and 3, our fd "leaked" in that child, and then we reached our
> step 5 before that child did execve (at which point the leaked fd would be
> closed thanks to O_CLOEXEC).
Egads... Let me get it straight - you have a bunch of threads sharing descriptor
tables and some of them are forking (or cloning without shared descriptor tables)
while that is going on?
Frankly, in such situation I would spawn a thread for that, did unshare(CLONE_FILES)
in it, replaced the binary and buggered off, with parent waiting for it to complete.
next prev parent reply other threads:[~2025-08-26 22:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 21:05 ETXTBSY window in __fput Alexander Monakov
2025-08-26 22:00 ` Al Viro [this message]
2025-08-27 7:22 ` Alexander Monakov
2025-08-27 11:52 ` Theodore Ts'o
2025-08-27 13:05 ` Alexander Monakov
2025-08-31 19:22 ` David Laight
2025-09-01 8:44 ` Jan Kara
2025-08-27 13:16 ` Aleksa Sarai
2025-08-27 14:29 ` Alexander Monakov
2025-08-29 7:21 ` Alexander Monakov
2025-08-29 9:47 ` Christian Brauner
2025-08-29 10:17 ` Alexander Monakov
2025-08-29 11:07 ` Christian Brauner
2025-08-29 11:45 ` Alexander Monakov
2025-08-29 14:02 ` Jan Kara
2025-09-01 17:53 ` Alexander Monakov
2025-09-02 10:36 ` Jan Kara
2025-08-29 18:32 ` Colin Walters
2025-09-01 18:39 ` Mateusz Guzik
2025-09-01 19:57 ` Colin Walters
2025-09-01 20:22 ` Mateusz Guzik
2025-09-02 8:33 ` Christian Brauner
2025-09-02 8:44 ` Mateusz Guzik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250826220033.GW39973@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=amonakov@ispras.ru \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.