Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1737539

[PATCH 4/5] exec: binfmt_misc: fix race between load_misc_binary() and kill_node()

From Oleg Nesterov <oleg@redhat.com>
Newsgroups linux.kernel
Subject [PATCH 4/5] exec: binfmt_misc: fix race between load_misc_binary() and kill_node()
Date 2017-09-22 16:40 +0200
Message-ID <usxhx-7bZ-31@gated-at.bofh.it> (permalink)
References <usxhw-7bZ-15@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


load_misc_binary() makes a local copy of fmt->interpreter under entries_lock
to avoid the race with kill_node() but this is not enough; the whole Node
can be freed after we drop entries_lock, not only the ->interpreter string.

Add dget/dput(fmt->dentry) to ensure bm_evict_inode() can't destroy/free
this Node.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 fs/binfmt_misc.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 45809c6..e59d006 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -138,20 +138,23 @@ static int load_misc_binary(struct linux_binprm *bprm)
 
 	retval = -ENOEXEC;
 	if (!enabled)
-		goto ret;
+		return retval;
 
 	/* to keep locking time low, we copy the interpreter string */
 	read_lock(&entries_lock);
 	fmt = check_file(bprm);
-	if (fmt)
+	if (fmt) {
+		dget(fmt->dentry);
 		strlcpy(iname, fmt->interpreter, BINPRM_BUF_SIZE);
+	}
 	read_unlock(&entries_lock);
 	if (!fmt)
-		goto ret;
+		return retval;
 
 	/* Need to be able to load the file after exec */
+	retval = -ENOENT;
 	if (bprm->interp_flags & BINPRM_FLAGS_PATH_INACCESSIBLE)
-		return -ENOENT;
+		goto ret;
 
 	if (!(fmt->flags & MISC_FMT_PRESERVE_ARGV0)) {
 		retval = remove_arg_zero(bprm);
@@ -235,6 +238,7 @@ static int load_misc_binary(struct linux_binprm *bprm)
 		goto error;
 
 ret:
+	dput(fmt->dentry);
 	return retval;
 error:
 	if (fd_binary > 0)
-- 
2.5.0

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/5] exec: binfmt_misc: fix use-after-free, kill  iname[BINPRM_BUF_SIZE] Oleg Nesterov <oleg@redhat.com> - 2017-09-22 16:40 +0200
  [PATCH 1/5] exec: binfmt_misc: don't nullify Node->dentry in  kill_node() Oleg Nesterov <oleg@redhat.com> - 2017-09-22 16:40 +0200
  [PATCH 4/5] exec: binfmt_misc: fix race between load_misc_binary()  and kill_node() Oleg Nesterov <oleg@redhat.com> - 2017-09-22 16:40 +0200
  Re: [PATCH 0/5] exec: binfmt_misc: fix use-after-free, kill iname[BINPRM_BUF_SIZE] Kees Cook <keescook@chromium.org> - 2017-09-22 17:30 +0200

csiph-web