44f318a38d
Porting patches from grub2_2.06-3~deb11u1 to fix below CVEs: CVE-2021-3695 CVE-2021-3696 CVE-2021-3697 CVE-2022-28733 CVE-2022-28734 The source code of grub2_2.06-3~deb11u1 is from: https://snapshot.debian.org/archive/debian/20220807T030023Z/pool /main/g/grub2/grub2_2.06-3~deb11u1.debian.tar.xz The relationship between commits and CVEs is as below: (1)CVE-2021-3695 commit <video/readers/png: Drop greyscale support to fix heap out-of-bounds write> (2)CVE-2021-3696 commit <video/readers/png: Avoid heap OOB R/W inserting huff table items> (3)CVE-2021-3697 commit <video/readers/jpeg: Block int underflow -> wild pointer write> (4)CVE-2022-28733 commit <net/ip: Do IP fragment maths safely> (5)CVE-2022-28734 commit <net/http: Fix OOB write for split http headers> commit <net/http: Error out on headers with LF without CR> Test plan: - PASS: build grub2/grub-efi. - PASS: build-image and install and boot up on lab/qemu. - PASS: check that the "stx.N" version number is right for both bios(grub2 ver) and uefi(grub-efi ver) boot. Partial-Bug: #2034119 Signed-off-by: Li Zhou <li.zhou@windriver.com> Change-Id: Ia27b1ee225f13e9c4ad08a0828f93ea37f8d3dfb
80 lines
2.6 KiB
Diff
80 lines
2.6 KiB
Diff
From a10c2350a766f9b315735931a49499a7e2c77bf3 Mon Sep 17 00:00:00 2001
|
|
From: Daniel Axtens <dja@axtens.net>
|
|
Date: Mon, 4 Sep 2023 16:32:43 +0800
|
|
Subject: [PATCH 3/6] video/readers/jpeg: Block int underflow -> wild pointer
|
|
write
|
|
|
|
Certain 1 px wide images caused a wild pointer write in
|
|
grub_jpeg_ycrcb_to_rgb(). This was caused because in grub_jpeg_decode_data(),
|
|
we have the following loop:
|
|
|
|
for (; data->r1 < nr1 && (!data->dri || rst);
|
|
data->r1++, data->bitmap_ptr += (vb * data->image_width - hb * nc1) * 3)
|
|
|
|
We did not check if vb * width >= hb * nc1.
|
|
|
|
On a 64-bit platform, if that turns out to be negative, it will underflow,
|
|
be interpreted as unsigned 64-bit, then be added to the 64-bit pointer, so
|
|
we see data->bitmap_ptr jump, e.g.:
|
|
|
|
0x6180_0000_0480 to
|
|
0x6181_0000_0498
|
|
^
|
|
~--- carry has occurred and this pointer is now far away from
|
|
any object.
|
|
|
|
On a 32-bit platform, it will decrement the pointer, creating a pointer
|
|
that won't crash but will overwrite random data.
|
|
|
|
Catch the underflow and error out.
|
|
|
|
Fixes: CVE-2021-3697
|
|
|
|
Signed-off-by: Daniel Axtens <dja@axtens.net>
|
|
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
[lz: Adapt the patch for context changes]
|
|
Signed-off-by: Li Zhou <li.zhou@windriver.com>
|
|
---
|
|
grub-core/video/readers/jpeg.c | 10 +++++++++-
|
|
1 file changed, 9 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c
|
|
index 0eeea0e..fdaef18 100644
|
|
--- a/grub-core/video/readers/jpeg.c
|
|
+++ b/grub-core/video/readers/jpeg.c
|
|
@@ -23,6 +23,7 @@
|
|
#include <grub/mm.h>
|
|
#include <grub/misc.h>
|
|
#include <grub/bufio.h>
|
|
+#include <grub/safemath.h>
|
|
|
|
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
@@ -643,6 +644,7 @@ static grub_err_t
|
|
grub_jpeg_decode_data (struct grub_jpeg_data *data)
|
|
{
|
|
unsigned c1, vb, hb, nr1, nc1;
|
|
+ unsigned stride_a, stride_b, stride;
|
|
int rst = data->dri;
|
|
|
|
vb = 8 << data->log_vs;
|
|
@@ -654,8 +656,14 @@ grub_jpeg_decode_data (struct grub_jpeg_data *data)
|
|
return grub_error(GRUB_ERR_BAD_FILE_TYPE,
|
|
"jpeg: attempted to decode data before start of stream");
|
|
|
|
+ if (grub_mul(vb, data->image_width, &stride_a) ||
|
|
+ grub_mul(hb, nc1, &stride_b) ||
|
|
+ grub_sub(stride_a, stride_b, &stride))
|
|
+ return grub_error (GRUB_ERR_BAD_FILE_TYPE,
|
|
+ "jpeg: cannot decode image with these dimensions");
|
|
+
|
|
for (; data->r1 < nr1 && (!data->dri || rst);
|
|
- data->r1++, data->bitmap_ptr += (vb * data->image_width - hb * nc1) * 3)
|
|
+ data->r1++, data->bitmap_ptr += stride * 3)
|
|
for (c1 = 0; c1 < nc1 && (!data->dri || rst);
|
|
c1++, rst--, data->bitmap_ptr += hb * 3)
|
|
{
|
|
--
|
|
2.17.1
|
|
|