In the Linux kernel, the following vulnerability has been resolved:
btrfs: fix use-after-free of block device file in _btrfsfreeextradevids()
Mounting btrfs from two images (which have the same one fsid and two different devuuids) in certain executing order may trigger an UAF for variable 'device->bdevfile' in _btrfsfreeextradevids(). And following are the details:
Attach image1 to loop0, attach image2 to loop1, and scan btrfs devices by ioctl(BTRFSIOCSCAN_DEV):
/ btrfs_device_1 → loop0
fsdevice \ btrfsdevice_2 → loop1
mount /dev/loop0 /mnt btrfsopendevices btrfsdevice1->bdevfile = btrfsgetbdevandsb(loop0) btrfsdevice2->bdevfile = btrfsgetbdevandsb(loop1) btrfsfillsuper openctree fail: btrfsclosedevices // -ENOMEM btrfsclosebdev(btrfsdevice1) fput(btrfsdevice1->bdevfile) // btrfsdevice1->bdevfile is freed btrfsclosebdev(btrfsdevice2) fput(btrfsdevice2->bdevfile)
mount /dev/loop1 /mnt btrfsopendevices btrfsgetbdevandsb(&bdevfile) // EIO, btrfsdevice1->bdevfile is not assigned, // which points to a freed memory area btrfsdevice2->bdevfile = btrfsgetbdevandsb(loop1) btrfsfillsuper openctree btrfsfreeextradevids if (btrfsdevice1->bdevfile) fput(btrfsdevice1->bdev_file) // UAF !
Fix it by setting 'device->bdevfile' as 'NULL' after closing the btrfsdevice in btrfscloseone_device().
{ "vanir_signatures": [ { "target": { "file": "fs/btrfs/volumes.c" }, "id": "CVE-2024-50217-c5c379ca", "signature_version": "v1", "digest": { "threshold": 0.9, "line_hashes": [ "80197728822733529507344794873192326895", "216341432441198476954662525294647799977", "84925743656828138964908150628747828749", "22132915072198052714898835685045499416" ] }, "deprecated": false, "signature_type": "Line", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@47a83f8df39545f3f552bb6a1b6d9c30e37621dd" }, { "target": { "file": "fs/btrfs/volumes.c", "function": "btrfs_close_one_device" }, "id": "CVE-2024-50217-d1d79ce4", "signature_version": "v1", "digest": { "length": 1121.0, "function_hash": "340102414517912206790538772477314714605" }, "deprecated": false, "signature_type": "Function", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@47a83f8df39545f3f552bb6a1b6d9c30e37621dd" } ] }