• CVE-2024-35784

发布时间: 2024年6月15日

修改时间: 2025年1月11日

概要

In the Linux kernel, the following vulnerability has been resolved: btrfs: fix deadlock with fiemap and extent locking While working on the patchset to remove extent locking I got a lockdep splat with fiemap and pagefaulting with my new extent lock replacement lock. This deadlock exists with our normal code, we just don't have lockdep annotations with the extent locking so we've never noticed it. Since we're copying the fiemap extent to user space on every iteration we have the chance of pagefaulting. Because we hold the extent lock for the entire range we could mkwrite into a range in the file that we have mmap'ed. This would deadlock with the following stack trace [<0&gt;] lock_extent+0x28d/0x2f0 [<0&gt;] btrfs_page_mkwrite+0x273/0x8a0 [<0&gt;] do_page_mkwrite+0x50/0xb0 [<0&gt;] do_fault+0xc1/0x7b0 [<0&gt;] __handle_mm_fault+0x2fa/0x460 [<0&gt;] handle_mm_fault+0xa4/0x330 [<0&gt;] do_user_addr_fault+0x1f4/0x800 [<0&gt;] exc_page_fault+0x7c/0x1e0 [<0&gt;] asm_exc_page_fault+0x26/0x30 [<0&gt;] rep_movs_alternative+0x33/0x70 [<0&gt;] _copy_to_user+0x49/0x70 [<0&gt;] fiemap_fill_next_extent+0xc8/0x120 [<0&gt;] emit_fiemap_extent+0x4d/0xa0 [<0&gt;] extent_fiemap+0x7f8/0xad0 [<0&gt;] btrfs_fiemap+0x49/0x80 [<0&gt;] __x64_sys_ioctl+0x3e1/0xb50 [<0&gt;] do_syscall_64+0x94/0x1a0 [<0&gt;] entry_SYSCALL_64_after_hwframe+0x6e/0x76 I wrote an fstest to reproduce this deadlock without my replacement lock and verified that the deadlock exists with our existing locking. To fix this simply don't take the extent lock for the entire duration of the fiemap. This is safe in general because we keep track of where we are when we're searching the tree, so if an ordered extent updates in the middle of our fiemap call we'll still emit the correct extents because we know what offset we were on before. The only place we maintain the lock is searching delalloc. Since the delalloc stuff can change during writeback we want to lock the extent range so we have a consistent view of delalloc at the time we're checking to see if we need to set the delalloc flag. With this patch applied we no longer deadlock with my testcase.

CVSS v3 指标

NVD openEuler
Confidentiality None None
Attack Vector Local Local
CVSS评分 5.5 5.5
Attack Complexity Low Low
Privileges Required Low Low
Scope Unchanged Unchanged
Integrity None None
User Interaction None None
Availability High High

安全公告

公告名 概要 发布时间
KylinSec-SA-2024-2736 In the Linux kernel, the following vulnerability has been resolved: btrfs: fix deadlock with fiemap and extent locking While working on the patchset to remove extent locking I got a lockdep splat with fiemap and pagefaulting with my new extent lock replacement lock. This deadlock exists with our normal code, we just don't have lockdep annotations with the extent locking so we've never noticed it. Since we're copying the fiemap extent to user space on every iteration we have the chance of pagefaulting. Because we hold the extent lock for the entire range we could mkwrite into a range in the file that we have mmap'ed. This would deadlock with the following stack trace [<0&gt;] lock_extent+0x28d/0x2f0 [<0&gt;] btrfs_page_mkwrite+0x273/0x8a0 [<0&gt;] do_page_mkwrite+0x50/0xb0 [<0&gt;] do_fault+0xc1/0x7b0 [<0&gt;] __handle_mm_fault+0x2fa/0x460 [<0&gt;] handle_mm_fault+0xa4/0x330 [<0&gt;] do_user_addr_fault+0x1f4/0x800 [<0&gt;] exc_page_fault+0x7c/0x1e0 [<0&gt;] asm_exc_page_fault+0x26/0x30 [<0&gt;] rep_movs_alternative+0x33/0x70 [<0&gt;] _copy_to_user+0x49/0x70 [<0&gt;] fiemap_fill_next_extent+0xc8/0x120 [<0&gt;] emit_fiemap_extent+0x4d/0xa0 [<0&gt;] extent_fiemap+0x7f8/0xad0 [<0&gt;] btrfs_fiemap+0x49/0x80 [<0&gt;] __x64_sys_ioctl+0x3e1/0xb50 [<0&gt;] do_syscall_64+0x94/0x1a0 [<0&gt;] entry_SYSCALL_64_after_hwframe+0x6e/0x76 I wrote an fstest to reproduce this deadlock without my replacement lock and verified that the deadlock exists with our existing locking. To fix this simply don't take the extent lock for the entire duration of the fiemap. This is safe in general because we keep track of where we are when we're searching the tree, so if an ordered extent updates in the middle of our fiemap call we'll still emit the correct extents because we know what offset we were on before. The only place we maintain the lock is searching delalloc. Since the delalloc stuff can change during writeback we want to lock the extent range so we have a consistent view of delalloc at the time we're checking to see if we need to set the delalloc flag. With this patch applied we no longer deadlock with my testcase. 2024年6月15日

影响产品

产品 状态
KY3.4-5 kernel Unaffected
KY3.5.2 kernel Unaffected
KY3.5.3 kernel Unaffected
V6 kernel Unaffected