Netdev List
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: xiexinet@gmail.com
Cc: Jakub Kicinski <kuba@kernel.org>,
	davem@davemloft.net, pabeni@redhat.com, edumazet@google.com,
	horms@kernel.org, shuah@kernel.org, lukma@denx.de,
	m-karicheri2@ti.com, fmaurer@redhat.com, luka.gejak@linux.dev,
	bigeasy@linutronix.de, ali@iusegentoo.com,
	qingfang.deng@linux.dev, netdev@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net v3 1/3] net: hsr: privatize interlink-bound skbs before address mutation
Date: Thu, 13 Aug 2026 18:27:36 -0700	[thread overview]
Message-ID: <20260814012736.2805965-1-kuba@kernel.org> (raw)
In-Reply-To: <20260808004525.1551-2-xiexinet@gmail.com>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
net: hsr: privatize interlink-bound skbs before address mutation

This adds an skb_cow() call in hsr_xmit() for interlink egress when the
frame either came in on the master port or is locally destined without
being local-exclusive, dropping the egress if the copy fails. The stated
goal is to stop hsr_deliver_master() and hsr_xmit() from writing
different source addresses into shared data.

> diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
> index 0774981a65c1..67aaf5a8622b 100644
> --- a/net/hsr/hsr_forward.c
> +++ b/net/hsr/hsr_forward.c
> @@ -420,6 +420,22 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
>  static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,
>  		    struct hsr_frame_info *frame)
>  {
> +	/* An interlink-bound skb from get_untagged_frame() can still alias
> +	 * another live consumer: for master-originated frames the clone
> +	 * shares the original TX skb (which taps or the TX path may still
> +	 * hold); for ring frames the master also consumes them when they
> +	 * are destined to the local node without being exclusive to it.
> +	 * Privatize before any address mutation.
> +	 */
> +	if (port->type == HSR_PT_INTERLINK &&
> +	    (frame->port_rcv->type == HSR_PT_MASTER ||
> +	     (frame->is_local_dest && !frame->is_local_exclusive)) &&
> +	    skb_cow(skb, 0)) {
> +		frame->port_rcv->dev->stats.rx_dropped++;
> +		kfree_skb(skb);
> +		return NET_XMIT_DROP;
> +	}
> +

[Severity: Medium]
Is the enumeration in this comment complete?  The unconditional interlink
source-address rewrite is pre-existing and was not introduced by this
patch, but the new guard and the commit message claim ("Other interlink
traffic keeps its zero-copy behavior") assert that the uncovered cases are
safe, and there looks to be one that isn't.

For an untagged ring frame, handle_std_frame() keeps the received skb:

net/hsr/hsr_forward.c:handle_std_frame() {
	frame->skb_hsr = NULL;
	frame->skb_prp = NULL;
	frame->skb_std = skb;
	...
}

and hsr_get_untagged_frame() hands the interlink a plain clone of that
skb.  So the interlink egress skb shares the receive head with any clone
already taken by a ptype_all tap, since __netif_receive_skb_core() runs
the deliver_skb() loop over skb->dev->ptype_all before it dereferences
skb->dev->rx_handler, and packet_rcv() then queues its skb_share_check()
clone on sk_receive_queue where the bytes are copied to userspace only
later.

For a remote unicast frame addressed to a SAN behind the RedBox,
check_local_dest() leaves frame->is_local_dest false (pkt_type is
PACKET_OTHERHOST) and frame->port_rcv->type is SLAVE_A or SLAVE_B, so the
new predicate is false, no copy happens, and the rewrite lower down in
hsr_xmit() still touches the shared data:

	if (port->type == HSR_PT_INTERLINK)
		ether_addr_copy(eth_hdr(skb)->h_source,
				port->hsr->macaddress_redbox);

Would the tap consumer on the ring slave then read the RedBox MAC instead
of the real source MAC?  Reaching this needs an HSR RedBox whose ring
slave advertises NETIF_F_HW_HSR_TAG_RM, so that untagged ring ingress is
forwarded rather than passed up:

net/hsr/hsr_slave.c:hsr_handle_frame() {
	if (!(port->dev->features & NETIF_F_HW_HSR_TAG_RM) &&
	    port->type != HSR_PT_INTERLINK &&
	    hsr->proto_ops->invalid_dan_ingress_frame &&
	    hsr->proto_ops->invalid_dan_ingress_frame(protocol))
		goto finish_pass;
	...
}

At this patch alone the same case also mutates a real on-wire frame,
because hsr_create_tagged_frame() and prp_create_tagged_frame() return a
bare clone of frame->skb_std for NETIF_F_HW_HSR_TAG_INS devices:

	} else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) {
		return skb_clone(frame->skb_std, GFP_ATOMIC);
	}

That second aliasing consumer is removed later in the series by "net: hsr:
return private clones from the tagged-frame helpers", which switches those
helpers to hsr_clone_private(), so only the tap aliasing remains at the
end of the series.

Since skb_cow(skb, 0) is a no-op for a non-cloned skb (__skb_cow() only
calls pskb_expand_head() when skb_cloned() or extra headroom is needed),
could the call be keyed on the actual sharing state, or simply made
unconditional for HSR_PT_INTERLINK, instead of on the topology predicate?
-- 
pw-bot: cr

  reply	other threads:[~2026-08-14  1:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-08  0:45 [PATCH net v3 0/3] net: hsr: fix shared-skb mutations in the forwarding path Xin Xie
2026-08-08  0:45 ` [PATCH net v3 1/3] net: hsr: privatize interlink-bound skbs before address mutation Xin Xie
2026-08-14  1:27   ` Jakub Kicinski [this message]
2026-08-14  1:27   ` Jakub Kicinski
2026-08-08  0:45 ` [PATCH net v3 2/3] net: hsr: return private clones from the tagged-frame helpers Xin Xie
2026-08-14  1:27   ` Jakub Kicinski
2026-08-08  0:45 ` [PATCH net v3 3/3] selftests: net: hsr: add shared-mutation regression test Xin Xie
2026-08-10 23:18   ` Xin Xie
2026-08-14  1:27   ` Jakub Kicinski
2026-08-14  1:30   ` Jakub Kicinski

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=20260814012736.2805965-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=ali@iusegentoo.com \
    --cc=bigeasy@linutronix.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fmaurer@redhat.com \
    --cc=horms@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luka.gejak@linux.dev \
    --cc=lukma@denx.de \
    --cc=m-karicheri2@ti.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=qingfang.deng@linux.dev \
    --cc=shuah@kernel.org \
    --cc=xiexinet@gmail.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