linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Rik van Riel <riel@redhat.com>, Will Deacon <will.deacon@arm.com>
Subject: Re: [PATCH] Detect early free of a live mm
Date: Thu, 1 Mar 2018 13:40:24 +0100	[thread overview]
Message-ID: <20180301124024.GE15057@dhcp22.suse.cz> (raw)
In-Reply-To: <20180301112237.pjn5rmvkkpxcntl7@lakrids.cambridge.arm.com>

On Thu 01-03-18 11:22:37, Mark Rutland wrote:
> On Thu, Mar 01, 2018 at 10:35:22AM +0100, Michal Hocko wrote:
> > On Wed 28-02-18 12:18:10, Mark Rutland wrote:
> > > Ugh, I messed up Peter's email when sending this out. please
> > > s/infraded/infradead/ if replying to the first mail.
> > > 
> > > Sorry about that.
> > > 
> > > Mark.
> > > 
> > > On Wed, Feb 28, 2018 at 12:14:58PM +0000, Mark Rutland wrote:
> > > > KASAN splats indicate that in some cases we free a live mm, then
> > > > continue to access it, with potentially disastrous results. This is
> > > > likely due to a mismatched mmdrop() somewhere in the kernel, but so far
> > > > the culprit remains elusive.
> > > > 
> > > > Let's have __mmdrop() verify that the mm isn't live for the current
> > > > task, similar to the existing check for init_mm. This way, we can catch
> > > > this class of issue earlier, and without requiring KASAN.
> > 
> > Wouldn't it be better to check the mm_users count instead?
> > {VM_}BUG_ON(atomic_read(&mm->mm_users));
> 
> Perhaps, but that won't catch a mismatched mmput(), which could
> decrement mm_users (and mm_count) to zero early, before current->mm is
> cleared in exit_mm().

true

> Locally, I'm testing with:
> 
>   BUG_ON(mm == current->mm);
>   BUG_ON(mm == current->active_mm);
>   BUG_ON(refcount_read(&mm->mm_users) != 0);
>   BUG_ON(refcount_read(&mm->mm_count) != 0);
> 
> ... so as to also catch an early free from another thread.

I would be careful about active_mm. At least {un}use_mm does some tricks
with it.

> > Relying on current->mm resetting works currently but this is quite a
> > subtle dependency.
> 
> Do you mean because it only catches an early free in a thread using that
> mm, or is there another subtlety you had in mind?

No, I was more thinking about future changes when we stop clearing
tsk->mm at exit. This is rather unlikely to be honest because that
requires more changes.
-- 
Michal Hocko
SUSE Labs

  reply	other threads:[~2018-03-01 12:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-28 12:14 [PATCH] Detect early free of a live mm Mark Rutland
2018-02-28 12:18 ` Mark Rutland
2018-03-01  9:35   ` Michal Hocko
2018-03-01 11:22     ` Mark Rutland
2018-03-01 12:40       ` Michal Hocko [this message]
2018-03-01 12:49         ` Mark Rutland
2018-03-02  1:16 ` Andrew Morton
2018-03-02 10:24   ` Mark Rutland
2018-03-09 21:11 ` 94d3a25408: kernel_BUG_at_kernel/fork.c kernel test robot
2018-03-12 13:46   ` Mark Rutland

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=20180301124024.GE15057@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=will.deacon@arm.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 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).