public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH] agp: amd64: fix null-ptr-deref in amd64_fetch_size
@ 2026-04-29  2:33 王明煜
  0 siblings, 0 replies; only message in thread
From: 王明煜 @ 2026-04-29  2:33 UTC (permalink / raw)
  To: dri-devel; +Cc: Mingyu Wang

During the initialization of the amd64_agp driver, the `amd64_fetch_size()`
function attempts to retrieve the PCI device pointer from the AMD
northbridge descriptor.

The code assumes that a valid AMD northbridge always exists when this
driver is probed:
	dev = node_to_amd_nb(0)->misc;

However, in mixed or emulated environments (e.g., an Intel CPU environment
with an AMD AGP bridge passed through or emulated), `node_to_amd_nb(0)`
will return NULL. This leads to an immediate null-pointer dereference
when attempting to access `->misc`, causing a kernel panic.

Fix this by properly checking the return value of `node_to_amd_nb()`
before dereferencing it.

Signed-off-by: Mingyu Wang <25181214217@stu.xidian.edu.cn>
---
 drivers/char/agp/amd64-agp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 2505df1f4e69..1c21787ded69 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -124,9 +124,14 @@ static int amd64_fetch_size(void)
 	int i;
 	u32 temp;
 	struct aper_size_info_32 *values;
+	struct amd_northbridge *nb;
 
-	dev = node_to_amd_nb(0)->misc;
-	if (dev==NULL)
+	nb = node_to_amd_nb(0);
+	if (!nb)
+		return 0;
+
+	dev = nb->misc;
+	if (!dev)
 		return 0;
 
 	pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &temp);
-- 
2.34.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-04-29 10:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-29  2:33 [PATCH] agp: amd64: fix null-ptr-deref in amd64_fetch_size 王明煜

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox