kernel/fork.c: detect early free of a live mm
authorMark Rutland <[email protected]>
Thu, 5 Apr 2018 23:25:12 +0000 (16:25 -0700)
committerLinus Torvalds <[email protected]>
Fri, 6 Apr 2018 04:36:27 +0000 (21:36 -0700)
commit3eda69c92d4751977baf2d34e88a29d4b6affa7d
tree931b5551d4d8a4732375d10f2babac7d74628798
parent0c7c1bed7e13dbb545375c231e6ba1dca5e8d725
kernel/fork.c: detect early free of a live mm

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.

Currently, idle_task_exit() leaves active_mm stale after it switches to
init_mm.  This isn't harmful, but will trigger the new assertions, so we
must adjust idle_task_exit() to update active_mm.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Mark Rutland <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Mathieu Desnoyers <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
kernel/fork.c
kernel/sched/core.c