kernel: always initialize task->pf_io_worker to NULL
authorStefan Metzmacher <metze@samba.org>
Sat, 24 Apr 2021 23:26:03 +0000 (01:26 +0200)
committerJens Axboe <axboe@kernel.dk>
Sun, 25 Apr 2021 16:29:03 +0000 (10:29 -0600)
Otherwise io_wq_worker_{running,sleeping}() may dereference an
invalid pointer (in future). Currently all users of create_io_thread()
are fine and get task->pf_io_worker = NULL implicitly from the
wq_manager, which got it either from the userspace thread
of the sq_thread, which explicitly reset it to NULL.

I think it's safer to always reset it in order to avoid future
problems.

Fixes: 3bfe6106693b ("io-wq: fork worker threads from original task")
cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
kernel/fork.c

index b81ccb1ca3a7d03416e23852efa5eff7bc646089..224c8317df342fb53c9f40f1d0a0e56a2c3619b2 100644 (file)
@@ -927,6 +927,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
        tsk->splice_pipe = NULL;
        tsk->task_frag.page = NULL;
        tsk->wake_q.next = NULL;
+       tsk->pf_io_worker = NULL;
 
        account_kernel_stack(tsk, 1);