Просмотр исходного кода

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

Co-authored-by: BernardXiong <1241087+BernardXiong@users.noreply.github.com>
copilot-swe-agent[bot] 8 часов назад
Родитель
Сommit
185ca043d9
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      components/drivers/block/partitions/efi.c

+ 6 - 2
components/drivers/block/partitions/efi.c

@@ -454,9 +454,13 @@ _fail:
  */
 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)) ||
-        rt_le64_to_cpu(pte->starting_lba) > lastlba ||
-        rt_le64_to_cpu(pte->ending_lba) > lastlba)
+        start > lastlba ||
+        end > lastlba ||
+        end < start)
     {
         return RT_FALSE;
     }