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

On Tue, 2024-10-08 at 13:30 +0200, Christian Brauner 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.

Consistency is good, so:

    Reviewed-by: Jeff Layton <jlayton@kernel.org>

...that said, we should document that -EBADF means that at least one of
the fd's is bogus, but this API doesn't tell you which ones those are.
To figure that out, I guess you'd need to do something like issue
F_GETFD against each and see which ones return -EBADF?

  parent reply	other threads:[~2024-10-08 11:42 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
2024-10-08 11:42 ` Jeff Layton [this message]
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=bb13f7016a1184196d959c2e2421fde820dcc30a.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=lennart@poettering.net \
    --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;
as well as URLs for NNTP newsgroup(s).