mirror of
https://git.yoctoproject.org/poky
synced 2026-06-03 13:49:49 +00:00
grub: fix a memory leak
Add a fix for a memory leak in grub's disk/ldm. It is a part of a security series [1]. [1] https://lists.gnu.org/archive/html/grub-devel/2021-03/msg00007.html (From OE-Core rev: 9fa41d5fbd1de899d1242c31d427262cd041d47c) Signed-off-by: Marta Rybczynska <marta.rybczynska@huawei.com> Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
90b1d407c6
commit
da4ba2d04e
+128
@@ -0,0 +1,128 @@
|
|||||||
|
From 0c5d0fd796e6cafba179321de396681a493c4158 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Marco A Benatto <mbenatto@redhat.com>
|
||||||
|
Date: Mon, 7 Dec 2020 11:53:03 -0300
|
||||||
|
Subject: [PATCH] disk/ldm: Make sure comp data is freed before exiting from
|
||||||
|
make_vg()
|
||||||
|
|
||||||
|
Several error handling paths in make_vg() do not free comp data before
|
||||||
|
jumping to fail2 label and returning from the function. This will leak
|
||||||
|
memory. So, let's fix all issues of that kind.
|
||||||
|
|
||||||
|
Fixes: CID 73804
|
||||||
|
|
||||||
|
Signed-off-by: Marco A Benatto <mbenatto@redhat.com>
|
||||||
|
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
||||||
|
|
||||||
|
Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/grub.git/commit/?id=23e39f50ca7a107f6b66396ed4d177a914dee035]
|
||||||
|
Signed-off-by: Marta Rybczynska <marta.rybczynska@huawei.com>
|
||||||
|
---
|
||||||
|
grub-core/disk/ldm.c | 51 ++++++++++++++++++++++++++++++++++++++------
|
||||||
|
1 file changed, 44 insertions(+), 7 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c
|
||||||
|
index 58f8a53..428415f 100644
|
||||||
|
--- a/grub-core/disk/ldm.c
|
||||||
|
+++ b/grub-core/disk/ldm.c
|
||||||
|
@@ -554,7 +554,11 @@ make_vg (grub_disk_t disk,
|
||||||
|
comp->segments = grub_calloc (comp->segment_alloc,
|
||||||
|
sizeof (*comp->segments));
|
||||||
|
if (!comp->segments)
|
||||||
|
- goto fail2;
|
||||||
|
+ {
|
||||||
|
+ grub_free (comp->internal_id);
|
||||||
|
+ grub_free (comp);
|
||||||
|
+ goto fail2;
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@@ -562,7 +566,11 @@ make_vg (grub_disk_t disk,
|
||||||
|
comp->segment_count = 1;
|
||||||
|
comp->segments = grub_malloc (sizeof (*comp->segments));
|
||||||
|
if (!comp->segments)
|
||||||
|
- goto fail2;
|
||||||
|
+ {
|
||||||
|
+ grub_free (comp->internal_id);
|
||||||
|
+ grub_free (comp);
|
||||||
|
+ goto fail2;
|
||||||
|
+ }
|
||||||
|
comp->segments->start_extent = 0;
|
||||||
|
comp->segments->extent_count = lv->size;
|
||||||
|
comp->segments->layout = 0;
|
||||||
|
@@ -574,15 +582,26 @@ make_vg (grub_disk_t disk,
|
||||||
|
comp->segments->layout = GRUB_RAID_LAYOUT_SYMMETRIC_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
- goto fail2;
|
||||||
|
+ {
|
||||||
|
+ grub_free (comp->segments);
|
||||||
|
+ grub_free (comp->internal_id);
|
||||||
|
+ grub_free (comp);
|
||||||
|
+ goto fail2;
|
||||||
|
+ }
|
||||||
|
ptr += *ptr + 1;
|
||||||
|
ptr++;
|
||||||
|
if (!(vblk[i].flags & 0x10))
|
||||||
|
- goto fail2;
|
||||||
|
+ {
|
||||||
|
+ grub_free (comp->segments);
|
||||||
|
+ grub_free (comp->internal_id);
|
||||||
|
+ grub_free (comp);
|
||||||
|
+ goto fail2;
|
||||||
|
+ }
|
||||||
|
if (ptr >= vblk[i].dynamic + sizeof (vblk[i].dynamic)
|
||||||
|
|| ptr + *ptr + 1 >= vblk[i].dynamic
|
||||||
|
+ sizeof (vblk[i].dynamic))
|
||||||
|
{
|
||||||
|
+ grub_free (comp->segments);
|
||||||
|
grub_free (comp->internal_id);
|
||||||
|
grub_free (comp);
|
||||||
|
goto fail2;
|
||||||
|
@@ -592,6 +611,7 @@ make_vg (grub_disk_t disk,
|
||||||
|
if (ptr + *ptr + 1 >= vblk[i].dynamic
|
||||||
|
+ sizeof (vblk[i].dynamic))
|
||||||
|
{
|
||||||
|
+ grub_free (comp->segments);
|
||||||
|
grub_free (comp->internal_id);
|
||||||
|
grub_free (comp);
|
||||||
|
goto fail2;
|
||||||
|
@@ -601,7 +621,12 @@ make_vg (grub_disk_t disk,
|
||||||
|
comp->segments->nodes = grub_calloc (comp->segments->node_alloc,
|
||||||
|
sizeof (*comp->segments->nodes));
|
||||||
|
if (!lv->segments->nodes)
|
||||||
|
- goto fail2;
|
||||||
|
+ {
|
||||||
|
+ grub_free (comp->segments);
|
||||||
|
+ grub_free (comp->internal_id);
|
||||||
|
+ grub_free (comp);
|
||||||
|
+ goto fail2;
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lv->segments->node_alloc == lv->segments->node_count)
|
||||||
|
@@ -611,11 +636,23 @@ make_vg (grub_disk_t disk,
|
||||||
|
|
||||||
|
if (grub_mul (lv->segments->node_alloc, 2, &lv->segments->node_alloc) ||
|
||||||
|
grub_mul (lv->segments->node_alloc, sizeof (*lv->segments->nodes), &sz))
|
||||||
|
- goto fail2;
|
||||||
|
+ {
|
||||||
|
+ grub_free (comp->segments->nodes);
|
||||||
|
+ grub_free (comp->segments);
|
||||||
|
+ grub_free (comp->internal_id);
|
||||||
|
+ grub_free (comp);
|
||||||
|
+ goto fail2;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
t = grub_realloc (lv->segments->nodes, sz);
|
||||||
|
if (!t)
|
||||||
|
- goto fail2;
|
||||||
|
+ {
|
||||||
|
+ grub_free (comp->segments->nodes);
|
||||||
|
+ grub_free (comp->segments);
|
||||||
|
+ grub_free (comp->internal_id);
|
||||||
|
+ grub_free (comp);
|
||||||
|
+ goto fail2;
|
||||||
|
+ }
|
||||||
|
lv->segments->nodes = t;
|
||||||
|
}
|
||||||
|
lv->segments->nodes[lv->segments->node_count].pv = 0;
|
||||||
@@ -62,6 +62,7 @@ SRC_URI = "${GNU_MIRROR}/grub/grub-${PV}.tar.gz \
|
|||||||
file://0013-io-lzopio-Resolve-unnecessary-self-assignment-errors.patch \
|
file://0013-io-lzopio-Resolve-unnecessary-self-assignment-errors.patch \
|
||||||
file://0014-zstd-Initialize-seq_t-structure-fully.patch \
|
file://0014-zstd-Initialize-seq_t-structure-fully.patch \
|
||||||
file://0015-kern-partition-Check-for-NULL-before-dereferencing-i.patch \
|
file://0015-kern-partition-Check-for-NULL-before-dereferencing-i.patch \
|
||||||
|
file://0016-disk-ldm-Make-sure-comp-data-is-freed-before-exiting.patch \
|
||||||
"
|
"
|
||||||
SRC_URI[md5sum] = "5ce674ca6b2612d8939b9e6abed32934"
|
SRC_URI[md5sum] = "5ce674ca6b2612d8939b9e6abed32934"
|
||||||
SRC_URI[sha256sum] = "f10c85ae3e204dbaec39ae22fa3c5e99f0665417e91c2cb49b7e5031658ba6ea"
|
SRC_URI[sha256sum] = "f10c85ae3e204dbaec39ae22fa3c5e99f0665417e91c2cb49b7e5031658ba6ea"
|
||||||
|
|||||||
Reference in New Issue
Block a user