From: Vladimir Oltean <olteanv@gmail.com>
To: Linus Walleij <linusw@kernel.org>
Cc: "Andrew Lunn" <andrew@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Florian Fainelli" <florian.fainelli@broadcom.com>,
"Jonas Gorski" <jonas.gorski@gmail.com>,
"Hauke Mehrtens" <hauke@hauke-m.de>,
"Kurt Kanzenbach" <kurt@linutronix.de>,
"Woojung Huh" <woojung.huh@microchip.com>,
UNGLinuxDriver@microchip.com,
"Chester A. Unal" <chester.a.unal@arinc9.com>,
"Daniel Golle" <daniel@makrotopia.org>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
"Wei Fang" <wei.fang@nxp.com>,
"Clark Wang" <xiaoning.wang@nxp.com>,
"Clément Léger" <clement.leger@bootlin.com>,
"George McCollister" <george.mccollister@gmail.com>,
"David Yang" <mmyangfl@gmail.com>,
netdev@vger.kernel.org,
"Sashiko AI Review" <sashiko-bot@kernel.org>
Subject: Re: [PATCH net-next v2] net: dsa: Fix skb ownership in taggers
Date: Wed, 17 Jun 2026 00:37:28 +0300 [thread overview]
Message-ID: <20260616213728.xhja2net2vbjmgzb@skbuf> (raw)
In-Reply-To: <20260616-dsa-fix-free-skb-v2-1-9dbda6a19e97@kernel.org> <20260616-dsa-fix-free-skb-v2-1-9dbda6a19e97@kernel.org>
On Tue, Jun 16, 2026 at 11:36:22AM +0200, Linus Walleij wrote:
> The tag_8021q.c tagger calls vlan_insert_tag() in dsa_8021q_xmit().
> vlan_insert_tag() will consume the skb with kfree_skb() on failure
> and return NULL.
>
> When NULL is returned as error code to ->xmit() in dsa_user_xmit()
> it will free the same skb again leading to a double-free.
>
> The idea of dsa_user_xmit() and dsa_switch_rcv() dropping the skb
> they held before the call to ->xmit() and ->rcv() is conceptually
> wrong: the pattern elsewhere in the networking code is that consumers
> drop their skb:s on failure.
>
> Modify the ->xmit() and ->rcv() call sites to not drop the SKB if
> the taggers return NULL from any of these calls. Move those drops into
> the taggers so every callback error path that retains ownership consumes
> the skb before returning NULL.
>
> Keep the existing helper ownership rules: VLAN insertion helpers already
> free on failure (this is the case in tag_8021q.c), while deferred
> transmit paths either transfer the skb reference to worker context or
> hold a worker reference with skb_get() and drop the caller's reference.
>
> For SJA1105 meta RX, transfer the buffered stampable skb under the meta
> lock and return NULL while the skb is waiting for its meta frame: the
> skb is not dropped in this case.
>
> Reported-by: Sashiko AI Review <sashiko-bot@kernel.org>
> Closes: https://lore.kernel.org/r/20260610153952.1685895-1-kuba@kernel.org/
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Assisted-by: Codex:gpt-5-5
> Acked-by: David Yang <mmyangfl@gmail.com> # yt921x
> Acked-by: Kurt Kanzenbach <kurt@linutronix.de> # hellcreek
> Signed-off-by: Linus Walleij <linusw@kernel.org>
> ---
> Changes in v2:
> - In some instances __skb_pad() and __skb_put_padto() followed by a
> kfree_skb() could be simplified to just call skb_pad() and
> skb_put_padto() which will free the skb on failure.
> - Use a label and goto for the kfree_skb(); return NULL; in
> the netc_rcv() callback in tag_netc.c as requested.
> - Collect ACKs.
> - Retag for net-next.
> - Link to v1: https://patch.msgid.link/20260616-dsa-fix-free-skb-v1-1-fd30b35dcf66@kernel.org
> ---
From my perspective, the tradeoff between pros and cons is not so well
explained. Consider the following not mentioned in the commit message:
- Changing the kfree_skb() convention, without any mechanical obstacle
preventing the backporting of patches that are written assuming one
convention down to trees expecting the other (obstacle like a failure
to compile, for example, which would warn people of their otherwise
silent incompatibility), is an avoidable experience (at best) from a
maintainance perspective.
- Has anyone proven that a real problem exists? Because dsa_user_xmit()
-> skb_ensure_writable_head_tail() has run successfully at this stage,
so we know that dev->needed_headroom bytes are available for writing.
Because DSA uses VLAN as a tag, dsa_user_setup_tagger() will increase
dev->needed_headroom by VLAN_HLEN for the tag_8021q protocols, so
vlan_insert_tag() should not fail. I've looked at this function at it
seems not to be coded up to fail for any other reason.
Otherwise, sure, it seems cleaner this way, but the way I see it, it
risks introducing more issues than it fixes. If maintainers feel
different about this please go ahead, but given the fact that I don't
really have a lot of time to do proper review during this period, I'm
more on the pragmatic side on this one.
prev parent reply other threads:[~2026-06-16 21:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 9:36 [PATCH net-next v2] net: dsa: Fix skb ownership in taggers Linus Walleij
2026-06-16 10:19 ` Wei Fang
2026-06-16 21:37 ` Vladimir Oltean [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=20260616213728.xhja2net2vbjmgzb@skbuf \
--to=olteanv@gmail.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=angelogioacchino.delregno@collabora.com \
--cc=chester.a.unal@arinc9.com \
--cc=clement.leger@bootlin.com \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=florian.fainelli@broadcom.com \
--cc=george.mccollister@gmail.com \
--cc=hauke@hauke-m.de \
--cc=horms@kernel.org \
--cc=jonas.gorski@gmail.com \
--cc=kuba@kernel.org \
--cc=kurt@linutronix.de \
--cc=linusw@kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=mmyangfl@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=wei.fang@nxp.com \
--cc=woojung.huh@microchip.com \
--cc=xiaoning.wang@nxp.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