From: 王明煜 <25181214217@stu.xidian.edu.cn>
To: dri-devel@lists.freedesktop.org
Cc: "Mingyu Wang" <25181214217@stu.xidian.edu.cn>
Subject: [PATCH] agp: amd64: fix null-ptr-deref in amd64_fetch_size
Date: Wed, 29 Apr 2026 10:33:50 +0800 (GMT+08:00) [thread overview]
Message-ID: <45f753f9.9a8c.19dd715ea5a.Coremail.25181214217@stu.xidian.edu.cn> (raw)
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
reply other threads:[~2026-04-29 10:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=45f753f9.9a8c.19dd715ea5a.Coremail.25181214217@stu.xidian.edu.cn \
--to=25181214217@stu.xidian.edu.cn \
--cc=dri-devel@lists.freedesktop.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