module: decompress: check return value of module_extend_max_pages()
Subsystems (2)
PATCH v2 1/1 module: decompress: check return value of module_extend_max_pages()
module_extend_max_pages() calls kvrealloc() internally and returns -ENOMEM on allocation failure. The return value is never checked. The decompression loop then continues calling module_get_next_page(), which writes struct page pointers into info->pages[]. When used_pages reaches the stale max_pages value (not updated due to the failed extend), a subsequent write to info->pages[used_pages++] goes out of bounds into adjacent heap memory.
Adjacent slab objects in the same kmalloc cache (pipe_buffer, seq_operations, cred) can be corrupted, potentially leading to local privilege escalation on kernels without SLAB_VIRTUAL mitigation.
The call order in finit_module() is:
module_decompress() <- vulnerable, runs FIRST
load_module()
module_sig_check() <- signature check, runs SECOND
Decompression happens before signature verification. A crafted compressed module submitted via finit_module(MODULE_INIT_COMPRESSED_FILE) reaches this code path before any signature gate is applied. On kernels with module.sig_enforce=0 (default without SecureBoot) or with unprivileged user namespaces (Ubuntu, Debian default), this is reachable without CAP_SYS_MODULE.
Confirmed present in mainline (tested on v6.14-rc3).
Fix: add the missing error check after module_extend_max_pages() and return immediately on failure. This matches the pattern used by every other kvrealloc() caller in the module loading path.
---
Changes in v2:
- Remove unnecessary initialization of 'error' to 0 (Christophe Leroy)
- Remove unrelated blank line after if (error) return error (Christophe Leroy)
kernel/module/decompress.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/module/decompress.c +0 -0
@@ -XXX,9 +XXX,12 @@ int module_decompress(struct load_info *info, const void *buf, size_t size) { unsigned int n_pages;int error;ssize_t data_size; n_pages =DIV_ROUND_UP (size,PAGE_SIZE ) *2 ; error =module_extend_max_pages (info, n_pages); +if (error) +return error; data_size =MODULE_DECOMPRESS_FN (info, buf, size);if (data_size <0 ) { error = data_size; --
2.39.0
Le 18/05/2026 à 16:32, Andrii Kuchmenko a écrit :
Quoted 65 lines
[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
module_extend_max_pages()callskvrealloc()internally and returns-ENOMEMon allocation failure. The return value is never checked. The decompression loop then continues callingmodule_get_next_page(), which writes struct page pointers into info->pages[]. Whenused_pagesreaches the stalemax_pagesvalue (not updated due to the failed extend), a subsequent write to info->pages[used_pages++] goes out of bounds into adjacent heap memory.Adjacent slab objects in the same kmalloc cache (
pipe_buffer,seq_operations, cred) can be corrupted, potentially leading to local privilege escalation on kernels withoutSLAB_VIRTUALmitigation.The call order in
finit_module()is:
module_decompress()<- vulnerable, runs FIRST
load_module()
module_sig_check()<- signature check, runs SECONDDecompression happens before signature verification. A crafted compressed module submitted via
finit_module(MODULE_INIT_COMPRESSED_FILE)reaches this code path before any signature gate is applied. On kernels with module.sig_enforce=0 (default without SecureBoot) or with unprivileged user namespaces (Ubuntu, Debian default), this is reachable withoutCAP_SYS_MODULE.Confirmed present in mainline (tested on v6.14-rc3).
Fix: add the missing error check after
module_extend_max_pages()and return immediately on failure. This matches the pattern used by every otherkvrealloc()caller in the module loading path.Fixes 169a58ad824d ("module: add in-kernel support for decompressing")Cc Dmitry Torokhov <[email protected]>Cc Luis Chamberlain <[email protected]>Signed-off-by Andrii Kuchmenko <[email protected]>---
Changes in v2:
- Remove unnecessary initialization of 'error' to 0 (Christophe Leroy)
- Remove unrelated blank line after if (error) return error (Christophe Leroy)kernel/module/decompress.c | 3 +++ 1 file changed, 3 insertions(+)kernel/module/decompress.c +0
-0@@ -XXX,9 +XXX,12 @@ int module_decompress(struct
load_info*info,
const void *buf,size_tsize){ unsigned int n_pages; int error; ssize_t data_size; n_pages = DIV_ROUND_UP(size, PAGE_SIZE) * 2; error = module_extend_max_pages(info, n_pages);kernel/module/decompress.c +2
-1+if (error) +return error; data_size =MODULE_DECOMPRESS_FN (info, buf, size);if (data_size <0 ) { error = data_size; --2.39.0
Christophe Leroy (CS GROUP)
Reviewed-byLooks like something went wrong with that reponse, so let's try again:
Le 18/05/2026 à 18:21, Christophe Leroy (CS GROUP) a écrit :
Quoted 70 lines
Le 18/05/2026 à 16:32, Andrii Kuchmenko a écrit :
Quoted 65 lines
[Vous ne recevez pas souvent de courriers de [email protected]. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
module_extend_max_pages()callskvrealloc()internally and returns-ENOMEMon allocation failure. The return value is never checked. The decompression loop then continues callingmodule_get_next_page(), which writes struct page pointers into info->pages[]. Whenused_pagesreaches the stalemax_pagesvalue (not updated due to the failed extend), a subsequent write to info->pages[used_pages++] goes out of bounds into adjacent heap memory.Adjacent slab objects in the same kmalloc cache (
pipe_buffer,seq_operations, cred) can be corrupted, potentially leading to local privilege escalation on kernels withoutSLAB_VIRTUALmitigation.The call order in
finit_module()is:module_decompress() <- vulnerable, runs FIRST
load_module()
module_sig_check() <- signature check, runs SECONDDecompression happens before signature verification. A crafted compressed module submitted via
finit_module(MODULE_INIT_COMPRESSED_FILE)reaches this code path before any signature gate is applied. On kernels with module.sig_enforce=0 (default without SecureBoot) or with unprivileged user namespaces (Ubuntu, Debian default), this is reachable withoutCAP_SYS_MODULE.Confirmed present in mainline (tested on v6.14-rc3).
Fix: add the missing error check after
module_extend_max_pages()and return immediately on failure. This matches the pattern used by every otherkvrealloc()caller in the module loading path.Fixes 169a58ad824d ("module: add in-kernel support for decompressing")Cc Dmitry Torokhov <[email protected]>Cc Luis Chamberlain <[email protected]>Signed-off-by Andrii Kuchmenko <[email protected]>---
Changes in v2:
- Remove unnecessary initialization of 'error' to 0 (Christophe Leroy)
- Remove unrelated blank line after if (error) return error (Christophe Leroy)
kernel/module/decompress.c| 3 +++1 file changed, 3 insertions(+)kernel/module/decompress.c +0
-0@@ -XXX,9 +XXX,12 @@ int
module_decompress(struct load_info *info, const void *buf, size_t size){
unsigned intn_pages;
int error;
ssize_tdata_size;
n_pages=DIV_ROUND_UP(size, PAGE_SIZE)* 2; error =module_extend_max_pages(info, n_pages); + if (error)
+ return error;
data_size=MODULE_DECOMPRESS_FN(info, buf, size); if (data_size< 0) {
error =data_size;Signature · 1 line
2.39.0
Sami Tolvanen
maintainerHi Andrii,
Quoted 2 lines · Andrii Kuchmenko
module_extend_max_pages()callskvrealloc()internally and returns-ENOMEMon allocation failure. The return value is never checked.
We should definitely fix this, but I'm not sure the rest of the commit message is entirely accurate.
Quoted 9 lines
The decompression loop then continues calling
module_get_next_page(), which writes struct page pointers into info->pages[]. Whenused_pagesreaches the stalemax_pagesvalue (not updated due to the failed extend), a subsequent write to info->pages[used_pages++] goes out of bounds into adjacent heap memory.Adjacent slab objects in the same kmalloc cache (
pipe_buffer,seq_operations, cred) can be corrupted, potentially leading to local privilege escalation on kernels withoutSLAB_VIRTUALmitigation.
Looking at the code:
- struct load_info info is zero-initialized in init_module_from_file().
- If module_extend_max_pages() fails, info->pages remains NULL and info->max_pages and info->used_pages both remain 0.
- module_get_next_page() sees info->max_pages == info->used_pages immediately and calls module_extend_max_pages(info, 0).
- kvrealloc() is called with a size of 0 and it returns ZERO_SIZE_PTR.
- Because ZERO_SIZE_PTR != NULL, module_extend_max_pages() sets info->pages to ZERO_SIZE_PTR and returns 0.
- module_get_next_page() writes to info->pages[info->used_pages++], and the write to ZERO_SIZE_PTR results in an immediate oops.
This isn't great, but I do not see a potential for an out-of-bounds write or slab corruption in this specific case. What am I missing?
Sami
A message that is not in the archive (sent off-list or not yet received): CAEABq7f3agKZqrBiu+UwXHY44mTcK360ryg-i0w=wEc_Lv+T0A@mail.gmail.com
Sami Tolvanen
maintainerQuoted 4 lines · On Tue, May 19, 2026 at 9:11 PM Afi0 <[email protected]> wrote:
Hi,
You are right, the commit message overstates the impact. The actual result is an immediate kernel oops, not an OOB write into adjacent slab objects. The fix is still correct - checking the return value avoids the oops. Shall I send a v3 with a corrected commit message?
Yes, please send v3.
Sami
Thanks for the correction. Updated commit message
Quoted 13 lines · Sami Tolvanen
Quoted 4 lines · On Tue, May 19, 2026 at 9:11 PM Afi0 <[email protected]> wrote:
Hi,
You are right, the commit message overstates the impact. The actual
result is an immediate kernel oops, not an OOB write into adjacent slab objects. The fix is still correct - checking the return value avoids the oops. Shall I send a v3 with a corrected commit message?
Yes, please send v3.
Sami
Le 20/05/2026 à 18:05, Afi0 a écrit :
Quoted 1 line
Thanks for the correction. Updated commit message
Please follow kernel rules:
- Mails in plain text, not Mime
- Patches as part of core text, no attachment
- Your real name, not Afi0 <[email protected]>
- No top-posting
See:
- https://docs.kernel.org/process/submitting-patches.html#use-trimmed-interleaved-replies-in-email-discussions
- https://docs.kernel.org/process/submitting-patches.html#no-mime-no-links-no-compression-no-attachments-just-plain-text
Christophe
Quoted 18 lines · On Wed, May 20, 2026 at 3:13 PM Sami Tolvanen <[email protected]…
On Tue, May 19, 2026 at 9:11 PM Afi0 <[email protected] <mailto:[email protected]>> wrote:
>
> Hi,
>
> You are right, the commit message overstates the impact. The
actual result is an immediate kernel oops, not an OOB write into adjacent slab objects. The fix is still correct - checking the return value avoids the oops. Shall I send a v3 with a corrected commit message?Yes, please send v3.
Sami
Quoted 1 line · On Wed, May 20, 2026 at 04:05:11PM +0000, Afi0 wrote:
Thanks for the correction. Updated commit message
Please follow submitting-patches instructions next time. I used the v3 commit message and changed the Fixes tag hash to point to the correct commit.
Applied to modules-next, thanks!
[1/1] module: decompress: check return value of module_extend_max_pages()
commit: 3537d8d21112c2fc664cc09895bbef01fa64d34f
Best regards,
Sami