From: James Clark <james.clark@linaro.org>
To: sashiko-reviews@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf: arm_pmuv3: Zero initialize hw_id branch stack field
Date: Fri, 7 Aug 2026 11:05:57 +0100 [thread overview]
Message-ID: <c925f9ef-b9e7-41cd-8809-d330283fed3a@linaro.org> (raw)
In-Reply-To: <20260807092755.CDF991F000E9@smtp.kernel.org>
On 07/08/2026 10:27, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Missing initialization of `new_type` and `priv` fields in `perf_clear_branch_entry_bitfields()` allows cross-sample metadata leakage and KASLR bypass.
> --
>
> --- Patch [1]: [PATCH] perf: arm_pmuv3: Zero initialize hw_id branch stack field ---
> commit 9362aa7ec453c50e757449959540fd185a720850
> Author: James Clark <james.clark@linaro.org>
>
> perf: arm_pmuv3: Zero initialize hw_id branch stack field
>
> This patch modifies the allocation of the BRBE branch_stack to use kzalloc
> instead of kmalloc. This ensures that the hw_id field, and any future fields,
> are safely zero-initialized upon allocation to comply with documentation.
>
>> diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c
>> --- a/drivers/perf/arm_pmuv3.c
>> +++ b/drivers/perf/arm_pmuv3.c
>> @@ -1361,7 +1361,7 @@ static int branch_records_alloc(struct arm_pmu *armpmu)
>> struct pmu_hw_events *events_cpu;
>>
>> events_cpu = per_cpu_ptr(armpmu->hw_events, cpu);
>> - events_cpu->branch_stack = kmalloc(size, GFP_KERNEL);
>> + events_cpu->branch_stack = kzalloc(size, GFP_KERNEL);
>
> [Severity: High]
> This is a pre-existing issue, but since we are fixing uninitialized branch
> stack fields on allocation, does the per-sample reuse of these entries later
> leak previous metadata?
>
> The perf_clear_branch_entry_bitfields() helper zeroes most bitfields, but
> misses the new_type and priv fields:
>
> include/linux/perf_event.h:perf_clear_branch_entry_bitfields() {
> br->mispred = 0;
> br->predicted = 0;
> ...
> br->reserved = 0;
> // new_type and priv are not cleared
> }
>
> In the ARM BRBE driver, the per-CPU branch_stack buffer entries are reused
> and cleared using this helper. If a hardware branch record is source-only,
> entry->priv is not explicitly set:
>
> drivers/perf/arm_brbe.c:perf_entry_from_brbe_regset() {
> perf_clear_branch_entry_bitfields(entry);
> ...
> if (!brbe_record_is_source_only(brbinf))
> entry->priv = brbinf_get_perf_priv(brbinf);
> }
>
> If the previous sample in that slot was a user-space branch, entry->priv
> retains PERF_BR_PRIV_USER. When filter_branch_privilege() later checks
> entry->priv, could this allow kernel source addresses to be exposed to
> unprivileged users and bypass KASLR?
>
>> if (!events_cpu->branch_stack)
>> return -ENOMEM;
>> }
>
Fixed by "[PATCH v6 3/3] perf/core: Clear the whole branch entry in
perf_clear_branch_entry()" on the list.
next prev parent reply other threads:[~2026-08-07 10:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 9:14 [PATCH] perf: arm_pmuv3: Zero initialize hw_id branch stack field James Clark
2026-08-07 9:27 ` sashiko-bot
2026-08-07 10:05 ` James Clark [this message]
2026-08-07 10:44 ` Anshuman Khandual
2026-08-07 12:18 ` James Clark
2026-08-07 14:27 ` Will Deacon
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=c925f9ef-b9e7-41cd-8809-d330283fed3a@linaro.org \
--to=james.clark@linaro.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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