Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sched/rseq: Fix concurrency ID handling of usermodehelper kthreads

sched_mm_cid_after_execve() does not expect NULL t->mm, but it may happen
if a usermodehelper kthread fails when attempting to execute a binary.

sched_mm_cid_fork() can be issued from a usermodehelper kthread, which
has t->flags PF_KTHREAD set.

Fixes: af7f588d8f73 ("sched: Introduce per-memory-map concurrency ID")
Reported-by: kernel test robot <yujie.liu@intel.com>
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/oe-lkp/202212301353.5c959d72-yujie.liu@intel.com

authored by

Mathieu Desnoyers and committed by
Borislav Petkov (AMD)
bbd0b031 c8997020

+3 -3
+3 -3
kernel/sched/core.c
··· 11343 11343 struct mm_struct *mm = t->mm; 11344 11344 unsigned long flags; 11345 11345 11346 - WARN_ON_ONCE((t->flags & PF_KTHREAD) || !t->mm); 11347 - 11346 + if (!mm) 11347 + return; 11348 11348 local_irq_save(flags); 11349 11349 t->mm_cid = mm_cid_get(mm); 11350 11350 t->mm_cid_active = 1; ··· 11354 11354 11355 11355 void sched_mm_cid_fork(struct task_struct *t) 11356 11356 { 11357 - WARN_ON_ONCE((t->flags & PF_KTHREAD) || !t->mm || t->mm_cid != -1); 11357 + WARN_ON_ONCE(!t->mm || t->mm_cid != -1); 11358 11358 t->mm_cid_active = 1; 11359 11359 } 11360 11360 #endif