disk: Prevent overflows when allocating memory for arrays
authorAlec Brown <alec.r.brown@oracle.com>
Wed, 22 Jan 2025 02:55:10 +0000 (02:55 +0000)
committerFelix Zielcke <fzielcke@z-51.de>
Wed, 11 Jun 2025 15:42:34 +0000 (17:42 +0200)
Use grub_calloc() when allocating memory for arrays to ensure proper
overflow checks are in place.

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Conflicts:
grub-core/disk/cryptodisk.c

Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name disk-Prevent-overflows-when-allocating-memory-for-arrays.patch

grub-core/disk/lvm.c

index 8535d5a5863aec24214af45d3dd045863cd6d7ac..03e2ed684daedc347d8548e378a636c5ac31ae28 100644 (file)
@@ -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)