{"id":"CVE-2024-50217","published":"2024-11-09T10:14:28Z","modified":"2026-08-05T11:42:34Z","title":"btrfs: fix use-after-free of block device file in __btrfs_free_extra_devids()","vendor":"Linux","product":"Linux","tier":"tail","description":{"text":"In the Linux kernel, the following vulnerability has been resolved:\n\nbtrfs: fix use-after-free of block device file in __btrfs_free_extra_devids()\n\nMounting btrfs from two images (which have the same one fsid and two\ndifferent dev_uuids) in certain executing order may trigger an UAF for\nvariable 'device->bdev_file' in __btrfs_free_extra_devids(). And\nfollowing are the details:\n\n1. Attach image_1 to loop0, attach image_2 to loop1, and scan btrfs\n   devices by ioctl(BTRFS_IOC_SCAN_DEV):\n\n             /  btrfs_device_1 → loop0\n   fs_device\n             \\  btrfs_device_2 → loop1\n2. mount /dev/loop0 /mnt\n   btrfs_open_devices\n    btrfs_device_1->bdev_file = btrfs_get_bdev_and_sb(loop0)\n    btrfs_device_2->bdev_file = btrfs_get_bdev_and_sb(loop1)\n   btrfs_fill_super\n    open_ctree\n     fail: btrfs_close_devices // -ENOMEM\n\t    btrfs_close_bdev(btrfs_device_1)\n             fput(btrfs_device_1->bdev_file)\n\t      // btrfs_device_1->bdev_file is freed\n\t    btrfs_close_bdev(btrfs_device_2)\n             fput(btrfs_device_2->bdev_file)\n\n3. mount /dev/loop1 /mnt\n   btrfs_open_devices\n    btrfs_get_bdev_and_sb(&bdev_file)\n     // EIO, btrfs_device_1->bdev_file is not assigned,\n     // which points to a freed memory area\n    btrfs_device_2->bdev_file = btrfs_get_bdev_and_sb(loop1)\n   btrfs_fill_super\n    open_ctree\n     btrfs_free_extra_devids\n      if (btrfs_device_1->bdev_file)\n       fput(btrfs_device_1->bdev_file) // UAF !\n\nFix it by setting 'device->bdev_file' as 'NULL' after closing the\nbtrfs_device in btrfs_close_one_device().","provenance":"source","from":"CVE.org"},"cvss":{"score":7.8,"severity":"HIGH","version":"3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","provenance":"source","from":"CVE.org CNA"},"epss":{"score":0.00278,"percentile":0.20735,"provenance":"source"},"cwes":[{"id":"CWE-416","name":"Use After Free"}],"references":[{"url":"https://git.kernel.org/stable/c/47a83f8df39545f3f552bb6a1b6d9c30e37621dd","tags":[]},{"url":"https://git.kernel.org/stable/c/aec8e6bf839101784f3ef037dcdb9432c3f32343","tags":[]},{"url":"http://www.openwall.com/lists/oss-security/2025/04/10/4","tags":[]},{"url":"http://www.openwall.com/lists/oss-security/2025/04/10/5","tags":[]},{"url":"http://www.openwall.com/lists/oss-security/2025/04/10/6","tags":[]}],"priority":{"score":9.6,"factors":[{"name":"EPSS percentile","points":4.15},{"name":"CVSS severity","points":5.46}]},"vendorSlug":"linux","affectedVersions":[{"vendor":"Linux","product":"Linux","versions":[">= 142388194191a3edc9ba01cfcfd8b691e0971fb2, < 47a83f8df39545f3f552bb6a1b6d9c30e37621dd",">= 142388194191a3edc9ba01cfcfd8b691e0971fb2, < aec8e6bf839101784f3ef037dcdb9432c3f32343"]},{"vendor":"Linux","product":"Linux","versions":["4.8"]}],"ssvc":{"exploitation":"none","automatable":"no","technicalImpact":"total","timestamp":"2024-12-11T14:25:44.077787Z","from":"CISA ADP","provenance":"source"},"euvd":{"id":"EUVD-2024-45154","exploited":false,"provenance":"source"}}