make __set_open_fd() set cloexec state as well

->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>
This commit is contained in:
Al Viro 2024-08-21 19:51:39 -04:00
parent e880d33b49
commit b8ea429d72

View File

@ -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_bit(fd, fdt->open_fds);
__set_close_on_exec(fd, fdt, set);
fd /= BITS_PER_LONG; fd /= BITS_PER_LONG;
if (!~fdt->open_fds[fd]) if (!~fdt->open_fds[fd])
__set_bit(fd, fdt->full_fds_bits); __set_bit(fd, fdt->full_fds_bits);
@ -517,8 +518,7 @@ static int alloc_fd(unsigned start, unsigned end, unsigned flags)
if (start <= files->next_fd) if (start <= files->next_fd)
files->next_fd = fd + 1; files->next_fd = fd + 1;
__set_open_fd(fd, fdt); __set_open_fd(fd, fdt, flags & O_CLOEXEC);
__set_close_on_exec(fd, fdt, flags & O_CLOEXEC);
error = fd; error = fd;
out: out:
@ -1186,8 +1186,7 @@ __releases(&files->file_lock)
goto Ebusy; goto Ebusy;
get_file(file); get_file(file);
rcu_assign_pointer(fdt->fd[fd], file); rcu_assign_pointer(fdt->fd[fd], file);
__set_open_fd(fd, fdt); __set_open_fd(fd, fdt, flags & O_CLOEXEC);
__set_close_on_exec(fd, fdt, flags & O_CLOEXEC);
spin_unlock(&files->file_lock); spin_unlock(&files->file_lock);
if (tofree) if (tofree)