Skip to contentSkip to conversation

powerpc: Disable syscall emulation and stepping

PATCH In review Nicholas Piggin 4 participants 12 messages Jan 24, 2022 – Jan 28, 2022 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
author reviewer
#1 lore raw

PATCH 1/2 powerpc/64: remove system call instruction emulation

In reply to Nicholas Piggin

emulate_step instruction emulation including sc instruction emulation initially appeared in xmon. It then emulation code was then moved into sstep.c where kprobes could use it too, and later hw_breakpoint and uprobes started to use it.

Until uprobes, the only instruction emulation users were for kernel mode instructions.

- xmon only steps / breaks on kernel addresses.
- kprobes is kernel only.
- hw_breakpoint only emulates kernel instructions, single steps user.

At one point there was support for the kernel to execute sc instructions, although that is long removed and it's not clear whether there was any in-tree code. So system call emulation is not required by the above users.

uprobes uses emulate_step and it appears possible to emulate sc instruction in userspace. Userspace system call emulation is broken and it's not clear it ever worked well.

The big complication is that userspace takes an interrupt to the kernel to emulate the instruction. The user->kernel interrupt sets up registers and interrupt stack frame expecting to return to userspace, then system call instruction emulation re-directs that stack frame to the kernel, early in the system call interrupt handler. This means the the interrupt return code takes the kernel->kernel restore path, which does not restore everything as the system call interrupt handler would expect coming from userspace. regs->iamr appears to get lost for example, because the kernel->kernel return does not restore the user iamr. Accounting such as irqflags tracing and CPU accounting does not get flipped back to user mode as the system call handler expects, so those appear to enter the kernel twice without returning to userspace.

These things may be individually fixable with various complication, but it is a big complexity for unclear real benefit.

