The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] powerpc/hw_breakpoint: Fix NULL pointer dereference in thread_change_pc()
@ 2026-11-26 23:04 Sridhar Markonda
  0 siblings, 0 replies; only message in thread
From: Sridhar Markonda @ 2026-11-26 23:04 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, ravi.bangoria,
	linux-kernel, Sridhar Markonda

Syzkaller reported a NULL pointer dereference on ppc64le:

  BUG: KASAN: null-ptr-deref in __set_breakpoint()
  Read of size 16 at addr 0000000000000190

  Call Trace:
  __set_breakpoint+0x6c/0xa0 arch/powerpc/kernel/process.c:880
  thread_change_pc+0x1c4/0x2f0 arch/powerpc/kernel/hw_breakpoint.c:247
  do_signal arch/powerpc/kernel/signal.c:279 [inline]
  arch_do_signal_or_restart+0x2dc/0x7c0 arch/powerpc/kernel/signal.c:360
  __exit_to_user_mode_loop kernel/entry/common.c:66 [inline]
  exit_to_user_mode_loop+0xa0/0x8d0 kernel/entry/common.c:101
  __exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
  syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline]
  syscall_exit_to_user_mode include/linux/entry-common.h:343 [inline]
  syscall_exit_prepare+0x494/0xc10 arch/powerpc/kernel/interrupt.c:124
  system_call_vectored_common+0x168/0x2ec

thread_change_pc() handles the case where a task changes its program
counter while a watchpoint is in perf_single_step state. The reset path
walks all watchpoint slots and restores watchpoints that were temporarily
disabled for single-stepping.

However, the number of installed watchpoints may be smaller than the
number of available hardware watchpoint slots, leaving unused bp_per_reg[]
entries NULL.

When the reset path encounters an unused slot, counter_arch_bp() operates
on a NULL perf_event pointer and produces an invalid arch_hw_breakpoint
pointer. This pointer is subsequently passed to __set_breakpoint(),
resulting in the reported NULL pointer dereference.

Fix this by skipping empty bp_per_reg[] slots and restore only watchpoints
that are currently in perf_single_step state.

Fixes: deb2bd9bcc84 ("powerpc/watchpoint: Return available watchpoints dynamically")

Signed-off-by: Sridhar Markonda <sridharm@linux.ibm.com>
---
 arch/powerpc/kernel/hw_breakpoint.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/hw_breakpoint.c b/arch/powerpc/kernel/hw_breakpoint.c
index a1318ce18d0e..4a5f0e27499a 100644
--- a/arch/powerpc/kernel/hw_breakpoint.c
+++ b/arch/powerpc/kernel/hw_breakpoint.c
@@ -228,12 +228,13 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,
 void thread_change_pc(struct task_struct *tsk, struct pt_regs *regs)
 {
 	struct arch_hw_breakpoint *info;
+	struct perf_event *bp;
 	int i;
 
 	preempt_disable();
 
 	for (i = 0; i < nr_wp_slots(); i++) {
-		struct perf_event *bp = __this_cpu_read(bp_per_reg[i]);
+		bp = __this_cpu_read(bp_per_reg[i]);
 
 		if (unlikely(bp && counter_arch_bp(bp)->perf_single_step))
 			goto reset;
@@ -243,9 +244,16 @@ void thread_change_pc(struct task_struct *tsk, struct pt_regs *regs)
 reset:
 	regs_set_return_msr(regs, regs->msr & ~MSR_SE);
 	for (i = 0; i < nr_wp_slots(); i++) {
-		info = counter_arch_bp(__this_cpu_read(bp_per_reg[i]));
-		__set_breakpoint(i, info);
-		info->perf_single_step = false;
+		bp = __this_cpu_read(bp_per_reg[i]);
+
+		if (!bp)
+			continue;
+
+		info = counter_arch_bp(bp);
+		if (info->perf_single_step) {
+			__set_breakpoint(i, info);
+			info->perf_single_step = false;
+		}
 	}
 
 out:
-- 
2.47.3


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-26 18:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 23:04 [PATCH] powerpc/hw_breakpoint: Fix NULL pointer dereference in thread_change_pc() Sridhar Markonda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox