Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Federico Parola" <fparola@amazon.de>
Cc: "Mike Rapoport" <rppt@kernel.org>,
	"Pasha Tatashin" <pasha.tatashin@soleen.com>,
	"Pratyush Yadav" <pratyush@kernel.org>,
	"Alexander Graf" <graf@amazon.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	kexec@lists.infradead.org, nh-open-source@amazon.com
Subject: Re: [PATCH 6.18.y 2/2] kho: free phys_bits bitmaps using free_page() in __kho_abort()
Date: Thu, 15 Oct 2026 14:59:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-173017@kernel.org> (raw)
In-Reply-To: <20261015144529.76911-3-fparola@amazon.de>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] mm: use-after-free of physxa in __kho_preserve_order() racing with abort
- [Medium] mm: memory leak of kho_vmalloc_chunk pages on KHO abort
--

commit a7bcf7c6e605c88c110bdd87cec6fe96445bb703
Author: Federico Parola <fparola@amazon.de>

kho: free phys_bits bitmaps using free_page() in __kho_abort()

This commit fixes a memory leak in KHO abort by replacing kfree() with
free_page() for releasing bitmap pages allocated via the buddy allocator.
Using kfree() on non-kmalloc buddy pages previously hit a WARN_ON_ONCE() and
leaked the pages during teardown.

> diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c
> index 9fe5d14f1ec54..9691f6bc2fba7 100644
> --- a/kernel/kexec_handover.c
> +++ b/kernel/kexec_handover.c
> @@ -1054,7 +1054,7 @@ static int __kho_abort(void)
>  		unsigned long phys;
>  
>  		xa_for_each(&physxa->phys_bits, phys, bits)
> -			kfree(bits);
> +			free_page((unsigned long)bits);
>  
>  		xa_destroy(&physxa->phys_bits);
>  		kfree(physxa);

[Severity: High]
Does this code introduce a use-after-free? The physxa structure is freed
without being removed from the XArray first, leaving a dangling pointer
visible to lockless readers until xa_destroy(&kho_out.ser.track.orders)
eventually clears the array.

If a driver calls kho_preserve_folio() concurrently with another thread
calling kho_abort(), could __kho_preserve_order() load the physxa pointer
locklessly and dereference it just after it is freed here?

kernel/kexec_handover.c:__kho_preserve_order() {
    ...
    physxa = xa_load(&track->orders, order);
    if (!physxa) {
        ...
    }

    bits = xa_load_or_alloc(&physxa->phys_bits, pfn_high / PRESERVE_BITS);
    ...
}

[Severity: Medium]
Does this code leak kho_vmalloc_chunk pages? When __kho_abort() drops the KHO
state by destroying the XArrays, it leaves the driver's metadata chunk
pages untracked.

In kho_preserve_vmalloc(), these pages are allocated and linked only to the
driver's struct kho_vmalloc object:

kernel/kexec_handover.c:kho_preserve_vmalloc() {
    ...
    chunk = new_vmalloc_chunk(NULL);
    if (!chunk)
        return -ENOMEM;
    KHOSER_STORE_PTR(preservation->first, chunk);
    ...
}

Since kho_vmalloc_free_chunks() is static, and there is no exported
kho_vmalloc_unpreserve() API, drivers cannot free these chunks inside their
KEXEC_KHO_ABORT notifiers. Doesn't this mean these pages are permanently
leaked whenever KHO finalization is aborted?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015144529.76911-1-fparola@amazon.de?part=2


      reply	other threads:[~2026-10-15 14:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 14:45 [PATCH 6.18.y 0/2] kho: free buddy-allocated metadata with free_page() Federico Parola
2026-10-15 14:45 ` [PATCH 6.18.y 1/2] kho: free chunks using free_page() instead of kfree() Federico Parola
2026-10-15 14:55   ` sashiko-bot
2026-10-15 14:45 ` [PATCH 6.18.y 2/2] kho: free phys_bits bitmaps using free_page() in __kho_abort() Federico Parola
2026-10-15 14:59   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-173017@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=fparola@amazon.de \
    --cc=graf@amazon.com \
    --cc=kexec@lists.infradead.org \
    --cc=nh-open-source@amazon.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox