Skip to content

Commit dd839f3

Browse files
minipli-ossKent Overstreet
authored andcommitted
bcachefs: install fd later to avoid race with close
Calling fd_install() makes a file reachable for userland, including the possibility to close the file descriptor, which leads to calling its 'release' hook. If that happens before the code had a chance to bump the reference of the newly created task struct, the release callback will call put_task_struct() too early, leading to the premature destruction of the kernel thread. Avoid that race by calling fd_install() later, after all the setup is done. Fixes: 1c6fdbd ("bcachefs: Initial commit") Signed-off-by: Mathias Krause <minipli@grsecurity.net> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 6bb3f7f commit dd839f3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/bcachefs/thread_with_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ int bch2_run_thread_with_file(struct thread_with_file *thr,
5353
if (ret)
5454
goto err;
5555

56-
fd_install(fd, file);
5756
get_task_struct(thr->task);
5857
wake_up_process(thr->task);
58+
fd_install(fd, file);
5959
return fd;
6060
err:
6161
if (fd >= 0)

0 commit comments

Comments
 (0)