From: Christian Brauner <brauner@kernel.org>
To: Steven Price <steven.price@arm.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org, torvalds@linux-foundation.org
Subject: Re: [PATCH v3 10/11] make __set_open_fd() set cloexec state as well
Date: Wed, 9 Oct 2024 16:19:47 +0200 [thread overview]
Message-ID: <20241009-unsachlich-otter-d17f60a780ba@brauner> (raw)
In-Reply-To: <f042b2db-df1f-4dcb-8eab-44583d0da0f6@arm.com>
On Wed, Oct 09, 2024 at 11:50:36AM GMT, Steven Price wrote:
> 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.
Good spot. Al, I folded the below fix so from my end you don't have to
do anything unless you want to nitpick how to fix it. Local variable
looked ugly to me.
Pushed and running through tests now.
diff --git a/fs/file.c b/fs/file.c
index c039e21c1cd1..52654415f17e 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -354,12 +354,17 @@ 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, bool set)
+static inline void __set_open(unsigned int fd, struct fdtable *fdt, bool set)
{
__set_bit(fd, fdt->open_fds);
fd /= BITS_PER_LONG;
if (!~fdt->open_fds[fd])
__set_bit(fd, fdt->full_fds_bits);
+}
+
+static inline void __set_open_fd(unsigned int fd, struct fdtable *fdt, bool set)
+{
+ __set_open(fd, fdt, set);
__set_close_on_exec(fd, fdt, set);
}
next prev parent reply other threads:[~2024-10-09 14:19 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
2024-10-09 14:19 ` Christian Brauner [this message]
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=20241009-unsachlich-otter-d17f60a780ba@brauner \
--to=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=steven.price@arm.com \
--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).