In the Linux kernel, the following vulnerability has been resolved:
xfs: fix exchange-range-to-eof file size exchange
Norbert Szetei posted a patch containing an incomplete description of a bug in XFS_IOC_EXCHANGE_RANGE's TO_EOF flag. The bug tricks exchange-range into modifying a file so that it has shared blocks starting beyond EOF, which is never allowed because files never have written data beyond EOF, and you can only share written data blocks. This is key to all the incorrect behavior that follows.
Eventually I got from Norbert a description of what's going wrong:
Fair. Here it is with physical block numbers, 4k blocks. peer is the file that gets rewritten and file1 is the one that ends up with the flag cleared.
Start, nothing shared:
peer size 4096 -> [100] file1 size 12288 -> [200] [201] [202] donor1 size 4096 -> [300] donor2 size 4096 -> [400]
- FICLONERANGE peer's block into file1's middle slot:
peer size 4096 -> [100] file1 size 12288 -> [200] [100] [202] reflink flag set ^^^^^ both files own block 100
- XFS_IOC_EXCHANGE_RANGE file1 against donor1, file1_offset 0, file2_offset 8192, length 0, TO_EOF. One block is exchanged, and the sizes are exchanged with it:
file1 size 4096 -> [200] [100] [300] reflink flag set ^^^^^^^^^^^ still owned, now past the size donor1 size 12288 -> [202]
file1 says it is one block long while it still owns three. Nothing was unmapped. file2_offset is block 2, so this exchange cannot clear a flag.
- XFS_IOC_EXCHANGE_RANGE file1 against donor2, both offsets 0, length 4096. By i_disk_size this is two one-block files exchanging everything, so xmi_can_exchange_reflink_flags() agrees and the flag is cleared:
file1 size 4096 -> [400] [100] [300] reflink flag CLEARED donor2 size 4096 -> [200]
Block 100 is still shared with peer.
- pwrite(file1, 4096, 4096), which is file1's second slot,...
Exploitability
AV:LAC:LPR:LUI:NScope
S:UImpact
C:HI:HA:H7.8/CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H