mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] module/decompress: fix kunmap_local() address in gzip path
@ 2026-11-29 18:26 Markus Rankl via B4 Relay
  0 siblings, 0 replies; only message in thread
From: Markus Rankl via B4 Relay @ 2026-11-29 18:26 UTC (permalink / raw)
  To: Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen, Aaron Tomlin
  Cc: Fabio M. De Francesco, linux-modules, linux-kernel, stable, Markus Rankl

From: Markus Rankl <markus.rankl@mesutronic.de>

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@vger.kernel.org
Signed-off-by: Markus Rankl <markus.rankl@mesutronic.de>
---
 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@mesutronic.de>



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-29 18:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 18:26 [PATCH] module/decompress: fix kunmap_local() address in gzip path Markus Rankl via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®