]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
make __set_open_fd() set cloexec state as well
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 21 Aug 2024 23:51:39 +0000 (19:51 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 9 Oct 2024 15:28:06 +0000 (11:28 -0400)
->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.

[braino fix folded]

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/file.c

index d8fccd4796a95a3c752d6f806aac11dd8560b92d..d468a9b6ef4d07658f6e79b4c2b9ee790bb4ef7b 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -248,9 +248,10 @@ 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);
+       __set_close_on_exec(fd, fdt, set);
        fd /= BITS_PER_LONG;
        if (!~fdt->open_fds[fd])
                __set_bit(fd, fdt->full_fds_bits);
@@ -517,8 +518,7 @@ repeat:
        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)