From: JunYoung Lee <ljyoung04@gmail.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org
Cc: mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
james.clark@linaro.org, linux-perf-users@vger.kernel.org,
linux-kernel@vger.kernel.org, JunYoung Lee <ljyoung04@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH v2 1/2] perf/core: Don't report a kernel IP for exclude_kernel events
Date: Wed, 2 Dec 2026 20:59:01 +0900 [thread overview]
Message-ID: <20261202115902.586760-2-ljyoung04@gmail.com> (raw)
In-Reply-To: <20261202115902.586760-1-ljyoung04@gmail.com>
perf_instruction_pointer() hides the IP of an exclude_kernel event only
when the sampled frame is not in user mode. A user mode frame can still
carry a kernel IP: a data breakpoint on the memory operand of an indirect
"jmp *mem" traps after the jump, so the user mode trap frame holds the
kernel jump target.
PERF_SAMPLE_CODE_PAGE_SIZE then reports the page size of that kernel
address, which lets an unprivileged user find the kernel image and the
direct map despite KASLR.
Also return 0 when the IP is a kernel address.
The problem was found with the help of an AI coding assistant (Claude).
Fixes: 995f088efebe ("perf/core: Add support for PERF_SAMPLE_CODE_PAGE_SIZE")
Cc: stable@vger.kernel.org
Signed-off-by: JunYoung Lee <ljyoung04@gmail.com>
---
Changes in v2:
- Filter the kernel IP in perf_instruction_pointer() instead of in
perf_get_page_size() (Peter).
- Move the bad pmd fix to its own patch, 2/2 (Peter).
- Shorten the changelog.
Tested on 693c2e04e3f1 with the kernelCTF LTS config, KASLR on, in a
KVM guest on an AMD host, as uid 65534 with perf_event_paranoid=2:
- Kernel addresses: samples now carry ip=0 and code_page_size=0, and a
scan of the kernel image and direct map windows finds nothing.
- User addresses: IP and page size unchanged.
- cpu-clock with exclude_kernel: all 7390 samples have a user IP and 4K.
- exclude_kernel=0 as root: _stext still reports 2M.
Kernels without the generic perf_instruction_pointer() (for example
v6.12.y) need the same check where perf_prepare_sample() sets data->ip.
kernel/events/core.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4ab3919ac..4c7f173d7 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7858,6 +7858,8 @@ unsigned long perf_misc_flags(struct perf_event *event,
unsigned long perf_instruction_pointer(struct perf_event *event,
struct pt_regs *regs)
{
+ unsigned long ip;
+
/*
* Hardware skid can lead to a scenario where a PMI is
* delivered after the CPU has already entered kernel mode.
@@ -7870,8 +7872,18 @@ unsigned long perf_instruction_pointer(struct perf_event *event,
0 : perf_guest_get_ip();
}
- return event->attr.exclude_kernel && !user_mode(regs) ?
- 0 : perf_arch_instruction_pointer(regs);
+ ip = perf_arch_instruction_pointer(regs);
+
+ /*
+ * A user mode frame can still carry a kernel IP, for example when a
+ * debug trap is taken right after a jump to a kernel address, before
+ * the instruction fetch faults.
+ */
+ if (event->attr.exclude_kernel &&
+ (!user_mode(regs) || ip >= TASK_SIZE_MAX))
+ return 0;
+
+ return ip;
}
u64 __weak perf_reg_value(struct pt_regs *regs, int idx)
base-commit: 693c2e04e3f1d4c59af236e1211b7b8cb165a790
--
2.56.1
next prev parent reply other threads:[~2026-12-02 11:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 11:59 [PATCH v2 0/2] perf/core: Fix kernel page size leak and espfix hang JunYoung Lee
2026-12-02 11:59 ` JunYoung Lee [this message]
2026-12-02 11:59 ` [PATCH v2 2/2] perf/core: Don't loop forever on a bad pmd in perf_get_pgtable_size() JunYoung Lee
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=20261202115902.586760-2-ljyoung04@gmail.com \
--to=ljyoung04@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®