Skip to contentSkip to conversation

s390/kprobes: Prevent kprobes on instructions with exception table entry

PATCH In review Heiko Carstens 2 participants 4 messages Sep 24 – Oct 2 s390

lore
Share & tools
lore

Heiko Carstens

author maintainer
#0 lore raw

PATCH 1/1 s390/kprobes: Prevent kprobes on instructions with exception table entry

The mvcos exception handler ex_handler_ua_mvcos() decodes the faulting instruction, assuming it is an mvcos instruction. In case the instruction is kprobed the decoded instruction is a breakpoint instruction instead, which leads to incorrect instruction decoding and potential register corruption.

Fix this by simply preventing to set a kprobe on such instructions, similar like arm64 is doing it.

Fixes c488f5187a24 ("s390/uaccess: Shorten raw_copy_from_user() / raw_copy_to_user() inline assemblies")
---
 arch/s390/kernel/kprobes.c | 3 +++
 1 file changed, 3 insertions(+)
arch/s390/kernel/kprobes.c +3 -0
index c450120b4474..e806b124e4ba 100644
@@ -85,6 +85,9 @@ static bool can_probe(unsigned long paddr)
 	if (!kallsyms_lookup_size_offset(paddr, NULL, &offset))
 		return false;
 
+	if (s390_search_extables(paddr))
+		return false;
+
 	/* Decode instructions */
 	addr = paddr - offset;
 	while (addr < paddr) {
Signature · 1 line
2.53.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines

The mvcos exception handler ex_handler_ua_mvcos() decodes the faulting instruction, assuming it is an mvcos instruction. In case the instruction is kprobed the decoded instruction is a breakpoint instruction instead, which leads to incorrect instruction decoding and potential register corruption.

Quoted 6 lines

Fix this by simply preventing to set a kprobe on such instructions, similar like arm64 is doing it.

Fixes c488f5187a24 ("s390/uaccess: Shorten raw_copy_from_user() / raw_copy_to_user() inline assemblies")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#2 lore raw
In reply to Heiko Carstens
Quoted 21 lines · Heiko Carstens

The mvcos exception handler ex_handler_ua_mvcos() decodes the faulting instruction, assuming it is an mvcos instruction. In case the instruction is kprobed the decoded instruction is a breakpoint instruction instead, which leads to incorrect instruction decoding and potential register corruption.

Fix this by simply preventing to set a kprobe on such instructions, similar like arm64 is doing it.

Fixes c488f5187a24 ("s390/uaccess: Shorten raw_copy_from_user() / raw_copy_to_user() inline assemblies")
---
 arch/s390/kernel/kprobes.c | 3 +++
 1 file changed, 3 insertions(+)
arch/s390/kernel/kprobes.c +0 -0
index c450120b4474..e806b124e4ba 100644

arch/s390/kernel/kprobes.c static bool can_probe(unsigned long paddr) · line 91

Quoted 7 lines
arch/s390/kernel/kprobes.c +3 -0
@@ -85,6 +85,9 @@ static bool can_probe(unsigned long paddr)
 	if (!kallsyms_lookup_size_offset(paddr, NULL, &offset))
 		return false;
 
+	if (s390_search_extables(paddr))
+		return false;
+
 	/* Decode instructions */

FWIW, I believe x86 has a similar problem since it tries to decode the mov instruction of load_unaligned_zeropad() in ex_handler_zeropad() which was introduced with [1]. If a kprobe is placed there instruction decoding will fail.

As far as I can tell there is nothing that prevents that a kprobe is placed there.

[1] c4e34dd99f2e ("x86: simplify load_unaligned_zeropad() implementation")

author maintainer
#3 lore raw
In reply to Heiko Carstens
Quoted 9 lines · Heiko Carstens

The mvcos exception handler ex_handler_ua_mvcos() decodes the faulting instruction, assuming it is an mvcos instruction. In case the instruction is kprobed the decoded instruction is a breakpoint instruction instead, which leads to incorrect instruction decoding and potential register corruption.

Fix this by simply preventing to set a kprobe on such instructions, similar like arm64 is doing it.

Quoted 6 lines
Fixes c488f5187a24 ("s390/uaccess: Shorten raw_copy_from_user() / raw_copy_to_user() inline assemblies")
---
 arch/s390/kernel/kprobes.c | 3 +++
 1 file changed, 3 insertions(+)

This patch has been integrated as first patch into
https://lore.kernel.org/all/[email protected]/