* [PATCH] powerpc/hw_breakpoint: Fix NULL pointer dereference in thread_change_pc()
@ 2026-11-26 23:04 Sridhar Markonda
2026-11-27 9:19 ` Gautam Menghani
0 siblings, 1 reply; 3+ messages 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 [flat|nested] 3+ messages in thread* Re: [PATCH] powerpc/hw_breakpoint: Fix NULL pointer dereference in thread_change_pc()
2026-11-26 23:04 [PATCH] powerpc/hw_breakpoint: Fix NULL pointer dereference in thread_change_pc() Sridhar Markonda
@ 2026-11-27 9:19 ` Gautam Menghani
2026-12-04 7:21 ` Sridhar Markonda
0 siblings, 1 reply; 3+ messages in thread
From: Gautam Menghani @ 2026-11-27 9:19 UTC (permalink / raw)
To: Sridhar Markonda
Cc: linuxppc-dev, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde,
ravi.bangoria, linux-kernel
Do you also have the reproducer for this issue? Also if this was
reported by upstream syzkaller, you have to put the Reported-by and
Closes tags.
Thanks,
Gautam
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/hw_breakpoint: Fix NULL pointer dereference in thread_change_pc()
2026-11-27 9:19 ` Gautam Menghani
@ 2026-12-04 7:21 ` Sridhar Markonda
0 siblings, 0 replies; 3+ messages in thread
From: Sridhar Markonda @ 2026-12-04 7:21 UTC (permalink / raw)
To: Gautam Menghani
Cc: linuxppc-dev, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde,
ravi.bangoria, linux-kernel
This issue was found by a local syzkaller instance running on
qemu-system-ppc64 (POWER10), not by upstream syzbot, so there is no
public syzbot report or Closes tag.
Syzkaller did not generate a standalone reproducer. Based on the crash
trace, I created the reproducer below. It installs a single hardware
watchpoint using perf_event_open() and repeatedly triggers it, while a
second thread continuously sends SIGUSR1 to the watched thread.
This exercises the thread_change_pc() reset path while a watchpoint is
in perf_single_step state.
On a POWER10 LPAR running an unpatched kernel, it crashes immediately
with the NULL pointer dereference. With the proposed fix applied, it
runs to completion.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <linux/perf_event.h>
#include <linux/hw_breakpoint.h>
static volatile int watch_target = 0;
static volatile int running = 1;
/* Signal handler: its delivery forces arch_do_signal_or_restart ->
thread_change_pc */
static void sig_handler(int sig)
{
/* Handled */
}
/* Thread that rapidly fires signals at the main thread */
static void *signal_flooder(void *arg)
{
pthread_t target_thread = *(pthread_t *)arg;
while (running) {
pthread_kill(target_thread, SIGUSR1);
usleep(10);
}
return NULL;
}
int main(void)
{
struct sigaction sa;
struct perf_event_attr pe;
pthread_t flooder;
pthread_t main_thread = pthread_self();
int fd;
/* 1. Register signal handler */
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sig_handler;
sigaction(SIGUSR1, &sa, NULL);
/* 2. Configure 1 hardware watchpoint (slot 0) */
memset(&pe, 0, sizeof(pe));
pe.type = PERF_TYPE_BREAKPOINT;
pe.size = sizeof(struct perf_event_attr);
pe.bp_type = HW_BREAKPOINT_W;
pe.bp_addr = (unsigned long)&watch_target;
pe.bp_len = sizeof(int);
pe.disabled = 0;
fd = syscall(__NR_perf_event_open, &pe, 0, -1, -1, 0);
if (fd < 0) {
perror("perf_event_open");
return 1;
}
printf("[+] HW Watchpoint installed on %p (fd=%d)\n",
&watch_target, fd);
printf("[+] Flooding signals to trigger thread_change_pc() race...\n");
/* 3. Start signal flooding thread */
pthread_create(&flooder, NULL, signal_flooder, &main_thread);
/* 4. Trigger watchpoint writes repeatedly */
for (int i = 0; i < 1000000; i++) {
watch_target = i; /* Triggers watchpoint exception & single-step */
}
running = 0;
pthread_join(flooder, NULL);
close(fd);
printf("[-] Finished without crash (kernel likely patched).\n");
return 0;
}
Thanks,
Sridhar
On 27/11/26 2:49 pm, Gautam Menghani wrote:
> Do you also have the reproducer for this issue? Also if this was
> reported by upstream syzkaller, you have to put the Reported-by and
> Closes tags.
>
> Thanks,
> Gautam
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 7:22 UTC | newest]
Thread overview: 3+ messages (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
2026-11-27 9:19 ` Gautam Menghani
2026-12-04 7:21 ` Sridhar Markonda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®