Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Linus Walleij" <linusw@kernel.org>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH net-next v6 3/5] net: dsa: tag_ks8995: Add the KS8995 tag handling
Date: Mon, 08 Jun 2026 22:42:13 +0000	[thread overview]
Message-ID: <20260608224213.C6C221F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260608-ks8995-to-ksz8-v6-3-d91eb43edcc5@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Double free of the socket buffer on the error path in `ks8995_rcv()` when `skb_vlan_untag()` fails.
- [High] Unhandled hardware-accelerated VLAN tags bypass clearing and break the required DSA tagging order on transmission.
--

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

net: dsa: tag_ks8995: Add the KS8995 tag handling

The KS8995 100Mbit switch can do proper DSA per-port tagging with the proper
set-up. This adds the code to handle ingress and egress KS8995 tags.

> diff --git a/net/dsa/tag_ks8995.c b/net/dsa/tag_ks8995.c
> new file mode 100644
> --- /dev/null
> +++ b/net/dsa/tag_ks8995.c
> @@ -0,0 +1,132 @@
> +// SPDX-License-Identifier: GPL-2.0

[ ... ]

> +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]
If a packet has a different hardware-accelerated tag (e.g., 802.1ad Provider
Bridge), does it bypass this clearing logic?

The KS8995 switch architecture requires the special DSA tag (STPID) to be the
first tag in the Ethernet frame immediately following the MAC addresses.

If the non-802.1Q hwaccel tag is left intact, the conduit network driver will
insert the pending hwaccel tag immediately after the MAC addresses, placing it
before the KS8995 DSA tag.

Could this cause the switch to fail to parse the DSA tag, leading to misrouted
or dropped packets?

[ ... ]

> +static struct sk_buff *ks8995_rcv(struct sk_buff *skb, struct net_device *dev)
> +{
> +	int portmask;
> +	u16 etype;
> +
> +	/* We are expecting all received packets to have a mangled VLAN
> +	 * TPID, so drop anything else. Because of the non-standard TPID,
> +	 * don't even bother looking for a tag in the hwaccel area.
> +	 *
> +	 * We have to inspect the ethertype directly because skb->protocol
> +	 * will contain garbage.
> +	 */
> +	etype = ntohs(*(__be16 *)dsa_etype_header_pos_rx(skb));
> +	if ((etype & KS8995M_STPID_STD) != ETH_P_8021Q) {
> +		netdev_dbg(dev, "%s: dropped ethertype 0x%04x\n",
> +			   __func__, etype);
> +		return NULL;
> +	}
> +	netdev_dbg(dev, "%s: received ethertype %04x\n",
> +		   __func__, 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]
Does this result in a double-free?

If skb_vlan_untag() fails, it frees the skb internally and returns NULL.
ks8995_rcv() then returns NULL to the DSA core function dsa_switch_rcv().

The API contract for the DSA .rcv callback dictates that it must not free the
original skb if it returns an error (NULL), because dsa_switch_rcv() will call
kfree_skb() on the original skb pointer when receiving a NULL return.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260608-ks8995-to-ksz8-v6-0-d91eb43edcc5@kernel.org?part=3

  reply	other threads:[~2026-06-08 22:42 UTC|newest]

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

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=20260608224213.C6C221F00893@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