From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>,
Evgeniy Polyakov <zbr@ioremap.net>,
Kees Cook <keescook@chromium.org>,
Zach Levis <zml@linux.vnet.ibm.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/8] exec: introduce exec_binprm() for "depth == 0" code
Date: Mon, 5 Aug 2013 15:41:30 +0200 [thread overview]
Message-ID: <20130805134130.GA15622@redhat.com> (raw)
In-Reply-To: <20130805134113.GA15603@redhat.com>
task_pid_nr_ns() and trace/ptrace code in the middle of the
recursive search_binary_handler() looks confusing and imho
annoying. We only need this code if "depth == 0", lets add
a simple helper which calls search_binary_handler() and does
trace_sched_process_exec() + ptrace_event().
The patch also moves the setting of task->did_exec, we need
to do this only once.
Note: we can kill either task->did_exec or PF_FORKNOEXEC.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Kees Cook <keescook@chromium.org>
---
fs/exec.c | 36 ++++++++++++++++++++++--------------
1 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index 9c73def..a9ae4f2 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1373,7 +1373,6 @@ int search_binary_handler(struct linux_binprm *bprm)
unsigned int depth = bprm->recursion_depth;
int try,retval;
struct linux_binfmt *fmt;
- pid_t old_pid, old_vpid;
/* This allows 4 levels of binfmt rewrites before failing hard. */
if (depth > 5)
@@ -1387,12 +1386,6 @@ int search_binary_handler(struct linux_binprm *bprm)
if (retval)
return retval;
- /* Need to fetch pid before load_binary changes it */
- old_pid = current->pid;
- rcu_read_lock();
- old_vpid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
- rcu_read_unlock();
-
retval = -ENOENT;
for (try=0; try<2; try++) {
read_lock(&binfmt_lock);
@@ -1407,16 +1400,11 @@ int search_binary_handler(struct linux_binprm *bprm)
retval = fn(bprm);
bprm->recursion_depth = depth;
if (retval >= 0) {
- if (depth == 0) {
- trace_sched_process_exec(current, old_pid, bprm);
- ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
- }
put_binfmt(fmt);
allow_write_access(bprm->file);
if (bprm->file)
fput(bprm->file);
bprm->file = NULL;
- current->did_exec = 1;
proc_exec_connector(current);
return retval;
}
@@ -1450,9 +1438,29 @@ int search_binary_handler(struct linux_binprm *bprm)
}
return retval;
}
-
EXPORT_SYMBOL(search_binary_handler);
+static int exec_binprm(struct linux_binprm *bprm)
+{
+ pid_t old_pid, old_vpid;
+ int ret;
+
+ /* Need to fetch pid before load_binary changes it */
+ old_pid = current->pid;
+ rcu_read_lock();
+ old_vpid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
+ rcu_read_unlock();
+
+ ret = search_binary_handler(bprm);
+ if (ret >= 0) {
+ trace_sched_process_exec(current, old_pid, bprm);
+ ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
+ current->did_exec = 1;
+ }
+
+ return ret;
+}
+
/*
* sys_execve() executes a new program.
*/
@@ -1541,7 +1549,7 @@ static int do_execve_common(const char *filename,
if (retval < 0)
goto out;
- retval = search_binary_handler(bprm);
+ retval = exec_binprm(bprm);
if (retval < 0)
goto out;
--
1.5.5.1
next prev parent reply other threads:[~2013-08-05 13:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-05 13:41 [PATCH v2 0/8] exec: cleanup search_binary_handler() Oleg Nesterov
2013-08-05 13:41 ` Oleg Nesterov [this message]
2013-08-05 13:41 ` [PATCH v2 2/8] exec: kill "int depth" in search_binary_handler() Oleg Nesterov
2013-08-05 13:41 ` [PATCH v2 3/8] exec: proc_exec_connector() should be called only once Oleg Nesterov
2013-08-05 13:41 ` [PATCH v2 4/8] exec: move allow_write_access/fput to exec_binprm() Oleg Nesterov
2013-08-05 13:41 ` [PATCH v2 5/8] exec: kill ->load_binary != NULL check in search_binary_handler() Oleg Nesterov
2013-08-05 13:41 ` [PATCH v2 6/8] exec: cleanup the CONFIG_MODULES logic Oleg Nesterov
2013-08-05 13:41 ` [PATCH v2 7/8] exec: don't retry if request_module() fails Oleg Nesterov
2013-08-05 13:41 ` [PATCH v2 8/8] exec: cleanup the error handling in search_binary_handler() Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130805134130.GA15622@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
--cc=zbr@ioremap.net \
--cc=zml@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.