[drivers][block][efi] Fix GPT partition entry underflow vulnerability

Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-19 12:22:26 +00:00
parent 8576d0177f
commit 185ca043d9

View File

@@ -454,9 +454,13 @@ _fail:
*/ */
rt_inline rt_bool_t is_pte_valid(const gpt_entry *pte, const rt_size_t lastlba) rt_inline rt_bool_t is_pte_valid(const gpt_entry *pte, const rt_size_t lastlba)
{ {
rt_uint64_t start = rt_le64_to_cpu(pte->starting_lba);
rt_uint64_t end = rt_le64_to_cpu(pte->ending_lba);
if ((!efi_guidcmp(pte->partition_type_guid, NULL_GUID)) || if ((!efi_guidcmp(pte->partition_type_guid, NULL_GUID)) ||
rt_le64_to_cpu(pte->starting_lba) > lastlba || start > lastlba ||
rt_le64_to_cpu(pte->ending_lba) > lastlba) end > lastlba ||
end < start)
{ {
return RT_FALSE; return RT_FALSE;
} }