Re: [PATCH 2/2] perf/x86/intel: Fix kernel address leakages in LBR stack
"Mi, Dapeng" <[email protected]>
| Newsgroups | dev.linux.lists.sashiko,org.kernel.vger.linux-perf-users |
|---|---|
| Message-ID | <[email protected]> |
On 4/14/2026 11:16 AM, [email protected] wrote: > Sashiko AI review found 1 potential issue(s): > - [High] The patch addresses kernel address leakage in Intel's LBR software filter but overlooks identical vulnerabilities in AMD's LBR and BRS software filters. > -- > > commit 8dbb741871f5824e6032a6a5fa35f5db78494ff9 > Author: Dapeng Mi <[email protected]> > > perf/x86/intel: Fix kernel address leakages in LBR stack > > This commit fixes a kernel address leakage in the Intel LBR stack by extending > the software filtering to check both the source and destination addresses. > Prior to this change, kernel-to-user branches like SYSRET could leak kernel > addresses to user space even when PERF_SAMPLE_BRANCH_USER was requested. > >> diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c >> index 16977e4c6f8a5..deef81c16571a 100644 >> --- a/arch/x86/events/intel/lbr.c >> +++ b/arch/x86/events/intel/lbr.c > [ ... ] >> @@ -1244,8 +1244,15 @@ intel_pmu_lbr_filter(struct cpu_hw_events *cpuc) >> type |= X86_BR_NO_TX; >> } >> >> - /* if type does not correspond, then discard */ >> - if ((type & ~X86_BR_PLM) == X86_BR_NONE || (br_sel & type) != type) { >> + from_plm = kernel_ip(from) ? X86_BR_KERNEL : X86_BR_USER; >> + /* >> + * If type does not correspond, then discard. >> + * Especially filter out the entries whose from or to address >> + * is a kernel address while only X86_BR_USER is set. This prevents >> + * kernel address from being leaked into a user-space-only LBR stack. >> + */ >> + if ((type & ~X86_BR_PLM) == X86_BR_NONE || (br_sel & type) != type || >> + (!(br_sel & X86_BR_KERNEL) && (from_plm & X86_BR_KERNEL))) { >> cpuc->lbr_entries[i].from = 0; >> compress = true; >> } > This patch successfully addresses the kernel address leakage in Intel's LBR > software filter, but does it leave AMD platforms exposed to the same KASLR > bypass? > > Looking at arch/x86/events/amd/lbr.c, amd_pmu_lbr_filter() appears to classify > branch privilege levels based exclusively on the destination address via > branch_type_fused(). Does this mean it classifies kernel-to-user branches as > user-space and leaks the source kernel address? > > Similarly in arch/x86/events/amd/brs.c, amd_brs_drain() filters branches > using amd_brs_match_plm() which explicitly checks only kernel_ip(to). Would > this also blindly accept the branch and log the source kernel address? > > Should equivalent privilege level checks for the source address be added to > the AMD routines to fully resolve the issue across platforms? AMD guys have known the issue, suppose they would post the fix in a separate patch. Thanks. >