* [PATCH v2] module: decompress: check return value of module_extend_max_pages()
@ 2026-05-18 12:18 Andrii Kuchmenko
2026-05-18 12:57 ` Greg KH
0 siblings, 1 reply; 9+ messages in thread
From: Andrii Kuchmenko @ 2026-05-18 12:18 UTC (permalink / raw)
To: linux-modules
Cc: chleroy, mcgrof, dmitry.torokhov, linux-kernel, stable,
Andrii Kuchmenko
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.
Fixes: 169a58ad824d ("module: add in-kernel support for decompressing")
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Andrii Kuchmenko <capyenglishlite@gmail.com>
---
kernel/module/decompress.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c
--- a/kernel/module/decompress.c
+++ b/kernel/module/decompress.c
@@ -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
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v2] module: decompress: check return value of module_extend_max_pages()
2026-05-18 12:18 [PATCH v2] module: decompress: check return value of module_extend_max_pages() Andrii Kuchmenko
@ 2026-05-18 12:57 ` Greg KH
0 siblings, 0 replies; 9+ messages in thread
From: Greg KH @ 2026-05-18 12:57 UTC (permalink / raw)
To: Andrii Kuchmenko
Cc: linux-modules, chleroy, mcgrof, dmitry.torokhov, linux-kernel,
stable
On Mon, May 18, 2026 at 03:18:58PM +0300, Andrii Kuchmenko wrote:
> 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.
>
> Fixes: 169a58ad824d ("module: add in-kernel support for decompressing")
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: Luis Chamberlain <mcgrof@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Andrii Kuchmenko <capyenglishlite@gmail.com>
> ---
> kernel/module/decompress.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c
> --- a/kernel/module/decompress.c
> +++ b/kernel/module/decompress.c
> @@ -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
>
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- This looks like a new version of a previously submitted patch, but you
did not list below the --- line any changes from the previous version.
Please read the section entitled "The canonical patch format" in the
kernel file, Documentation/process/submitting-patches.rst for what
needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] module: decompress: check return value of module_extend_max_pages()
@ 2026-05-18 14:32 Andrii Kuchmenko
2026-05-18 16:21 ` Christophe Leroy (CS GROUP)
2026-05-19 21:23 ` Sami Tolvanen
0 siblings, 2 replies; 9+ messages in thread
From: Andrii Kuchmenko @ 2026-05-18 14:32 UTC (permalink / raw)
To: linux-modules
Cc: chleroy, mcgrof, dmitry.torokhov, linux-kernel, stable,
Andrii Kuchmenko
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.
Fixes: 169a58ad824d ("module: add in-kernel support for decompressing")
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: stable@vger.kernel.org
Signed-off-by: Andrii Kuchmenko <capyenglishlite@gmail.com>
---
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(+)
diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c
--- a/kernel/module/decompress.c
+++ b/kernel/module/decompress.c
@@ -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
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v2] module: decompress: check return value of module_extend_max_pages()
2026-05-18 14:32 Andrii Kuchmenko
@ 2026-05-18 16:21 ` Christophe Leroy (CS GROUP)
2026-05-19 14:56 ` Christophe Leroy (CS GROUP)
2026-05-19 21:23 ` Sami Tolvanen
1 sibling, 1 reply; 9+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-05-18 16:21 UTC (permalink / raw)
To: Andrii Kuchmenko, linux-modules
Cc: mcgrof, dmitry.torokhov, linux-kernel, stable
Le 18/05/2026 à 16:32, Andrii Kuchmenko a écrit :
> [Vous ne recevez pas souvent de courriers de capyenglishlite@gmail.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
>
> 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.
>
> Fixes: 169a58ad824d ("module: add in-kernel support for decompressing")
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: Luis Chamberlain <mcgrof@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Andrii Kuchmenko <capyenglishlite@gmail.com>
> ---
> 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(+)
>
> diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c
> --- a/kernel/module/decompress.c
> +++ b/kernel/module/decompress.c
> @@ -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
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v2] module: decompress: check return value of module_extend_max_pages()
2026-05-18 16:21 ` Christophe Leroy (CS GROUP)
@ 2026-05-19 14:56 ` Christophe Leroy (CS GROUP)
0 siblings, 0 replies; 9+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-05-19 14:56 UTC (permalink / raw)
To: Andrii Kuchmenko, linux-modules
Cc: mcgrof, dmitry.torokhov, linux-kernel, stable
Looks like something went wrong with that reponse, so let's try again:
Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Le 18/05/2026 à 18:21, Christophe Leroy (CS GROUP) a écrit :
>
>
> Le 18/05/2026 à 16:32, Andrii Kuchmenko a écrit :
>> [Vous ne recevez pas souvent de courriers de
>> capyenglishlite@gmail.com. Découvrez pourquoi ceci est important à
>> https://aka.ms/LearnAboutSenderIdentification ]
>>
>> 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.
>>
>> Fixes: 169a58ad824d ("module: add in-kernel support for decompressing")
>> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>> Cc: Luis Chamberlain <mcgrof@kernel.org>
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Andrii Kuchmenko <capyenglishlite@gmail.com>
>> ---
>> 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(+)
>>
>> diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c
>> --- a/kernel/module/decompress.c
>> +++ b/kernel/module/decompress.c
>> @@ -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
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] module: decompress: check return value of module_extend_max_pages()
2026-05-18 14:32 Andrii Kuchmenko
2026-05-18 16:21 ` Christophe Leroy (CS GROUP)
@ 2026-05-19 21:23 ` Sami Tolvanen
[not found] ` <CAEABq7f3agKZqrBiu+UwXHY44mTcK360ryg-i0w=wEc_Lv+T0A@mail.gmail.com>
1 sibling, 1 reply; 9+ messages in thread
From: Sami Tolvanen @ 2026-05-19 21:23 UTC (permalink / raw)
To: Andrii Kuchmenko
Cc: linux-modules, chleroy, mcgrof, dmitry.torokhov, linux-kernel,
stable
Hi Andrii,
On Mon, May 18, 2026 at 05:32:33PM +0300, Andrii Kuchmenko wrote:
> module_extend_max_pages() calls kvrealloc() internally and returns
> -ENOMEM on 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.
> 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.
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
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-05-20 21:33 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-18 12:18 [PATCH v2] module: decompress: check return value of module_extend_max_pages() Andrii Kuchmenko
2026-05-18 12:57 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2026-05-18 14:32 Andrii Kuchmenko
2026-05-18 16:21 ` Christophe Leroy (CS GROUP)
2026-05-19 14:56 ` Christophe Leroy (CS GROUP)
2026-05-19 21:23 ` Sami Tolvanen
[not found] ` <CAEABq7f3agKZqrBiu+UwXHY44mTcK360ryg-i0w=wEc_Lv+T0A@mail.gmail.com>
2026-05-20 15:12 ` Sami Tolvanen
2026-05-20 16:05 ` Afi0
2026-05-20 21:33 ` Christophe Leroy (CS GROUP)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox