From: Linus Torvalds Date: Fri, 3 Jun 2022 23:03:05 +0000 (-0700) Subject: Merge tag 'kthread-cleanups-for-v5.19' of git://git.kernel.org/pub/scm/linux/kernel... X-Git-Tag: baikal/mips/sdk6.1~5569 X-Git-Url: https://git.baikalelectronics.ru/?a=commitdiff_plain;h=f73e145f46a948adb297640c7f9ca73267b09c25;p=kernel.git Merge tag 'kthread-cleanups-for-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace Pull kthread updates from Eric Biederman: "This updates init and user mode helper tasks to be ordinary user mode tasks. Commit 169a5179aab6 ("kthread: Ensure struct kthread is present for all kthreads") caused init and the user mode helper threads that call kernel_execve to have struct kthread allocated for them. This struct kthread going away during execve in turned made a use after free of struct kthread possible. Here, commit 14549687236b ("kthread: Don't allocate kthread_struct for init and umh") is enough to fix the use after free and is simple enough to be backportable. The rest of the changes pass struct kernel_clone_args to clean things up and cause the code to make sense. In making init and the user mode helpers tasks purely user mode tasks I ran into two complications. The function task_tick_numa was detecting tasks without an mm by testing for the presence of PF_KTHREAD. The initramfs code in populate_initrd_image was using flush_delayed_fput to ensuere the closing of all it's file descriptors was complete, and flush_delayed_fput does not work in a userspace thread. I have looked and looked and more complications and in my code review I have not found any, and neither has anyone else with the code sitting in linux-next" * tag 'kthread-cleanups-for-v5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: sched: Update task_tick_numa to ignore tasks without an mm fork: Stop allowing kthreads to call execve fork: Explicitly set PF_KTHREAD init: Deal with the init process being a user mode process fork: Generalize PF_IO_WORKER handling fork: Explicity test for idle tasks in copy_thread fork: Pass struct kernel_clone_args into copy_thread kthread: Don't allocate kthread_struct for init and umh --- f73e145f46a948adb297640c7f9ca73267b09c25 diff --cc arch/x86/kernel/process.c index 58fb48d3004fe,d20eaad52a859..9b2772b7e1f39 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@@ -193,10 -193,14 +195,10 @@@ int copy_thread(struct task_struct *p, if (sp) childregs->sp = sp; - if (unlikely(p->flags & PF_IO_WORKER)) { -#ifdef CONFIG_X86_32 - task_user_gs(p) = get_user_gs(current_pt_regs()); -#endif - + if (unlikely(args->fn)) { /* - * An IO thread is a user space thread, but it doesn't - * return to ret_after_fork(). + * A user space thread, but it doesn't return to + * ret_after_fork(). * * In order to indicate that to tools like gdb, * we reset the stack and instruction pointers. diff --cc init/initramfs.c index dc84cf756cea1,41e7857d510d6..18229cfe8906b --- a/init/initramfs.c +++ b/init/initramfs.c @@@ -15,13 -15,11 +15,14 @@@ #include #include #include + #include #include -static ssize_t __init xwrite(struct file *file, const char *p, size_t count, - loff_t *pos) +static __initdata bool csum_present; +static __initdata u32 io_csum; + +static ssize_t __init xwrite(struct file *file, const unsigned char *p, + size_t count, loff_t *pos) { ssize_t out = 0;