From: Al Viro <viro@zeniv.linux.org.uk>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH (repost)] umh: fix refcount underflow in fork_usermode_blob().
Date: Sun, 29 Mar 2020 04:17:02 +0100 [thread overview]
Message-ID: <20200329031702.GB23230@ZenIV.linux.org.uk> (raw)
In-Reply-To: <9b846b1f-a231-4f09-8c37-6bfb0d1e7b05@i-love.sakura.ne.jp>
On Fri, Mar 27, 2020 at 09:51:34AM +0900, Tetsuo Handa wrote:
> diff --git a/fs/exec.c b/fs/exec.c
> index db17be51b112..ded3fa368dc7 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -1761,11 +1761,17 @@ static int __do_execve_file(int fd, struct filename *filename,
> check_unsafe_exec(bprm);
> current->in_execve = 1;
>
> - if (!file)
> + if (!file) {
> file = do_open_execat(fd, filename, flags);
> - retval = PTR_ERR(file);
> - if (IS_ERR(file))
> - goto out_unmark;
> + retval = PTR_ERR(file);
> + if (IS_ERR(file))
> + goto out_unmark;
> + } else {
> + retval = deny_write_access(file);
> + if (retval)
> + goto out_unmark;
> + get_file(file);
> + }
I still don't like it. The bug is real, but... *yeccchhhh*
First of all, this assignment to "file" is misguiding -
assignment to bprm->file would've been a lot easier to
follow. Furthermore, the damn thing already has much
too confusing cleanup logics.
Why is
out:
if (bprm->mm) {
acct_arg_size(bprm, 0);
mmput(bprm->mm);
}
done on failure exit in this function and not in free_bprm(),
while dropping bprm->file is in free_bprm()?
Note that flush_old_exec() will zero bprm->mm (after it transfers
the damn thing into current->mm), so we are fine here. And getting
rid of that thing in __do_execve_file() simplifies the logics
in there, especially if you take everything from this
if (!file)
up to
retval = exec_binprm(bprm);
into a new function. All those goto out_unmark/goto out turn
into plain returns. And in __do_execve_file() we are left with
....
current->in_execve = 1;
retval = this_new_helper(whatever it needs passed to it);
current->fs->in_exec = 0;
current->in_execve = 0;
if (!retval) {
/* execve succeeded */
rseq_execve(current);
acct_update_integrals(current);
task_numa_free(current, false);
}
out_free:
free_bprm(bprm);
kfree(pathbuf);
out_files:
if (displaced)
put_files_struct(displaced);
out_ret:
if (filename)
putname(filename);
return retval;
which is a lot easier to follow. Especially if we lift the logics
for freeing pathbuf into free_bprm() as well (will need a flag there,
for "does ->filename need to be freed?"). And I really wonder if
sched_exec() is called in the right place - what's special about the
point after opening the binary to be and setting bprm->file to what
we got?
prev parent reply other threads:[~2020-03-29 3:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-12 13:43 [PATCH] umh: fix refcount underflow in fork_usermode_blob() Tetsuo Handa
2020-03-12 14:38 ` Al Viro
2020-03-13 9:46 ` Tetsuo Handa
2020-03-20 10:31 ` Tetsuo Handa
2020-03-27 0:51 ` [PATCH (repost)] " Tetsuo Handa
2020-03-29 0:55 ` Andrew Morton
2020-03-29 4:28 ` Tetsuo Handa
2020-03-29 3:17 ` Al Viro [this message]
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=20200329031702.GB23230@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=akpm@linux-foundation.org \
--cc=ast@kernel.org \
--cc=davem@davemloft.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).