Skip to contentSkip to conversation

powerpc: Restore KUAP registers on syscall restart exit

PATCH Applied Mukesh Kumar Chaurasiya (IBM) 3 participants 3 messages Jun 15 – Jun 19 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 powerpc: Restore KUAP registers on syscall restart exit

During a syscall restart, block KUAP so that pending interrupts can be replayed. The original KUAP state is not restored before returning to userspace, causing subsequent userspace accesses to fault and eventually trigger bad_access_pkey(), crashing the kernel.

The original KUAP register values are already saved in arch_enter_from_user_mode(). Restore them on the syscall restart exit path before returning to userspace.

Fixes bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")

---
V1 -> V2:
- Commit message rephrased
V1: https://lore.kernel.org/all/[email protected]

 arch/powerpc/kernel/interrupt.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/kernel/interrupt.c +1 -0
index 89a999be1352..f04978080837 100644
@@ -166,6 +166,7 @@ notrace unsigned long syscall_exit_restart(unsigned long r3, struct pt_regs *reg
 		goto again;
 	}
 
+	kuap_user_restore(regs);
 	regs->exit_result |= regs->exit_flags;
 
 	return regs->exit_result;
Signature · 1 line
2.54.0
Tested-by on v2 1/1
#1 lore raw
Quoted 25 lines · Mukesh Kumar Chaurasiya (IBM)

During a syscall restart, block KUAP so that pending interrupts can be replayed. The original KUAP state is not restored before returning to userspace, causing subsequent userspace accesses to fault and eventually trigger bad_access_pkey(), crashing the kernel.

The original KUAP register values are already saved in arch_enter_from_user_mode(). Restore them on the syscall restart exit path before returning to userspace.

Fixes bee25f97ad24 ("powerpc: Enable GENERIC_ENTRY feature")

---
V1 -> V2:
- Commit message rephrased
V1: https://lore.kernel.org/all/[email protected]

  arch/powerpc/kernel/interrupt.c | 1 +
  1 file changed, 1 insertion(+)
arch/powerpc/kernel/interrupt.c +0 -0
index 89a999be1352..f04978080837 100644

arch/powerpc/kernel/interrupt.c notrace unsigned long syscall_exit_restart(unsigned long r3, struct pt_regs *reg · line 172

Quoted 7 lines
arch/powerpc/kernel/interrupt.c +1 -0
@@ -166,6 +166,7 @@ notrace unsigned long syscall_exit_restart(unsigned long r3, struct pt_regs *reg
  		goto again;
  	}
 
+	kuap_user_restore(regs);
  	regs->exit_result |= regs->exit_flags;
 
  	return regs->exit_result;

This fixes the reported issue.

maintainer Applied
#2 lore raw
In reply to Mukesh Kumar Chaurasiya (IBM)
Quoted 10 lines · Mukesh Kumar Chaurasiya (IBM)

During a syscall restart, block KUAP so that pending interrupts can be replayed. The original KUAP state is not restored before returning to userspace, causing subsequent userspace accesses to fault and eventually trigger bad_access_pkey(), crashing the kernel.

The original KUAP register values are already saved in arch_enter_from_user_mode(). Restore them on the syscall restart exit path before returning to userspace.

[...]

Applied to powerpc/next.

[1/1] powerpc: Restore KUAP registers on syscall restart exit

      https://git.kernel.org/powerpc/c/4e1187e12de40b5301977b2476d21b569358dafb

cheers