This patch removes system call emulation and disables stepping system calls (because they don't work with trace interrupts, as commented).

---
 arch/powerpc/kernel/interrupt_64.S | 10 -------
 arch/powerpc/lib/sstep.c           | 42 ++++++++----------------------
 2 files changed, 11 insertions(+), 41 deletions(-)
arch/powerpc/kernel/interrupt_64.S +0 -10
index 7bab2d7de372..6471034c7909 100644
@@ -219,16 +219,6 @@ system_call_vectored common 0x3000
  */
 system_call_vectored sigill 0x7ff0
 
-
-/*
- * Entered via kernel return set up by kernel/sstep.c, must match entry regs
- */
-	.globl system_call_vectored_emulate
-system_call_vectored_emulate:
-_ASM_NOKPROBE_SYMBOL(system_call_vectored_emulate)
-	li	r10,IRQS_ALL_DISABLED
-	stb	r10,PACAIRQSOFTMASK(r13)
-	b	system_call_vectored_common
 #endif /* CONFIG_PPC_BOOK3S */
 
 	.balign IFETCH_ALIGN_BYTES
arch/powerpc/lib/sstep.c +11 -31

59 lines not on this page · raw message

Signature · 1 line
2.23.0

Nicholas Piggin

author reviewer
#0 lore raw

cover powerpc: Disable syscall emulation and stepping

As discussed previously

https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-January/238946.html

I'm wondering whether PPC32 should be returning -1 for syscall instructions too here? That could be done in another patch anyway.

Thanks,
Nick

Nicholas Piggin (2):
powerpc/64: remove system call instruction emulation powerpc/uprobes: Reject uprobe on a system call instruction

 arch/powerpc/include/asm/ppc-opcode.h |  1 +
 arch/powerpc/kernel/interrupt_64.S    | 10 -------
 arch/powerpc/kernel/uprobes.c         |  6 ++++
 arch/powerpc/lib/sstep.c              | 42 +++++++--------------------
 4 files changed, 18 insertions(+), 41 deletions(-)
Signature · 1 line
2.23.0
author reviewer
#2 lore raw

PATCH 2/2 powerpc/uprobes: Reject uprobe on a system call instruction

Per the ISA, a Trace interrupt is not generated for a system call [vectored] instruction. Reject uprobes on such instructions as we are not emulating a system call [vectored] instruction anymore.

[np: Switch to pr_info_ratelimited]
---
 arch/powerpc/include/asm/ppc-opcode.h | 1 +
 arch/powerpc/kernel/uprobes.c         | 6 ++++++
 2 files changed, 7 insertions(+)
arch/powerpc/include/asm/ppc-opcode.h +1 -0
index 9675303b724e..8bbe16ce5173 100644
@@ -411,6 +411,7 @@
 #define PPC_RAW_DCBFPS(a, b)		(0x7c0000ac | ___PPC_RA(a) | ___PPC_RB(b) | (4 << 21))
 #define PPC_RAW_DCBSTPS(a, b)		(0x7c0000ac | ___PPC_RA(a) | ___PPC_RB(b) | (6 << 21))
 #define PPC_RAW_SC()			(0x44000002)
+#define PPC_RAW_SCV()			(0x44000001)
 #define PPC_RAW_SYNC()			(0x7c0004ac)
 #define PPC_RAW_ISYNC()			(0x4c00012c)
 
arch/powerpc/kernel/uprobes.c +6 -0
index c6975467d9ff..3779fde804bd 100644
@@ -41,6 +41,12 @@ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe,
 	if (addr & 0x03)
 		return -EINVAL;
 
+	if (ppc_inst_val(ppc_inst_read(auprobe->insn)) == PPC_RAW_SC() ||
+	    ppc_inst_val(ppc_inst_read(auprobe->insn)) == PPC_RAW_SCV()) {
+		pr_info_ratelimited("Rejecting uprobe on system call instruction\n");
+		return -EINVAL;
+	}
+
 	if (cpu_has_feature(CPU_FTR_ARCH_31) &&
 	    ppc_inst_prefixed(ppc_inst_read(auprobe->insn)) &&
 	    (addr & 0x3f) == 60) {
Signature · 1 line
2.23.0
#6 lore raw
In reply to Nicholas Piggin

Le 24/01/2022 à 06:57, Nicholas Piggin a écrit :

Quoted 7 lines

As discussed previously

https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-January/238946.html

I'm wondering whether PPC32 should be returning -1 for syscall instructions too here? That could be done in another patch anyway.

The 'Programming Environments Manual for 32-Bit Implementations of the PowerPC™ Architecture' says:

The following are not traced:
• rfi instruction
• sc and trap instructions that trap
• Other instructions that cause interrupts (other than trace interrupts)
• The first instruction of any interrupt handler
• Instructions that are emulated by software

So I think PPC32 should return -1 as well.

Christophe

author reviewer
#7 lore raw

+Naveen (sorry missed cc'ing you at first)

Excerpts from Christophe Leroy's message of January 24, 2022 4:39 pm:

Quoted 22 lines

Le 24/01/2022 à 06:57, Nicholas Piggin a écrit :

Quoted 7 lines

As discussed previously

https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-January/238946.html

I'm wondering whether PPC32 should be returning -1 for syscall instructions too here? That could be done in another patch anyway.

The 'Programming Environments Manual for 32-Bit Implementations of the PowerPC™ Architecture' says:

The following are not traced:
• rfi instruction
• sc and trap instructions that trap
• Other instructions that cause interrupts (other than trace interrupts)
• The first instruction of any interrupt handler
• Instructions that are emulated by software

Quoted 1 line

So I think PPC32 should return -1 as well.

I agree.

What about the trap instructions? analyse_instr returns 0 for them which falls through to return 0 for emulate_step, should they return -1 as well or am I missing something?

Thanks,
Nick

#8 lore raw

Le 25/01/2022 à 04:04, Nicholas Piggin a écrit :

Quoted 25 lines

+Naveen (sorry missed cc'ing you at first)

Excerpts from Christophe Leroy's message of January 24, 2022 4:39 pm:

Quoted 22 lines

Le 24/01/2022 à 06:57, Nicholas Piggin a écrit :

Quoted 7 lines

As discussed previously

https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-January/238946.html

I'm wondering whether PPC32 should be returning -1 for syscall instructions too here? That could be done in another patch anyway.

The 'Programming Environments Manual for 32-Bit Implementations of the PowerPC™ Architecture' says:

The following are not traced:
• rfi instruction
• sc and trap instructions that trap
• Other instructions that cause interrupts (other than trace interrupts)
• The first instruction of any interrupt handler
• Instructions that are emulated by software

Quoted 8 lines
Quoted 1 line

So I think PPC32 should return -1 as well.

I agree.

What about the trap instructions? analyse_instr returns 0 for them which falls through to return 0 for emulate_step, should they return -1 as well or am I missing something?

For the traps I don't know. The manual says "trap instructions that trap" are not traced. It means that "trap instructions that _don't_ trap" are traced. Taking into account that trap instructions don't trap at least 99.9% of the time, not sure if returning -1 is needed.

Allthought that'd probably be the safest.

But then what happens with other instruction that will sparsely generate an exception like a DSI or so ? If we do it for the traps then we should do it for this as well, and then it becomes a non ending story.

So at the end it's probably ok with return 0, both for them and for traps.

Christophe

#3 lore raw

Re: [PATCH 2/2] powerpc/uprobes: Reject uprobe on a system call instruction

In reply to Nicholas Piggin
Quoted 3 lines · Nicholas Piggin

Per the ISA, a Trace interrupt is not generated for a system call [vectored] instruction. Reject uprobes on such instructions as we are not emulating a system call [vectored] instruction anymore.

This should really be patch 1, otherwise there's a single commit window where we allow uprobes on sc but don't honour them.

Quoted 25 lines
[np: Switch to pr_info_ratelimited]
---
 arch/powerpc/include/asm/ppc-opcode.h | 1 +
 arch/powerpc/kernel/uprobes.c         | 6 ++++++
 2 files changed, 7 insertions(+)
arch/powerpc/include/asm/ppc-opcode.h +1 -0
index 9675303b724e..8bbe16ce5173 100644
@@ -411,6 +411,7 @@
 #define PPC_RAW_DCBFPS(a, b)		(0x7c0000ac | ___PPC_RA(a) | ___PPC_RB(b) | (4 << 21))
 #define PPC_RAW_DCBSTPS(a, b)		(0x7c0000ac | ___PPC_RA(a) | ___PPC_RB(b) | (6 << 21))
 #define PPC_RAW_SC()			(0x44000002)
+#define PPC_RAW_SCV()			(0x44000001)
 #define PPC_RAW_SYNC()			(0x7c0004ac)
 #define PPC_RAW_ISYNC()			(0x4c00012c)
 
arch/powerpc/kernel/uprobes.c +0 -0
index c6975467d9ff..3779fde804bd 100644

arch/powerpc/kernel/uprobes.c int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, · line 45

Quoted 5 lines
arch/powerpc/kernel/uprobes.c +2 -0
@@ -41,6 +41,12 @@ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe,
 	if (addr & 0x03)
 		return -EINVAL;
 
+	if (ppc_inst_val(ppc_inst_read(auprobe->insn)) == PPC_RAW_SC() ||
+	    ppc_inst_val(ppc_inst_read(auprobe->insn)) == PPC_RAW_SCV()) {

We should probably reject hypercall too?

There's also a lot of reserved fields in sc, so doing an exact match like this risks missing instructions that are badly formed but the CPU will happily execute as sc.

We'd obviously never expect to see those in compiler generated code, but it'd still be safer to mask. We could probably just reject opcode 17 entirely.

And I guess for a subsequent patch, but we should be rejecting some others here as well shouldn't we? Like rfid etc.

cheers

Quoted 9 lines
arch/powerpc/kernel/uprobes.c +4 -0
+		pr_info_ratelimited("Rejecting uprobe on system call instruction\n");
+		return -EINVAL;
+	}
+
 	if (cpu_has_feature(CPU_FTR_ARCH_31) &&
 	    ppc_inst_prefixed(ppc_inst_read(auprobe->insn)) &&
 	    (addr & 0x3f) == 60) {
Signature · 1 line
2.23.0
author reviewer
#10 lore raw
In reply to a message not in the archive

Excerpts from naverao1's message of January 25, 2022 8:48 pm:

Quoted 63 lines · Christophe Leroy
Quoted 35 lines

Le 25/01/2022 à 04:04, Nicholas Piggin a écrit :

Quoted 34 lines

+Naveen (sorry missed cc'ing you at first)

Excerpts from Christophe Leroy's message of January 24, 2022 4:39 pm:

Quoted 24 lines

Le 24/01/2022 à 06:57, Nicholas Piggin a écrit :

Quoted 7 lines

As discussed previously

https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-January/238946.html

I'm wondering whether PPC32 should be returning -1 for syscall instructions too here? That could be done in another patch anyway.

The 'Programming Environments Manual for 32-Bit Implementations of the
PowerPC™ Architecture' says:

The following are not traced:
• rfi instruction
• sc and trap instructions that trap
• Other instructions that cause interrupts (other than trace interrupts)
• The first instruction of any interrupt handler
• Instructions that are emulated by software

Quoted 1 line

So I think PPC32 should return -1 as well.

I agree.

What about the trap instructions? analyse_instr returns 0 for them which falls through to return 0 for emulate_step, should they return -1 as well or am I missing something?

Yeah, good point about the trap instructions.

Quoted 8 lines
Quoted 1 line

For the traps I don't know. The manual says "trap instructions that trap" are not traced. It means that "trap instructions that _don't_ trap" are traced. Taking into account that trap instructions don't trap at least 99.9% of the time, not sure if returning -1 is needed.

Allthought that'd probably be the safest.

'trap' is a special case since it is predominantly used by debuggers and/or tracing infrastructure. Kprobes and Uprobes do not allow probes on a trap instruction. But, xmon can be asked to step on a trap instruction and that can interfere with kprobes in weird ways.

So, I think it is best if we also exclude trap instructions from being single stepped.

Quoted 6 lines

But then what happens with other instruction that will sparsely generate
an exception like a DSI or so ? If we do it for the traps then we should
do it for this as well, and then it becomes a non ending story.

Quoted 4 lines

For a DSI, we restart the same instruction after handling the page fault.
The single step exception is raised on the subsequent successful completion of the instruction.

Although it can cause a signal, and the signal handler can decide to resume somewhere else. Or kernel mode equivalent it can go to a fixup handler and resume somewhere else.

How are those handled?

Thanks,
Nick

Quoted 9 lines

For most other interrupts (alignment, vsx
unavailable, ...), we end up emulating the single step exception itself (see emulate_single_step()). So, those are ok if caused by an instruction
being stepped.

- Naveen

author reviewer
#4 lore raw

Re: [PATCH 2/2] powerpc/uprobes: Reject uprobe on a system call instruction

In reply to Michael Ellerman

Excerpts from Michael Ellerman's message of January 25, 2022 9:45 pm:

Quoted 7 lines
Quoted 3 lines · Nicholas Piggin

Per the ISA, a Trace interrupt is not generated for a system call [vectored] instruction. Reject uprobes on such instructions as we are not emulating a system call [vectored] instruction anymore.

This should really be patch 1, otherwise there's a single commit window where we allow uprobes on sc but don't honour them.

Yep true. I also messed up Naveen's attribution! Will re-send (or maybe Naveen would take over the series).

Quoted 29 lines
Quoted 29 lines
[np: Switch to pr_info_ratelimited]
---
 arch/powerpc/include/asm/ppc-opcode.h | 1 +
 arch/powerpc/kernel/uprobes.c         | 6 ++++++
 2 files changed, 7 insertions(+)
arch/powerpc/include/asm/ppc-opcode.h +1 -0
index 9675303b724e..8bbe16ce5173 100644
@@ -411,6 +411,7 @@
 #define PPC_RAW_DCBFPS(a, b)		(0x7c0000ac | ___PPC_RA(a) | ___PPC_RB(b) | (4 << 21))
 #define PPC_RAW_DCBSTPS(a, b)		(0x7c0000ac | ___PPC_RA(a) | ___PPC_RB(b) | (6 << 21))
 #define PPC_RAW_SC()			(0x44000002)
+#define PPC_RAW_SCV()			(0x44000001)
 #define PPC_RAW_SYNC()			(0x7c0004ac)
 #define PPC_RAW_ISYNC()			(0x4c00012c)
 
arch/powerpc/kernel/uprobes.c +0 -0
index c6975467d9ff..3779fde804bd 100644
@@ -41,6 +41,12 @@ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe,
 	if (addr & 0x03)
 		return -EINVAL;
 
Quoted 8 lines

arch/powerpc/kernel/uprobes.c int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, · line 45

Quoted 2 lines
arch/powerpc/kernel/uprobes.c +2 -0
+	if (ppc_inst_val(ppc_inst_read(auprobe->insn)) == PPC_RAW_SC() ||
+	    ppc_inst_val(ppc_inst_read(auprobe->insn)) == PPC_RAW_SCV()) {

We should probably reject hypercall too?

There's also a lot of reserved fields in sc, so doing an exact match like this risks missing instructions that are badly formed but the CPU will happily execute as sc.

Yeah, scv as well has lev != 0 unsupported so should be excluded.

Quoted 7 lines

We'd obviously never expect to see those in compiler generated code, but it'd still be safer to mask. We could probably just reject opcode 17 entirely.

And I guess for a subsequent patch, but we should be rejecting some others here as well shouldn't we? Like rfid etc.

Traps under discussion I guess. For uprobe, rfid will be just another privilege fault. Is that dealt with somehow or do all privileged and illegal instructions also need to be excluded from stepping? (I assume we must handle that in a general way somehow)

Thanks,
Nick

#12 lore raw
In reply to Christophe Leroy

[Sorry if you receive this in duplicate. Resending since this message didn't hit the list]

Quoted 33 lines · Christophe Leroy

Le 25/01/2022 à 04:04, Nicholas Piggin a écrit :

Quoted 32 lines

+Naveen (sorry missed cc'ing you at first)

Excerpts from Christophe Leroy's message of January 24, 2022 4:39 pm:

Quoted 22 lines

Le 24/01/2022 à 06:57, Nicholas Piggin a écrit :

Quoted 7 lines

As discussed previously

https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-January/238946.html

I'm wondering whether PPC32 should be returning -1 for syscall instructions too here? That could be done in another patch anyway.

The 'Programming Environments Manual for 32-Bit Implementations of the PowerPC™ Architecture' says:

The following are not traced:
• rfi instruction
• sc and trap instructions that trap
• Other instructions that cause interrupts (other than trace interrupts)
• The first instruction of any interrupt handler
• Instructions that are emulated by software

Quoted 1 line

So I think PPC32 should return -1 as well.

I agree.

What about the trap instructions? analyse_instr returns 0 for them which falls through to return 0 for emulate_step, should they return -1 as well or am I missing something?

Yeah, good point about the trap instructions.

Quoted 8 lines
Quoted 1 line

For the traps I don't know. The manual says "trap instructions that trap" are not traced. It means that "trap instructions that _don't_ trap" are traced. Taking into account that trap instructions don't trap at least 99.9% of the time, not sure if returning -1 is needed.

Allthought that'd probably be the safest.

'trap' is a special case since it is predominantly used by debuggers and/or tracing infrastructure. Kprobes and Uprobes do not allow probes on a trap instruction. But, xmon can be asked to step on a trap instruction and that can interfere with kprobes in weird ways.

So, I think it is best if we also exclude trap instructions from being single stepped.

Quoted 4 lines

But then what happens with other instruction that will sparsely generate an exception like a DSI or so ? If we do it for the traps then we should do it for this as well, and then it becomes a non ending story.

For a DSI, we restart the same instruction after handling the page fault. The single step exception is raised on the subsequent successful completion of the instruction. For most other interrupts (alignment, vsx unavailable, ...), we end up emulating the single step exception itself (see emulate_single_step()). So, those are ok if caused by an instruction being stepped.

- Naveen

#11 lore raw
In reply to Nicholas Piggin
Quoted 64 lines · Nicholas Piggin

Excerpts from naverao1's message of January 25, 2022 8:48 pm:

Quoted 63 lines · Christophe Leroy
Quoted 35 lines

Le 25/01/2022 à 04:04, Nicholas Piggin a écrit :

Quoted 34 lines

+Naveen (sorry missed cc'ing you at first)

Excerpts from Christophe Leroy's message of January 24, 2022 4:39 pm:

Quoted 24 lines

Le 24/01/2022 à 06:57, Nicholas Piggin a écrit :

Quoted 7 lines

As discussed previously

https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-January/238946.html

I'm wondering whether PPC32 should be returning -1 for syscall instructions too here? That could be done in another patch anyway.

The 'Programming Environments Manual for 32-Bit Implementations of the
PowerPC™ Architecture' says:

The following are not traced:
• rfi instruction
• sc and trap instructions that trap
• Other instructions that cause interrupts (other than trace interrupts)
• The first instruction of any interrupt handler
• Instructions that are emulated by software

Quoted 1 line

So I think PPC32 should return -1 as well.

I agree.

What about the trap instructions? analyse_instr returns 0 for them which falls through to return 0 for emulate_step, should they return -1 as well or am I missing something?

Yeah, good point about the trap instructions.

Quoted 8 lines
Quoted 1 line

For the traps I don't know. The manual says "trap instructions that trap" are not traced. It means that "trap instructions that _don't_ trap" are traced. Taking into account that trap instructions don't trap at least 99.9% of the time, not sure if returning -1 is needed.

Allthought that'd probably be the safest.

'trap' is a special case since it is predominantly used by debuggers and/or tracing infrastructure. Kprobes and Uprobes do not allow probes on a trap instruction. But, xmon can be asked to step on a trap instruction and that can interfere with kprobes in weird ways.

So, I think it is best if we also exclude trap instructions from being single stepped.

Quoted 6 lines

But then what happens with other instruction that will sparsely generate
an exception like a DSI or so ? If we do it for the traps then we should
do it for this as well, and then it becomes a non ending story.

Quoted 7 lines
Quoted 4 lines

For a DSI, we restart the same instruction after handling the page fault.
The single step exception is raised on the subsequent successful completion of the instruction.

Although it can cause a signal, and the signal handler can decide to resume somewhere else.

If a signal is generated while we are single-stepping, we delay signal delivery (see uprobe_deny_signal()) until after the single stepping. For fatal signals, single stepping is disabled before we allow the signal to be delivered.

Quoted 2 lines

Or kernel mode equivalent it can go to a
fixup handler and resume somewhere else.

For kprobes, we do not allow probing instructions that have an extable entry.

- Naveen

#5 lore raw

Re: [PATCH 2/2] powerpc/uprobes: Reject uprobe on a system call instruction

In reply to Nicholas Piggin
Quoted 11 lines · Nicholas Piggin

Excerpts from Michael Ellerman's message of January 25, 2022 9:45 pm:

Quoted 7 lines
Quoted 3 lines · Nicholas Piggin

Per the ISA, a Trace interrupt is not generated for a system call [vectored] instruction. Reject uprobes on such instructions as we are not emulating a system call [vectored] instruction anymore.

This should really be patch 1, otherwise there's a single commit window where we allow uprobes on sc but don't honour them.

Yep true. I also messed up Naveen's attribution! Will re-send (or maybe Naveen would take over the series).

Yes, let me come up with a better, more complete patch for this.

Quoted 38 lines
Quoted 38 lines
Quoted 29 lines
[np: Switch to pr_info_ratelimited]
---
 arch/powerpc/include/asm/ppc-opcode.h | 1 +
 arch/powerpc/kernel/uprobes.c         | 6 ++++++
 2 files changed, 7 insertions(+)
arch/powerpc/include/asm/ppc-opcode.h +1 -0
index 9675303b724e..8bbe16ce5173 100644
@@ -411,6 +411,7 @@
 #define PPC_RAW_DCBFPS(a, b)		(0x7c0000ac | ___PPC_RA(a) | 
 ___PPC_RB(b) | (4 << 21))
 #define PPC_RAW_DCBSTPS(a, b)		(0x7c0000ac | ___PPC_RA(a) | 
 ___PPC_RB(b) | (6 << 21))
 #define PPC_RAW_SC()			(0x44000002)
+#define PPC_RAW_SCV()			(0x44000001)
 #define PPC_RAW_SYNC()			(0x7c0004ac)

#define PPC_RAW_ISYNC() (0x4c00012c)

arch/powerpc/kernel/uprobes.c +0 -0
index c6975467d9ff..3779fde804bd 100644

arch/powerpc/kernel/uprobes.c int arch_uprobe_analyze_insn(struct arch_uprobe · line 46

Quoted 6 lines
arch/powerpc/kernel/uprobes.c +2 -0
@@ -41,6 +41,12 @@ int arch_uprobe_analyze_insn(struct arch_uprobe 
 *auprobe,
 	if (addr & 0x03)
 		return -EINVAL;
 
+	if (ppc_inst_val(ppc_inst_read(auprobe->insn)) == PPC_RAW_SC() ||
+	    ppc_inst_val(ppc_inst_read(auprobe->insn)) == PPC_RAW_SCV()) {

We should probably reject hypercall too?

Quoted 9 lines
Quoted 3 lines

There's also a lot of reserved fields in sc, so doing an exact match like this risks missing instructions that are badly formed but the CPU will happily execute as sc.

Yeah, scv as well has lev != 0 unsupported so should be excluded.

Quoted 4 lines

We'd obviously never expect to see those in compiler generated code, but it'd still be safer to mask. We could probably just reject opcode 17 entirely.

Indeed, thanks.

Quoted 8 lines
Quoted 3 lines

And I guess for a subsequent patch, but we should be rejecting some others here as well shouldn't we? Like rfid etc.

Traps under discussion I guess. For uprobe, rfid will be just another privilege fault. Is that dealt with somehow or do all privileged and illegal instructions also need to be excluded from stepping? (I assume we must handle that in a general way somehow)

Yes, this is all handled in our interrupt code if we emulate any of those privileged instructions. Otherwise, if a signal is generated, that would be caught by uprobe_deny_signal().

Thanks,
Naveen