From: "Eric W. Biederman"
mainline inclusion
from mainline-5.11-rc1
commit 878f12dbb8f514799d126544d59be4d2675caac3
category: bugfix
issue: #I3ZXZF
CVE: NA
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
-------------------------------------------------
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
Link: https://lkml.kernel.org/r/87k0tqr6zi.fsf_-_@x220.int.ebiederm.org
Signed-off-by: Eric W. Biederman
Signed-off-by: Baokun Li
Reviewed-by: Zhang Yi
Signed-off-by: Chen Jun
Signed-off-by: Yu Changchun
---
fs/exec.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index c7a4ef8df305..7c9d6a8c2b45 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1812,8 +1812,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 */
--
2.22.0