# CVE-2024-50217: btrfs: fix use-after-free of block device file in __btrfs_free_extra_devids()

CVE-2024-50217 is fixed in linux on 1 platform, first by DEBIAN-CVE-2024-50217, released November 9, 2024. It is not reported as exploited. Patch Radar priority: High.

- Web page: https://patchblox.com/security/cve/CVE-2024-50217
- Priority: High
- CVSS: 7.8 (Important)
- EPSS: 0.0028
- CISA KEV: not listed
- Exploited (vendor report): no
- Publicly disclosed: no
- Published: Nov 9, 2024
- Weakness: Use After Free
- Vendor advisory: https://msrc.microsoft.com/update-guide/vulnerability/CVE-2024-50217

## Description

In the Linux kernel, the following vulnerability has been resolved:  btrfs: fix use-after-free of block device file in __btrfs_free_extra_devids()  Mounting btrfs from two images (which have the same one fsid and two different dev_uuids) in certain executing order may trigger an UAF for variable 'device->bdev_file' in __btrfs_free_extra_devids(). And following are the details:  1. Attach image_1 to loop0, attach image_2 to loop1, and scan btrfs    devices by ioctl(BTRFS_IOC_SCAN_DEV):               /  btrfs_device_1 → loop0    fs_device              \  btrfs_device_2 → loop1 2. mount /dev/loop0 /mnt    btrfs_open_devices     btrfs_device_1->bdev_file = btrfs_get_bdev_and_sb(loop0)     btrfs_device_2->bdev_file = btrfs_get_bdev_and_sb(loop1)    btrfs_fill_super     open_ctree      fail: btrfs_close_devices // -ENOMEM 	    btrfs_close_bdev(btrfs_device_1)              fput(btrfs_device_1->bdev_file) 	      // btrfs_device_1->bdev_file is freed 	    btrfs_close_bdev(btrfs_device_2)              fput(btrfs_device_2->bdev_file)  3. mount /dev/loop1 /mnt    btrfs_open_devices     btrfs_get_bdev_and_sb(&bdev_file)      // EIO, btrfs_device_1->bdev_file is not assigned,      // which points to a freed memory area     btrfs_device_2->bdev_file = btrfs_get_bdev_and_sb(loop1)    btrfs_fill_super     open_ctree      btrfs_free_extra_devids       if (btrfs_device_1->bdev_file)        fput(btrfs_device_1->bdev_file) // UAF !  Fix it by setting 'device->bdev_file' as 'NULL' after closing the btrfs_device in btrfs_close_one_device().

## Where it's fixed

| Platform | Product | Fixed in | Fix | Released |
|---|---|---|---|---|
| Linux | linux Debian 13.5 (trixie) | 6.11.7-1 | [DEBIAN-CVE-2024-50217](https://patchblox.com/security/data/fix/linux/debian-cve-2024-50217.md) | Nov 9, 2024 |
| Linux | linux Debian 14 | 6.11.7-1 | [DEBIAN-CVE-2024-50217](https://patchblox.com/security/data/fix/linux/debian-cve-2024-50217.md) | Nov 9, 2024 |

---

Data as of 2026-11-08T19:12:23Z UTC. Source: Patchblox Patch Radar (https://patchblox.com/security/patch-radar). Patchblox finds out-of-date software on Windows, macOS and Linux and updates it through release rings: https://patchblox.com/demo

Free to use with attribution: show "Data: Patchblox Patch Radar" with a link to https://patchblox.com/security/patch-radar. Terms, including what needs a written agreement: https://patchblox.com/security/patch-radar/use-the-data

Product names, logos and trademarks shown on Patch Radar belong to their respective owners. They are used only to identify the software each security fix applies to and to help readers find their platform. Their use does not imply any affiliation with, or endorsement by, those owners, and Patchblox is not affiliated with any of them.
