CVE: CVE-2022-48833
Published: 2024-07-16
Description: In the Linux kernel, the following vulnerability has been resolved:

btrfs: skip reserved bytes warning on unmount after log cleanup failure

After the recent changes made by commit c2e39305299f01 ("btrfs: clear
extent buffer uptodate when we fail to write it") and its followup fix,
commit 651740a5024117 ("btrfs: check WRITE_ERR when trying to read an
extent buffer"), we can now end up not cleaning up space reservations of
log tree extent buffers after a transaction abort happens, as well as not
cleaning up still dirty extent buffers.

This happens because if writeback for a log tree extent buffer failed,
then we have cleared the bit EXTENT_BUFFER_UPTODATE from the extent buffer
and we have also set the bit EXTENT_BUFFER_WRITE_ERR on it. Later on,
when trying to free the log tree with free_log_tree(), which iterates
over the tree, we can end up getting an -EIO error when trying to read
a node or a leaf, since read_extent_buffer_pages() returns -EIO if an
extent buffer does not have EXTENT_BUFFER_UPTODATE set and has the
EXTENT_BUFFER_WRITE_ERR bit set. Getting that -EIO means that we return
immediately as we can not iterate over the entire tree.

In that case we never update the reserved space for an extent buffer in
the respective block group and space_info object.

When this happens we get the following traces when unmounting the fs:

[[PII_REDACTED]09] BTRFS: error (device dm-0) in cleanup_transaction:1913: errno=-5 IO failure
[[PII_REDACTED]97] BTRFS: error (device dm-0) in free_log_tree:3420: errno=-5 IO failure
[[PII_REDACTED]79] ------------[ cut here ]------------
[[PII_REDACTED]97] WARNING: CPU: 2 PID: 3206883 at fs/btrfs/block-group.c:127 btrfs_put_block_group+0x77/0xb0 [btrfs]
[[PII_REDACTED]23] Modules linked in: btrfs overlay dm_zero (...)
[[PII_REDACTED]17] CPU: 2 PID: 3206883 Comm: umount Tainted: G        W         5.16.0-rc5-btrfs-next-109 #1
[[PII_REDACTED]89] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
[[PII_REDACTED]16] RIP: 0010:btrfs_put_block_group+0x77/0xb0 [btrfs]
[[PII_REDACTED]17] Code: 21 48 8b bd (...)
[[PII_REDACTED]67] RSP: 0018:ffffb70d41cffdd0 EFLAGS: 00010206
[[PII_REDACTED]32] RAX: [PII_REDACTED] RBX: ffff8b09c3848000 RCX: ffff8b0758edd1c8
[[PII_REDACTED]89] RDX: [PII_REDACTED] RSI: ffffffffc0b467e7 RDI: ffff8b0758edd000
[[PII_REDACTED]68] RBP: ffff8b0758edd000 R08: [PII_REDACTED] R09: [PII_REDACTED]
[[PII_REDACTED]14] R10: [PII_REDACTED] R11: [PII_REDACTED] R12: ffff8b09c3848148
[[PII_REDACTED]40] R13: ffff8b09c3848198 R14: ffff8b0758edd188 R15: dead[PII_REDACTED]00
[[PII_REDACTED]17] FS:  00007f328fb82800(0000) GS:ffff8b0a2d200000(0000) knlGS:[PII_REDACTED]
[[PII_REDACTED]02] CS:  0010 DS: 0000 ES: 0000 CR0: [PII_REDACTED]
[[PII_REDACTED]64] CR2: 00007fff13563e98 CR3:[PII_REDACTED]f4e005 CR4:[PII_REDACTED]370ee0
[[PII_REDACTED]17] DR0: [PII_REDACTED] DR1: [PII_REDACTED] DR2: [PII_REDACTED]
[[PII_REDACTED]76] DR3: [PII_REDACTED] DR6: 00000000fffe0ff0 DR7: [PII_REDACTED]
[[PII_REDACTED]48] Call Trace:
[[PII_REDACTED]64]  <TASK>
[[PII_REDACTED]38]  btrfs_free_block_groups+0x255/0x3c0 [btrfs]
[[PII_REDACTED]38]  close_ctree+0x301/0x357 [btrfs]
[[PII_REDACTED]03]  ? call_rcu+0x16c/0x290
[[PII_REDACTED]50]  generic_shutdown_super+0x74/0x120
[[PII_REDACTED]32]  kill_anon_super+0x14/0x30
[[PII_REDACTED]05]  btrfs_kill_super+0x12/0x20 [btrfs]
[[PII_REDACTED]90]  deactivate_locked_super+0x31/0xa0
[[PII_REDACTED]40]  cleanup_mnt+0x147/0x1c0
[[PII_REDACTED]88]  task_work_run+0x5c/0xa0
[[PII_REDACTED]36]  exit_to_user_mode_prepare+0x1e5/0x1f0
[[PII_REDACTED]34]  syscall_exit_to_user_mode+0x16/0x40
[[PII_REDACTED]12]  do_syscall_64+0x48/0xc0
[[PII_REDACTED]80]  entry_SYSCALL_64_after_hwframe+0x44/0xae
[[PII_REDACTED]05] RIP: 0033:0x7f328fdc4a97
[[PII_REDACTED]59] Code: 03 0c 00 f7 (...)
[[PII_REDACTED]20] RSP: 002b:00007fff13564ec8 EFLAGS: 00000246 ORIG_RAX:[PII_REDACTED]0000a6
[[PII_REDACTED]62] RAX: [PII_REDACTED] RBX: 00007f328feea264 RCX: 00007f328fdc4a97
[[PII_REDACTED]31] RDX: [PII_REDACTED] RSI:[PII_REDACTED]0000
---truncated---
CVSS Score: 5.5 (MEDIUM)
References: https://git.kernel.org/stable/c/40cdc509877bacb438213b83c7541c5e24a1d9ec; https://git.kernel.org/stable/c/44557a8f539a822c91238c1f95a95f98a5093d82; https://git.kernel.org/stable/c/4c5d94990fa2fd609360ecd0f7e183212a7d115c