* [PATCH] block: partitions: reject GPT entries with starting_lba > ending_lba
@ 2026-11-02 8:04 Zizhi Wo
2026-11-03 5:34 ` Christoph Hellwig
2026-11-03 14:31 ` Jens Axboe
0 siblings, 2 replies; 5+ messages in thread
From: Zizhi Wo @ 2026-11-02 8:04 UTC (permalink / raw)
To: axboe, bvanassche, hch, yukuai, linux-block
Cc: linux-kernel, yangerkun, chengzhihao1, wozizhi
From: Zizhi Wo <wozizhi@huawei.com>
A GPT entry whose starting_lba is greater than its ending_lba is accepted,
and the kernel creates a partition with a bogus size. The bogus sector
count defeats the end-of-device check, so I/O through that partition is not
confined to it and can access sectors outside the partition on the same
disk.
is_pte_valid() only rejects an entry when its type is NULL or when
starting_lba or ending_lba is greater than lastlba; it never checks that
starting_lba <= ending_lba. For a reversed entry both field checks still
pass, but efi_partition() computes size = ending_lba - starting_lba + 1 in
u64, which underflows to a huge value. That value also wraps in the
end-of-device check in blk_add_partition() (from + size) and does not fit
the signed i_size, which turns negative.
Reject entries with starting_lba > ending_lba in is_pte_valid(), matching
the head-level check against last_usable_lba < first_usable_lba.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
---
block/partitions/efi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index 9865d59093fa..b31227a13db0 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -458,10 +458,11 @@ static int is_gpt_valid(struct parsed_partitions *state, u64 lba,
*/
static inline int
is_pte_valid(const gpt_entry *pte, const u64 lastlba)
{
if ((!efi_guidcmp(pte->partition_type_guid, NULL_GUID)) ||
+ le64_to_cpu(pte->starting_lba) > le64_to_cpu(pte->ending_lba) ||
le64_to_cpu(pte->starting_lba) > lastlba ||
le64_to_cpu(pte->ending_lba) > lastlba)
return 0;
return 1;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] block: partitions: reject GPT entries with starting_lba > ending_lba
2026-11-02 8:04 [PATCH] block: partitions: reject GPT entries with starting_lba > ending_lba Zizhi Wo
@ 2026-11-03 5:34 ` Christoph Hellwig
2026-11-03 6:39 ` Zizhi Wo
2026-11-03 14:31 ` Jens Axboe
1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2026-11-03 5:34 UTC (permalink / raw)
To: Zizhi Wo
Cc: axboe, bvanassche, hch, yukuai, linux-block, linux-kernel,
yangerkun, chengzhihao1, wozizhi
On Mon, Nov 02, 2026 at 04:04:42PM +0800, Zizhi Wo wrote:
> From: Zizhi Wo <wozizhi@huawei.com>
>
> A GPT entry whose starting_lba is greater than its ending_lba is accepted,
> and the kernel creates a partition with a bogus size. The bogus sector
> count defeats the end-of-device check, so I/O through that partition is not
> confined to it and can access sectors outside the partition on the same
> disk.
>
> is_pte_valid() only rejects an entry when its type is NULL or when
> starting_lba or ending_lba is greater than lastlba; it never checks that
> starting_lba <= ending_lba. For a reversed entry both field checks still
> pass, but efi_partition() computes size = ending_lba - starting_lba + 1 in
> u64, which underflows to a huge value. That value also wraps in the
> end-of-device check in blk_add_partition() (from + size) and does not fit
> the signed i_size, which turns negative.
>
> Reject entries with starting_lba > ending_lba in is_pte_valid(), matching
> the head-level check against last_usable_lba < first_usable_lba.
Looks good in general. But should this be a >= to also catch zero-sized
entries?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] block: partitions: reject GPT entries with starting_lba > ending_lba
2026-11-03 5:34 ` Christoph Hellwig
@ 2026-11-03 6:39 ` Zizhi Wo
2026-11-03 6:55 ` Christoph Hellwig
0 siblings, 1 reply; 5+ messages in thread
From: Zizhi Wo @ 2026-11-03 6:39 UTC (permalink / raw)
To: Christoph Hellwig, Zizhi Wo
Cc: axboe, bvanassche, yukuai, linux-block, linux-kernel, yangerkun,
chengzhihao1
在 2026/11/3 13:34, Christoph Hellwig 写道:
> On Mon, Nov 02, 2026 at 04:04:42PM +0800, Zizhi Wo wrote:
>> From: Zizhi Wo <wozizhi@huawei.com>
>>
>> A GPT entry whose starting_lba is greater than its ending_lba is accepted,
>> and the kernel creates a partition with a bogus size. The bogus sector
>> count defeats the end-of-device check, so I/O through that partition is not
>> confined to it and can access sectors outside the partition on the same
>> disk.
>>
>> is_pte_valid() only rejects an entry when its type is NULL or when
>> starting_lba or ending_lba is greater than lastlba; it never checks that
>> starting_lba <= ending_lba. For a reversed entry both field checks still
>> pass, but efi_partition() computes size = ending_lba - starting_lba + 1 in
>> u64, which underflows to a huge value. That value also wraps in the
>> end-of-device check in blk_add_partition() (from + size) and does not fit
>> the signed i_size, which turns negative.
>>
>> Reject entries with starting_lba > ending_lba in is_pte_valid(), matching
>> the head-level check against last_usable_lba < first_usable_lba.
>
> Looks good in general. But should this be a >= to also catch zero-sized
> entries?
>
Thanks. I think > is the correct boundary here because GPT's EndingLBA
is inclusive and efi_partition() computes the size as:
size = le64_to_cpu(ptes[i].ending_lba) -
le64_to_cpu(ptes[i].starting_lba) + 1ULL;
so starting_lba == ending_lba is a valid one-sector partition, not a
zero-sized one?
Thanks,
Zizhi Wo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] block: partitions: reject GPT entries with starting_lba > ending_lba
2026-11-03 6:39 ` Zizhi Wo
@ 2026-11-03 6:55 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2026-11-03 6:55 UTC (permalink / raw)
To: Zizhi Wo
Cc: Christoph Hellwig, axboe, bvanassche, yukuai, linux-block,
linux-kernel, yangerkun, chengzhihao1
Ok. Looks good then:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] block: partitions: reject GPT entries with starting_lba > ending_lba
2026-11-02 8:04 [PATCH] block: partitions: reject GPT entries with starting_lba > ending_lba Zizhi Wo
2026-11-03 5:34 ` Christoph Hellwig
@ 2026-11-03 14:31 ` Jens Axboe
1 sibling, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2026-11-03 14:31 UTC (permalink / raw)
To: bvanassche, hch, yukuai, linux-block, Zizhi Wo
Cc: linux-kernel, yangerkun, chengzhihao1, wozizhi
On Mon, 02 Nov 2026 16:04:42 +0800, Zizhi Wo wrote:
> A GPT entry whose starting_lba is greater than its ending_lba is accepted,
> and the kernel creates a partition with a bogus size. The bogus sector
> count defeats the end-of-device check, so I/O through that partition is not
> confined to it and can access sectors outside the partition on the same
> disk.
>
> is_pte_valid() only rejects an entry when its type is NULL or when
> starting_lba or ending_lba is greater than lastlba; it never checks that
> starting_lba <= ending_lba. For a reversed entry both field checks still
> pass, but efi_partition() computes size = ending_lba - starting_lba + 1 in
> u64, which underflows to a huge value. That value also wraps in the
> end-of-device check in blk_add_partition() (from + size) and does not fit
> the signed i_size, which turns negative.
>
> [...]
Applied, thanks!
[1/1] block: partitions: reject GPT entries with starting_lba > ending_lba
commit: 7e3801d12ebabaa3db6e2685ccc80b6e6f6d1ff7
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-03 14:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-02 8:04 [PATCH] block: partitions: reject GPT entries with starting_lba > ending_lba Zizhi Wo
2026-11-03 5:34 ` Christoph Hellwig
2026-11-03 6:39 ` Zizhi Wo
2026-11-03 6:55 ` Christoph Hellwig
2026-11-03 14:31 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox