Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Wei-chung Hsu <weihsu@google.com>
To: Russell King <linux@armlinux.org.uk>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	Nathan Chancellor <nathan@kernel.org>,
	 Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	 Ard Biesheuvel <ardb@kernel.org>,
	Prasanna Kumar T S M <ptsm@linux.microsoft.com>,
	 linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev,
	 linux-kernel@vger.kernel.org, Wei-chung Hsu <weihsu@google.com>,
	stable@vger.kernel.org
Subject: [PATCH v2] ARM: stacktrace: Fix Clang frame pointer upper bound and alignment check
Date: Wed,  2 Dec 2026 19:31:15 +0000	[thread overview]
Message-ID: <20261202193116.982004-1-weihsu@google.com> (raw)

When built with Clang (CONFIG_CC_IS_CLANG) and frame pointers
(CONFIG_FRAME_POINTER), unwind_frame() reads two 32-bit words starting
at fp: *(unsigned long *)(fp) and *(unsigned long *)(fp + 4), i.e. 8
bytes [fp, fp + 7].

However, frame_pointer_check() copied the GCC upper-bound check
(fp > high - 4), which assumes accesses stay below fp (fp - 12 .. fp - 4).
It also does not verify 4-byte alignment of fp.

With CONFIG_VMAP_STACK=y, if an interrupt or lockdep trace_hardirqs_on()
unwinds through hand-written assembly that uses r11 (fp) as a scratch
pointer (such as __aes_arm_encrypt / __aes_arm_decrypt), an unaligned or
top-of-stack fp value in (high - 8, high - 4] (e.g. 0xf554bffb or
0xf6733ff9, 5-7 bytes below high) passes frame_pointer_check(), and the
subsequent read of *(unsigned long *)(fp + 4) faults into the unmapped
VMAP_STACK guard page:

  Unable to handle kernel paging request at virtual address f554c000
  Internal error: Oops: 207 [#1] SMP ARM
  PC is at walk_stackframe+0x11c/0x17c
   walk_stackframe from return_address+0x6c/0xa8
   return_address from trace_hardirqs_on+0x158/0x1e8
   trace_hardirqs_on from __aes_arm_encrypt+0x4b8/0x500

Reject unaligned frame pointers via !IS_ALIGNED(fp, 4) before the
call_with_stack() pc check (call_with_stack() always keeps fp 4-byte
aligned on both Clang and GCC), and tighten the Clang upper bound to
fp > high - 8 so both *(fp) and *(fp + 4) stay strictly within
[low, high).

Fixes: b4d5ec9b39f8 ("ARM: 8992/1: Fix unwind_frame for clang-built kernels")
Cc: stable@vger.kernel.org
Signed-off-by: Wei-chung Hsu <weihsu@google.com>
---
Changes in v2:
- Move the !IS_ALIGNED(fp, 4) check before the call_with_stack() pc check
  with its own comment (per Nick Desaulniers). Dropped Prasanna's v1
  Reviewed-by due to the control-flow reorder.
- Add Cc: stable@vger.kernel.org (per Nick Desaulniers).
- Verified call_with_stack() in arch/arm/lib/call_with_stack.S maintains
  4-byte fp alignment on both Clang and GCC.
- Will submit to Russell King's ARM patch tracker after list review.

Link to v1: https://lore.kernel.org/all/20261130232454.176395-1-weihsu@google.com/

 arch/arm/kernel/stacktrace.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c
index 620aa82e3..dae8ac614 100644
--- a/arch/arm/kernel/stacktrace.c
+++ b/arch/arm/kernel/stacktrace.c
@@ -50,6 +50,10 @@ static int frame_pointer_check(struct stackframe *frame)
 	unsigned long fp = frame->fp;
 	unsigned long pc = frame->pc;
 
+	/* check current frame pointer is 4-byte aligned */
+	if (!IS_ALIGNED(fp, 4))
+		return -EINVAL;
+
 	/*
 	 * call_with_stack() is the only place we allow SP to jump from one
 	 * stack to another, with FP and SP pointing to different stacks,
@@ -65,7 +69,7 @@ static int frame_pointer_check(struct stackframe *frame)
 
 	/* check current frame pointer is within bounds */
 #ifdef CONFIG_CC_IS_CLANG
-	if (fp < low + 4 || fp > high - 4)
+	if (fp < low + 4 || fp > high - 8)
 		return -EINVAL;
 #else
 	if (fp < low + 12 || fp > high - 4)
-- 
2.56.1.915.g69d5ec7298-goog


                 reply	other threads:[~2026-12-02 19:31 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=20261202193116.982004-1-weihsu@google.com \
    --to=weihsu@google.com \
    --cc=ardb@kernel.org \
    --cc=justinstitt@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=ptsm@linux.microsoft.com \
    --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