partitions/efi: reject GPT entries with starting_lba > ending_lba - #1043
partitions/efi: reject GPT entries with starting_lba > ending_lba#1043blktests-ci[bot] wants to merge 1 commit into
Conversation
|
Upstream branch: 2d2338c |
c0cc428 to
23d8cf0
Compare
|
Upstream branch: 0d83957 |
1206188 to
f43a58c
Compare
612ae31 to
863d43a
Compare
|
Upstream branch: 06cf618 |
f43a58c to
c2c5e98
Compare
863d43a to
29ac21d
Compare
|
Upstream branch: d58772d |
c2c5e98 to
100ed63
Compare
29ac21d to
ea2c39d
Compare
|
Upstream branch: f5bbbfe |
100ed63 to
d3f02b5
Compare
ea2c39d to
4082a30
Compare
|
Upstream branch: 3d6d817 |
d3f02b5 to
f6c395a
Compare
4082a30 to
36bd7eb
Compare
|
Upstream branch: 3aa1dca |
f6c395a to
28f102e
Compare
d89ab11 to
fdba928
Compare
|
Upstream branch: fd923b3 |
28f102e to
52f3b2f
Compare
fdba928 to
60442a3
Compare
|
Upstream branch: 8d3ae59 |
52f3b2f to
0cfa40f
Compare
60442a3 to
3df366e
Compare
is_pte_valid() checks that both LBAs of a GPT partition entry are within the device, but never that the entry describes a forward range: if ((!efi_guidcmp(pte->partition_type_guid, NULL_GUID)) || le64_to_cpu(pte->starting_lba) > lastlba || le64_to_cpu(pte->ending_lba) > lastlba) return 0; EndingLBA is defined as the last LBA of the partition, so a conforming entry always has StartingLBA <= EndingLBA. A crafted table can invert the two while keeping both within the device, and efi_partition() then computes the length as u64 size = le64_to_cpu(ptes[i].ending_lba) - le64_to_cpu(ptes[i].starting_lba) + 1ULL; which underflows to a value close to U64_MAX. The "extends beyond EOD" clamp in blk_add_partition() does not contain this, because it tests if (from + size > get_capacity(disk)) and from + size wraps for a size of that magnitude, so the sum comes out small, the clamp is skipped and the partition is registered with the underflowed length. From then on bio_check_eod() is evaluated against bdev_nr_sectors() of that partition, i.e. against the bogus length, so I/O submitted through the partition device is no longer confined to the partition and reaches sectors owned by other partitions of the same disk. This was verified on 6.8.12 with a crafted two partition image: the inverted entry is registered as a partition of nearly 2^64 sectors with no "extends beyond EOD" warning, and BLKZEROOUT issued on that partition overwrote known marker data belonging to the other, unrelated partition on the same disk. No privileged step is needed on the victim side beyond getting the table parsed, which happens automatically for removable media on a typical desktop. Reject the inverted range in is_pte_valid(), the single place every GPT entry is gated on. The code has been this way since the beginning of git history. Fixes: 1da177e ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Nguyen Le Thanh Tung <nguyenlethanhtung555@gmail.com>
|
Upstream branch: bd5f485 |
0cfa40f to
b852501
Compare
Pull request for series with
subject: partitions/efi: reject GPT entries with starting_lba > ending_lba
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1134859