From 792ff175e7ca00f813362be4da411ce6d275ac8e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 4 Feb 2019 07:03:44 +0100 Subject: [PATCH] 3.18-stable patches added patches: mm-oom-fix-use-after-free-in-oom_kill_process.patch --- ...x-use-after-free-in-oom_kill_process.patch | 70 +++++++++++++++++++ queue-3.18/series | 1 + 2 files changed, 71 insertions(+) create mode 100644 queue-3.18/mm-oom-fix-use-after-free-in-oom_kill_process.patch diff --git a/queue-3.18/mm-oom-fix-use-after-free-in-oom_kill_process.patch b/queue-3.18/mm-oom-fix-use-after-free-in-oom_kill_process.patch new file mode 100644 index 00000000000..4e3dfb5f798 --- /dev/null +++ b/queue-3.18/mm-oom-fix-use-after-free-in-oom_kill_process.patch @@ -0,0 +1,70 @@ +From cefc7ef3c87d02fc9307835868ff721ea12cc597 Mon Sep 17 00:00:00 2001 +From: Shakeel Butt +Date: Fri, 1 Feb 2019 14:20:54 -0800 +Subject: mm, oom: fix use-after-free in oom_kill_process + +From: Shakeel Butt + +commit cefc7ef3c87d02fc9307835868ff721ea12cc597 upstream. + +Syzbot instance running on upstream kernel found a use-after-free bug in +oom_kill_process. On further inspection it seems like the process +selected to be oom-killed has exited even before reaching +read_lock(&tasklist_lock) in oom_kill_process(). More specifically the +tsk->usage is 1 which is due to get_task_struct() in oom_evaluate_task() +and the put_task_struct within for_each_thread() frees the tsk and +for_each_thread() tries to access the tsk. The easiest fix is to do +get/put across the for_each_thread() on the selected task. + +Now the next question is should we continue with the oom-kill as the +previously selected task has exited? However before adding more +complexity and heuristics, let's answer why we even look at the children +of oom-kill selected task? The select_bad_process() has already selected +the worst process in the system/memcg. Due to race, the selected +process might not be the worst at the kill time but does that matter? +The userspace can use the oom_score_adj interface to prefer children to +be killed before the parent. I looked at the history but it seems like +this is there before git history. + +Link: http://lkml.kernel.org/r/20190121215850.221745-1-shakeelb@google.com +Reported-by: syzbot+7fbbfa368521945f0e3d@syzkaller.appspotmail.com +Fixes: 6b0c81b3be11 ("mm, oom: reduce dependency on tasklist_lock") +Signed-off-by: Shakeel Butt +Reviewed-by: Roman Gushchin +Acked-by: Michal Hocko +Cc: David Rientjes +Cc: Johannes Weiner +Cc: Tetsuo Handa +Cc: +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman + +--- + mm/oom_kill.c | 8 ++++++++ + 1 file changed, 8 insertions(+) + +--- a/mm/oom_kill.c ++++ b/mm/oom_kill.c +@@ -464,6 +464,13 @@ void oom_kill_process(struct task_struct + * still freeing memory. + */ + read_lock(&tasklist_lock); ++ ++ /* ++ * The task 'p' might have already exited before reaching here. The ++ * put_task_struct() will free task_struct 'p' while the loop still try ++ * to access the field of 'p', so, get an extra reference. ++ */ ++ get_task_struct(p); + for_each_thread(p, t) { + list_for_each_entry(child, &t->children, sibling) { + unsigned int child_points; +@@ -483,6 +490,7 @@ void oom_kill_process(struct task_struct + } + } + } ++ put_task_struct(p); + read_unlock(&tasklist_lock); + + p = find_lock_task_mm(victim); diff --git a/queue-3.18/series b/queue-3.18/series index d17cf45b56a..2a215435ced 100644 --- a/queue-3.18/series +++ b/queue-3.18/series @@ -27,3 +27,4 @@ arm64-hyp-stub-forbid-kprobing-of-the-hyp-stub.patch gfs2-revert-fix-loop-in-gfs2_rbm_find.patch platform-x86-asus-nb-wmi-map-0x35-to-key_screenlock.patch platform-x86-asus-nb-wmi-drop-mapping-of-0x33-and-0x.patch +mm-oom-fix-use-after-free-in-oom_kill_process.patch -- 2.47.2