Skip to contentSkip to conversation

agp/amd64: Fix broken error propagation in agp_amd64_probe()

PATCH In review Alexander Martyniuk 4 participants 4 messages Jun 29 – Jun 30 Stable branch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 agp/amd64: Fix broken error propagation in agp_amd64_probe()

From: Mingyu Wang <[email protected]>

commit b08472db93b1ccff84a7adec5779d47f0e9d3a30 upstream.

A NULL pointer dereference was observed in the AMD64 AGP driver when running in a virtualized environment (e.g. qemu/kvm) without a physical AMD northbridge. The crash occurs in amd64_fetch_size() when attempting to dereference the pointer returned by node_to_amd_nb(0).

The root cause of this crash is broken error propagation in agp_amd64_probe(): When no AMD northbridges are found, cache_nbs() correctly returns -ENODEV. However, the probe function erroneously checks the return value against exactly -1, rather than < 0.

As a result, the hardware absence error is masked, allowing the driver to improperly proceed with initialization. It eventually calls agp_add_bridge(), which invokes amd64_fetch_size(). Since the hardware does not exist, node_to_amd_nb(0) returns NULL, leading to a General Protection Fault (GPF) when accessing its ->misc member.

Fix the issue by correcting the error check in agp_amd64_probe() to abort properly when cache_nbs() returns any negative error code. This prevents the driver from erroneously proceeding without hardware, thereby avoiding the subsequent NULL pointer dereference at its source.

Fixes a32073bffc65 ("[PATCH] x86_64: Clean and enhance up K8 northbridge access code")
Cc [email protected] # v2.6.18+
---
 drivers/char/agp/amd64-agp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/agp/amd64-agp.c +1 -1
index 8e41731d3642..c9d7cefa5192 100644
@@ -546,7 +546,7 @@ static int agp_amd64_probe(struct pci_dev *pdev,
 	/* Fill in the mode register */
 	pci_read_config_dword(pdev, bridge->capndx+PCI_AGP_STATUS, &bridge->mode);
 
-	if (cache_nbs(pdev, cap_ptr) == -1) {
+	if (cache_nbs(pdev, cap_ptr) < 0) {
 		agp_put_bridge(bridge);
 		return -ENODEV;
 	}
Signature · 1 line
2.43.0
#1 lore raw
Quoted 8 lines · Alexander Martyniuk

From: Mingyu Wang <[email protected]>

commit b08472db93b1ccff84a7adec5779d47f0e9d3a30 upstream.

A NULL pointer dereference was observed in the AMD64 AGP driver when running in a virtualized environment (e.g. qemu/kvm) without a physical AMD northbridge. The crash occurs in amd64_fetch_size() when attempting to dereference the pointer returned by node_to_amd_nb(0).

What is special about this virtual environment? Nobody else seems to have seen that in 20+ years.

Or maybe the Fixes tag is not quite correct and something else more recent has caused it.

-Andi

#2 lore raw
Quoted 6 lines

What is special about this virtual environment? Nobody else seems to have seen that in 20+ years.

Or maybe the Fixes tag is not quite correct and something else more recent has caused it.

Hi Andi,

You are right that normal users will not see this crash in the wild.

The environment is a QEMU-based driver fuzzing framework. Rather than functionally emulating specific hardware, the framework extracts device matching information from the driver and synthesizes a mock PCI device just to trigger the driver's binding and initialization paths.

In this case, the synthesized PCI device matched the AGP bridge's IDs, forcing agp_amd64_probe() to run. However, because this is a synthetic fuzzing environment, there was no physical or emulated AMD Northbridge present in the system.

In a real-world system, the AGP bridge and the Northbridge exist together. Because the fuzzing framework provided the mock PCI device but did not provide the Northbridge, cache_nbs() returned -ENODEV, exposing the flawed == -1 error handling path.

The Fixes tag is correct. The logic flaw was introduced in that commit, but it remained dormant because standard hardware configurations do not produce this specific missing-hardware scenario.

Best regards,
Mingyu Wang

#3 lore raw
Quoted 17 lines · Mingyu Wang
Quoted 6 lines

What is special about this virtual environment? Nobody else seems to have seen that in 20+ years.

Or maybe the Fixes tag is not quite correct and something else more recent has caused it.

Hi Andi,

You are right that normal users will not see this crash in the wild.

The environment is a QEMU-based driver fuzzing framework. Rather than functionally emulating specific hardware, the framework extracts device matching information from the driver and synthesizes a mock PCI device just to trigger the driver's binding and initialization paths.

Quoted 4 lines

In this case, the synthesized PCI device matched the AGP bridge's IDs, forcing agp_amd64_probe() to run. However, because this is a synthetic fuzzing environment, there was no physical or emulated AMD Northbridge present in the system.

Which means this is a contrivied environment that no one will actually use, so there is no need to backport this change anywhere.

thanks,

greg k-h