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