[PATCH] module/decompress: fix kunmap_local() address in gzip path
From: Markus Rankl via B4 Relay
Date: Sun Nov 29 2026 - 13:27:34 EST
From: Markus Rankl <markus.rankl@xxxxxxxxxxxxx>
zlib_inflate() advances s.next_out past the bytes it has written, and
module_gzip_decompress() then passes that pointer to kunmap_local().
kunmap_local() rounds the address down to its page, so this works while
the page is only partly filled. All pages of a module except the last
one are filled completely, though, and s.next_out then points to the
start of the following page.
For a highmem page that address is the neighbouring kmap_local fixmap
slot. kunmap_local_indexed() warns about the mismatch, clears the wrong
PTE and leaves the page mapped, and a later kmap_local_page() on that
slot hits the BUG_ON() in __kmap_local_pfn_prot(). Lowmem pages are not
affected because kunmap_local() does nothing for them.
Seen on a 32-bit ARM board (AM437x, 1 GiB RAM, CONFIG_HIGHMEM) loading
gzip-compressed modules with CONFIG_MODULE_DECOMPRESS:
WARNING: CPU: 0 PID: 224 at mm/highmem.c:623 kunmap_local_indexed+0x17c/0x184
Call trace:
kunmap_local_indexed from module_decompress+0x1ac/0x2d0
module_decompress from init_module_from_file+0xc8/0xe4
init_module_from_file from sys_finit_module+0x13c/0x304
sys_finit_module from ret_fast_syscall+0x0/0x54
...
kernel BUG at mm/highmem.c:565!
PC is at __kmap_local_pfn_prot+0x164/0x168
Unmap the address returned by kmap_local_page(), as the xz and zstd
paths do.
Fixes: 554694ba120b ("module: Replace kmap() with kmap_local_page()")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Markus Rankl <markus.rankl@xxxxxxxxxxxxx>
---
kernel/module/decompress.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c
index cce098671be97513e67c64bc38f0f72c6e790e11..67894a78ccf60c0ae53ea05c883f0ceede413c6d 100644
--- a/kernel/module/decompress.c
+++ b/kernel/module/decompress.c
@@ -113,16 +113,18 @@ static ssize_t module_gzip_decompress(struct load_info *info,
do {
struct page *page = module_get_next_page(info);
+ void *dst;
if (IS_ERR(page)) {
retval = PTR_ERR(page);
goto out_inflate_end;
}
- s.next_out = kmap_local_page(page);
+ dst = kmap_local_page(page);
+ s.next_out = dst;
s.avail_out = PAGE_SIZE;
rc = zlib_inflate(&s, 0);
- kunmap_local(s.next_out);
+ kunmap_local(dst);
new_size += PAGE_SIZE - s.avail_out;
} while (rc == Z_OK);
---
base-commit: 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046
change-id: 20261129-module-decompress-fix-4e215829b31e
Best regards,
--
Markus Rankl <markus.rankl@xxxxxxxxxxxxx>