{"id":"CVE-2024-26616","published":"2024-02-29T15:52:19Z","modified":"2026-05-11T20:00:50Z","title":"btrfs: scrub: avoid use-after-free when chunk length is not 64K aligned","vendor":"Linux","product":"Linux","tier":"tail","description":{"text":"In the Linux kernel, the following vulnerability has been resolved:\n\nbtrfs: scrub: avoid use-after-free when chunk length is not 64K aligned\n\n[BUG]\nThere is a bug report that, on a ext4-converted btrfs, scrub leads to\nvarious problems, including:\n\n- \"unable to find chunk map\" errors\n  BTRFS info (device vdb): scrub: started on devid 1\n  BTRFS critical (device vdb): unable to find chunk map for logical 2214744064 length 4096\n  BTRFS critical (device vdb): unable to find chunk map for logical 2214744064 length 45056\n\n  This would lead to unrepariable errors.\n\n- Use-after-free KASAN reports:\n  ==================================================================\n  BUG: KASAN: slab-use-after-free in __blk_rq_map_sg+0x18f/0x7c0\n  Read of size 8 at addr ffff8881013c9040 by task btrfs/909\n  CPU: 0 PID: 909 Comm: btrfs Not tainted 6.7.0-x64v3-dbg #11 c50636e9419a8354555555245df535e380563b2b\n  Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 2023.11-2 12/24/2023\n  Call Trace:\n   <TASK>\n   dump_stack_lvl+0x43/0x60\n   print_report+0xcf/0x640\n   kasan_report+0xa6/0xd0\n   __blk_rq_map_sg+0x18f/0x7c0\n   virtblk_prep_rq.isra.0+0x215/0x6a0 [virtio_blk 19a65eeee9ae6fcf02edfad39bb9ddee07dcdaff]\n   virtio_queue_rqs+0xc4/0x310 [virtio_blk 19a65eeee9ae6fcf02edfad39bb9ddee07dcdaff]\n   blk_mq_flush_plug_list.part.0+0x780/0x860\n   __blk_flush_plug+0x1ba/0x220\n   blk_finish_plug+0x3b/0x60\n   submit_initial_group_read+0x10a/0x290 [btrfs e57987a360bed82fe8756dcd3e0de5406ccfe965]\n   flush_scrub_stripes+0x38e/0x430 [btrfs e57987a360bed82fe8756dcd3e0de5406ccfe965]\n   scrub_stripe+0x82a/0xae0 [btrfs e57987a360bed82fe8756dcd3e0de5406ccfe965]\n   scrub_chunk+0x178/0x200 [btrfs e57987a360bed82fe8756dcd3e0de5406ccfe965]\n   scrub_enumerate_chunks+0x4bc/0xa30 [btrfs e57987a360bed82fe8756dcd3e0de5406ccfe965]\n   btrfs_scrub_dev+0x398/0x810 [btrfs e57987a360bed82fe8756dcd3e0de5406ccfe965]\n   btrfs_ioctl+0x4b9/0x3020 [btrfs e57987a360bed82fe8756dcd3e0de5406ccfe965]\n   __x64_sys_ioctl+0xbd/0x100\n   do_syscall_64+0x5d/0xe0\n   entry_SYSCALL_64_after_hwframe+0x63/0x6b\n  RIP: 0033:0x7f47e5e0952b\n\n- Crash, mostly due to above use-after-free\n\n[CAUSE]\nThe converted fs has the following data chunk layout:\n\n    item 2 key (FIRST_CHUNK_TREE CHUNK_ITEM 2214658048) itemoff 16025 itemsize 80\n        length 86016 owner 2 stripe_len 65536 type DATA|single\n\nFor above logical bytenr 2214744064, it's at the chunk end\n(2214658048 + 86016 = 2214744064).\n\nThis means btrfs_submit_bio() would split the bio, and trigger endio\nfunction for both of the two halves.\n\nHowever scrub_submit_initial_read() would only expect the endio function\nto be called once, not any more.\nThis means the first endio function would already free the bbio::bio,\nleaving the bvec freed, thus the 2nd endio call would lead to\nuse-after-free.\n\n[FIX]\n- Make sure scrub_read_endio() only updates bits in its range\n  Since we may read less than 64K at the end of the chunk, we should not\n  touch the bits beyond chunk boundary.\n\n- Make sure scrub_submit_initial_read() only to read the chunk range\n  This is done by calculating the real number of sectors we need to\n  read, and add sector-by-sector to the bio.\n\nThankfully the scrub read repair path won't need extra fixes:\n\n- scrub_stripe_submit_repair_read()\n  With above fixes, we won't update error bit for range beyond chunk,\n  thus scrub_stripe_submit_repair_read() should never submit any read\n  beyond the chunk.","provenance":"source","from":"CVE.org"},"cvss":null,"epss":{"score":0.00317,"percentile":0.17042,"provenance":"source"},"cwes":[],"references":[{"url":"https://git.kernel.org/stable/c/642b9c520ef2f104277ad1f902f8526edbe087fb","tags":[]},{"url":"https://git.kernel.org/stable/c/34de0f04684ec00c093a0455648be055f0e8e24f","tags":[]},{"url":"https://git.kernel.org/stable/c/f546c4282673497a06ecb6190b50ae7f6c85b02f","tags":[]}],"priority":{"score":3.4,"factors":[{"name":"EPSS percentile","points":3.41}]},"vendorSlug":"linux","affectedVersions":[{"vendor":"Linux","product":"Linux","versions":[">= e02ee89baa66c40e1002cf8b09141fce7265e0f5, < 642b9c520ef2f104277ad1f902f8526edbe087fb",">= e02ee89baa66c40e1002cf8b09141fce7265e0f5, < 34de0f04684ec00c093a0455648be055f0e8e24f",">= e02ee89baa66c40e1002cf8b09141fce7265e0f5, < f546c4282673497a06ecb6190b50ae7f6c85b02f"]},{"vendor":"Linux","product":"Linux","versions":["6.4"]}],"ssvc":{"exploitation":"none","automatable":"no","technicalImpact":"partial","timestamp":"2024-09-10T15:57:14.247460Z","from":"CISA ADP","provenance":"source"},"euvd":{"id":"EUVD-2024-23878","exploited":false,"provenance":"source"}}