Skip to content

Commit 9b7da57

Browse files
shao mingyinbrauner
authored andcommitted
file: flush delayed work in delayed fput()
The fput() of file rcS might not have completed causing issues when executing the file. rcS is opened in do_populate_rootfs before executed. At the end of do_populate_rootfs() flush_delayed_fput() is called. Now do_populate_rootfs() assumes that all fput()s caused by do_populate_rootfs() have completed. But flush_delayed_fput() can only ensure that fput() on the current delayed_fput_list has finished. Any file that has been removed from delayed_fput_list asynchronously in the meantime might not have completed causing the exec to fail. do_populate_rootfs delayed_fput_list delayed_fput execve fput() a fput() a->b fput() a->b->rcS __fput(a) fput() c fput() c->d __fput(b) flush_delayed_fput __fput(c) __fput(d) __fput(b) __fput(b) execve(rcS) Ensure that all delayed work is done by calling flush_delayed_work() in flush_delayed_fput() explicitly. Signed-off-by: Chen Lin <[email protected]> Signed-off-by: Shao Mingyin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: Yang Yang <[email protected]> Cc: Yang Tao <[email protected]> Cc: Xu Xin <[email protected]> [brauner: rewrite commit message] Signed-off-by: Christian Brauner <[email protected]>
1 parent 1197867 commit 9b7da57

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/file_table.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ static void ____fput(struct callback_head *work)
478478
__fput(container_of(work, struct file, f_task_work));
479479
}
480480

481+
static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
482+
481483
/*
482484
* If kernel thread really needs to have the final fput() it has done
483485
* to complete, call this. The only user right now is the boot - we
@@ -491,11 +493,10 @@ static void ____fput(struct callback_head *work)
491493
void flush_delayed_fput(void)
492494
{
493495
delayed_fput(NULL);
496+
flush_delayed_work(&delayed_fput_work);
494497
}
495498
EXPORT_SYMBOL_GPL(flush_delayed_fput);
496499

497-
static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
498-
499500
void fput(struct file *file)
500501
{
501502
if (file_ref_put(&file->f_ref)) {

0 commit comments

Comments
 (0)