[patch -mm 2/2] oom: protect task name when killing threads sharing memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It's necessary to prevent dereferences of q->comm for a task q when
q != current because its name may change during prctl() with
PR_SET_NAME.

Unfortunately, we can't use get_task_comm() when killing other threads
sharing the same memory as the oom killed task since it would require a
string to be allocated on the stack which may be very deep, especially
during failed page allocations.

This patch protects the dereference with task_lock() instead.

Suggested-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: David Rientjes <rientjes@xxxxxxxxxx>
---
 mm/oom_kill.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -429,8 +429,10 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem)
 	 */
 	for_each_process(q)
 		if (q->mm == mm && !same_thread_group(q, p)) {
+			task_lock(q);
 			pr_err("Kill process %d (%s) sharing same memory\n",
 				task_pid_nr(q), q->comm);
+			task_unlock(q);
 			force_sig(SIGKILL, q);
 		}
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxxx  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]