]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ukify: fix version detection for aarch64 zboot kernels with gzip or lzma compression
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 9 Jul 2025 21:02:28 +0000 (23:02 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 10 Jul 2025 04:37:07 +0000 (13:37 +0900)
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

src/ukify/ukify.py

index c5cf21cde983c0b5f500f464a3a59dacbe7ae254..5bbe9b1ea68b3d21346c520c6f690a812df13dda 100755 (executable)
@@ -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}')