Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Linus Walleij" <linusw@kernel.org>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v5 3/5] net: dsa: tag_ks8995: Add the KS8995 tag handling
Date: Fri, 05 Jun 2026 08:16:49 +0000	[thread overview]
Message-ID: <20260605081649.C76251F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260604-ks8995-to-ksz8-v5-3-98baeb45e665@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Double free of skb in ks8995_xmit() and ks8995_rcv() on tag allocation failures.
- [High] ks8995_xmit() fails to clear hardware-accelerated VLAN tags for non-802.1Q protocols (like 802.1ad QinQ), breaking DSA port isolation.
--

commit 69e87755967f9829df353d79046ed354251e2a4a
Author: Linus Walleij <linusw@kernel.org>

net: dsa: tag_ks8995: Add the KS8995 tag handling

This commit adds ingress and egress tagging support for the KS8995 100Mbit
switch in the DSA subsystem. The tag is implemented as a modified 0x8100
ethertype tag.

> diff --git a/net/dsa/tag_ks8995.c b/net/dsa/tag_ks8995.c
> new file mode 100644
> index 0000000000000..5bdb182715827
> --- /dev/null
> +++ b/net/dsa/tag_ks8995.c

[ ... ]

> +static struct sk_buff *ks8995_xmit(struct sk_buff *skb, struct net_device *dev)
> +{
> +	struct vlan_ethhdr *hdr = vlan_eth_hdr(skb);
> +	bool have_hwaccel_tag = false;
> +	u16 tci = 0, portmask;
> +
> +	/* Prepare the special KS8995 tags */
> +	portmask = dsa_xmit_port_mask(skb, dev);
> +
> +	if (skb_vlan_tag_present(skb) && skb->vlan_proto == htons(ETH_P_8021Q)) {
> +		tci = skb_vlan_tag_get(skb);
> +		__vlan_hwaccel_clear_tag(skb);
> +		have_hwaccel_tag = true;
> +	}

[Severity: High]
Does this strict check for ETH_P_8021Q fail to clear hardware-accelerated
VLAN tags for other protocols, such as 802.1ad?

If a non-802.1Q hwaccel tag is left intact, the conduit driver might offload
it as the outermost tag on the wire. Since the KS8995 switch expects its
STPID tag to immediately follow the MAC addresses, could seeing the uncleared
tag instead cause it to misinterpret the DSA routing tag and bypass port
isolation?

> +
> +	if (have_hwaccel_tag || hdr->h_vlan_proto != htons(ETH_P_8021Q)) {
> +		skb = vlan_insert_tag(skb, KS8995M_STPID(portmask), tci);
> +		if (!skb)
> +			return NULL;

[Severity: Critical]
Can this cause a double-free of the skb on allocation failure?

Looking at vlan_insert_tag(), it unconditionally consumes and frees the skb if
it fails to allocate memory. However, returning NULL from a DSA tagger's xmit
routine instructs the caller, dsa_user_xmit(), to explicitly free the original
skb again.

> +		hdr = vlan_eth_hdr(skb);
> +		netdev_dbg(dev, "%s: inserted VLAN TAG %04x TCI %04x\n",
> +			   __func__, hdr->h_vlan_proto, hdr->h_vlan_TCI);
> +	} else {

[ ... ]

> +static struct sk_buff *ks8995_rcv(struct sk_buff *skb, struct net_device *dev)
> +{
> +	int portmask;
> +	u16 etype;

[ ... ]

> +	/* Move the custom DSA+VLAN tag into the hwaccel area and strip
> +	 * it from the skb head
> +	 */
> +	skb = skb_vlan_untag(skb);
> +	if (!skb) {
> +		netdev_err(dev, "%s: unable to untag skb\n", __func__);
> +		return NULL;
> +	}

[Severity: Critical]
Will this result in a double-free of the skb?

Similar to the xmit path, skb_vlan_untag() frees the skb when it encounters an
error. Returning NULL from ks8995_rcv() instructs dsa_switch_rcv() to free the
skb a second time.

> +
> +	portmask = FIELD_GET(KS8995M_STPID_PORTMASK, etype);
> +	netdev_dbg(dev, "%s: etype %04x portmask %04x (%d)\n",
> +		   __func__, etype, portmask, ilog2(portmask));

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260604-ks8995-to-ksz8-v5-0-98baeb45e665@kernel.org?part=3

  reply	other threads:[~2026-06-05  8:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04  8:15 [PATCH net-next v5 0/5] net: dsa: microchip: Add support for KSZ8995XA/KS8995XA Linus Walleij
2026-06-04  8:15 ` [PATCH net-next v5 1/5] net: dsa: microchip: Add fallback Micrel compatibles Linus Walleij
2026-06-04  8:15 ` [PATCH net-next v5 2/5] dt-bindings: net: dsa: microchip: Add KSZ8995XA Linus Walleij
2026-06-04  8:15 ` [PATCH net-next v5 3/5] net: dsa: tag_ks8995: Add the KS8995 tag handling Linus Walleij
2026-06-05  8:16   ` sashiko-bot [this message]
2026-06-04  8:15 ` [PATCH net-next v5 4/5] net: dsa: microchip: Support Microchip KSZ8995XA / KS8995XA Linus Walleij
2026-06-05  8:16   ` sashiko-bot
2026-06-04  8:15 ` [PATCH net-next v5 5/5] net: dsa: ks8995: Delete surplus driver Linus Walleij
2026-06-05  8:16   ` sashiko-bot

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=20260605081649.C76251F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linusw@kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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