From: sashiko-bot@kernel.org
To: "Zide Chen" <zide.chen@intel.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 1/7] perf/x86/intel/uncore: Rename refcount fields and other cleanups
Date: Thu, 14 May 2026 00:58:09 +0000 [thread overview]
Message-ID: <20260514005809.D4D0CC19425@smtp.kernel.org> (raw)
In-Reply-To: <20260512233048.9577-2-zide.chen@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] NULL Pointer Dereference in `uncore_pci_pmu_unregister()` when device registration fails.
- [High] NULL Pointer Dereference (previously reported as UAF) during perf event operations if a PCI device is removed while events are active.
--
commit 247a617f910d49e9f19af35d0216a5b938d9d034
Author: Zide Chen <zide.chen@intel.com>
perf/x86/intel/uncore: Rename refcount fields and other cleanups
This commit renames several fields and parameters in the intel uncore PMU
driver to clarify their purpose, such as activeboxes to die_refcnt and
box->refcnt to box->cpu_refcnt. It also fixes a typo and removes an
incorrect refcount increment.
> diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c
> index e9cc1ba921c5e..e200f4744eb9b 100644
> --- a/arch/x86/events/intel/uncore.c
> +++ b/arch/x86/events/intel/uncore.c
[ ... ]
> @@ -1230,7 +1229,7 @@ static void uncore_pci_pmu_unregister(struct intel_uncore_pmu *pmu, int die)
> struct intel_uncore_box *box = pmu->boxes[die];
>
> pmu->boxes[die] = NULL;
> - if (atomic_dec_return(&pmu->activeboxes) == 0)
> + if (atomic_dec_return(&pmu->die_refcnt) == 0)
> uncore_pmu_unregister(pmu);
> uncore_box_exit(box);
While reviewing these unregistration changes, I noticed a pre-existing issue
here.
If PMU registration fails during PCI device probe, uncore_pci_pmu_register()
frees the box and sets pmu->boxes[die] = NULL.
Later, when the device is removed, the bus notifier calls
uncore_pci_pmu_unregister() which fetches the NULL box:
struct intel_uncore_box *box = pmu->boxes[die];
and passes it to uncore_box_exit(box).
Since uncore_box_exit() does not check for NULL before testing box->flags:
static inline void uncore_box_exit(struct intel_uncore_box *box)
{
if (test_and_clear_bit(UNCORE_BOX_FLAG_INITIALIZED, &box->flags)) {
Does this sequence result in a NULL pointer dereference?
Additionally, if a PCI device is removed while perf events are still active
on its CPU, this function sets pmu->boxes[die] = NULL and frees the box.
If other dies still have boxes present, die_refcnt will be greater than zero
and uncore_pmu_unregister(pmu) is bypassed.
Could this leave active events scheduled in the perf subsystem?
If the perf subsystem later attempts to read or stop the event,
uncore_event_to_box() would return NULL. Would subsequent calls like
uncore_perf_event_update() or accesses to box->n_active then trigger a NULL
pointer dereference when operating on the missing box?
> kfree(box);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260512233048.9577-1-zide.chen@intel.com?part=1
next prev parent reply other threads:[~2026-05-14 0:58 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 23:30 [PATCH 0/7] perf/x86/intel/uncore: PMU setup robustness fixes Zide Chen
2026-05-12 23:30 ` [PATCH 1/7] perf/x86/intel/uncore: Rename refcount fields and other cleanups Zide Chen
2026-05-13 0:26 ` Ian Rogers
2026-05-14 0:58 ` sashiko-bot [this message]
2026-05-12 23:30 ` [PATCH 2/7] perf/x86/intel/uncore: Let init_box() callback report failures Zide Chen
2026-05-13 0:23 ` Ian Rogers
2026-05-14 2:14 ` sashiko-bot
2026-05-12 23:30 ` [PATCH 3/7] perf/x86/intel/uncore: Keep PCI PMUs working when MMIO/MSR setup fails Zide Chen
2026-05-13 0:30 ` Ian Rogers
2026-05-12 23:30 ` [PATCH 4/7] perf/x86/intel/uncore: Factor out box setup code Zide Chen
2026-05-13 0:27 ` Ian Rogers
2026-05-14 3:34 ` sashiko-bot
2026-05-12 23:30 ` [PATCH 5/7] perf/x86/intel/uncore: Introduce PMU flags and broken state Zide Chen
2026-05-13 0:28 ` Ian Rogers
2026-05-14 4:27 ` sashiko-bot
2026-05-12 23:30 ` [PATCH 6/7] perf/x86/intel/uncore: Fix uncore_box ref/unref ordering on CPU hotplug Zide Chen
2026-05-13 0:32 ` Ian Rogers
2026-05-13 8:59 ` Mi, Dapeng
2026-05-13 18:43 ` Chen, Zide
2026-05-14 5:12 ` sashiko-bot
2026-05-12 23:30 ` [PATCH 7/7] perf/x86/intel/uncore: Implement lazy setup for MSR/MMIO PMU Zide Chen
2026-05-13 0:34 ` Ian Rogers
2026-05-13 9:03 ` Mi, Dapeng
2026-05-13 16:47 ` Chen, Zide
2026-05-14 5:38 ` sashiko-bot
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=20260514005809.D4D0CC19425@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zide.chen@intel.com \
/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