Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Maciej Grochowski <Maciej.Grochowski@sony.com>
To: kurt.schwemmer@microsemi.com, logang@deltatee.com
Cc: jdmason@kudzu.us, dave.jiang@intel.com, allenbh@gmail.com,
	linux-pci@vger.kernel.org, ntb@lists.linux.dev,
	Maciej Grochowski <Maciej.Grochowski@sony.com>
Subject: [PATCH 2/3] [PATCH 2/3] ntb: ntb_hw_switchtec: Fix array-index-out-of-bounds access
Date: Thu, 13 Feb 2025 14:53:18 -0800	[thread overview]
Message-ID: <20250213225319.1965-3-Maciej.Grochowski@sony.com> (raw)
In-Reply-To: <20250213225319.1965-1-Maciej.Grochowski@sony.com>

Number of MW LUTs depends on NTB configuration and can be set to MAX_MWS,
This patch protects against invalid index out of bounds access to mw_sizes
When invalid access print message to user that configuration is not valid.

Signed-off-by: Maciej Grochowski <Maciej.Grochowski@sony.com>
---
 drivers/ntb/hw/mscc/ntb_hw_switchtec.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
index 6ab094b0850a..51a3766b3f67 100644
--- a/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
+++ b/drivers/ntb/hw/mscc/ntb_hw_switchtec.c
@@ -1316,6 +1316,11 @@ static void switchtec_ntb_init_shared(struct switchtec_ntb *sndev)
 	for (i = 0; i < sndev->nr_lut_mw; i++) {
 		int idx = sndev->nr_direct_mw + i;
 
+		if (idx >= MAX_MWS) {
+			dev_err(&sndev->stdev->dev,
+				"Total number of MW cannot be bigger than %d", MAX_MWS);
+			break;
+
 		sndev->self_shared->mw_sizes[idx] = LUT_SIZE;
 	}
 }
-- 
2.20.1


  parent reply	other threads:[~2025-02-13 22:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-13 22:53 [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Maciej Grochowski
2025-02-13 22:53 ` [PATCH 1/3] [PATCH 1/3] ntb: ntb_hw_switchtec: Fix shift-out-of-bounds for 0 mw lut Maciej Grochowski
2025-02-13 22:53 ` Maciej Grochowski [this message]
2025-02-13 22:53 ` [PATCH 3/3] [PATCH 3/3] ntb: ntb_hw_switchtec: Increase MAX_MWS limit to 256 Maciej Grochowski
2025-02-13 22:58 ` [PATCH 0/3] ntb_hw_switchtec enable 256 LUTs Dave Jiang
2025-02-14  0:49 ` Logan Gunthorpe

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=20250213225319.1965-3-Maciej.Grochowski@sony.com \
    --to=maciej.grochowski@sony.com \
    --cc=allenbh@gmail.com \
    --cc=dave.jiang@intel.com \
    --cc=jdmason@kudzu.us \
    --cc=kurt.schwemmer@microsemi.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=ntb@lists.linux.dev \
    /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