From: alexander.antonov@linux.intel.com
To: peterz@infradead.org, linux-kernel@vger.kernel.org
Cc: kan.liang@linux.intel.com, kyle.meyer@hpe.com,
alexey.v.bayduraev@linux.intel.com,
alexander.antonov@linux.intel.com
Subject: [PATCH v2 1/2] perf/x86/intel/uncore: Fix NULL pointer dereference issue in upi_fill_topology()
Date: Mon, 27 Nov 2023 10:52:45 -0800 [thread overview]
Message-ID: <20231127185246.2371939-2-alexander.antonov@linux.intel.com> (raw)
In-Reply-To: <20231127185246.2371939-1-alexander.antonov@linux.intel.com>
From: Alexander Antonov <alexander.antonov@linux.intel.com>
Get logical socket id instead of physical id in discover_upi_topology()
to avoid out-of-bound access on 'upi = &type->topology[nid][idx];' line
that leads to NULL pointer dereference in upi_fill_topology()
Fixes: f680b6e6062e ("perf/x86/intel/uncore: Enable UPI topology discovery for Icelake Server")
Reported-by: Kyle Meyer <kyle.meyer@hpe.com>
Tested-by: Kyle Meyer <kyle.meyer@hpe.com>
Signed-off-by: Alexander Antonov <alexander.antonov@linux.intel.com>
---
arch/x86/events/intel/uncore_snbep.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 8250f0f59c2b..49bc27ab26ad 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -5596,7 +5596,7 @@ static int discover_upi_topology(struct intel_uncore_type *type, int ubox_did, i
struct pci_dev *ubox = NULL;
struct pci_dev *dev = NULL;
u32 nid, gid;
- int i, idx, ret = -EPERM;
+ int i, idx, lgc_pkg, ret = -EPERM;
struct intel_uncore_topology *upi;
unsigned int devfn;
@@ -5614,8 +5614,13 @@ static int discover_upi_topology(struct intel_uncore_type *type, int ubox_did, i
for (i = 0; i < 8; i++) {
if (nid != GIDNIDMAP(gid, i))
continue;
+ lgc_pkg = topology_phys_to_logical_pkg(i);
+ if (lgc_pkg < 0) {
+ ret = -EPERM;
+ goto err;
+ }
for (idx = 0; idx < type->num_boxes; idx++) {
- upi = &type->topology[nid][idx];
+ upi = &type->topology[lgc_pkg][idx];
devfn = PCI_DEVFN(dev_link0 + idx, ICX_UPI_REGS_ADDR_FUNCTION);
dev = pci_get_domain_bus_and_slot(pci_domain_nr(ubox->bus),
ubox->bus->number,
@@ -5626,6 +5631,7 @@ static int discover_upi_topology(struct intel_uncore_type *type, int ubox_did, i
goto err;
}
}
+ break;
}
}
err:
--
2.25.1
next prev parent reply other threads:[~2023-11-27 18:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 18:52 [PATCH v2 0/2] Fix NULL pointer dereference issue during discovering UPI topology alexander.antonov
2023-11-27 18:52 ` alexander.antonov [this message]
2023-11-30 13:36 ` [tip: perf/core] perf/x86/intel/uncore: Fix NULL pointer dereference issue in upi_fill_topology() tip-bot2 for Alexander Antonov
2023-11-27 18:52 ` [PATCH v2 2/2] perf/x86/intel/uncore: Factor out topology_gidnid_map() alexander.antonov
2023-11-30 13:36 ` [tip: perf/core] " tip-bot2 for Alexander Antonov
2023-11-27 21:09 ` [PATCH v2 0/2] Fix NULL pointer dereference issue during discovering UPI topology Liang, Kan
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=20231127185246.2371939-2-alexander.antonov@linux.intel.com \
--to=alexander.antonov@linux.intel.com \
--cc=alexey.v.bayduraev@linux.intel.com \
--cc=kan.liang@linux.intel.com \
--cc=kyle.meyer@hpe.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.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®