From: Martin Schiller <ms@dev.tdt.de>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Hui Peng <benquike@gmail.com>,
linux-x25@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Martin Schiller <ms@dev.tdt.de>
Subject: [PATCH net v2] net: wan: lapbether: validate the frame length in lapbeth_rcv()
Date: Mon, 30 Nov 2026 10:22:41 +0100 (CET) [thread overview]
Message-ID: <20261130-lapbether-length-v2-1-db62bd1e2ea7@dev.tdt.de> (raw)
From: Hui Peng <benquike@gmail.com>
lapbeth_rcv() takes the length of the LAPB frame from a 2-byte field in
front of it and trims the skb to that length with skb_trim().
skb_trim() only works on linear skbs: a nonlinear skb hits the
WARN_ON() in __skb_set_length() and is not trimmed at all, so LAPB
gets the Ethernet padding as part of the frame. A length field that is
larger than the received data is not caught either.
Use pskb_trim_rcsum(), which trims nonlinear skbs as well, and drop
frames whose length field is larger than the received data. Count a
frame in the statistics only once it has been accepted.
This is easy to trigger without kernel changes: a packet socket with
a virtio-net header and a small hdr_len builds a nonlinear skb for a
frame larger than a page, and a veth pair hands it to lapbether
unchanged. With a length field shorter than the frame, an unpatched
kernel warns:
WARNING: ./include/linux/skbuff.h:3347 at skb_trim+0xf/0x18, CPU#0: x25test/26
Call Trace:
<IRQ>
lapbeth_rcv+0x130/0x178
__netif_receive_skb_one_core+0x3e/0x44
process_backlog+0x85/0x1c5
__napi_poll.constprop.0+0x1f/0x107
net_rx_action+0x134/0x26c
handle_softirqs+0x14c/0x2e5
With this patch the frame is trimmed without a warning.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Hui Peng <benquike@gmail.com>
[ms: also drop frames shorter than their length field, new message]
Signed-off-by: Martin Schiller <ms@dev.tdt.de>
---
v2 (Martin Schiller):
- also drop frames whose length field is larger than the received data
- new subject and commit message that describe the actual change; v1
also mentioned pskb_may_pull() and headroom changes that were not
part of the patch
- add how to trigger the warning
- drop the Assisted-by line; v1 said an LLM was used, without naming
which
- v2 was prepared with the help of an AI assistant (Claude, Anthropic)
- Link to v1: https://lore.kernel.org/all/20260919223433.3882618-1-benquike@gmail.com/
---
drivers/net/wan/lapbether.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
index c3630a82913bfa300d6e9add078b9bfab51755cc..b1996297cfc54510c364855f4ce5485c7a6927f6 100644
--- a/drivers/net/wan/lapbether.c
+++ b/drivers/net/wan/lapbether.c
@@ -133,11 +133,14 @@ static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev,
goto drop_unlock;
len = skb->data[0] + skb->data[1] * 256;
- dev->stats.rx_packets++;
- dev->stats.rx_bytes += len;
skb_pull(skb, 2); /* Remove the length bytes */
- skb_trim(skb, len); /* Set the length of the data */
+ /* Drop frames that are shorter than their length field */
+ if (len > skb->len || pskb_trim_rcsum(skb, len))
+ goto drop_unlock;
+
+ dev->stats.rx_packets++;
+ dev->stats.rx_bytes += len;
err = lapb_data_received(lapbeth->axdev, skb);
if (err != LAPB_OK) {
---
base-commit: e2fb9368a41662bc54624f9be87ea8989b109306
change-id: 20261130-lapbether-length-a3c09a48be6a
Best regards,
--
Martin Schiller <ms@dev.tdt.de>
reply other threads:[~2026-11-30 9:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261130-lapbether-length-v2-1-db62bd1e2ea7@dev.tdt.de \
--to=ms@dev.tdt.de \
--cc=andrew+netdev@lunn.ch \
--cc=benquike@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-x25@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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
all inboxes | Powered by JetHome®