linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: mm: Disregard user space addresses in BUG() address check
@ 2024-01-17 15:07 Ard Biesheuvel
  2024-01-17 18:25 ` Mark Brown
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Ard Biesheuvel @ 2024-01-17 15:07 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Ard Biesheuvel, Kees Cook, Russell King, Mark Brown, Zhen Lei,
	Linus Walleij

From: Ard Biesheuvel <ardb@kernel.org>

is_valid_bugaddr() dereferences the faulting PC to fetch the instruction
that triggered the fault, to decide whether it is a BRK instruction used
to force an exception. This is used by the BUG() infrastructure to keep
the handling logic (which should never execute) separate from the code
that normally runs.

This dereference may attempt to access user memory if the faulting PC
happens to contain a user address. One way this might happen is when
the kernel is tricked into executing from user space while PAN
protections (Privileged Access Never) are in effect: the instruction
fetch will trigger a prefetch abort, the handling of which involves a
check whether the instruction that caused it is a BRK, requiring a
load from the same address. This load is privileged too, and so it will
trigger another exception, which we fail to recover from.

Given that BRK instructions tied to BUG() handling can only appear in
kernel code, let's check first that the PC actually points into kernel
memory.

Cc: Kees Cook <keescook@chromium.org>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Mark Brown <broonie@kernel.org>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Link: https://lkml.kernel.org/r/202401111544.18EBB6AA%40keescook
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm/kernel/traps.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index 3bad79db5d6e..f342bd6b2a5d 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -402,6 +402,9 @@ int is_valid_bugaddr(unsigned long pc)
 	u32 insn = __opcode_to_mem_arm(BUG_INSTR_VALUE);
 #endif
 
+	if (pc < TASK_SIZE)
+		return 0;
+
 	if (get_kernel_nofault(bkpt, (void *)pc))
 		return 0;
 
-- 
2.43.0.381.gb435a96ce8-goog


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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-01-19 12:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-17 15:07 [PATCH] ARM: mm: Disregard user space addresses in BUG() address check Ard Biesheuvel
2024-01-17 18:25 ` Mark Brown
2024-01-18 13:16   ` Ard Biesheuvel
2024-01-18 20:15 ` Kees Cook
2024-01-19 11:52   ` Ard Biesheuvel
2024-01-19 12:14     ` Russell King (Oracle)
2024-01-19 12:24       ` Ard Biesheuvel
2024-01-18 20:35 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).