The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Ibrahim Hashimov <security@auditcode.ai>
To: guoren@kernel.org
Cc: arnd@arndb.de, linux-csky@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] csky: alignment: validate address before emulated load/store
Date: Fri, 24 Jul 2026 13:19:31 +0200	[thread overview]
Message-ID: <20260724111931.76451-1-security@auditcode.ai> (raw)

The abiv1 misalignment fixup csky_alignment() re-executes a trapped
unaligned load/store from kernel context. It computes the target address
entirely from user-controlled state -- the base register read from the
saved user regs via get_ptreg() plus an immediate decoded from the
faulting instruction -- and then performs the access with raw supervisor
ldb/stb instructions in ldb_asm()/stb_asm(), without checking that the
address points into user space.

A local unprivileged process can therefore execute a crafted unaligned
STW/STH whose base register holds a kernel address: the fixup emulates it
and stores an attacker-controlled value to an attacker-chosen kernel
address -- an arbitrary kernel write, i.e. a privilege-escalation
primitive. The symmetric load path is an arbitrary kernel read. The
__ex_table entry on the asm only recovers from an unmapped fault; a store
to a mapped, writable kernel page completes. The existing rx/rz != {0,1}
test is a register-index filter, not an address bound.

Reject the emulated access when the fault came from user mode and the
target is not a valid user address, using access_ok(). Rejected accesses
fall through to the existing bad_area path, which delivers
SIGBUS/BUS_ADRALN like every other rejected case. Kernel-mode faults
legitimately touch kernel memory and are deliberately left unchecked.

Found by inspection; CK610 (CONFIG_CPU_CK610) abiv1 silicon has no
upstream emulation target, so this is not runtime-reproduced.

Fixes: 081860b970ad ("csky: Exception handling and mm-fault")
Cc: stable@vger.kernel.org
Signed-off-by: Ibrahim Hashimov <security@auditcode.ai>
Assisted-by: AuditCode-AI:2026.07
---
 arch/csky/abiv1/alignment.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/csky/abiv1/alignment.c b/arch/csky/abiv1/alignment.c
index aee904833dec..19337946e0d5 100644
--- a/arch/csky/abiv1/alignment.c
+++ b/arch/csky/abiv1/alignment.c
@@ -261,18 +261,26 @@ void csky_alignment(struct pt_regs *regs)
 	switch (opcode) {
 	case OP_LDH:
 		addr = get_ptreg(regs, rx) + (imm << 1);
+		if (user_mode(regs) && !access_ok((void __user *)addr, 2))
+			goto bad_area;
 		ret = ldh_c(regs, rz, addr);
 		break;
 	case OP_LDW:
 		addr = get_ptreg(regs, rx) + (imm << 2);
+		if (user_mode(regs) && !access_ok((void __user *)addr, 4))
+			goto bad_area;
 		ret = ldw_c(regs, rz, addr);
 		break;
 	case OP_STH:
 		addr = get_ptreg(regs, rx) + (imm << 1);
+		if (user_mode(regs) && !access_ok((void __user *)addr, 2))
+			goto bad_area;
 		ret = sth_c(regs, rz, addr);
 		break;
 	case OP_STW:
 		addr = get_ptreg(regs, rx) + (imm << 2);
+		if (user_mode(regs) && !access_ok((void __user *)addr, 4))
+			goto bad_area;
 		ret = stw_c(regs, rz, addr);
 		break;
 	}
--
2.50.1 (Apple Git-155)

                 reply	other threads:[~2026-07-24 11:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260724111931.76451-1-security@auditcode.ai \
    --to=security@auditcode.ai \
    --cc=arnd@arndb.de \
    --cc=guoren@kernel.org \
    --cc=linux-csky@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@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