|
|
8e15ce |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
8e15ce |
From: Colin Watson <cjwatson@debian.org>
|
|
|
8e15ce |
Date: Fri, 24 Jul 2020 17:18:09 +0100
|
|
|
8e15ce |
Subject: [PATCH] efilinux: Fix integer overflows in grub_cmd_initrd
|
|
|
8e15ce |
|
|
|
8e15ce |
These could be triggered by an extremely large number of arguments to
|
|
|
8e15ce |
the initrd command on 32-bit architectures, or a crafted filesystem with
|
|
|
8e15ce |
very large files on any architecture.
|
|
|
8e15ce |
|
|
|
8e15ce |
Signed-off-by: Colin Watson <cjwatson@debian.org>
|
|
|
8e15ce |
---
|
|
|
8e15ce |
grub-core/loader/i386/efi/linux.c | 10 ++++++++--
|
|
|
8e15ce |
1 file changed, 8 insertions(+), 2 deletions(-)
|
|
|
8e15ce |
|
|
|
8e15ce |
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
|
|
|
b35c50 |
index 15d40d6e35..f992ceeef2 100644
|
|
|
8e15ce |
--- a/grub-core/loader/i386/efi/linux.c
|
|
|
8e15ce |
+++ b/grub-core/loader/i386/efi/linux.c
|
|
|
8e15ce |
@@ -28,6 +28,8 @@
|
|
|
8e15ce |
#include <grub/efi/efi.h>
|
|
|
8e15ce |
#include <grub/efi/linux.h>
|
|
|
8e15ce |
#include <grub/cpu/efi/memory.h>
|
|
|
8e15ce |
+#include <grub/tpm.h>
|
|
|
8e15ce |
+#include <grub/safemath.h>
|
|
|
8e15ce |
|
|
|
8e15ce |
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
8e15ce |
|
|
|
8e15ce |
@@ -206,7 +208,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
|
|
8e15ce |
goto fail;
|
|
|
8e15ce |
}
|
|
|
8e15ce |
|
|
|
8e15ce |
- files = grub_zalloc (argc * sizeof (files[0]));
|
|
|
8e15ce |
+ files = grub_calloc (argc, sizeof (files[0]));
|
|
|
8e15ce |
if (!files)
|
|
|
8e15ce |
goto fail;
|
|
|
8e15ce |
|
|
|
8e15ce |
@@ -216,7 +218,11 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
|
|
|
8e15ce |
if (! files[i])
|
|
|
8e15ce |
goto fail;
|
|
|
8e15ce |
nfiles++;
|
|
|
8e15ce |
- size += ALIGN_UP (grub_file_size (files[i]), 4);
|
|
|
8e15ce |
+ if (grub_add (size, ALIGN_UP (grub_file_size (files[i]), 4), &size))
|
|
|
8e15ce |
+ {
|
|
|
8e15ce |
+ grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow is detected"));
|
|
|
8e15ce |
+ goto fail;
|
|
|
8e15ce |
+ }
|
|
|
8e15ce |
}
|
|
|
8e15ce |
|
|
|
8e15ce |
initrd_mem = kernel_alloc(size, N_("can't allocate initrd"));
|