From: Alec Brown Date: Wed, 22 Jan 2025 02:55:10 +0000 (+0000) Subject: disk: Prevent overflows when allocating memory for arrays X-Git-Tag: archive/raspbian/2.12-8+rpi1^2~27 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=40f6bb71d2358cd5bd29258ce6557bfa6984331d;p=grub2.git disk: Prevent overflows when allocating memory for arrays Use grub_calloc() when allocating memory for arrays to ensure proper overflow checks are in place. Signed-off-by: Alec Brown Reviewed-by: Daniel Kiper Conflicts: grub-core/disk/cryptodisk.c Gbp-Pq: Topic cve-2025-jan Gbp-Pq: Name disk-Prevent-overflows-when-allocating-memory-for-arrays.patch --- diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c index 8535d5a..03e2ed6 100644 --- a/grub-core/disk/lvm.c +++ b/grub-core/disk/lvm.c @@ -671,8 +671,7 @@ grub_lvm_detect (grub_disk_t disk, goto lvs_segment_fail; } - seg->nodes = grub_zalloc (sizeof (seg->nodes[0]) - * seg->node_count); + seg->nodes = grub_calloc (seg->node_count, sizeof (seg->nodes[0])); p = grub_strstr (p, "mirrors = ["); if (p == NULL) @@ -760,8 +759,7 @@ grub_lvm_detect (grub_disk_t disk, } } - seg->nodes = grub_zalloc (sizeof (seg->nodes[0]) - * seg->node_count); + seg->nodes = grub_calloc (seg->node_count, sizeof (seg->nodes[0])); p = grub_strstr (p, "raids = ["); if (p == NULL)