mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: linux-kernel@vger.kernel.org
Cc: Mark Rutland <mark.rutland@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Michal Hocko <mhocko@suse.com>,
	Peter Zijlstra <peterz@infraded.org>,
	Rik van Riel <riel@redhat.com>, Will Deacon <will.deacon@arm.com>
Subject: [PATCH] Detect early free of a live mm
Date: Wed, 28 Feb 2018 12:14:58 +0000	[thread overview]
Message-ID: <20180228121458.2230-1-mark.rutland@arm.com> (raw)

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.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Peter Zijlstra <peterz@infraded.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Will Deacon <will.deacon@arm.com>
---
 kernel/fork.c | 2 ++
 1 file changed, 2 insertions(+)

Hi,

For context, we're seeing an intermittent use-after-free of an mm on
arm64 [1], where it looks like an mm has been freed earlier than
expected. So far KASAN has only caught legitimate mmdrop() uses, where
mm_count is presumably already bogus.

Mark.

[1] https://lkml.kernel.org/r/20180214120254.qq4w4s42ecxio7lu@lakrids.cambridge.arm.com

diff --git a/kernel/fork.c b/kernel/fork.c
index e5d9d405ae4e..6922d93551b8 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -595,6 +595,8 @@ static void check_mm(struct mm_struct *mm)
 void __mmdrop(struct mm_struct *mm)
 {
 	BUG_ON(mm == &init_mm);
+	BUG_ON(mm == current->mm);
+	BUG_ON(mm == current->active_mm);
 	mm_free_pgd(mm);
 	destroy_context(mm);
 	hmm_mm_destroy(mm);
-- 
2.11.0

             reply	other threads:[~2018-02-28 12:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-28 12:14 Mark Rutland [this message]
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
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=20180228121458.2230-1-mark.rutland@arm.com \
    --to=mark.rutland@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhocko@suse.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infraded.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

all inboxes | Powered by JetHome®