DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Simakov <bigalex934@gmail.com>
To: Chaoyong He <chaoyong.he@corigine.com>,
	Alejandro Lucero <alejandro.lucero@netronome.com>
Cc: dev@dpdk.org, stable@dpdk.org, Alexey Simakov <bigalex934@gmail.com>
Subject: [PATCH] net/nfp: fix UB in BAR size shift operations
Date: Tue,  7 Jul 2026 17:01:11 +0300	[thread overview]
Message-ID: <20260707140112.140833-1-bigalex934@gmail.com> (raw)

The literal '1' is a signed 32-bit int. Shifting it by bar->bitsize
is undefined behavior when bitsize >= 31, and sign-extends when
bitsize == 31 (producing a wrong upper-bound check). BAR aperture
sizes from hardware can exceed this range.

Fix by using RTE_BIT64() which produces a 64-bit unsigned value,
matching the type of the operands (uint64_t base, uint64_t offset).

Fixes: c7e9729da6b5 ("net/nfp: support CPP")
Fixes: 1fbe51cd9c3a ("net/nfp: extend usage of BAR from 8 to 24")
Cc: stable@dpdk.org

Signed-off-by: Alexey Simakov <bigalex934@gmail.com>
---
 drivers/net/nfp/nfpcore/nfp6000_pcie.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/nfp/nfpcore/nfp6000_pcie.c
index 83b7116097..e03c4776d0 100644
--- a/drivers/net/nfp/nfpcore/nfp6000_pcie.c
+++ b/drivers/net/nfp/nfpcore/nfp6000_pcie.c
@@ -55,11 +55,11 @@
  */
 #define NFP_PCI_MIN_MAP_SIZE        0x080000        /* 512K */
 
-#define NFP_PCIE_P2C_FIXED_SIZE(bar)               (1 << (bar)->bitsize)
-#define NFP_PCIE_P2C_BULK_SIZE(bar)                (1 << (bar)->bitsize)
+#define NFP_PCIE_P2C_FIXED_SIZE(bar)               RTE_BIT64((bar)->bitsize)
+#define NFP_PCIE_P2C_BULK_SIZE(bar)                RTE_BIT64((bar)->bitsize)
 #define NFP_PCIE_P2C_GENERAL_TARGET_OFFSET(bar, x) ((x) << ((bar)->bitsize - 2))
 #define NFP_PCIE_P2C_GENERAL_TOKEN_OFFSET(bar, x) ((x) << ((bar)->bitsize - 4))
-#define NFP_PCIE_P2C_GENERAL_SIZE(bar)             (1 << ((bar)->bitsize - 4))
+#define NFP_PCIE_P2C_GENERAL_SIZE(bar)             RTE_BIT64(((bar)->bitsize - 4))
 
 #define NFP_PCIE_P2C_EXPBAR_OFFSET(bar_index)      ((bar_index) * 4)
 
@@ -443,7 +443,7 @@ matching_bar_exist(struct nfp_bar *bar,
 			(bar_token < 0 || bar_token == token) &&
 			bar_action == action &&
 			bar->base <= offset &&
-			(bar->base + (1 << bar->bitsize)) >= (offset + size))
+			(bar->base + RTE_BIT64(bar->bitsize)) >= (offset + size))
 		return true;
 
 	/* No match */
-- 
2.34.1


             reply	other threads:[~2026-07-07 14:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 14:01 Alexey Simakov [this message]
2026-07-10 14:38 ` [PATCH] net/nfp: fix UB in BAR size shift operations Thomas Monjalon

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=20260707140112.140833-1-bigalex934@gmail.com \
    --to=bigalex934@gmail.com \
    --cc=alejandro.lucero@netronome.com \
    --cc=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=stable@dpdk.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