All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@nvidia.com>
To: Eric Dumazet <edumazet@google.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, Nikolay Aleksandrov <razor@blackwall.org>,
	eric.dumazet@gmail.com
Subject: Re: [PATCH net-next 05/11] bridge: provide lockless access to p->path_cost
Date: Sun, 24 May 2026 15:48:02 +0300	[thread overview]
Message-ID: <20260524124802.GE74116@shredder> (raw)
In-Reply-To: <20260521131916.3627204-6-edumazet@google.com>

On Thu, May 21, 2026 at 01:19:10PM +0000, Eric Dumazet wrote:
> diff --git a/net/bridge/br_stp.c b/net/bridge/br_stp.c
> index 024210f95468308066827ac2ae71f68f99fa77f5..1367cd3ac4dd6a587d4a6471184453a14af6879c 100644
> --- a/net/bridge/br_stp.c
> +++ b/net/bridge/br_stp.c
> @@ -125,11 +125,12 @@ static int br_should_become_root_port(const struct net_bridge_port *p,
>  	else if (t > 0)
>  		return 0;
>  
> -	if (p->designated_cost + p->path_cost <
> -	    rp->designated_cost + rp->path_cost)
> +	t = p->designated_cost + READ_ONCE(p->path_cost) -
> +	    (rp->designated_cost + READ_ONCE(rp->path_cost));
> +
> +	if (t < 0)
>  		return 1;
> -	else if (p->designated_cost + p->path_cost >
> -		 rp->designated_cost + rp->path_cost)
> +	else if (t > 0)
>  		return 0;
>  
>  	t = memcmp(&p->designated_bridge, &rp->designated_bridge, 8);

Both Sashiko instances complain about integer overflow and I think they
are correct.

p->path_cost is [1, 64k] and p->designated_cost is unbounded. So, even
before this change the check could overflow, but now it can overflow for
a wider range of p->designated_cost values.

In practice it's probably not a problem since 802.1Q recommends a range
of 1-200M for port path cost, but I suggest to keep this change purely
about the READ_ONCE() / WRITE_ONCE() annotations and avoid the
unintended side effect.

  reply	other threads:[~2026-05-24 12:48 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 13:19 [PATCH net-next 00/11] bridge: prepare lockless br_port_fill_attrs() (I) Eric Dumazet
2026-05-21 13:19 ` [PATCH net-next 01/11] bridge: add a READ_ONCE() in br_timer_value() Eric Dumazet
2026-05-24 12:46   ` Ido Schimmel
2026-05-21 13:19 ` [PATCH net-next 02/11] bridge: add bridge_flags_bit enum Eric Dumazet
2026-05-24 12:46   ` Ido Schimmel
2026-05-21 13:19 ` [PATCH net-next 03/11] bridge: use BR_PROMISC_BIT Eric Dumazet
2026-05-24 12:47   ` Ido Schimmel
2026-05-21 13:19 ` [PATCH net-next 04/11] bridge: use BR_ADMIN_COST_BIT Eric Dumazet
2026-05-24 12:47   ` Ido Schimmel
2026-05-21 13:19 ` [PATCH net-next 05/11] bridge: provide lockless access to p->path_cost Eric Dumazet
2026-05-24 12:48   ` Ido Schimmel [this message]
2026-06-03  5:56     ` Eric Dumazet
2026-05-21 13:19 ` [PATCH net-next 06/11] bridge: provide lockless access to p->designated_cost Eric Dumazet
2026-05-24 12:48   ` Ido Schimmel
2026-05-21 13:19 ` [PATCH net-next 07/11] bridge: provide lockless access to p->designated_port Eric Dumazet
2026-05-24 12:48   ` Ido Schimmel
2026-05-21 13:19 ` [PATCH net-next 08/11] bridge: provide lockless access to p->priority Eric Dumazet
2026-05-24 12:49   ` Ido Schimmel
2026-05-21 13:19 ` [PATCH net-next 09/11] bridge: provide lockless access to p->port_id Eric Dumazet
2026-05-24 12:49   ` Ido Schimmel
2026-05-21 13:19 ` [PATCH net-next 10/11] bridge: provide lockless access to p->config_pending Eric Dumazet
2026-05-24 12:49   ` Ido Schimmel
2026-05-21 13:19 ` [PATCH net-next 11/11] bridge: read p->flags once in br_port_fill_attrs() Eric Dumazet
2026-05-24 12:49   ` Ido Schimmel
2026-05-22  8:45 ` [PATCH net-next 00/11] bridge: prepare lockless br_port_fill_attrs() (I) Ido Schimmel
2026-05-22  9:31   ` Eric Dumazet
2026-05-22  9:32   ` Nikolay Aleksandrov

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=20260524124802.GE74116@shredder \
    --to=idosch@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.