diff options
| author | Filipe Manana <fdmanana@suse.com> | 2026-11-10 22:21:19 +0000 |
|---|---|---|
| committer | David Sterba <dsterba@suse.com> | 2026-11-23 19:47:33 +0100 |
| commit | 2d8b3d9b210a388129e41757372d70c66ae20a5b (patch) | |
| tree | 88ab82c12f22b8a92206d750ed3f703b59606733 /tools/perf/scripts/python | |
| parent | ad4bb983915d8588dc9dd3aeb60cf58aff574e3b (diff) | |
btrfs: zstd: fix UAF due to race between putting workspace and reclaim
When we put a workspace with a level matching the requested level, we add
it back to the lru list of the workspace manager and set the timer to
run the reclaim function (zstd_reclaim_timer_fn()). If that workspace than
gets used by some other task, obtained with zstd_find_workspace(), for
some compression level lower than the workspace's level, we set the
workspace's req_level field to the requested level (done in
zstd_find_workspace()) and leave it in the lru list without updating the
last_used field of the workspace. Once the last_used field ages past the
ZSTD_BTRFS_RECLAIM_JIFFIES value, when zstd_put_workspace() is called it
skips the lru update branch because the workspace's req_level does not
match its level, and then it sets its req_level to 0 before releasing
the workspace manager's lock - and after that and before
zstd_put_workspace() does:
if (workspace->level == clip_level(ZSTD_BTRFS_MAX_LEVEL))
cond_wake_up(&zwsm->wait);
the reclaim function, zstd_reclaim_timer_fn(), can run, see the workspace
in the lru list and see that it has a req_level of 0 and an expired
last_used time, and therefore call zstd_free_workspace() to free the
workspace, right before the task that is putting the workspace executes
the code above to read its level.
Fix this by reading the workspace's level before unlocking the workspace
manager in zstd_put_workspace().
Link: https://sashiko.dev/#/bug/linux-92b08485-a86c-4bb5-9138-fa80c84389f0
Fixes: 3f93aef535c8 ("btrfs: add zstd compression level support")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions
