From: Christian Eggers <ceggers@arri.de>
To: Woojung Huh <woojung.huh@microchip.com>,
Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Vladimir Oltean <olteanv@gmail.com>
Cc: Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Christian Eggers <ceggers@arri.de>
Subject: [PATCH net] net: dsa: ksz: don't pad a cloned sk_buff
Date: Fri, 16 Oct 2020 09:35:27 +0200 [thread overview]
Message-ID: <20201016073527.5087-1-ceggers@arri.de> (raw)
If the supplied sk_buff is cloned (e.g. in dsa_skb_tx_timestamp()),
__skb_put_padto() will allocate a new sk_buff with size = skb->len +
padlen. So the condition just tested for (skb_tailroom(skb) >= padlen +
len) is not fulfilled anymore. Although the real size will usually be
larger than skb->len + padlen (due to alignment), there is no guarantee
that the required memory for the tail tag will be available
Instead of letting __skb_put_padto allocate a new (too small) sk_buff,
lets take the already existing path and allocate a new sk_buff ourself
(with sufficient size).
Fixes: 8b8010fb7876 ("dsa: add support for Microchip KSZ tail tagging")
Signed-off-by: Christian Eggers <ceggers@arri.de>
---
I am not sure whether this is a problem for current kernels (it depends
whether cloned sk_buffs can happen on any paths). But when adding time
stamping (will be submitted soon), this will become an issue.
This patch supersedes "net: dsa: ksz: fix padding size of skb" from
yesterday.
net/dsa/tag_ksz.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index 945a9bd5ba35..cb1f27e15201 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -22,7 +22,7 @@ static struct sk_buff *ksz_common_xmit(struct sk_buff *skb,
padlen = (skb->len >= ETH_ZLEN) ? 0 : ETH_ZLEN - skb->len;
- if (skb_tailroom(skb) >= padlen + len) {
+ if (skb_tailroom(skb) >= padlen + len && !skb_cloned(skb)) {
/* Let dsa_slave_xmit() free skb */
if (__skb_put_padto(skb, skb->len + padlen, false))
return NULL;
@@ -45,7 +45,7 @@ static struct sk_buff *ksz_common_xmit(struct sk_buff *skb,
/* Let skb_put_padto() free nskb, and let dsa_slave_xmit() free
* skb
*/
- if (skb_put_padto(nskb, nskb->len + padlen))
+ if (skb_put_padto(nskb, ETH_ZLEN + len))
return NULL;
consume_skb(skb);
--
Christian Eggers
Embedded software developer
Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler
next reply other threads:[~2020-10-16 7:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-16 7:35 Christian Eggers [this message]
2020-10-16 14:00 ` [PATCH net] net: dsa: ksz: don't pad a cloned sk_buff Andrew Lunn
2020-10-16 14:06 ` Vladimir Oltean
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=20201016073527.5087-1-ceggers@arri.de \
--to=ceggers@arri.de \
--cc=UNGLinuxDriver@microchip.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=vivien.didelot@gmail.com \
--cc=woojung.huh@microchip.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;
as well as URLs for NNTP newsgroup(s).