public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: carlos.bilbao@kernel.org
To: mani@kernel.org, kwilczynski@kernel.org, kishon@kernel.org
Cc: arnd@arndb.de, gregkh@linuxfoundation.org,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	bilbao@vt.edu, Carlos Bilbao <carlos.bilbao@kernel.org>
Subject: [PATCH 1/2] misc: pci_endpoint_test: validate BAR index in doorbell test
Date: Fri,  3 Apr 2026 18:20:01 -0700	[thread overview]
Message-ID: <20260404012002.111873-2-carlos.bilbao@kernel.org> (raw)
In-Reply-To: <20260404012002.111873-1-carlos.bilbao@kernel.org>

From: Carlos Bilbao <carlos.bilbao@kernel.org>

pci_endpoint_test_doorbell() reads the BAR number directly from an endpoint
test register and uses it as an index into test->bar[] without bounds
checking. Since the value is a raw u32 from device MMIO, any value is
possible and if greater than or equal to PCI_STD_NUM_BARS the access goes
out of bounds.

Add a bounds check before dereferencing test->bar[bar].

Fixes: eefb83790a0d ("misc: pci_endpoint_test: Add doorbell test case")
Signed-off-by: Carlos Bilbao (Lambda) <carlos.bilbao@kernel.org>
---
 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..276bed3f1c18 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 >= PCI_STD_NUM_BARS) {
+		dev_err(dev, "BAR %u 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


  reply	other threads:[~2026-04-04  1:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-04  1:20 [PATCH 0/2] misc: pci_endpoint_test: doorbell fixes carlos.bilbao
2026-04-04  1:20 ` carlos.bilbao [this message]
2026-04-06 16:39   ` [PATCH 1/2] misc: pci_endpoint_test: validate BAR index in doorbell test Koichiro Den
2026-04-10 22:47     ` Carlos Bilbao
2026-04-04  1:20 ` [PATCH 2/2] misc: pci_endpoint_test: remove dead BAR read before doorbell trigger carlos.bilbao
2026-04-06 16:41   ` Koichiro Den

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=20260404012002.111873-2-carlos.bilbao@kernel.org \
    --to=carlos.bilbao@kernel.org \
    --cc=arnd@arndb.de \
    --cc=bilbao@vt.edu \
    --cc=gregkh@linuxfoundation.org \
    --cc=kishon@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mani@kernel.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