btrfs: wait for fixup workers before stopping cleaner kthread during umount
Linux
Affected versions
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
Linux
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
≥ f4b1363cae43fef7c86c993b7ca7fe7d546b3c68 · < bf0de0f9a0544c11f96f93206da04ab87dcea1f4| No fix yet |
| Linux Linux |
|
|
In the Linux kernel, the following vulnerability has been resolved:
btrfs: wait for fixup workers before stopping cleaner kthread during umount
During unmount, at close_ctree(), we have the following steps in this order:
1) Park the cleaner kthread - this doesn't destroy the kthread, it basically halts its execution (wake ups against it work but do nothing);
2) We stop the cleaner kthread - this results in freeing the respective struct task_struct;
3) We call btrfs_stop_all_workers() which waits for any jobs running in all the work queues and then free the work queues.
Syzbot reported a case where a fixup worker resulted in a crash when doing a delayed iput on its inode while attempting to wake up the cleaner at btrfs_add_delayed_iput(), because the task_struct of the cleaner kthread was already freed. This can happen during unmount because we don't wait for any fixup workers still running before we call kthread_stop() against the cleaner kthread, which stops and free all its resources.
Fix this by waiting for any fixup workers at close_ctree() before we call kthread_stop() against the cleaner and run pending delayed iputs.
From the CVE record · Linux
The Linux kernel’s btrfs unmount path can stop and free the cleaner thread while a fixup worker is still running. During unmount, that worker can try to wake the freed thread, causing a use-after-free crash. The input does not specify attacker access requirements or user interaction.
Engineers running Linux kernels with btrfs should check whether their kernel includes the fix; affected versions are not specified.