* [PATCH] module/decompress: Avoid open-coded kvrealloc()
@ 2025-11-19 22:54 Kees Cook
2025-11-20 12:31 ` Petr Pavlu
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2025-11-19 22:54 UTC (permalink / raw)
To: Petr Pavlu
Cc: Kees Cook, Luis Chamberlain, Sami Tolvanen, Daniel Gomez,
linux-modules, Daniel Gomez, linux-kernel, linux-hardening
Replace open-coded allocate/copy with kvrealloc().
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Petr Pavlu <petr.pavlu@suse.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: Daniel Gomez <da.gomez@samsung.com>
Cc: <linux-modules@vger.kernel.org>
---
kernel/module/decompress.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c
index 474e68f0f063..36f52a232a12 100644
--- a/kernel/module/decompress.c
+++ b/kernel/module/decompress.c
@@ -17,16 +17,16 @@
static int module_extend_max_pages(struct load_info *info, unsigned int extent)
{
struct page **new_pages;
+ unsigned int new_max = info->max_pages + extent;
- new_pages = kvmalloc_array(info->max_pages + extent,
- sizeof(info->pages), GFP_KERNEL);
+ new_pages = kvrealloc(info->pages,
+ size_mul(new_max, sizeof(*info->pages)),
+ GFP_KERNEL);
if (!new_pages)
return -ENOMEM;
- memcpy(new_pages, info->pages, info->max_pages * sizeof(info->pages));
- kvfree(info->pages);
info->pages = new_pages;
- info->max_pages += extent;
+ info->max_pages = new_max;
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] module/decompress: Avoid open-coded kvrealloc()
2025-11-19 22:54 [PATCH] module/decompress: Avoid open-coded kvrealloc() Kees Cook
@ 2025-11-20 12:31 ` Petr Pavlu
0 siblings, 0 replies; 2+ messages in thread
From: Petr Pavlu @ 2025-11-20 12:31 UTC (permalink / raw)
To: Kees Cook
Cc: Luis Chamberlain, Sami Tolvanen, Daniel Gomez, linux-modules,
Daniel Gomez, linux-kernel, linux-hardening
On 11/19/25 11:54 PM, Kees Cook wrote:
> Replace open-coded allocate/copy with kvrealloc().
>
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> Cc: Petr Pavlu <petr.pavlu@suse.com>
> Cc: Luis Chamberlain <mcgrof@kernel.org>
> Cc: Sami Tolvanen <samitolvanen@google.com>
> Cc: Daniel Gomez <da.gomez@samsung.com>
> Cc: <linux-modules@vger.kernel.org>
> ---
> kernel/module/decompress.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c
> index 474e68f0f063..36f52a232a12 100644
> --- a/kernel/module/decompress.c
> +++ b/kernel/module/decompress.c
> @@ -17,16 +17,16 @@
> static int module_extend_max_pages(struct load_info *info, unsigned int extent)
> {
> struct page **new_pages;
> + unsigned int new_max = info->max_pages + extent;
>
> - new_pages = kvmalloc_array(info->max_pages + extent,
> - sizeof(info->pages), GFP_KERNEL);
> + new_pages = kvrealloc(info->pages,
> + size_mul(new_max, sizeof(*info->pages)),
> + GFP_KERNEL);
Nit: Using the array_size() alias of size_mul() might be clearer in this
context.
It looks ok to me in any case.
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
--
Thanks,
Petr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-20 12:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-19 22:54 [PATCH] module/decompress: Avoid open-coded kvrealloc() Kees Cook
2025-11-20 12:31 ` Petr Pavlu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).