From: Eric Biggers <ebiggers3@gmail.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, Dmitry Vyukov <dvyukov@google.com>,
Ingo Molnar <mingo@kernel.org>,
Konstantin Khlebnikov <koct9i@gmail.com>,
Michal Hocko <mhocko@suse.com>,
Peter Zijlstra <peterz@infradead.org>,
Vlastimil Babka <vbabka@suse.cz>,
stable@vger.kernel.org, Eric Biggers <ebiggers@google.com>
Subject: Re: [PATCH] fork: fix incorrect fput of ->exe_file causing use-after-free
Date: Thu, 24 Aug 2017 09:59:35 -0700 [thread overview]
Message-ID: <20170824165935.GA21624@gmail.com> (raw)
In-Reply-To: <20170824132041.GA22882@redhat.com>
On Thu, Aug 24, 2017 at 03:20:41PM +0200, Oleg Nesterov wrote:
> On 08/23, Eric Biggers wrote:
> >
> > From: Eric Biggers <ebiggers@google.com>
> >
> > Commit 7c051267931a ("mm, fork: make dup_mmap wait for mmap_sem for
> > write killable") made it possible to kill a forking task while it is
> > waiting to acquire its ->mmap_sem for write, in dup_mmap(). However, it
> > was overlooked that this introduced an new error path before a reference
> > is taken on the mm_struct's ->exe_file.
>
> Hmm. Unless I am totally confused, the same problem with mm->exol_area?
> I'll recheck....
I'm not sure what you mean by ->exol_area.
>
> > --- a/kernel/fork.c
> > +++ b/kernel/fork.c
> > @@ -806,6 +806,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
> > mm_init_cpumask(mm);
> > mm_init_aio(mm);
> > mm_init_owner(mm, p);
> > + RCU_INIT_POINTER(mm->exe_file, NULL);
>
> Can't we simply move
>
> RCU_INIT_POINTER(mm->exe_file, get_mm_exe_file(oldmm));
>
> from dup_mmap() here? Afaics this doesn't need mmap_sem.
>
Two problems, even assuming that get_mm_exe_file() doesn't require mmap_sem:
- If mm_alloc_pgd() or init_new_context() in mm_init() fails, mm_init() doesn't
do the full mmput(), so the file reference would not be dropped. So it would
need to be changed to drop the file reference too.
- The file would also be set when called from mm_alloc() which is used when
exec'ing a new task. *Maybe* it would be safe to do temporarily, but it's
pointless because ->exe_file will be set later by flush_old_exec().
Eric
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-08-24 16:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-23 21:14 [PATCH] fork: fix incorrect fput of ->exe_file causing use-after-free Eric Biggers
2017-08-24 13:20 ` Oleg Nesterov
2017-08-24 16:59 ` Eric Biggers [this message]
2017-08-25 14:40 ` Oleg Nesterov
2017-08-28 15:55 ` Eric Biggers
2017-08-24 15:02 ` Mark Rutland
2017-08-25 10:49 ` Mark Rutland
2017-11-16 22:24 ` Jason A. Donenfeld
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=20170824165935.GA21624@gmail.com \
--to=ebiggers3@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=ebiggers@google.com \
--cc=koct9i@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=vbabka@suse.cz \
/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).