The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Sridhar Markonda <sridharm@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
	chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
	ravi.bangoria@linux.ibm.com, linux-kernel@vger.kernel.org,
	Sridhar Markonda <sridharm@linux.ibm.com>
Subject: [PATCH] powerpc/hw_breakpoint: Fix NULL pointer dereference in thread_change_pc()
Date: Thu, 26 Nov 2026 18:04:22 -0500	[thread overview]
Message-ID: <20261126230422.1533-1-sridharm@linux.ibm.com> (raw)

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


                 reply	other threads:[~2026-11-26 18:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126230422.1533-1-sridharm@linux.ibm.com \
    --to=sridharm@linux.ibm.com \
    --cc=chleroy@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=ravi.bangoria@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=sshegde@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox