From: Steven Price <steven.price@arm.com>
To: Al Viro <viro@zeniv.linux.org.uk>, linux-fsdevel@vger.kernel.org
Cc: torvalds@linux-foundation.org, brauner@kernel.org
Subject: Re: [PATCH v3 10/11] make __set_open_fd() set cloexec state as well
Date: Wed, 9 Oct 2024 11:50:36 +0100 [thread overview]
Message-ID: <f042b2db-df1f-4dcb-8eab-44583d0da0f6@arm.com> (raw)
In-Reply-To: <20241007174358.396114-10-viro@zeniv.linux.org.uk>
On 07/10/2024 18:43, Al Viro wrote:
> ->close_on_exec[] state is maintained only for opened descriptors;
> as the result, anything that marks a descriptor opened has to
> set its cloexec state explicitly.
>
> As the result, all calls of __set_open_fd() are followed by
> __set_close_on_exec(); might as well fold it into __set_open_fd()
> so that cloexec state is defined as soon as the descriptor is
> marked opened.
>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---
> fs/file.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/fs/file.c b/fs/file.c
> index d8fccd4796a9..b63294ed85ec 100644
> --- a/fs/file.c
> +++ b/fs/file.c
> @@ -248,12 +248,13 @@ static inline void __set_close_on_exec(unsigned int fd, struct fdtable *fdt,
> }
> }
>
> -static inline void __set_open_fd(unsigned int fd, struct fdtable *fdt)
> +static inline void __set_open_fd(unsigned int fd, struct fdtable *fdt, bool set)
> {
> __set_bit(fd, fdt->open_fds);
> fd /= BITS_PER_LONG;
Here fd is being modified...
> if (!~fdt->open_fds[fd])
> __set_bit(fd, fdt->full_fds_bits);
> + __set_close_on_exec(fd, fdt, set);
... which means fd here isn't the same as the passed in value. So this
call to __set_close_on_exec affects a different fd to the expected one.
Steve
> }
>
> static inline void __clear_open_fd(unsigned int fd, struct fdtable *fdt)
> @@ -517,8 +518,7 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags)
> if (start <= files->next_fd)
> files->next_fd = fd + 1;
>
> - __set_open_fd(fd, fdt);
> - __set_close_on_exec(fd, fdt, flags & O_CLOEXEC);
> + __set_open_fd(fd, fdt, flags & O_CLOEXEC);
> error = fd;
>
> out:
> @@ -1186,8 +1186,7 @@ __releases(&files->file_lock)
> goto Ebusy;
> get_file(file);
> rcu_assign_pointer(fdt->fd[fd], file);
> - __set_open_fd(fd, fdt);
> - __set_close_on_exec(fd, fdt, flags & O_CLOEXEC);
> + __set_open_fd(fd, fdt, flags & O_CLOEXEC);
> spin_unlock(&files->file_lock);
>
> if (tofree)
next prev parent reply other threads:[~2024-10-09 10:50 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-22 0:20 [PATCHES] fdtable series v2 Al Viro
2024-08-22 0:22 ` [PATCH 01/12] close_range(): fix the logics in descriptor table trimming Al Viro
2024-08-22 0:22 ` [PATCH 02/12] get rid of ...lookup...fdget_rcu() family Al Viro
2024-08-22 0:22 ` [PATCH 03/12] remove pointless includes of <linux/fdtable.h> Al Viro
2024-08-22 0:22 ` [PATCH 04/12] close_files(): don't bother with xchg() Al Viro
2024-08-22 0:22 ` [PATCH 05/12] move close_range(2) into fs/file.c, fold __close_range() into it Al Viro
2024-08-22 0:22 ` [PATCH 06/12] fs/file.c: remove sanity_check and add likely/unlikely in alloc_fd() Al Viro
2024-08-22 0:22 ` [PATCH 07/12] fs/file.c: conditionally clear full_fds Al Viro
2024-08-22 0:22 ` [PATCH 08/12] fs/file.c: add fast path in find_next_fd() Al Viro
2024-08-22 0:22 ` [PATCH 09/12] alloc_fdtable(): change calling conventions Al Viro
2024-08-22 0:22 ` [PATCH 10/12] file.c: merge __{set,clear}_close_on_exec() Al Viro
2024-08-22 0:22 ` [PATCH 11/12] make __set_open_fd() set cloexec state as well Al Viro
2024-08-22 0:22 ` [PATCH 12/12] expand_files(): simplify calling conventions Al Viro
2024-10-07 17:39 ` [PATCHES] fdtable series v3 Al Viro
2024-10-07 17:43 ` [PATCH v3 01/11] get rid of ...lookup...fdget_rcu() family Al Viro
2024-10-07 17:43 ` [PATCH v3 02/11] remove pointless includes of <linux/fdtable.h> Al Viro
2024-10-07 17:43 ` [PATCH v3 03/11] close_files(): don't bother with xchg() Al Viro
2024-10-07 17:43 ` [PATCH v3 04/11] move close_range(2) into fs/file.c, fold __close_range() into it Al Viro
2024-10-07 17:43 ` [PATCH v3 05/11] fs/file.c: remove sanity_check and add likely/unlikely in alloc_fd() Al Viro
2024-10-07 17:43 ` [PATCH v3 06/11] fs/file.c: conditionally clear full_fds Al Viro
2024-10-07 17:43 ` [PATCH v3 07/11] fs/file.c: add fast path in find_next_fd() Al Viro
2024-10-07 17:43 ` [PATCH v3 08/11] alloc_fdtable(): change calling conventions Al Viro
2024-10-07 17:43 ` [PATCH v3 09/11] file.c: merge __{set,clear}_close_on_exec() Al Viro
2024-10-07 17:43 ` [PATCH v3 10/11] make __set_open_fd() set cloexec state as well Al Viro
2024-10-09 10:50 ` Steven Price [this message]
2024-10-09 14:19 ` Christian Brauner
2024-10-09 15:24 ` Al Viro
2024-10-09 15:36 ` Al Viro
2024-10-10 8:13 ` Christian Brauner
[not found] ` <CGME20241009114254eucas1p2c174307fe53b3d5563795cc8eb92b91d@eucas1p2.samsung.com>
2024-10-09 11:42 ` Marek Szyprowski
2024-10-07 17:43 ` [PATCH v3 11/11] expand_files(): simplify calling conventions Al Viro
2024-10-07 18:12 ` [PATCHES] fdtable series v3 Linus Torvalds
2024-10-08 11:15 ` 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=f042b2db-df1f-4dcb-8eab-44583d0da0f6@arm.com \
--to=steven.price@arm.com \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@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).