lkml.org 
[lkml]   [2020]   [Feb]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v4 3/8] mm: validate mm in do_madvise
Date
Oleg pointed out mm could be nulllified right after mm_access succeeds.
This patch validates it before the using.

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
mm/madvise.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 8611f1d39289..bb04c7897eb9 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1073,7 +1073,11 @@ int do_madvise(struct task_struct *task, unsigned long start,
int write;
size_t len;
struct blk_plug plug;
- struct mm_struct *mm = task->mm;
+ struct mm_struct *mm = READ_ONCE(task->mm);
+
+ /* task can exit and nullify its ->mm right after mm_access() */
+ if (!mm)
+ return -ESRCH;

start = untagged_addr(start);

--
2.25.0.225.g125e21ebc7-goog
\
 
 \ /
  Last update: 2020-02-13 00:41    [W:0.103 / U:1.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site