History

kthread: Never put_user the set_child_tid address

Kernel threads abuse set_child_tid. Historically that has been fine as set_child_tid was initialized after the kernel thread had been forked. Unfortunately storing struct kthread in set_child_tid after the thread is running makes struct kthread being unusable for storing result codes of the thread. When set_child_tid is set to struct kthread during fork that results in schedule_tail writing the thread id to the beggining of struct kthread (if put_user does not realize it is a kernel address). Solve this by skipping the put_user for all kthreads.

Eric W. Biederman committed 4 years ago

Commit 00580f01 parent dd621ee1 file · +1 −1Browse files

Unified · Split

kernel/sched/core.c+1−1
@@ -4908,7 +4908,7 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev) · 4907 unmodified lines
49084908 finish_task_switch(prev);
49094909 preempt_enable();
49104910
4911− if (current->set_child_tid)
4911+ if (!(current->flags & PF_KTHREAD) && current->set_child_tid)
49124912 put_user(task_pid_vnr(current), current->set_child_tid);
49134913
49144914 calculate_sigpending();