Skip to contentSkip to conversation

ARM: xip: end _etext before the read-only data

PATCH In review Brad Hawthorne 2 participants 2 messages Nov 25 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: xip: end _etext before the read-only data

The XIP linker script sets _etext after the read-only data, while vmlinux.lds.S sets it at the end of the text. Hardened usercopy refuses any copy to user space from _stext to _etext, so with XIP_KERNEL=y and HARDENED_USERCOPY=y, copying a const string from .rodata to user space ends in BUG(). The first readdir() of /dev is enough:

usercopy: Kernel memory exposure attempt detected from kernel text (offset 2955300, size 1)!
__check_object_size from filldir+0xd6/0xfc
filldir from dir_emit_dots+0x34/0x80

Commit 14c4a533e099 ("ARM: 8583/1: mm: fix location of _etext") moved _etext in vmlinux.lds.S for the same reason; the XIP script was missed. Set _etext at the end of the text there too.

Tested under QEMU (mps2-an385) and on an RP2350 board, both XIP: the BUG is gone and directories list normally.

This patch was written with an AI coding assistant (Claude Opus 5.5, Anthropic): it found the cause of the usercopy report, wrote the fix and this changelog, and ran the QEMU and board tests; I reviewed the reasoning and the test results.

Fixes dfd45b6103c9 ("ARM: uaccess: Enable hardened usercopy")
---
 arch/arm/kernel/vmlinux-xip.lds.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/kernel/vmlinux-xip.lds.S +2 -2
index 5afb725998ec..76e024cc50c9 100644
@@ -58,6 +58,8 @@ SECTIONS
 		ARM_TEXT
 	}
 
+	_etext = .;			/* End of text section */
+
 	RO_DATA(PAGE_SIZE)
 
 	. = ALIGN(4);
@@ -71,8 +73,6 @@ SECTIONS
 	ARM_UNWIND_SECTIONS
 #endif
 
-	_etext = .;			/* End of text and rodata section */
-
 	ARM_VECTORS
 	INIT_TEXT_SECTION(8)
 	.exit.text : {

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Brad Hawthorne

The XIP linker script sets _etext after the read-only data, while vmlinux.lds.S sets it at the end of the text. Hardened usercopy refuses any copy to user space from _stext to _etext, so with XIP_KERNEL=y and HARDENED_USERCOPY=y, copying a const string from .rodata to user space ends in BUG(). The first readdir() of /dev is enough:

usercopy: Kernel memory exposure attempt detected from kernel text
(offset 2955300, size 1)!
__check_object_size from filldir+0xd6/0xfc
filldir from dir_emit_dots+0x34/0x80

Commit 14c4a533e099 ("ARM: 8583/1: mm: fix location of _etext") moved _etext in vmlinux.lds.S for the same reason; the XIP script was missed. Set _etext at the end of the text there too.

Tested under QEMU (mps2-an385) and on an RP2350 board, both XIP: the BUG is gone and directories list normally.

Quoted 8 lines

This patch was written with an AI coding assistant (Claude Opus 5.5, Anthropic): it found the cause of the usercopy report, wrote the fix and this changelog, and ran the QEMU and board tests; I reviewed the reasoning and the test results.

Fixes dfd45b6103c9 ("ARM: uaccess: Enable hardened usercopy")

Looks good to me,