[BUG] module: compressed-module decoders accept incomplete or invalid integrity data
From: Puranam, Ananta Srikar
Date: Wed Nov 11 2026 - 01:10:54 EST
Hi,
I'm Ananta Srikar Puranam, a PhD student at Washington State University.
I'm reporting this bug on behalf of my team: Dr. Swarn Priya and
Dr. Basavesh Ammanaghatta Shivakumar (both Cc'd).
With CONFIG_MODULE_DECOMPRESS, finit_module() with
MODULE_INIT_COMPRESSED_FILE loads a gzip-compressed module whose CRC32
is wrong or whose trailer is truncated, and a zstd-compressed module
whose frame checksum is truncated. The gzip and zstd command-line
tools reject the same files.
Trigger
=======
One minimal external module, compressed once per codec, and variants
that change only the integrity data:
gzip-control the module gzip-compressed at level 9,
single member
gzip-bad-crc32 control with the low bit of the first
CRC32 byte flipped
gzip-incomplete-trailer control with the last byte (end of ISIZE)
removed
zstd-control zstd -19 --check of the module, one frame
zstd-incomplete-checksum control with the last byte of the 4-byte
content checksum removed
Each file is loaded with finit_module(fd, "", MODULE_INIT_COMPRESSED_FILE);
an accepted module is then removed with delete_module().
Observed (current mainline, x86_64)
===================================
gzip kernel, every case loads and unloads:
case=gzip-control.bin load=0 errno=0 after=1 unload=0 cleanup=0
case=gzip-bad-crc32.bin load=0 errno=0 after=1 unload=0 cleanup=0
case=gzip-incomplete-trailer.bin load=0 errno=0 after=1 unload=0 cleanup=0
zstd kernel:
case=zstd-control.bin load=0 errno=0 after=1 unload=0 cleanup=0
case=zstd-incomplete-checksum.bin load=0 errno=0 after=1 unload=0 cleanup=0
(load is the finit_module() return value; after=1 means the module is
listed in /proc/modules; cleanup=0 means it is gone after unload. The
loader's before=0 and unload_errno=0 fields are omitted.)
For every case, dmesg shows only the module's own init and exit
messages (plus the out-of-tree taint notice on the first load):
compressed_repro: loaded
compressed_repro: unloaded
There is no decompression error, warning, or oops.
The same files on the host:
$ gzip -t gzip-bad-crc32.bin
gzip: gzip-bad-crc32.bin: invalid compressed data--crc error
$ gzip -t gzip-incomplete-trailer.bin
gzip: gzip-incomplete-trailer.bin: unexpected end of file
$ zstd -t zstd-incomplete-checksum.bin
zstd-incomplete-checksum.bin : Read error (39) : premature end
gzip -t and zstd -t accept both control files.
Tested
======
- Mainline 067c5c24cef2 ("Merge tag 'page_alloc-for-7.4-rc2' ..."),
7.4.0-rc2-g067c5c24cef2, x86_64 under KVM, one kernel per codec:
gzip: bad CRC32 and truncated trailer loaded in 3/3 boots;
control loaded in 3/3
zstd: truncated checksum loaded in 3/3 boots; control loaded
in 3/3
Each accepted module was unloaded and absent afterwards.
Cause
=====
In kernel/module/decompress.c, module_gzip_decompress() skips the gzip
header itself and inflates the payload as raw DEFLATE:
rc = zlib_inflateInit2(&s, -MAX_WBITS);
and returns success as soon as inflate reports the end of the DEFLATE
stream:
if (rc != Z_STREAM_END) {
pr_err("decompression failed with status %d\n", rc);
retval = -EINVAL;
goto out_inflate_end;
}
retval = new_size;
With negative window bits zlib does not process the gzip wrapper, and
nothing reads the 8-byte CRC32/ISIZE trailer that follows the DEFLATE
data, so a wrong or missing trailer is not noticed.
module_zstd_decompress() loops with:
} while (zstd_dec.pos == PAGE_SIZE && ret != 0);
and afterwards only checks whether zstd_decompress_stream() returned an
error. A nonzero, non-error return means the frame is not finished,
for example because checksum bytes are still expected. When the last
call fills less than a page the loop exits, that return value is never
checked, and the function reports success.
The gzip path was introduced by:
b1ae6dc41eaa ("module: add in-kernel support for decompressing")
which is in v5.17-rc1 and later, and the zstd path by:
169a58ad824d ("module/decompress: Support zstd in-kernel decompression")
which is in v6.2-rc1 and later.
Impact
======
Triggering requires CONFIG_MODULE_DECOMPRESS and permission to load a
module (CAP_SYS_MODULE). I observed modules loading from compressed
files that fail their format's own integrity check, not a crash,
memory corruption, or an unprivileged boundary crossing. With module
signing the signature is checked on the decompressed image, so this
does not bypass signature verification; I tested with signing
disabled. Per Documentation/process/threat-model.rst I am treating
this as a correctness and integrity-checking bug, not a vulnerability.
Setup
=====
Host: Ubuntu 26.04.1 LTS, x86_64
Toolchain: Ubuntu GCC 15.2.0 / GNU ld 2.46 (built with O=)
Config: x86_64_defconfig plus kernel/configs/kvm_guest.config
plus
CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_MODULE_COMPRESS=y
CONFIG_MODULE_COMPRESS_GZIP=y (or _ZSTD=y)
CONFIG_MODULE_DECOMPRESS=y
# CONFIG_MODULE_SIG is not set
(resolved with olddefconfig; full .config available)
Module: minimal out-of-tree GPL module, built with M= against
the same build tree; the compressed files are produced
on the host from that .ko
Host tools: gzip 1.14, zstd v1.5.7
QEMU: qemu-system-x86_64 10.2.1 with KVM, -smp 16 -m 8G
Guest: Ubuntu 26.04 amd64 rootfs (debootstrap); cases loaded
over SSH by a small static loader that calls
finit_module() and delete_module(), with dmesg read
after each load
The source reproducer (module, case generator and QEMU wrapper) is
available privately on request. Per
Documentation/process/security-bugs.rst I have not posted it to the
list.
Possible fix
============
The gzip path could check the CRC32 and ISIZE in the trailer against
the decompressed output after Z_STREAM_END, and the zstd path could
require that zstd_decompress_stream() returned 0 (frame complete)
before reporting success. I have not written or tested a patch.
Tool transparency
=================
The root-cause analysis and original reproducer were prepared with the
help of an AI coding assistant (OpenAI Codex). The QEMU/KVM
reproduction environment and the reproducer used for the results above
were set up with Anthropic's Claude Code. I re-ran the reproduction
myself and have checked the statements in this report.
Thanks,
Srikar