From: Zbigniew Jędrzejewski-Szmek Date: Wed, 9 Jul 2025 21:02:28 +0000 (+0200) Subject: ukify: fix version detection for aarch64 zboot kernels with gzip or lzma compression X-Git-Tag: v258-rc1~124 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=85830b0d62ac215952774cf07157c113f2f92cae;p=thirdparty%2Fsystemd.git ukify: fix version detection for aarch64 zboot kernels with gzip or lzma compression Fixes https://github.com/systemd/systemd/issues/34780. The number in the header is the size of the *compressed* data, so for gzip we'd read the initial part of the decompressed data (equal to the size of the compressed data) and not find the version string. Later on, Fedora switched to zstd compression, and there we correctly use the number as the size of the compressed data, so we stopped hitting the issue, but we should still fix it for older kernels. I verified that the fix works for gzip-compressed kernels. I also made the same change for the code for lzma compression. I'm pretty sure it is the right thing, even though I don't have such a kernel at hand to test. >>> ukify.Uname.scrape('/lib/modules/6.12.0-0.rc2.24.fc42.aarch64/vmlinuz') Real-Mode Kernel Header magic not found + readelf --notes /lib/modules/6.12.0-0.rc2.24.fc42.aarch64/vmlinuz readelf: Error: Not an ELF file - it has the wrong magic bytes at the start Found uname version: 6.12.0-0.rc2.24.fc42.aarch64 --- diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index c5cf21cde98..5bbe9b1ea68 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -183,20 +183,24 @@ def get_zboot_kernel(f: IO[bytes]) -> bytes: f.seek(start) if comp_type.startswith(b'gzip'): gzip = try_import('gzip') - return cast(bytes, gzip.open(f).read(size)) + data = f.read(size) + return cast(bytes, gzip.decompress(data)) elif comp_type.startswith(b'lz4'): lz4 = try_import('lz4.frame', 'lz4') - return cast(bytes, lz4.frame.decompress(f.read(size))) + data = f.read(size) + return cast(bytes, lz4.frame.decompress(data)) elif comp_type.startswith(b'lzma'): lzma = try_import('lzma') - return cast(bytes, lzma.open(f).read(size)) + data = f.read(size) + return cast(bytes, lzma.decompress(data)) elif comp_type.startswith(b'lzo'): raise NotImplementedError('lzo decompression not implemented') elif comp_type.startswith(b'xzkern'): raise NotImplementedError('xzkern decompression not implemented') elif comp_type.startswith(b'zstd'): zstd = try_import('zstandard') - return cast(bytes, zstd.ZstdDecompressor().stream_reader(f.read(size)).read()) + data = f.read(size) + return cast(bytes, zstd.ZstdDecompressor().stream_reader(data).read()) raise NotImplementedError(f'unknown compressed type: {comp_type!r}')