All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexander Gordeev" <agordeev@linux.ibm.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [RFC PATCH 1/4] mm: use proper PTE accessors in madvise() and mremap()
Date: Fri, 17 Jul 2026 13:53:06 +0000	[thread overview]
Message-ID: <20260717135306.E8C571F000E9@smtp.kernel.org> (raw)
In-Reply-To: <3c4d3c768ebf9cc7bbc7667e0e08bf5ad2fe8729.1784292223.git.agordeev@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Calling `set_pte()` on an uninitialized stack variable causes undefined behavior, stack memory reads, and potential kernel panics.
--

--- Patch [1]: [RFC PATCH 1/4] mm: use proper PTE accessors in madvise() and mremap() ---
commit 75c34d0a3dcbb3f5f12f6bd64e11ac6572b6f8f8
Author: Alexander Gordeev <agordeev@linux.ibm.com>

mm: use proper PTE accessors in madvise() and mremap()

This commit converts direct page table entry pointer dereferences to use
the proper accessors in madvise() and mremap().

> diff --git a/mm/madvise.c b/mm/madvise.c
> index 07a21ca31bad4..77508ef1c1836 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -1106,7 +1106,7 @@ static int guard_install_set_pte(unsigned long addr, unsigned long next,
>  	unsigned long *nr_pages = (unsigned long *)walk->private;
>  
>  	/* Simply install a PTE marker, this causes segfault on access. */
> -	*ptep = make_pte_marker(PTE_MARKER_GUARD);
> +	set_pte(ptep, make_pte_marker(PTE_MARKER_GUARD));

[Severity: Critical]
Is it safe to use set_pte() here?  In this code path, ptep is an out-parameter
pointing to an uninitialized stack variable rather than a live page table
entry.  This can be seen in the caller walk_pte_range_inner() in mm/pagewalk.c:

	pte_t new_pte;
	err = ops->install_pte(addr, addr + PAGE_SIZE, &new_pte, walk);

Because ptep points to the stack and not a live page table, this violates the
architectural API contracts of set_pte().  For example, on arm64, set_pte()
calls __ptep_get() which reads the uninitialized stack memory and passes it to
WARN_ON_ONCE(). On other architectures like Xen PV or PowerPC, set_pte() expects
a live page table mapping and can trigger hypercalls or specific cache flushes
using a stack address, potentially leading to crashes or unpredictable behavior.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1784292223.git.agordeev@linux.ibm.com?part=1

  reply	other threads:[~2026-07-17 13:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 13:32 [RFC PATCH 0/4] mm: introduce __ptent sparse attribute Alexander Gordeev
2026-07-17 13:32 ` [RFC PATCH 1/4] mm: use proper PTE accessors in madvise() and mremap() Alexander Gordeev
2026-07-17 13:53   ` sashiko-bot [this message]
2026-07-17 17:14   ` Kevin Brodsky
2026-07-17 13:32 ` [RFC PATCH 2/4] mm: introduce ptep_get_nopgtable() and set_pte_nopgtable() accessors Alexander Gordeev
2026-07-17 14:10   ` sashiko-bot
2026-07-17 13:32 ` [RFC PATCH 3/4] mm: introduce __ptent sparse attribute Alexander Gordeev
2026-07-17 13:32 ` [RFC PATCH 4/4] s390/mm: implement __ptent-aware pte_t type Alexander Gordeev
2026-07-17 13:39   ` sashiko-bot
2026-07-17 14:53 ` [RFC PATCH 0/4] mm: introduce __ptent sparse attribute David Hildenbrand (Arm)

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=20260717135306.E8C571F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.