[PATCH v2 next] misc: pci_endpoint_test: Fix array underflow in pci_endpoint_test_ioctl()

Dan Carpenter posted 1 patch 2 months ago
drivers/misc/pci_endpoint_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2 next] misc: pci_endpoint_test: Fix array underflow in pci_endpoint_test_ioctl()
Posted by Dan Carpenter 2 months ago
Commit eefb83790a0d ("misc: pci_endpoint_test: Add doorbell test case")
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")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
v2: Update the commit message to mention the commit which adds the
    NO_BAR.

 drivers/misc/pci_endpoint_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 1c156a3f845e..f935175d8bf5 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -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
Re: [PATCH v2 next] misc: pci_endpoint_test: Fix array underflow in pci_endpoint_test_ioctl()
Posted by Manivannan Sadhasivam 1 month, 3 weeks ago
On Fri, 01 Aug 2025 20:03:35 +0300, Dan Carpenter wrote:
> Commit eefb83790a0d ("misc: pci_endpoint_test: Add doorbell test case")
> 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().
> 
> 
> [...]

Applied, thanks!

[1/1] misc: pci_endpoint_test: Fix array underflow in pci_endpoint_test_ioctl()
      (no commit info)

Best regards,
-- 
Manivannan Sadhasivam <mani@kernel.org>