All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hangbin Liu <liuhangbin@gmail.com>
To: Sasha Levin <sashal@kernel.org>
Cc: stable@vger.kernel.org, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>
Subject: Re: [PATCH 6.12.y] hsr: hold rcu and dev lock for hsr_get_port_ndev
Date: Fri, 19 Dec 2025 04:26:48 +0000	[thread overview]
Message-ID: <aUTUCAdm92qjaXqt@fedora> (raw)
In-Reply-To: <20251218153736.3435271-1-sashal@kernel.org>

On Thu, Dec 18, 2025 at 10:37:36AM -0500, Sasha Levin wrote:
> From: Hangbin Liu <liuhangbin@gmail.com>
> 
> [ Upstream commit 847748fc66d08a89135a74e29362a66ba4e3ab15 ]
> 
> hsr_get_port_ndev calls hsr_for_each_port, which need to hold rcu lock.
> On the other hand, before return the port device, we need to hold the
> device reference to avoid UaF in the caller function.
> 
> Suggested-by: Paolo Abeni <pabeni@redhat.com>
> Fixes: 9c10dd8eed74 ("net: hsr: Create and export hsr_get_port_ndev()")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> Reviewed-by: Simon Horman <horms@kernel.org>
> Link: https://patch.msgid.link/20250905091533.377443-4-liuhangbin@gmail.com
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> [ Drop multicast filtering changes ]
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
>  net/hsr/hsr_device.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
> index 386aba50930a3..acbd77ce6afce 100644
> --- a/net/hsr/hsr_device.c
> +++ b/net/hsr/hsr_device.c
> @@ -682,9 +682,14 @@ struct net_device *hsr_get_port_ndev(struct net_device *ndev,
>  	struct hsr_priv *hsr = netdev_priv(ndev);
>  	struct hsr_port *port;
>  
> +	rcu_read_lock();
>  	hsr_for_each_port(hsr, port)
> -		if (port->type == pt)
> +		if (port->type == pt) {
> +			dev_hold(port->dev);
> +			rcu_read_unlock();
>  			return port->dev;
> +		}
> +	rcu_read_unlock();
>  	return NULL;
>  }
>  EXPORT_SYMBOL(hsr_get_port_ndev);
> -- 
> 2.51.0
> 

Thanks for the fix. This looks good to me since we are missing commit
161087db66d6 ("net: ti: icssg-prueth: Add Support for Multicast filtering with VLAN in HSR mode")
on 6.12.

Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>

      reply	other threads:[~2025-12-19  4:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-18 13:38 FAILED: patch "[PATCH] hsr: hold rcu and dev lock for hsr_get_port_ndev" failed to apply to 6.12-stable tree gregkh
2025-12-18 15:37 ` [PATCH 6.12.y] hsr: hold rcu and dev lock for hsr_get_port_ndev Sasha Levin
2025-12-19  4:26   ` Hangbin Liu [this message]

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=aUTUCAdm92qjaXqt@fedora \
    --to=liuhangbin@gmail.com \
    --cc=horms@kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.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.