diff options
| author | Marta Rybczynska <rybczynska@gmail.com> | 2022-02-18 11:05:26 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-03-02 00:21:37 +0000 |
| commit | 40d7b770308a4fb349665b52c63f02520857d09e (patch) | |
| tree | 343b249f3ebc4e079ac51639d5bea1ce1ab5f239 | |
| parent | b854e27c584ea746b6274d3c69b9d6346afe38ed (diff) | |
| download | poky-40d7b770308a4fb349665b52c63f02520857d09e.tar.gz | |
grub: fix a memory leak
Add a fix for a memory leak in grub'd 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: eb899a83bab5ab12143bd75a96427fa7615f2a6e)
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>
| -rw-r--r-- | meta/recipes-bsp/grub/files/0018-disk-ldm-Fix-memory-leak-on-uninserted-lv-references.patch | 50 | ||||
| -rw-r--r-- | meta/recipes-bsp/grub/grub2.inc | 1 |
2 files changed, 51 insertions, 0 deletions
diff --git a/meta/recipes-bsp/grub/files/0018-disk-ldm-Fix-memory-leak-on-uninserted-lv-references.patch b/meta/recipes-bsp/grub/files/0018-disk-ldm-Fix-memory-leak-on-uninserted-lv-references.patch new file mode 100644 index 0000000000..26932f674c --- /dev/null +++ b/meta/recipes-bsp/grub/files/0018-disk-ldm-Fix-memory-leak-on-uninserted-lv-references.patch | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | From 3e1d2f1959acbe5152cdd5818d495f6455d1a158 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Darren Kenny <darren.kenny@oracle.com> | ||
| 3 | Date: Tue, 8 Dec 2020 10:00:51 +0000 | ||
| 4 | Subject: [PATCH] disk/ldm: Fix memory leak on uninserted lv references | ||
| 5 | |||
| 6 | The problem here is that the memory allocated to the variable lv is not | ||
| 7 | yet inserted into the list that is being processed at the label fail2. | ||
| 8 | |||
| 9 | As we can already see at line 342, which correctly frees lv before going | ||
| 10 | to fail2, we should also be doing that at these earlier jumps to fail2. | ||
| 11 | |||
| 12 | Fixes: CID 73824 | ||
| 13 | |||
| 14 | Signed-off-by: Darren Kenny <darren.kenny@oracle.com> | ||
| 15 | Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> | ||
| 16 | |||
| 17 | Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/grub.git/commit/?id=156c281a1625dc73fd350530630c6f2d5673d4f6] | ||
| 18 | Signed-off-by: Marta Rybczynska <marta.rybczynska@huawei.com> | ||
| 19 | --- | ||
| 20 | grub-core/disk/ldm.c | 10 ++++++++-- | ||
| 21 | 1 file changed, 8 insertions(+), 2 deletions(-) | ||
| 22 | |||
| 23 | diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c | ||
| 24 | index 54713f4..e82e989 100644 | ||
| 25 | --- a/grub-core/disk/ldm.c | ||
| 26 | +++ b/grub-core/disk/ldm.c | ||
| 27 | @@ -321,7 +321,10 @@ make_vg (grub_disk_t disk, | ||
| 28 | lv->visible = 1; | ||
| 29 | lv->segments = grub_zalloc (sizeof (*lv->segments)); | ||
| 30 | if (!lv->segments) | ||
| 31 | - goto fail2; | ||
| 32 | + { | ||
| 33 | + grub_free (lv); | ||
| 34 | + goto fail2; | ||
| 35 | + } | ||
| 36 | lv->segments->start_extent = 0; | ||
| 37 | lv->segments->type = GRUB_DISKFILTER_MIRROR; | ||
| 38 | lv->segments->node_count = 0; | ||
| 39 | @@ -329,7 +332,10 @@ make_vg (grub_disk_t disk, | ||
| 40 | lv->segments->nodes = grub_calloc (lv->segments->node_alloc, | ||
| 41 | sizeof (*lv->segments->nodes)); | ||
| 42 | if (!lv->segments->nodes) | ||
| 43 | - goto fail2; | ||
| 44 | + { | ||
| 45 | + grub_free (lv); | ||
| 46 | + goto fail2; | ||
| 47 | + } | ||
| 48 | ptr = vblk[i].dynamic; | ||
| 49 | if (ptr + *ptr + 1 >= vblk[i].dynamic | ||
| 50 | + sizeof (vblk[i].dynamic)) | ||
diff --git a/meta/recipes-bsp/grub/grub2.inc b/meta/recipes-bsp/grub/grub2.inc index a8ee0dd68a..2fccdc2d62 100644 --- a/meta/recipes-bsp/grub/grub2.inc +++ b/meta/recipes-bsp/grub/grub2.inc | |||
| @@ -64,6 +64,7 @@ SRC_URI = "${GNU_MIRROR}/grub/grub-${PV}.tar.gz \ | |||
| 64 | file://0015-kern-partition-Check-for-NULL-before-dereferencing-i.patch \ | 64 | file://0015-kern-partition-Check-for-NULL-before-dereferencing-i.patch \ |
| 65 | file://0016-disk-ldm-Make-sure-comp-data-is-freed-before-exiting.patch \ | 65 | file://0016-disk-ldm-Make-sure-comp-data-is-freed-before-exiting.patch \ |
| 66 | file://0017-disk-ldm-If-failed-then-free-vg-variable-too.patch \ | 66 | file://0017-disk-ldm-If-failed-then-free-vg-variable-too.patch \ |
| 67 | file://0018-disk-ldm-Fix-memory-leak-on-uninserted-lv-references.patch \ | ||
| 67 | " | 68 | " |
| 68 | SRC_URI[md5sum] = "5ce674ca6b2612d8939b9e6abed32934" | 69 | SRC_URI[md5sum] = "5ce674ca6b2612d8939b9e6abed32934" |
| 69 | SRC_URI[sha256sum] = "f10c85ae3e204dbaec39ae22fa3c5e99f0665417e91c2cb49b7e5031658ba6ea" | 70 | SRC_URI[sha256sum] = "f10c85ae3e204dbaec39ae22fa3c5e99f0665417e91c2cb49b7e5031658ba6ea" |
