1. 11 May, 2022 1 commit
    • Eric W. Biederman's avatar
      sched: Update task_tick_numa to ignore tasks without an mm · b3f9916d
      Eric W. Biederman authored
      Qian Cai <quic_qiancai@quicinc.com> wrote:
      > Reverting the last 3 commits of the series fixed a boot crash.
      >
      > 1b2552cb fork: Stop allowing kthreads to call execve
      > 753550eb fork: Explicitly set PF_KTHREAD
      > 68d85f0a init: Deal with the init process being a user mode process
      >
      >  BUG: KASAN: null-ptr-deref in task_nr_scan_windows.isra.0
      >  arch_atomic_long_read at ./include/linux/atomic/atomic-long.h:29
      >  (inlined by) atomic_long_read at ./include/linux/atomic/atomic-instrumented.h:1266
      >  (inlined by) get_mm_counter at ./include/linux/mm.h:1996
      >  (inlined by) get_mm_rss at ./include/linux/mm.h:2049
      >  (inlined by) task_nr_scan_windows at kernel/sched/fair.c:1123
      >  Read of size 8 at addr 00000000000003d0 by task swapper/0/1
      
      With the change to init and the user mode helper processes to not have
      PF_KTHREAD set before they call kernel_execve the PF_KTHREAD test in
      task_tick_numa became insufficient to detect all tasks that have
      "->mm == NULL".  Correct that by testing for "->mm == NULL" directly.
      Reported-by: default avatarQian Cai <quic_qiancai@quicinc.com>
      Tested-by: default avatarQian Cai <quic_qiancai@quicinc.com>
      Fixes: 1b2552cb ("fork: Stop allowing kthreads to call execve")
      Link: https://lkml.kernel.org/r/87r150ug1l.fsf_-_@email.froward.int.ebiederm.orgSigned-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
      b3f9916d
  2. 07 May, 2022 6 commits
  3. 06 May, 2022 1 commit
    • Eric W. Biederman's avatar
      kthread: Don't allocate kthread_struct for init and umh · 343f4c49
      Eric W. Biederman authored
      If kthread_is_per_cpu runs concurrently with free_kthread_struct the
      kthread_struct that was just freed may be read from.
      
      This bug was introduced by commit 40966e31 ("kthread: Ensure
      struct kthread is present for all kthreads").  When kthread_struct
      started to be allocated for all tasks that have PF_KTHREAD set.  This
      in turn required the kthread_struct to be freed in kernel_execve and
      violated the assumption that kthread_struct will have the same
      lifetime as the task.
      
      Looking a bit deeper this only applies to callers of kernel_execve
      which is just the init process and the user mode helper processes.
      These processes really don't want to be kernel threads but are for
      historical reasons.  Mostly that copy_thread does not know how to take
      a kernel mode function to the process with for processes without
      PF_KTHREAD or PF_IO_WORKER set.
      
      Solve this by not allocating kthread_struct for the init process and
      the user mode helper processes.
      
      This is done by adding a kthread member to struct kernel_clone_args.
      Setting kthread in fork_idle and kernel_thread.  Adding
      user_mode_thread that works like kernel_thread except it does not set
      kthread.  In fork only allocating the kthread_struct if .kthread is set.
      
      I have looked at kernel/kthread.c and since commit 40966e31
      ("kthread: Ensure struct kthread is present for all kthreads") there
      have been no assumptions added that to_kthread or __to_kthread will
      not return NULL.
      
      There are a few callers of to_kthread or __to_kthread that assume a
      non-NULL struct kthread pointer will be returned.  These functions are
      kthread_data(), kthread_parmme(), kthread_exit(), kthread(),
      kthread_park(), kthread_unpark(), kthread_stop().  All of those functions
      can reasonably expected to be called when it is know that a task is a
      kthread so that assumption seems reasonable.
      
      Cc: stable@vger.kernel.org
      Fixes: 40966e31 ("kthread: Ensure struct kthread is present for all kthreads")
      Reported-by: default avatarМаксим Кутявин <maximkabox13@gmail.com>
      Link: https://lkml.kernel.org/r/20220506141512.516114-1-ebiederm@xmission.comSigned-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
      343f4c49
  4. 03 Apr, 2022 8 commits
  5. 02 Apr, 2022 24 commits