]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
exec: Don't open code get_close_on_exec
authorEric W. Biederman <ebiederm@xmission.com>
Wed, 9 Dec 2020 21:42:57 +0000 (15:42 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Jun 2024 12:52:46 +0000 (14:52 +0200)
[ Upstream commit 878f12dbb8f514799d126544d59be4d2675caac3 ]

Al Viro pointed out that using the phrase "close_on_exec(fd,
rcu_dereference_raw(current->files->fdt))" instead of wrapping it in
rcu_read_lock(), rcu_read_unlock() is a very questionable
optimization[1].

Once wrapped with rcu_read_lock()/rcu_read_unlock() that phrase
becomes equivalent the helper function get_close_on_exec so
simplify the code and make it more robust by simply using
get_close_on_exec.

[1] https://lkml.kernel.org/r/20201207222214.GA4115853@ZenIV.linux.org.uk
Suggested-by: Al Viro <viro@ftp.linux.org.uk>
Link: https://lkml.kernel.org/r/87k0tqr6zi.fsf_-_@x220.int.ebiederm.org
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/exec.c

index ebe9011955b9b71e27af25f0997c20a3a216d9c3..fb8813cc532d0b3857e21a96a65ed0c183482b60 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1821,8 +1821,7 @@ static int bprm_execve(struct linux_binprm *bprm,
         * inaccessible after exec. Relies on having exclusive access to
         * current->files (due to unshare_files above).
         */
-       if (bprm->fdpath &&
-           close_on_exec(fd, rcu_dereference_raw(current->files->fdt)))
+       if (bprm->fdpath && get_close_on_exec(fd))
                bprm->interp_flags |= BINPRM_FLAGS_PATH_INACCESSIBLE;
 
        /* Set the unchanging part of bprm->cred */