From: Oleg Nesterov <oleg@redhat.com>
To: Eric Biggers <ebiggers3@gmail.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: Fri, 25 Aug 2017 16:40:36 +0200 [thread overview]
Message-ID: <20170825144036.GA26620@redhat.com> (raw)
In-Reply-To: <20170824165935.GA21624@gmail.com>
On 08/24, Eric Biggers wrote:
>
> 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.
I meant mm->uprobes_state.xol_area, sorry
> > > --- 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.
Ah yes, I forgot that mm_init() can fail after that, thanks for correcting me.
Oleg.
--
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>
WARNING: multiple messages have this Message-ID (diff)
From: Oleg Nesterov <oleg@redhat.com>
To: Eric Biggers <ebiggers3@gmail.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: Fri, 25 Aug 2017 16:40:36 +0200 [thread overview]
Message-ID: <20170825144036.GA26620@redhat.com> (raw)
In-Reply-To: <20170824165935.GA21624@gmail.com>
On 08/24, Eric Biggers wrote:
>
> 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.
I meant mm->uprobes_state.xol_area, sorry
> > > --- 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.
Ah yes, I forgot that mm_init() can fail after that, thanks for correcting me.
Oleg.
next prev parent reply other threads:[~2017-08-25 14:40 UTC|newest]
Thread overview: 16+ 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-23 21:14 ` Eric Biggers
2017-08-24 13:20 ` Oleg Nesterov
2017-08-24 13:20 ` Oleg Nesterov
2017-08-24 16:59 ` Eric Biggers
2017-08-24 16:59 ` Eric Biggers
2017-08-25 14:40 ` Oleg Nesterov [this message]
2017-08-25 14:40 ` Oleg Nesterov
2017-08-28 15:55 ` Eric Biggers
2017-08-28 15:55 ` Eric Biggers
2017-08-24 15:02 ` Mark Rutland
2017-08-24 15:02 ` Mark Rutland
2017-08-25 10:49 ` Mark Rutland
2017-08-25 10:49 ` Mark Rutland
2017-11-16 22:24 ` Jason A. Donenfeld
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=20170825144036.GA26620@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=ebiggers3@gmail.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=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 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.