Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Lennart Poettering <lennart@poettering.net>
To: Christian Brauner <brauner@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Jeff Layton <jlayton@kernel.org>,
	Josef Bacik <josef@toxicpanda.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] fcntl: make F_DUPFD_QUERY associative
Date: Tue, 8 Oct 2024 13:41:40 +0200	[thread overview]
Message-ID: <ZwUac8RIaV0E4Jwa@gardel-login> (raw)
In-Reply-To: <20241008-duften-formel-251f967602d5@brauner>

On Di, 08.10.24 13:30, Christian Brauner (brauner@kernel.org) wrote:

> 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
>
> Fixes: c62b758bae6a ("fcntl: add F_DUPFD_QUERY fcntl()")
> Cc: <stable@vger.kernel.org>
> Reported-by: Lennart Poettering <lennart@poettering.net>
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
>  fs/fcntl.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/fs/fcntl.c b/fs/fcntl.c
> index 22dd9dcce7ec..3d89de31066a 100644
> --- a/fs/fcntl.c
> +++ b/fs/fcntl.c
> @@ -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.

Thanks! LGTM!

Reviewed-By: Lennart Poettering <lennart@poettering.net>

Lennart

--
Lennart Poettering, Berlin

  reply	other threads:[~2024-10-08 11:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-08 11:30 [PATCH] fcntl: make F_DUPFD_QUERY associative Christian Brauner
2024-10-08 11:41 ` Lennart Poettering [this message]
2024-10-08 11:42 ` Jeff Layton
2024-10-08 12:25   ` Christian Brauner

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=ZwUac8RIaV0E4Jwa@gardel-login \
    --to=lennart@poettering.net \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox