Skip to content

Commit bf956be

Browse files
Alexei Starovoitovdavem330
authored andcommitted
umh: fix race condition
kasan reported use-after-free: BUG: KASAN: use-after-free in call_usermodehelper_exec_work+0x2d3/0x310 kernel/umh.c:195 Write of size 4 at addr ffff8801d9202370 by task kworker/u4:2/50 Workqueue: events_unbound call_usermodehelper_exec_work Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x1b9/0x294 lib/dump_stack.c:113 print_address_description+0x6c/0x20b mm/kasan/report.c:256 kasan_report_error mm/kasan/report.c:354 [inline] kasan_report.cold.7+0x242/0x2fe mm/kasan/report.c:412 __asan_report_store4_noabort+0x17/0x20 mm/kasan/report.c:437 call_usermodehelper_exec_work+0x2d3/0x310 kernel/umh.c:195 process_one_work+0xc1e/0x1b50 kernel/workqueue.c:2145 worker_thread+0x1cc/0x1440 kernel/workqueue.c:2279 kthread+0x345/0x410 kernel/kthread.c:240 ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:412 The reason is that 'sub_info' cannot be accessed out of parent task context, since it will be freed by the child. Instead remember the pid in the child task. Fixes: 449325b ("umh: introduce fork_usermode_blob() helper") Reported-by: [email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2ac0e15 commit bf956be

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

kernel/umh.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static int call_usermodehelper_exec_async(void *data)
9999

100100
commit_creds(new);
101101

102+
sub_info->pid = task_pid_nr(current);
102103
if (sub_info->file)
103104
retval = do_execve_file(sub_info->file,
104105
sub_info->argv, sub_info->envp);
@@ -191,8 +192,6 @@ static void call_usermodehelper_exec_work(struct work_struct *work)
191192
if (pid < 0) {
192193
sub_info->retval = pid;
193194
umh_complete(sub_info);
194-
} else {
195-
sub_info->pid = pid;
196195
}
197196
}
198197
}

0 commit comments

Comments
 (0)