perf/hw_breakpoint: Avoid leaking private x86 breakpoint ranges
Subsystems (2)
PATCH 1/1 perf/hw_breakpoint: Avoid leaking private x86 breakpoint ranges
An unprivileged caller can open a user breakpoint and submit a rejected PERF_EVENT_IOC_MODIFY_ATTRIBUTES request that changes exclude_kernel to zero. The architecture parser runs before the immutable-attribute check, so an x86 blacklist hit returns EINVAL while an ordinary kernel address reaches the CAP_SYS_ADMIN check and returns EPERM.
Moving the attribute check alone is insufficient. On CPUs without BPEXT, an aligned power-of-two data range larger than eight bytes normally returns EOPNOTSUPP, but overlapping the CPU-entry blacklist returns EINVAL first. Such requests can keep exclude_kernel set and can also be made through perf_event_open(). In particular, the __per_cpu_offset check exposes the relocated kernel image.
Validate immutable attributes before parsing a modify request. Also check x86 kernel-breakpoint access before consulting either private blacklist, using the whole requested data range even when its length is unsupported. Check instruction lengths first so that the sizeof(long) ABI does not turn a single-address user instruction breakpoint into a kernel range. Keep the overflow check, the generic post-parse permission check, and all blacklist restrictions on authorized kernel breakpoints.
--- arch/x86/kernel/hw_breakpoint.c | 44 ++++++++++++++++++++++----------- kernel/events/hw_breakpoint.c | 8 +++--- 2 files changed, 33 insertions(+), 19 deletions(-)
arch/x86/kernel/hw_breakpoint.c +29 -15
@@ -15,6 +15,7 @@* using the CPU's debug registers. */ +#include <linux/capability.h> #include <linux/perf_event.h> #include <linux/hw_breakpoint.h> #include <linux/irqflags.h>
@@ -332,14 +333,35 @@ static int arch_build_bp_info(struct perf_event *bp,return -EINVAL ;/* -* Prevent any breakpoint of any type that overlaps the CPU -* entry area and data. This protects the IST stacks and also -* reduces the chance that we ever find out what happens if -* there's a data breakpoint on the GDT, IDT, or TSS. +* Instruction breakpoints match only the address, but their ABI +* requires a length of sizeof(long). Reject other lengths before +* checking the address range. */ -if (within_cpu_entry (attr->bp_addr, bp_end)) +if (attr->bp_type ==HW_BREAKPOINT_X && attr->bp_len !=sizeof (long ))return -EINVAL ; +/* +* Check permissions before consulting the private kernel address +* ranges below. Otherwise their errors disclose the kernel layout, +* including for unsupported range-breakpoint lengths. +*/ +if (attr->bp_addr >=TASK_SIZE_MAX || + (attr->bp_type !=HW_BREAKPOINT_X && bp_end >=TASK_SIZE_MAX )) { +if (attr->exclude_kernel) +return -EINVAL ; +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +/* +* Prevent any breakpoint of any type that overlaps the CPU +* entry area and data. This protects the IST stacks and also +* reduces the chance that we ever find out what happens if +* there's a data breakpoint on the GDT, IDT, or TSS. +*/ +if (within_cpu_entry (attr->bp_addr, bp_end)) +return -EINVAL ; + } + hw->address = attr->bp_addr; hw->mask =0 ;
@@ -363,16 +385,8 @@ static int arch_build_bp_info(struct perf_event *bp, } hw->type =X86_BREAKPOINT_EXECUTE ; -/* -* x86 inst breakpoints need to have a specific undefined len. -* But we still need to check userspace is not trying to setup -* an unsupported length, to get a range breakpoint for example. -*/ -if (attr->bp_len ==sizeof (long )) { - hw->len =X86_BREAKPOINT_LEN_X ; -return 0 ; - } - fallthrough; + hw->len =X86_BREAKPOINT_LEN_X ; +return 0 ;default :return -EINVAL ; }
kernel/events/hw_breakpoint.c +4 -4
@@ -765,10 +765,6 @@ modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *astruct arch_hw_breakpoint hw = { };int err; - err =hw_breakpoint_parse (bp, attr, &hw); -if (err) -return err; -if (check) {struct perf_event_attr old_attr;
@@ -778,6 +774,10 @@ modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *areturn -EINVAL ; } + err =hw_breakpoint_parse (bp, attr, &hw); +if (err) +return err; +if (bp->attr.bp_type != attr->bp_type) { err =modify_bp_slot (bp, bp->attr.bp_type, attr->bp_type);if (err)
base-commit: fd179f8a05be3ccae366b9b96e176b51fbe54aab
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf/hw_breakpoint: memcmp validates uninitialized flag-gated fields --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf/hw_breakpoint: memcmp validates uninitialized flag-gated fields --
commit 0cb8c384abc8b74fee8923d87b586e123993d285
Author: Kyle Zeng <[email protected]>
perf/hw_breakpoint: Avoid leaking private x86 breakpoint ranges
This commit addresses a security issue where private x86 breakpoint ranges can be leaked to unprivileged callers by validating immutable attributes before parsing a modify request. It also checks x86 kernel-breakpoint access before consulting private blacklists and validates instruction lengths early.
Quoted 4 lines
kernel/events/hw_breakpoint.c +0
-0
[ ... ]
kernel/events/hw_breakpoint.c modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *a · line 774
Quoted 13 lines
kernel/events/hw_breakpoint.c +0
-4@@ -765,10 +765,6 @@ modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *astruct arch_hw_breakpoint hw = { };int err; - err =hw_breakpoint_parse (bp, attr, &hw); -if (err) -return err; -if (check) {struct perf_event_attr old_attr;@@ -778,6 +774,10 @@ modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *areturn -EINVAL ;
[Severity: Medium]
Does this memcmp() inappropriately enforce equality on uninitialized, unused, and flag-gated fields?
Userspace is not required to zero unused fields in the perf_event_attr struct. If a user opens a hw_breakpoint event with uninitialized stack garbage in unused fields (e.g., sample_regs_user, config2), and later calls PERF_EVENT_IOC_MODIFY_ATTRIBUTES with a new perf_event_attr to modify bp_addr, the new struct may contain different stack garbage.
Since perf_copy_attr() copies the struct verbatim from userspace, this memcmp() fails when comparing the original and new structs due to the differing uninitialized bytes. This will spuriously reject valid modification requests with -EINVAL.
Quoted 9 lines
kernel/events/hw_breakpoint.c +4
-0} + err =hw_breakpoint_parse (bp, attr, &hw); +if (err) +return err; +if (bp->attr.bp_type != attr->bp_type) { err =modify_bp_slot (bp, bp->attr.bp_type, attr->bp_type);if (err)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 51 lines · On Tue, Oct 06, 2026 at 10:44:55PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf/hw_breakpoint: memcmp validates uninitialized flag-gated fields --commit
0cb8c384abc8b74fee8923d87b586e123993d285
Author: Kyle Zeng <[email protected]>perf/hw_breakpoint: Avoid leaking private x86 breakpoint ranges
This commit addresses a security issue where private x86 breakpoint ranges can be leaked to unprivileged callers by validating immutable attributes before parsing a modify request. It also checks x86 kernel-breakpoint access before consulting private blacklists and validates instruction lengths early.
Quoted 4 lines
kernel/events/hw_breakpoint.c +0
-0[ ... ]
kernel/events/hw_breakpoint.c modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *a · line 774
Quoted 13 lines
kernel/events/hw_breakpoint.c +0
-4@@ -765,10 +765,6 @@ modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *astruct arch_hw_breakpoint hw = { };int err; - err =hw_breakpoint_parse (bp, attr, &hw); -if (err) -return err; -if (check) {struct perf_event_attr old_attr;@@ -778,6 +774,10 @@ modify_user_hw_breakpoint_check(struct perf_event *bp, struct perf_event_attr *areturn -EINVAL ;[Severity: Medium]
Does thismemcmp()inappropriately enforce equality on uninitialized, unused, and flag-gated fields?Userspace is not required to zero unused fields in the
perf_event_attrstruct. If a user opens ahw_breakpointevent with uninitialized stack garbage in unused fields (e.g.,sample_regs_user, config2), and later callsPERF_EVENT_IOC_MODIFY_ATTRIBUTESwith a newperf_event_attrto modifybp_addr, the new struct may contain different stack garbage.Since
perf_copy_attr()copies the struct verbatim from userspace, thismemcmp()fails when comparing the original and new structs due to the differing uninitialized bytes. This will spuriously reject valid modification requests with-EINVAL.Quoted 2 lines
kernel/events/hw_breakpoint.c +0
-0}
Quoted 10 lines
Quoted 7 lines
kernel/events/hw_breakpoint.c +4
-0+ err =hw_breakpoint_parse (bp, attr, &hw); +if (err) +return err; +if (bp->attr.bp_type != attr->bp_type) { err =modify_bp_slot (bp, bp->attr.bp_type, attr->bp_type);if (err)Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
old_attr is initialized in hw_breakpoint_copy_attr. I don't see use of uninitialized data in the path.
Best,
Kyle