mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ricky Ringler <richard.rringler@gmail.com>
To: Max Filippov <jcmvbkbc@gmail.com>, Chris Zankel <chris@zankel.net>
Cc: linux-kernel@vger.kernel.org, Ricky Ringler <richard.rringler@gmail.com>
Subject: [PATCH v3] xtensa: align: validate access in fast_load_store
Date: Mon, 15 Dec 2025 08:33:23 -0600	[thread overview]
Message-ID: <20251215143323.2771889-1-richard.rringler@gmail.com> (raw)
In-Reply-To: <CAMo8BfJiuPYk8tBVKt6=c3E2SzHBe+0QTo02k3u8KL1CGtEvFQ@mail.gmail.com>

access_ok() is used only in user mode and
branches to .Linvalid_instruction on fault.
Kernel mode skips access_ok().

Tested-by: Ricky Ringler <richard.rringler@gmail.com>

Signed-off-by: Ricky Ringler <richard.rringler@gmail.com>
---
v3:
- Changed kernel mode behavior to skip access_ok()

v2:
- Address Max's feedback
- Fixed formatting
- Added user mode branch

Testing:
- Built with CONFIG_MMU enabled
- objdump before/after comparison and validated code path

 arch/xtensa/kernel/align.S | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/xtensa/kernel/align.S b/arch/xtensa/kernel/align.S
index ee97edce2300..f2d0d831ce43 100644
--- a/arch/xtensa/kernel/align.S
+++ b/arch/xtensa/kernel/align.S
@@ -21,6 +21,9 @@
 #include <asm/asm-offsets.h>
 #include <asm/asmmacro.h>
 #include <asm/processor.h>
+#ifdef CONFIG_MMU
+#include <asm/asm-uaccess.h>
+#endif
 
 #if XCHAL_UNALIGNED_LOAD_EXCEPTION || defined CONFIG_XTENSA_LOAD_STORE
 #define LOAD_EXCEPTION_HANDLER
@@ -185,8 +188,11 @@ ENTRY(fast_load_store)
 
 #ifdef CONFIG_MMU
 	/* l32e can't be used here even when it's available. */
-	/* TODO access_ok(a3) could be used here */
-	j	.Linvalid_instruction
+	rsr	a6, ps
+	bbci.l	a6, PS_UM_BIT, 1f # kernel mode
+	movi	a5, 8
+	access_ok a3, a5, a6, a2, .Linvalid_instruction
+1:
 #endif
 	l32i	a5, a3, 0
 	l32i	a6, a3, 4
-- 
2.43.0


  reply	other threads:[~2025-12-15 14:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-13  2:52 [PATCH] xtensa: align: validate user access in fast_load_store under MMU Ricky Ringler
2025-12-13  2:52 ` [PATCH] xtensa: mmu: validate user access in fast_load_store with MMU Ricky Ringler
2025-12-14  7:14   ` Max Filippov
2025-12-14  7:24     ` Max Filippov
2025-12-14 22:28   ` [PATCH v2] xtensa: align: validate access in fast_load_store Ricky Ringler
2025-12-15  3:06     ` Max Filippov
2025-12-15 14:33       ` Ricky Ringler [this message]
2025-12-15 15:11         ` [PATCH v3] " Max Filippov

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=20251215143323.2771889-1-richard.rringler@gmail.com \
    --to=richard.rringler@gmail.com \
    --cc=chris@zankel.net \
    --cc=jcmvbkbc@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®