nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0380-video-readers-jpeg-Catch-OOB-reads-writes-in-grub_jp.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
9723a8
From: Daniel Axtens <dja@axtens.net>
9723a8
Date: Fri, 15 Jan 2021 13:29:53 +1100
9723a8
Subject: [PATCH] video/readers/jpeg: Catch OOB reads/writes in
9723a8
 grub_jpeg_decode_du()
9723a8
9723a8
The key line is:
9723a8
9723a8
  du[jpeg_zigzag_order[pos]] = val * (int) data->quan_table[qt][pos];
9723a8
9723a8
jpeg_zigzag_order is grub_uint8_t[64].
9723a8
9723a8
I don't understand JPEG decoders quite well enough to explain what's
9723a8
going on here. However, I observe sometimes pos=64, which leads to an
9723a8
OOB read of the jpeg_zigzag_order global then an OOB write to du.
9723a8
That leads to various unpleasant memory corruption conditions.
9723a8
9723a8
Catch where pos >= ARRAY_SIZE(jpeg_zigzag_order) and bail.
9723a8
9723a8
Signed-off-by: Daniel Axtens <dja@axtens.net>
9723a8
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9723a8
---
9723a8
 grub-core/video/readers/jpeg.c | 8 ++++++++
9723a8
 1 file changed, 8 insertions(+)
9723a8
9723a8
diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c
9723a8
index 856573996ac..28c1d62515e 100644
9723a8
--- a/grub-core/video/readers/jpeg.c
9723a8
+++ b/grub-core/video/readers/jpeg.c
9723a8
@@ -526,6 +526,14 @@ grub_jpeg_decode_du (struct grub_jpeg_data *data, int id, jpeg_data_unit_t du)
9723a8
       val = grub_jpeg_get_number (data, num & 0xF);
9723a8
       num >>= 4;
9723a8
       pos += num;
9723a8
+
9723a8
+      if (pos >= ARRAY_SIZE (jpeg_zigzag_order))
9723a8
+	{
9723a8
+	  grub_error (GRUB_ERR_BAD_FILE_TYPE,
9723a8
+		      "jpeg: invalid position in zigzag order!?");
9723a8
+	  return;
9723a8
+	}
9723a8
+
9723a8
       du[jpeg_zigzag_order[pos]] = val * (int) data->quan_table[qt][pos];
9723a8
       pos++;
9723a8
     }