abootimg: Fix gzip decompressed kernel size passed to load_image() - #15
Conversation
gzip_decompress() was discarding the out_consumed return value from miniz_oxide's decompress(), leaving FastbootBuffer::len set to the full 128 MiB allocation. load_image() then passed that oversized buffer to UEFI's LoadImage, causing it to fail with LOAD_ERROR since the trailing zeroes don't constitute a valid PE image. Fix by returning out_consumed from gzip_decompress() and updating kernel.len to the actual decompressed size before calling load_image(). It fixes the failure below seen on qcs9100-ride when booting Image.gz built into abootimg. Dev_Common_Speed: Dev Bus Speed: Super, state 2 Allocated E18000 bytes Response: DATA00E18000 (12) Response: OKAY (4) kernel: 0xBA5780@0x1000 ramdisk: 0x240224@0xBA7000 dtb: 0x2FBDC@0xDE8000 ERROR: Encountered NULL ImageContext Error: Failed to load kernel image Fixes: 87a7388 ("abootimg: Implement decompress") Signed-off-by: Shawn Guo <shengchao.guo@oss.qualcomm.com>
Hm, interesting.. I've been running GZ-compressed kernels for quite a while and haven't seen this issue. May it be that I just got lucky.. Do you have CONFIG_EFI(_STUB)=y? |
Yes, I have the options. |
|
FWIW the PR looks good, but for reference could you do Here's one that didn't: |
|
Here is the one that failed. |
|
I don't know for sure and I don't really want to spend more time digging, but.. I would guesstimate that my image having the section table (starts with seems like that's a combination of CONFIG_EFI_DEBUG=n and CONFIG_ARM64_BTI_KERNEL=y that makes it be aligned like this |
gzip_decompress() was discarding the out_consumed return value from miniz_oxide's decompress(), leaving FastbootBuffer::len set to the full 128 MiB allocation. load_image() then passed that oversized buffer to UEFI's LoadImage, causing it to fail with LOAD_ERROR since the trailing zeroes don't constitute a valid PE image.
Fix by returning out_consumed from gzip_decompress() and updating kernel.len to the actual decompressed size before calling load_image().
It fixes the failure below seen on qcs9100-ride when booting Image.gz built into abootimg.
Dev_Common_Speed: Dev Bus Speed: Super, state 2
Allocated E18000 bytes
Response: DATA00E18000 (12)
Response: OKAY (4)
kernel: 0xBA5780@0x1000
ramdisk: 0x240224@0xBA7000
dtb: 0x2FBDC@0xDE8000
ERROR: Encountered NULL ImageContext
Error: Failed to load kernel image
Fixes: 87a7388 ("abootimg: Implement decompress")