public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
From: Michael Neuling <mikey@neuling.org>
To: "Björn Töpel" <bjorn@rivosinc.com>,
	"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
	"Vishal Moola (Oracle)" <vishal.moola@gmail.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Aleksa Paunovic" <aleksa.paunovic@htecgroup.com>,
	"Aleksandar Rikalo" <arikalo@gmail.com>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Andrew Jones" <ajones@ventanamicro.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"David Hildenbrand" <david@redhat.com>,
	"Djordje Todorovic" <djordje.todorovic@htecgroup.com>,
	"Guo Ren" <guoren@kernel.org>,
	"Junhui Liu" <junhui.liu@pigmoral.tech>,
	"Kevin Brodsky" <kevin.brodsky@arm.com>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Nam Cao" <namcao@linutronix.de>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Oscar Salvador" <osalvador@suse.de>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Paul Walmsley" <pjw@kernel.org>,
	"Qinglin Pan" <panqinglin2020@iscas.ac.cn>,
	"Raj Vishwanathan4" <rvishwanathan@mips.com>,
	linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org
Cc: Michael Neuling <mikey@neuling.org>
Subject: [PATCH 4/5] riscv: mm: Fix NULL dereferences in napot hugetlb functions
Date: Thu,  9 Apr 2026 09:11:42 +0000	[thread overview]
Message-ID: <20260409091143.1348853-5-mikey@neuling.org> (raw)
In-Reply-To: <20260409091143.1348853-1-mikey@neuling.org>

huge_pte_offset() can return NULL when any level of the page table walk
encounters a non-present entry. Both huge_ptep_set_access_flags() and
huge_ptep_set_wrprotect() re-derive ptep via huge_pte_offset() in the
napot path but use the result without a NULL check, leading to NULL
pointer dereferences in get_clear_contig_flush() and set_pte_at().

Add NULL checks after huge_pte_offset() in both functions.

Fixes: 82a1a1f3bf ("riscv: mm: support Svnapot in hugetlb page")
Signed-off-by: Michael Neuling <mikey@neuling.org>
Assisted-by: Cursor:claude-4.6-opus-high-thinking
---
 arch/riscv/mm/hugetlbpage.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c
index a6d217112c..7d155341cf 100644
--- a/arch/riscv/mm/hugetlbpage.c
+++ b/arch/riscv/mm/hugetlbpage.c
@@ -288,6 +288,8 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma,
 	order = napot_cont_order(pte);
 	pte_num = napot_pte_num(order);
 	ptep = huge_pte_offset(mm, addr, napot_cont_size(order));
+	if (!ptep)
+		return 0;
 	orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num);
 
 	if (pte_dirty(orig_pte))
@@ -335,6 +337,8 @@ void huge_ptep_set_wrprotect(struct mm_struct *mm,
 	order = napot_cont_order(pte);
 	pte_num = napot_pte_num(order);
 	ptep = huge_pte_offset(mm, addr, napot_cont_size(order));
+	if (!ptep)
+		return;
 	orig_pte = get_clear_contig_flush(mm, addr, ptep, pte_num);
 
 	orig_pte = pte_wrprotect(orig_pte);
-- 
2.43.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  parent reply	other threads:[~2026-04-09  9:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-09  9:11 [PATCH 0/5] riscv: Assorted bug fixes Michael Neuling
2026-04-09  9:11 ` [PATCH 1/5] riscv: errata: Fix bitwise vs logical AND in MIPS errata patching Michael Neuling
2026-04-09  9:11 ` [PATCH 2/5] riscv: ptrace: Fix register corruption in compat_riscv_gpr_set on error Michael Neuling
2026-04-09  9:11 ` [PATCH 3/5] riscv: mm: Fix NULL pointer dereference in __set_memory Michael Neuling
2026-04-09 12:37   ` David Hildenbrand (Arm)
2026-04-10  6:23     ` Michael Neuling
2026-04-10  7:42       ` David Hildenbrand (Arm)
2026-04-10  7:53         ` Mike Rapoport
2026-04-10  7:59           ` David Hildenbrand (Arm)
2026-04-10  8:55             ` Michael Neuling
2026-04-09  9:11 ` Michael Neuling [this message]
2026-04-09 12:36   ` [PATCH 4/5] riscv: mm: Fix NULL dereferences in napot hugetlb functions David Hildenbrand (Arm)
2026-04-09  9:11 ` [PATCH 5/5] riscv: mm: Fix TOCTOU race in remove_pte_mapping Michael Neuling
2026-04-09 12:32   ` 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=20260409091143.1348853-5-mikey@neuling.org \
    --to=mikey@neuling.org \
    --cc=ajones@ventanamicro.com \
    --cc=akpm@linux-foundation.org \
    --cc=aleksa.paunovic@htecgroup.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=arikalo@gmail.com \
    --cc=arnd@arndb.de \
    --cc=bjorn@rivosinc.com \
    --cc=david@redhat.com \
    --cc=djordje.todorovic@htecgroup.com \
    --cc=guoren@kernel.org \
    --cc=junhui.liu@pigmoral.tech \
    --cc=kevin.brodsky@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=ljs@kernel.org \
    --cc=namcao@linutronix.de \
    --cc=oleg@redhat.com \
    --cc=osalvador@suse.de \
    --cc=palmer@dabbelt.com \
    --cc=panqinglin2020@iscas.ac.cn \
    --cc=pjw@kernel.org \
    --cc=rppt@kernel.org \
    --cc=rvishwanathan@mips.com \
    --cc=vishal.moola@gmail.com \
    /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