[PATCH v2 1/2] misc: pci_endpoint_test: validate BAR index in doorbell test
From: Carlos Bilbao (Lambda)
Date: Fri Apr 10 2026 - 19:04:18 EST
From: Carlos Bilbao <carlos.bilbao@xxxxxxxxxx>
pci_endpoint_test_doorbell() reads the BAR number directly from an endpoint
test register and uses it as an index into test->bar[]. Add a defensive
bounds check before the dereference: positive values >= PCI_STD_NUM_BARS
are out of range, and NO_BAR (-1) as a negative signed value would slip
past an upper-bound-only check.
Signed-off-by: Carlos Bilbao (Lambda) <carlos.bilbao@xxxxxxxxxx>
---
drivers/misc/pci_endpoint_test.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 74ab5b5b9011..0d0b430de0e8 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -1089,6 +1089,11 @@ static int pci_endpoint_test_doorbell(struct pci_endpoint_test *test)
pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, 0);
bar = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_DB_BAR);
+ if (bar < BAR_0 || bar >= PCI_STD_NUM_BARS) {
+ dev_err(dev, "BAR %d reported by endpoint out of range [0, %u]\n",
+ bar, PCI_STD_NUM_BARS - 1);
+ return -EINVAL;
+ }
writel(data, test->bar[bar] + addr);
--
2.43.0