mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/mm: remove freed init memory from kmemleak in free_init_pages()
@ 2026-07-09 12:41 jiang.kun2
  2026-07-22 15:04 ` Borislav Petkov
  0 siblings, 1 reply; 2+ messages in thread
From: jiang.kun2 @ 2026-07-09 12:41 UTC (permalink / raw)
  To: dave.hansen, luto, peterz, tglx, mingo, bp
  Cc: x86, hpa, linux-kernel, xu.xin16

From: Jiang Kun <jiang.kun2@zte.com.cn>

free_init_pages() already informs kmemleak when init memory is unmapped
under debug_pagealloc_enabled(), but the normal free path only releases
the pages through free_reserved_area() without removing the range from
kmemleak.

This can leave stale kmemleak objects for boot-time init memory such as
initrd/initramfs buffers. Once the freed range is later reused, kmemleak
may detect overlapping objects and report:

  kmemleak: Cannot insert ... into the object search tree (overlaps existing)

followed by disabling the leak detector.

Make both paths consistent by calling kmemleak_free_part() before
freeing the range in the normal path as well.

This matches the existing debug_pagealloc behavior and ensures that
freed init memory is removed from kmemleak before being reused.

Signed-off-by: Jiang Kun <jiang.kun2@zte.com.cn>
---
 arch/x86/mm/init.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index fb67217fddcd..3bed63ec1568 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -933,6 +933,7 @@ void free_init_pages(const char *what, unsigned long begin, unsigned long end)
  set_memory_nx(begin, (end - begin) >> PAGE_SHIFT);
  set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);

+ kmemleak_free_part((void *)begin, end - begin);
  free_reserved_area((void *)begin, (void *)end,
     POISON_FREE_INITMEM, what);
  }
-- 
2.25.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86/mm: remove freed init memory from kmemleak in free_init_pages()
  2026-07-09 12:41 [PATCH] x86/mm: remove freed init memory from kmemleak in free_init_pages() jiang.kun2
@ 2026-07-22 15:04 ` Borislav Petkov
  0 siblings, 0 replies; 2+ messages in thread
From: Borislav Petkov @ 2026-07-22 15:04 UTC (permalink / raw)
  To: jiang.kun2
  Cc: dave.hansen, luto, peterz, tglx, mingo, x86, hpa, linux-kernel, xu.xin16

On Thu, Jul 09, 2026 at 08:41:34PM +0800, jiang.kun2@zte.com.cn wrote:
> From: Jiang Kun <jiang.kun2@zte.com.cn>
> 
> free_init_pages() already informs kmemleak when init memory is unmapped
> under debug_pagealloc_enabled(), but the normal free path only releases
> the pages through free_reserved_area() without removing the range from
> kmemleak.
> 
> This can leave stale kmemleak objects for boot-time init memory such as
> initrd/initramfs buffers. Once the freed range is later reused, kmemleak
> may detect overlapping objects and report:
> 
>   kmemleak: Cannot insert ... into the object search tree (overlaps existing)
> 
> followed by disabling the leak detector.
> 
> Make both paths consistent by calling kmemleak_free_part() before
> freeing the range in the normal path as well.
> 
> This matches the existing debug_pagealloc behavior and ensures that
> freed init memory is removed from kmemleak before being reused.
> 
> Signed-off-by: Jiang Kun <jiang.kun2@zte.com.cn>
> ---
>  arch/x86/mm/init.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
> index fb67217fddcd..3bed63ec1568 100644
> --- a/arch/x86/mm/init.c
> +++ b/arch/x86/mm/init.c
> @@ -933,6 +933,7 @@ void free_init_pages(const char *what, unsigned long begin, unsigned long end)
>   set_memory_nx(begin, (end - begin) >> PAGE_SHIFT);
>   set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);
> 
> + kmemleak_free_part((void *)begin, end - begin);
>   free_reserved_area((void *)begin, (void *)end,
>      POISON_FREE_INITMEM, what);
>   }

How about you do not duplicate that call but make it unconditional, regardless
of the if-else?

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-22 15:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-09 12:41 [PATCH] x86/mm: remove freed init memory from kmemleak in free_init_pages() jiang.kun2
2026-07-22 15:04 ` Borislav Petkov

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®