Article View: linux.kernel.netdev
Article #22729Re: [PATCH net-next 3/6] packet: validate TX header length before skb allocation
From: netdev-bot+sashiko
Date: Wed, 25 Nov 2026 20:06
Date: Wed, 25 Nov 2026 20:06
115 lines
11994 bytes
11994 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In packet_sendmsg_spkt() (net/packet/af_packet.c), the header-
length check (`len < hard_header_len || !len`) now runs only on the…
--
packet: validate TX header length before skb allocation
This patch moves the TX header length checks in packet_sendmsg_spkt(),
tpacket_snd() and packet_snd() ahead of skb allocation. The checks now
compare against the snapshotted hard_header_len. It also drops the
network header reset in packet_sendmsg_spkt(), which can no longer be
reached, and the hdrlen clamp in tpacket_fill_skb().
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 230b16742346c..e8326cade94af 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -2024,8 +2024,13 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
> }
>
> /* Keep the allocation-time header length across retry. */
> - if (!skb)
> + if (!skb) {
> hard_header_len = READ_ONCE(dev->hard_header_len);
> + if (len < hard_header_len || !len) {
> + err = -EINVAL;
> + goto out_unlock;
> + }
> + }
>
> err = -EMSGSIZE;
> if (len > dev->mtu + hard_header_len + VLAN_HLEN + extra_len)
[ ... ]
> @@ -2060,10 +2063,6 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
> goto retry;
> }
>
> - if (len < hard_header_len || !skb->len) {
> - err = -EINVAL;
> - goto out_unlock;
> - }
> if (len > (dev->mtu + hard_header_len + extra_len) &&
> !packet_extra_vlan_len_allowed(dev, skb)) {
> err = -EMSGSIZE;
[Severity: Medium]
With this check removed, is len ever validated against the device that
actually transmits the skb?
The new check in the first hunk only runs while skb is NULL. It uses the
device returned by the first dev_get_by_name_rcu() lookup. After that,
packet_sendmsg_spkt() drops the RCU read lock and calls sock_wmalloc()
with GFP_KERNEL and then memcpy_from_msg(). Both can sleep. It then jumps
back and looks the device up again by name:
retry:
rcu_read_lock();
dev = dev_get_by_name_rcu(sock_net(sk), saddr->spkt_device);
Suppose spkt_device now names a different netdev (renamed, or deleted and
recreated) with a larger hard_header_len. Only the MTU checks remain
before dev_queue_xmit().
For example, a 1 byte frame sized for a tun device (hard_header_len 0)
could be sent on a veth device (hard_header_len 14). This needs
CAP_NET_RAW and CAP_NET_ADMIN. Both are available inside an unprivileged
user plus network namespace.
On veth the call path is:
veth_xmit()->veth_forward_skb()->__dev_forward_skb()->eth_type_trans()
->eth_skb_pull_mac()
eth_skb_pull_mac() reads the ethhdr at skb->data even when skb->len is
less than ETH_HLEN:
include/linux/etherdevice.h:eth_skb_pull_mac() {
struct ethhdr *eth = (struct ethhdr *)skb->data;
skb_pull_inline(skb, ETH_HLEN);
return eth;
}
Would eth->h_proto and the pkt_type classification then come from
uninitialized bytes past skb->len?
Before the series, dev_validate_header(dev, skb->data, len) ran after the
retry. It checked the live transmit device, inside the same RCU section
as dev_queue_xmit().
The earlier patch "net: remove header_ops->validate and
dev_validate_header()" switched that check to the snapshotted value. This
patch then removes the post-retry check. The gap is still there at the
end of the series ("net: remove unused net_device::min_header_len").
Could len be checked here again against READ_ONCE(dev->hard_header_len)
of the retry device? Another option is to bail out if the device changed
between the two lookups.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124170551.1874487-1-willemdebruijn.kernel%40gmail.com
Technical Details
Message-ID:
<179563717264.3135.14653977581584751949@kernel.org>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371652-linux-kernel-netdev=dewy.ruReferences:
<20261124170551.1874487-4-willemdebruijn.kernel@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371652-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next 3/6] packet: validate TX header length before skb allocation Date: Wed, 25 Nov 2026 20:06:12 +0000 Organization: Usenet Network Message-ID: <179563717264.3135.14653977581584751949@kernel.org> References: <20261124170551.1874487-4-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="292027"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:FndcIv7OvYHyug4EQunJpBaGpOQ= sha256:j8Uv17+io8/bEsjXv68LQ7vl4zLSwHyvLOC2UDTZu2k= sha1:fRrJ6R7uOUaClA4wosyFdy2fMgI= sha256:2C/Wbvgp1S38RYSmwGa09hUmoWL9VkcZSu9EAHVsDcI= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 1DF82125E94; Wed, 25 Nov 2026 23:06:32 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2lMovLa_li3u; Wed, 25 Nov 2026 23:06:28 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-371652-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 1B39F125E9D; Wed, 25 Nov 2026 23:06:19 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 814B629834; Wed, 25 Nov 2026 20:06:17 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795637174; b=jLwel42EG9VqENeZXe8kcJNHGIdUIpHVc0i3bNMBelcxJqYrsTC/c1bY/KRoLruLTxX9 atqQZLNM2B/Z6wKD/xukP5wf2xqJMcQN7MgHLpyaGb50OzBjd3LMQZDStbsvFcGEPMHWL eYXuekWrjCrmpVOEEkX2SQeofmfXZaQ31U2QwL4xgenD15oHMRhcn0Tc+qtnpPhcHudXp hg8pBgqQgQBy8c9O2jazHA2lrZ2ccAu8PDCi296twRc0mdJz/bnh+OK9RaDTQPRi9MIZY NVqdGd5yRAwyFJov4zHo1nkCKX1dmO5arG8Ht14UFBJf9upipc5eyQzLVAhP25hxMEQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795637174; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=5TK6R24Cb2mY9pz9CbFvv5hJT9lRBIRvHI65CvSOF68=; b=5gWc6KbJoI8dJ2Ll8dtFB9+G+qzp1pgxBAqR9BEqST1OMMKhxdl+8wOcAshz+W7eH8xi l6yox2fAG4kFva6MCxfi/ZOuzAfv3nRX7/flpRGiei9K3wAk8FhezUV5eI2GqqW7d2SAq B1osApE5CMaS9vcv6BUlCmwrprw4yKhyMqcOOyfvhOM9P4LTT0qwbKQukiHA16LfaRomG WKEM03HNGR2/FX5e529os73VAyL95AtEHRO/2pnEaDCjYhYM9Xo+aAC9v9b8Ku5kf4ypg PLSo6atSJQ9BrVO+kcXkTnhr8UeYQ2XQgbifiL1etX4cSG67KDfeqoh4oDQgC6AVXPw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l5ySOJMS; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B15DE606A321; Wed, 25 Nov 2026 20:06:14 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l5ySOJMS X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795637173; b=P8HbmoTC1RHyA7pBOXeNIEcTZiGwyWISjzMNeKh4xX5wIHvoTTa+/fUCrEKOdDWqq29E QCZYs+mocCxMp8N/D3ZyNhvCiPynQ/lBc/Q09U5Tv1qoTYV5Uc7KOr6L2IP3LuW1biILx 8CEKOpu2FYWm5jVXtBfsxJcJ2ZSOw2O5I798sf2gjEvhV4Wbqp9atzTqjcJeg4IMmPAPg CdyFOL2nKHuncjQiN80USOnp1xfiEnTAmoqCAoEY/iYrYf1smLAbNvbfwKNUonbO1BfpI +zfWRq9Q6aeEtq7bUqZscu/u4x+qalnMR/rksp0pCiSli86jdQIR67cMfrTQlFqtXrw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795637173; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=5TK6R24Cb2mY9pz9CbFvv5hJT9lRBIRvHI65CvSOF68=; b=XQrFMCxYMJC4h/6lv9WiaqeZqaL+sLy1cZqirHDqOb0pExCFBuRGhd4MpHds61j1IzQm HZIN1k5fawPcyKCmjLgS+S4uz1Cr9zJfED5ZOW87qxkGE/wM0RwmMxnFsHHPvdMml7a7n Phsr0xzqgnqnyH26E4jzewbLsAAAndEKa88ghQHzWVsL9xDB7LAmoQ8EwEIgnJw3YYRhO G/2JEaWeYtm7BwxYWO8U/Z9cb31QPoqGabD0jX+DEt8f12lgu29h2fY1+9TyvYHdZ6JVN j/zP8joJLi23/CKtY0IV9iZOFkJ7kpobXWsjFlg5p8I3BOcn7l+cev/vqSyFIEuOhZQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l5ySOJMS; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE4AE606A32C for <netdev@vger.kernel.org>; Wed, 25 Nov 2026 20:06:13 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E3351F000C6; Wed, 25 Nov 2026 20:06:13 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795637173; bh=5TK6R24Cb2mY9pz9CbFvv5hJT9lRBIRvHI65CvSOF68=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=l5ySOJMScnSPcYueTHsnz5pLl78/iTzkycEyy3mANznTq+RExHCXWjrxxROBNeti0 8LgnJkc/XnWVPw/w57zhDlb9UcLpaIJBLK/n+kRPgrhaAxvSH8NlBAKSE7uPm8U98c dVnC6P/FG0CN3yu8oyqosahg7990/0bbrHyArgA5LH+9/Wlda3qMVTz+E0iqLBcVwe IVlpwvTjpbhjpeNvhmSWh5vGg/T5xqc+evEQx5VxPDxWDLYYja12HjbtMRBU1wDzLq 79jqyAHNDo7PXGCqpuuajz+oismF8x67WtNEZcMFLQ96wUxUrNPfkZz9mSXw46wBKP W64CNtBMVpkqQ== X-Cc: netdev@vger.kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, elder@kernel.org, willemb@google.com X-In-Reply-To: <20261124170551.1874487-4-willemdebruijn.kernel@gmail.com> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list