All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Anshuman Khandual" <anshuman.khandual@arm.com>
Cc: "Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"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: [PATCH 6/8] sh/mm: Stop using [p4d|pud|pmd]_ERROR()
Date: Mon, 31 Aug 2026 06:29:48 +0000	[thread overview]
Message-ID: <20260831062949.686051F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831054331.625505-7-anshuman.khandual@arm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] `__get_pte_phys()` can return `NULL` on error, but its callers (`set_pte_phys()` and `clear_pte_phys()`) immediately dereference the returned pointer without checking, leading to a guaranteed kernel crash.
- [High] `__get_pte_phys()` uses allocation functions (`p4d_alloc`, `pud_alloc`, `pmd_alloc`) passing `NULL` for the `mm` argument, which will cause a kernel crash if allocation is actually needed.
--

commit 0098935d861a1c9cf1496880ca35e1a49aecdf51
Author: Anshuman Khandual <anshuman.khandual@arm.com>

sh/mm: Stop using [p4d|pud|pmd]_ERROR()

This commit replaces the use of [p4d|pud|pmd]_ERROR() with pr_err() in
__get_pte_phys() when page table allocations fail. This avoids a NULL
pointer dereference when attempting to pass the failed allocation result
to the error macros.

> diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
> index 9466ae6f9f164..8d65e60688dcb 100644
> --- a/arch/sh/mm/init.c
> +++ b/arch/sh/mm/init.c
> @@ -59,19 +59,19 @@ static pte_t *__get_pte_phys(unsigned long addr)
>  
>  	p4d = p4d_alloc(NULL, pgd, addr);

[Severity: High]
This isn't a bug introduced by this patch, but passing NULL for the mm
argument to p4d_alloc() will cause a kernel panic if allocation is actually
needed. The slow path requires a valid mm_struct to acquire the page table
lock. Should this be passing &init_mm instead?

>  	if (unlikely(!p4d)) {
> -		p4d_ERROR(*p4d);
> +		pr_err("allocating p4d table failed\n");
>  		return NULL;
>  	}

[Severity: High]
This isn't a bug introduced by this patch, but while this fixes a NULL
pointer dereference here in the callee, the callers still unconditionally
dereference the returned pointer.

For example, in set_pte_phys():

    pte = __get_pte_phys(addr);
    if (!pte_none(*pte)) {

And in clear_pte_phys():

    pte = __get_pte_phys(addr);
    
    if (pgprot_val(prot) & _PAGE_WIRED)
        tlb_unwire_entry();
        
    set_pte(pte, pfn_pte(0, __pgprot(0)));

Could these callers be updated to check if the returned pte is NULL
before dereferencing it to avoid guaranteed crashes on the error paths?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260831054331.625505-1-anshuman.khandual@arm.com?part=6

  reply	other threads:[~2026-08-31  6:29 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31  5:43 [PATCH 0/8] mm: Drop pxd_ERROR() Anshuman Khandual
2026-08-31  5:43 ` Anshuman Khandual
2026-08-31  5:43 ` Anshuman Khandual
2026-08-31  5:43 ` [PATCH 1/8] mm: Make ptval_to_str() generally available Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  5:54   ` sashiko-bot
2026-08-31  5:43 ` [PATCH 2/8] mm: Stop using pxd_ERROR() Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  5:59   ` sashiko-bot
2026-08-31  5:43 ` [PATCH 3/8] loongarch/mm: Stop using pte_ERROR() Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  6:10   ` sashiko-bot
2026-08-31  5:43 ` [PATCH 4/8] parisc/mm: Directly use generic [pmd|pgd]_clear_bad() Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  6:15   ` sashiko-bot
2026-08-31  5:43 ` [PATCH 5/8] sh/mm: Stop using pte_ERROR() Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  6:21   ` sashiko-bot
2026-08-31  5:43 ` [PATCH 6/8] sh/mm: Stop using [p4d|pud|pmd]_ERROR() Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  6:29   ` sashiko-bot [this message]
2026-09-01  1:53   ` Andrew Morton
2026-09-01  1:53     ` Andrew Morton
2026-09-01  1:53     ` Andrew Morton
2026-08-31  5:43 ` [PATCH 7/8] sh/mm: Stop using pgd_ERROR() Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  6:40   ` sashiko-bot
2026-08-31  5:43 ` [PATCH 8/8] mm: Drop pxd_ERROR() Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  5:43   ` Anshuman Khandual
2026-08-31  6:44   ` sashiko-bot
2026-10-08  9:20   ` Andreas Larsson
2026-10-08  9:20     ` Andreas Larsson
2026-10-08  9:20     ` Andreas Larsson
2026-10-09  2:24     ` Anshuman Khandual
2026-10-09  2:24       ` Anshuman Khandual
2026-10-09  2:24       ` Anshuman Khandual
2026-08-31  6:08 ` [PATCH 0/8] " John Paul Adrian Glaubitz
2026-08-31  6:08   ` John Paul Adrian Glaubitz
2026-08-31  6:08   ` John Paul Adrian Glaubitz
2026-08-31  6:49   ` Anshuman Khandual
2026-08-31  6:49     ` Anshuman Khandual
2026-08-31  6:49     ` Anshuman Khandual
2026-09-01  1:55 ` Andrew Morton
2026-09-01  1:55   ` Andrew Morton
2026-09-01  1:55   ` Andrew Morton
2026-09-01  2:48   ` Anshuman Khandual
2026-09-01  2:48     ` Anshuman Khandual
2026-09-01  2:48     ` Anshuman Khandual

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=20260831062949.686051F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=anshuman.khandual@arm.com \
    --cc=borntraeger@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.