Skip to contentSkip to conversation

misc: pci_endpoint_test: Fix array underflow in pci_endpoint_test_ioctl()

PATCH Superseded Dan Carpenter 2 participants 2 messages Aug 1, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: pci_endpoint_test: Fix array underflow in pci_endpoint_test_ioctl()

We recently added NO_BAR (-1) to the pci_barno enum which, in practical terms, changes the enum from an unsigned int to a signed int. If the user passes a negative number in pci_endpoint_test_ioctl() then it results in an array underflow in pci_endpoint_test_bar().

Fixes eefb83790a0d ("misc: pci_endpoint_test: Add doorbell test case")
---
 drivers/misc/pci_endpoint_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/pci_endpoint_test.c +1 -1
index 1c156a3f845e..f935175d8bf5 100644
@@ -937,7 +937,7 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,
 	switch (cmd) {
 	case PCITEST_BAR:
 		bar = arg;
-		if (bar > BAR_5)
+		if (bar <= NO_BAR || bar > BAR_5)
 			goto ret;
 		if (is_am654_pci_dev(pdev) && bar == BAR_0)
 			goto ret;
Signature · 1 line
2.47.2
#1 lore raw
Quoted 1 line · Dan Carpenter

We recently added NO_BAR (-1) to the pci_barno enum which, in practical

Since commit ...., add NO_BAR (-1) to the pci_barno enum, ...

Frank

Quoted 26 lines

terms, changes the enum from an unsigned int to a signed int. If the user passes a negative number in pci_endpoint_test_ioctl() then it results in an array underflow in pci_endpoint_test_bar().

Fixes eefb83790a0d ("misc: pci_endpoint_test: Add doorbell test case")
---
 drivers/misc/pci_endpoint_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/pci_endpoint_test.c +1 -2
index 1c156a3f845e..f935175d8bf5 100644
@@ -937,7 +937,7 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,
 	switch (cmd) {
 	case PCITEST_BAR:
 		bar = arg;
-		if (bar > BAR_5)
+		if (bar <= NO_BAR || bar > BAR_5)
 			goto ret;
 		if (is_am654_pci_dev(pdev) && bar == BAR_0)
 			goto ret;
--

2.47.2