Skip to content
Snippets Groups Projects
Commit a4fc6966 authored by Christian Brauner's avatar Christian Brauner Committed by Greg Kroah-Hartman
Browse files

fcntl: make F_DUPFD_QUERY associative

commit 2714b0d1f36999dbd99a3474a24e7301acbd74f1 upstream.

Currently when passing a closed file descriptor to
fcntl(fd, F_DUPFD_QUERY, fd_dup) the order matters:

    fd = open("/dev/null");
    fd_dup = dup(fd);

When we now close one of the file descriptors we get:

    (1) fcntl(fd, fd_dup) // -EBADF
    (2) fcntl(fd_dup, fd) // 0 aka not equal

depending on which file descriptor is passed first. That's not a huge
deal but it gives the api I slightly weird feel. Make it so that the
order doesn't matter by requiring that both file descriptors are valid:

(1') fcntl(fd, fd_dup) // -EBADF
(2') fcntl(fd_dup, fd) // -EBADF

Link: https://lore.kernel.org/r/20241008-duften-formel-251f967602d5@brauner


Fixes: c62b758b ("fcntl: add F_DUPFD_QUERY fcntl()")
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Reviewed-By: default avatarLennart Poettering <lennart@poettering.net>
Cc: stable@vger.kernel.org
Reported-by: default avatarLennart Poettering <lennart@poettering.net>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2bd8303a
No related branches found
No related tags found
1 merge request!176🤖 Sync Bot: Update v6.12-ktn to Latest Stable Kernel (v6.12.4)
......@@ -397,6 +397,9 @@ static long f_dupfd_query(int fd, struct file *filp)
{
CLASS(fd_raw, f)(fd);
if (fd_empty(f))
return -EBADF;
/*
* We can do the 'fdput()' immediately, as the only thing that
* matters is the pointer value which isn't changed by the fdput.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment