From: sashiko-bot@kernel.org
To: "Fil Dunsky" <filipp.dunsky@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH RFC net-next 2/7] net: dsa: add a QCA four-byte CPU tagger
Date: Thu, 26 Nov 2026 20:54:28 +0000 [thread overview]
Message-ID: <sashiko-outbox-236171@kernel.org> (raw)
In-Reply-To: <20261125-almondplus-offload-rfc-v1-2-703175c6340c@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] net: dsa: qca4_private_parse() drops or misparses RX hwaccel
VLAN frames
- [Medium] net: dsa: qca4_private_flow_dissect() underflows hlen on
short skbs
- [Low] net: dsa: NULL pointer dereference in qca4_test_exit() on init
failure
--
commit c8cea6af2b64b5e0ce96ccaac0aca53bdfc162fa
Author: Fil Dunsky <filipp.dunsky@gmail.com>
net: dsa: add a QCA four-byte CPU tagger
This commit adds a four-byte QCA DSA tag driver using the 0x8100
identifier and two-byte QCA metadata, along with KUnit tests for sk_buff
handling.
> diff --git a/net/dsa/tag_qca4.c b/net/dsa/tag_qca4.c
> new file mode 100644
> index 0000000000000..41375667978b2
> --- /dev/null
> +++ b/net/dsa/tag_qca4.c
[ ... ]
> +static int qca4_private_parse(struct sk_buff *skb, u16 *metadata)
> +{
> + unsigned int reason;
> + u8 *tag;
> + u16 hdr;
> +
> + if (skb_headroom(skb) < ETH_HLEN ||
> + !pskb_may_pull(skb, QCA4_PRIVATE_LEN)) {
> + return -EINVAL;
> + }
> + if (skb_cow_head(skb, 0))
> + return -ENOMEM;
> + tag = dsa_etype_header_pos_rx(skb);
> + if (get_unaligned_be16(tag) != QCA4_PRIVATE_IDENTIFIER)
> + return -EPROTO;
> + hdr = get_unaligned_be16(tag + 2);
> + if (FIELD_GET(QCA_HDR_RECV_VERSION, hdr) != QCA_HDR_VERSION)
> + return -EPROTO;
> + reason = FIELD_GET(QCA_HDR_RECV_TYPE, hdr);
> + /*
> + * These fixed14-byte pseudo-Ethernet formats are disabled in private4 mode.
> + * Never dispatch them into legacy MDIO/MIB callbacks with the wrong layout.
> + * Other normal/trap reasons remain valid, including observed flooding0x19.
> + */
> + if (reason == QCA_HDR_RECV_TYPE_MIB ||
> + reason == QCA_HDR_RECV_TYPE_RW_REG_ACK) {
> + return -EOPNOTSUPP;
> + }
> + *metadata = hdr;
> + return 0;
> +}
> +
> +static struct sk_buff *qca4_private_rcv(struct sk_buff *skb,
> + struct net_device *conduit)
> +{
> + struct net_device *user;
> + u16 metadata;
> + int port;
> +
> + if (qca4_private_parse(skb, &metadata))
> + goto drop;
> + port = FIELD_GET(QCA_HDR_RECV_SOURCE_PORT, metadata);
> + user = dsa_conduit_find_user(conduit, 0, port);
> + if (!user)
> + goto drop;
> +
> + skb->dev = user;
> + skb_pull_rcsum(skb, QCA4_PRIVATE_LEN);
> + dsa_strip_etype_header(skb, QCA4_PRIVATE_LEN);
[Severity: High]
Because QCA4_PRIVATE_IDENTIFIER is 0x8100 (ETH_P_8021Q), a conduit NIC
with NETIF_F_HW_VLAN_CTAG_RX enabled strips the four-byte QCA4 tag into
skb->vlan_proto and skb->vlan_tci before passing the frame to the stack.
When skb_vlan_tag_present(skb) is true on receive, does
qca4_private_parse() read the inner EtherType at tag instead of the
stripped QCA4 tag? Untagged ingress frames will fail the 0x8100 check
and be dropped with -EPROTO, while 802.1Q VLAN-tagged frames will have
their customer VLAN TCI parsed as the QCA4 header (allowing a crafted
VLAN tag to select the source port) before qca4_private_rcv() strips the
customer VLAN tag from the packet and leaves the raw QCA4 metadata in
skb->vlan_tci.
Other 0x8100-based taggers (such as lan9303_rcv(), ks8995_rcv() and
dsa_8021q_rcv()) check skb_vlan_tag_present(skb) on receive or push the
hardware-accelerated tag back inline before parsing.
> +
> + /*
> + * DSA core pushes ETH_HLEN and invokes user eth_type_trans, exposing only
> + * the real inner EtherType/VLAN after the complete four-byte tag is gone.
> + */
> + return skb;
> +drop:
> + kfree_skb(skb);
> + return NULL;
> +}
> +
> +/*
> + * Called before rcv(): do not assume the metadata or inner EtherType is
> + * linear or even present. Keep the const skb and its layout unchanged.
> + */
> +static void qca4_private_flow_dissect(const struct sk_buff *skb, __be16 *proto,
> + int *offset)
> +{
> + __be16 temporary;
> + const void *inner;
> +
> + *offset = QCA4_PRIVATE_LEN;
> + *proto = 0;
> + inner = skb_header_pointer(skb, 2, sizeof(temporary), &temporary);
> + if (inner)
> + *proto = get_unaligned((const __be16 *)inner);
> +}
[Severity: Medium]
When a frame is truncated (skb->len < QCA4_PRIVATE_LEN) or has fewer than
four linear bytes (skb_headlen(skb) < QCA4_PRIVATE_LEN), does setting
*offset = QCA4_PRIVATE_LEN unconditionally cause __skb_flow_dissect() to
underflow hlen and advance nhoff past the linear data?
net/core/flow_dissector.c:__skb_flow_dissect() {
...
if (unlikely(netdev_uses_dsa(skb->dev))) {
const struct dsa_device_ops *ops;
int offset = 0;
ops = skb->dev->dsa_ptr->tag_ops;
if (ops->flow_dissect)
ops->flow_dissect(skb, &proto, &offset);
else
dsa_tag_generic_flow_dissect(skb, &proto,
&offset);
hlen -= offset;
nhoff += offset;
}
...
}
When a BPF flow dissector is attached, __skb_flow_dissect() then passes a
negative hlen to bpf_flow_dissect(), where clamp_t(u16, flow_keys->nhoff,
nhoff, hlen) casts hlen to 65532..65535. Like ks8995_flow_dissect(),
*offset should stay 0 when the tag header cannot be read (and
qca4_test_flow_dissect() updated accordingly).
> diff --git a/net/dsa/tag_qca4_kunit.h b/net/dsa/tag_qca4_kunit.h
> new file mode 100644
> index 0000000000000..cc520b7fb154b
> --- /dev/null
> +++ b/net/dsa/tag_qca4_kunit.h
[ ... ]
> +static int qca4_test_init(struct kunit *test)
> +{
> + struct qca4_test_context *c =
> + kunit_kzalloc(test, sizeof(*c), GFP_KERNEL);
> + struct dsa_user_priv *p;
> +
> + if (!c)
> + return -ENOMEM;
> + c->conduit = alloc_etherdev(0);
> + c->netdev = alloc_etherdev(sizeof(*p));
> + if (!c->conduit || !c->netdev) {
> + if (c->conduit)
> + free_netdev(c->conduit);
> + if (c->netdev)
> + free_netdev(c->netdev);
> + return -ENOMEM;
> + }
[ ... ]
> + test->priv = c;
> + return 0;
> +}
> +
> +static void qca4_test_exit(struct kunit *test)
> +{
> + struct qca4_test_context *c = test->priv;
> +
> + free_netdev(c->netdev);
> + free_netdev(c->conduit);
> +}
[Severity: Low]
Can qca4_test_exit() hit a NULL pointer dereference if an allocation in
qca4_test_init() fails? KUnit still invokes suite->exit(test) via
kunit_run_case_cleanup() when suite->init(test) returns an error, at
which point test->priv is NULL.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-almondplus-offload-rfc-v1-0-703175c6340c@gmail.com?part=2
next prev parent reply other threads:[~2026-11-26 20:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
2026-11-25 20:50 ` Fil Dunsky
2026-11-25 20:50 ` [PATCH RFC net-next 1/7] dt-bindings: net: dsa: allow the QCA four-byte tag protocol Fil Dunsky via B4 Relay
2026-11-25 20:50 ` Fil Dunsky
2026-11-25 20:50 ` [PATCH RFC net-next 2/7] net: dsa: add a QCA four-byte CPU tagger Fil Dunsky via B4 Relay
2026-11-25 20:50 ` Fil Dunsky
2026-11-25 21:15 ` Andrew Lunn
2026-11-26 20:54 ` sashiko-bot [this message]
2026-11-25 20:50 ` [PATCH RFC net-next 3/7] netfilter: flowtable: expose route MTU and established TCP context Fil Dunsky via B4 Relay
2026-11-25 20:50 ` Fil Dunsky
2026-11-25 20:50 ` [PATCH RFC net-next 4/7] net: cortina: add a serialized CS7542 forwarding engine owner Fil Dunsky
2026-11-25 20:50 ` Fil Dunsky via B4 Relay
2026-11-26 20:54 ` sashiko-bot
2026-11-25 20:50 ` [PATCH RFC net-next 5/7] net: dsa: qca8k: select the four-byte format before port activation Fil Dunsky
2026-11-25 20:50 ` Fil Dunsky via B4 Relay
2026-11-25 21:13 ` Andrew Lunn
2026-11-26 20:54 ` sashiko-bot
2026-11-25 20:50 ` [PATCH RFC net-next 6/7] net: cortina: connect wired IPv4 NAT to nftables hardware flowtables Fil Dunsky
2026-11-25 20:50 ` Fil Dunsky via B4 Relay
2026-11-26 20:54 ` sashiko-bot
2026-11-25 20:50 ` [PATCH RFC net-next 7/7] docs: networking: describe the CS7542 flowtable RFC limits Fil Dunsky
2026-11-25 20:50 ` Fil Dunsky via B4 Relay
2026-11-26 20:54 ` sashiko-bot
2026-11-25 21:10 ` [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Andrew Lunn
2026-11-25 21:55 ` Fil Dunsky
2026-11-25 22:10 ` Andrew Lunn
2026-11-25 22:56 ` Fil Dunsky
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=sashiko-outbox-236171@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=filipp.dunsky@gmail.com \
--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 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.