Skip to content

Commit

Permalink
coreboot patches: remove lib/jpeg patches for heap increase and alloc…
Browse files Browse the repository at this point in the history
… failure. Add https://review.coreboot.org/c/coreboot/+/83895

Repro:
git fetch https://review.coreboot.org/coreboot refs/changes/95/83895/3 && git format-patch -1 --stdout FETCH_HEAD > patches/coreboot-24.02.01/0001-lib_jpeg-avoidcalling-malloc-and-free.patch
cp patches/coreboot-24.02.01/0001-lib_jpeg-avoidcalling-malloc-and-free.patch patches/coreboot-system76-unreleased/0001-lib_jpeg-avoidcalling-malloc-and-free.patch
sed -i 's/CONFIG_HEAP_SIZE=0x400000/CONFIG_HEAP_SIZE=0x100000/g' config/coreboot-*

Signed-off-by: Thierry Laurion <[email protected]>
  • Loading branch information
tlaurion committed Sep 11, 2024
1 parent 753e1e6 commit 127e5df
Show file tree
Hide file tree
Showing 29 changed files with 206 additions and 192 deletions.
2 changes: 1 addition & 1 deletion config/coreboot-galp5.config
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-librem_11.config
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-librem_13v2.config
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-librem_13v4.config
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-librem_14.config
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-librem_15v3.config
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-librem_15v4.config
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-librem_l1um_v2.config
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-librem_mini.config
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-librem_mini_v2.config
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-qemu-tpm1.config
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-qemu-tpm2.config
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-t420-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-t430-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-t440p.config
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-t530-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-w530-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-w541.config
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x220-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x230-legacy-flash.config
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x230-legacy.config
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x230-maximized-fhd_edp.config
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x230-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-z220-cmt.config
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ CONFIG_NO_EARLY_GFX_INIT=y
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
CONFIG_BOOTSPLASH=y
CONFIG_HEAP_SIZE=0x400000
CONFIG_HEAP_SIZE=0x100000
# end of Display

CONFIG_PCI=y
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
From efad423f8472c1b9c130842e3d92625500f82d5d Mon Sep 17 00:00:00 2001
From: Nigel Tao <[email protected]>
Date: Tue, 13 Aug 2024 22:29:21 +1000
Subject: [PATCH] lib/jpeg: avoid calling malloc and free

Since commit 1d029b40c9de ("lib/jpeg: Replace decoder with Wuffs'
implementation"), a relatively large heap allocation is needed to decode
many JPEGs for use as work area. The prior decoder did not need this,
but also had many limitations in the JPEGs it could decode, was not as
memory-safe and quickly crashed under fuzzing.

This commit keeps using Wuffs' JPEG decoder, but it no longer requires
any heap allocation (and thus configuring the heap size depending on how
big a bootsplash image you want to support).

Change-Id: Ie4c52520cbce498539517c4898ff765365a6beba
Signed-off-by: Nigel Tao <[email protected]>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/83895
Tested-by: build bot (Jenkins) <[email protected]>
Reviewed-by: Nico Huber <[email protected]>
Reviewed-by: Felix Singer <[email protected]>
Reviewed-by: Jonathon Hall <[email protected]>
---
src/lib/jpeg.c | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/lib/jpeg.c b/src/lib/jpeg.c
index 242cf0ca8e..617ab0b22a 100644
--- a/src/lib/jpeg.c
+++ b/src/lib/jpeg.c
@@ -1,9 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */

/*
- * Provide a simple API around the Wuffs JPEG decoder
- * Uses the heap (and lots of it) for the image-size specific
- * work buffer, so ramstage-only.
+ * Provide a simple API around the Wuffs JPEG decoder.
*/

#include <stdint.h>
@@ -85,6 +83,24 @@ int jpeg_decode(unsigned char *filedata, size_t filesize, unsigned char *pic,
return JPEG_DECODE_FAILED;
}

+ /* Opting in to lower quality means that we can pass an empty slice as the
+ * "work buffer" argument to wuffs_jpeg__decoder__decode_frame below.
+ *
+ * Decoding progressive (not sequential) JPEGs would still require dynamic
+ * memory allocation (and the amount of work buffer required depends on the
+ * image dimensions), but we choose to just reject progressive JPEGs. It is
+ * simpler than sometimes calling malloc (which can fail, especially for
+ * large allocations) and free.
+ *
+ * More commentary about these quirks is at
+ * https://github.com/google/wuffs/blob/beaf45650085a16780b5f708b72daaeb1aa865c8/std/jpeg/decode_quirks.wuffs
+ */
+ wuffs_jpeg__decoder__set_quirk(
+ &dec, WUFFS_BASE__QUIRK_QUALITY,
+ WUFFS_BASE__QUIRK_QUALITY__VALUE__LOWER_QUALITY);
+ wuffs_jpeg__decoder__set_quirk(
+ &dec, WUFFS_JPEG__QUIRK_REJECT_PROGRESSIVE_JPEGS, 1);
+
wuffs_base__image_config imgcfg;
wuffs_base__io_buffer src = wuffs_base__ptr_u8__reader(filedata, filesize, true);
status = wuffs_jpeg__decoder__decode_image_config(&dec, &imgcfg, &src);
@@ -104,19 +120,9 @@ int jpeg_decode(unsigned char *filedata, size_t filesize, unsigned char *pic,
return JPEG_DECODE_FAILED;
}

- uint64_t workbuf_len_min_incl = wuffs_jpeg__decoder__workbuf_len(&dec).min_incl;
- uint8_t *workbuf_array = malloc(workbuf_len_min_incl);
- if ((workbuf_array == NULL) && workbuf_len_min_incl) {
- return JPEG_DECODE_FAILED;
- }
-
- wuffs_base__slice_u8 workbuf =
- wuffs_base__make_slice_u8(workbuf_array, workbuf_len_min_incl);
status = wuffs_jpeg__decoder__decode_frame(&dec, &pixbuf, &src,
- WUFFS_BASE__PIXEL_BLEND__SRC, workbuf, NULL);
-
- free(workbuf_array);
-
+ WUFFS_BASE__PIXEL_BLEND__SRC,
+ wuffs_base__empty_slice_u8(), NULL);
if (status.repr) {
return JPEG_DECODE_FAILED;
}
--
2.39.2

This file was deleted.

Loading

0 comments on commit 127e5df

Please sign in to comment.