Skip to content

Commit ec052fa

Browse files
mjguzikbrauner
authored andcommitted
fs: sort out a stale comment about races between fd alloc and dup2
It claims the issue is only relevant for shared descriptor tables which is of no concern for POSIX (but then is POSIX of concern to anyone today?), which I presume predates standarized threading. The comment also mentions the following systems: - OpenBSD installing a larval file -- they moved away from it, file is installed late and EBUSY is returned on conflict - FreeBSD returning EBADF -- reworked to install the file early like OpenBSD used to do - NetBSD "deadlocks in amusing ways" -- their solution looks Solaris-inspired (not a compliment) and I would not be particularly surprised if it indeed deadlocked, in amusing ways or otherwise I don't believe mentioning any of these adds anything and the statement about the issue not being POSIX-relevant is outdated. dup2 description in POSIX still does not mention the problem. Just shorten the comment and be done with it. Signed-off-by: Mateusz Guzik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 175c6a2 commit ec052fa

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

fs/file.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,17 +1230,9 @@ __releases(&files->file_lock)
12301230

12311231
/*
12321232
* We need to detect attempts to do dup2() over allocated but still
1233-
* not finished descriptor. NB: OpenBSD avoids that at the price of
1234-
* extra work in their equivalent of fget() - they insert struct
1235-
* file immediately after grabbing descriptor, mark it larval if
1236-
* more work (e.g. actual opening) is needed and make sure that
1237-
* fget() treats larval files as absent. Potentially interesting,
1238-
* but while extra work in fget() is trivial, locking implications
1239-
* and amount of surgery on open()-related paths in VFS are not.
1240-
* FreeBSD fails with -EBADF in the same situation, NetBSD "solution"
1241-
* deadlocks in rather amusing ways, AFAICS. All of that is out of
1242-
* scope of POSIX or SUS, since neither considers shared descriptor
1243-
* tables and this condition does not arise without those.
1233+
* not finished descriptor.
1234+
*
1235+
* POSIX is silent on the issue, we return -EBUSY.
12441236
*/
12451237
fdt = files_fdtable(files);
12461238
fd = array_index_nospec(fd, fdt->max_fds);

0 commit comments

Comments
 (0)