From: Ratheesh Kannoth <rkannoth@marvell.com>
To: <Sergey.V.Frolov@kaspersky.com>
Cc: <sgoutham@marvell.com>, <gakula@marvell.com>,
<sbhatta@marvell.com>, <bbhushan2@marvell.com>,
<andrew+netdev@lunn.ch>, <davem@davemloft.net>,
<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
<netdev@vger.kernel.org>
Subject: Re: [PATCH net] net: octeontx2-pf: Fix UB in shift operation
Date: Mon, 27 Jul 2026 08:57:52 +0530 [thread overview]
Message-ID: <ambQOBLp5yYDbRSr@rkannoth-OptiPlex-7090> (raw)
In-Reply-To: <20260724121941.2637908-1-Sergey.V.Frolov@kaspersky.com>
On 2026-07-24 at 17:49:43, Sergey.V.Frolov@kaspersky.com (Sergey.V.Frolov@kaspersky.com) wrote:
> From: "Sergey.V.Frolov" <Sergey.V.Frolov@kaspersky.com>
>
> In function otx2_get_egress_burst_cfg, when the parameter `burst` is
> 255 and the max mantissa is 255 (0xFFULL), `burst_exp` is set to
> `ilog2(255) - 1`, which equals 6.
>
> This results in an unsigned wrap-around when calculating
> `(1ULL << (*burst_exp - 7))`, since `*burst_exp - 7` becomes -1,
> which makes the shift operand 0xFFFFFFFF. This value is greater than
> the width of the left operand.
>
> According to standard 6.5.7 p.3:
> "The type of the result is that of the promoted left operand.
> If the value of the right operand is negative or is greater than
> or equal to the width of the promoted left operand, the behavior
> is undefined."
>
> Add a check to handle cases where `*burst_exp` is less than 7.
>
> Signed-off-by: Sergey.V.Frolov <Sergey.V.Frolov@kaspersky.com>
> ---
> drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
> index 40162b08014d..39bd73a214af 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
> @@ -53,10 +53,15 @@ static void otx2_get_egress_burst_cfg(struct otx2_nic *nic, u32 burst,
> if (burst) {
> *burst_exp = ilog2(burst) ? ilog2(burst) - 1 : 0;
> tmp = burst - rounddown_pow_of_two(burst);
> - if (burst < max_mantissa)
> + if (burst <= max_mantissa) {
Thanks.
can we handle 255 case with <= ? it looks simple to me.
next prev parent reply other threads:[~2026-07-27 3:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 12:19 [PATCH net] net: octeontx2-pf: Fix UB in shift operation Sergey.V.Frolov
2026-07-27 3:27 ` Ratheesh Kannoth [this message]
2026-07-27 11:46 ` Sergey V. Frolov
2026-07-28 3:47 ` Ratheesh Kannoth
2026-07-28 8:13 ` Sergey V. Frolov
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=ambQOBLp5yYDbRSr@rkannoth-OptiPlex-7090 \
--to=rkannoth@marvell.com \
--cc=Sergey.V.Frolov@kaspersky.com \
--cc=andrew+netdev@lunn.ch \
--cc=bbhushan2@marvell.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gakula@marvell.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sbhatta@marvell.com \
--cc=sgoutham@marvell.com \
/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