Skip to contentSkip to conversation

mm/oom_kill: fix wild pointer in out_of_memory

PATCH In review Jiang Biao 2 participants 2 messages Mar 13, 2021 – Mar 15, 2021

Subsystems (2)
lore
Share & tools
lore

Jiang Biao

author
#0 lore raw

PATCH 1/1 mm/oom_kill: fix wild pointer in out_of_memory

From: Bin Lai <[email protected]>

From: Bin Lai <[email protected]>

The oc->chosen is used by oom implementation, and the caller does not initialize this variable. If the tasks of memcg are all unkillable, oom_evaluate_task cann't choose any task, and the oc->chosen will be a wild pointer. So we should initialize oc->chosen before calling oom_evaluate_task.

mm/oom_kill.c +1 -0
index 9efaf43..0658a30 100644
@@ -366,6 +366,7 @@ static int oom_evaluate_task(struct task_struct *task, void *arg)
 static void select_bad_process(struct oom_control *oc)
 {
 	oc->chosen_points = LONG_MIN;
+	oc->chosen = NULL;
 
 	if (is_memcg_oom(oc))
 		mem_cgroup_scan_tasks(oc->memcg, oom_evaluate_task, oc);
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 9 lines · Jiang Biao

From: Bin Lai <[email protected]>

From: Bin Lai <[email protected]>

The oc->chosen is used by oom implementation, and the caller does not initialize this variable. If the tasks of memcg are all unkillable, oom_evaluate_task cann't choose any task, and the oc->chosen will be a wild pointer. So we should initialize oc->chosen before calling oom_evaluate_task.

All callers do initialize oom_control on the stack and even partial structure initialization on stack will result in the zeroying of all other structure's element. So I do not think there is any problem.

Quoted 19 lines
mm/oom_kill.c +1 -0
index 9efaf43..0658a30 100644
@@ -366,6 +366,7 @@ static int oom_evaluate_task(struct task_struct *task, void *arg)
 static void select_bad_process(struct oom_control *oc)
 {
 	oc->chosen_points = LONG_MIN;
+	oc->chosen = NULL;
 
 	if (is_memcg_oom(oc))
 		mem_cgroup_scan_tasks(oc->memcg, oom_evaluate_task, oc);
Signature · 1 line
1.8.3.1
Signature · 2 lines
Michal Hocko
SUSE Labs