Subject: Re: [PATCH net-next 05/11] bridge: provide lockless access to p->path_cost

From: Ido Schimmel <[email-masked]>
Date: Sun, 24 May 2026 15:48:02 +0300

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.