* [PATCH net-next v2 0/5] net: remove dev_validate_header() and net_device::min_header_len
@ 2026-11-29 16:30 Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 1/5] net: ipa: remove ethernet-specific artifacts from modem netdev setup Willem de Bruijn
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Willem de Bruijn @ 2026-11-29 16:30 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, elder,
Willem de Bruijn
Remove unused link-layer header validation plumbing, clean up the
remaining af_packet users, and drop net_device::min_header_len.
Mostly cleanup, with two user-visible changes:
- Patch 3: on devices that set hard_header_len but have no link layer
header (e.g., PPP), SOCK_RAW sends, with or without a TX_RING, now
always have skb->network_header at the start of the packet. Before,
only short packets sent without a TX_RING did.
- Patch 4: on SOCK_DGRAM, the VLAN TCI of non-offloaded tags is now
reported on all Ethernet devices, including those with
hard_header_len != ETH_HLEN, and omitted (without setting
TP_STATUS_VLAN_VALID) on non-Ethernet devices.
1. Drop stale Ethernet fields (including min_header_len) in IPA modem.
2. Remove header_ops->validate and dev_validate_header().
3. Reset network header on all headerless devices via dev_has_header().
4. Use ARPHRD_ETHER / ARPHRD_LOOPBACK and ETH_HLEN in vlan_get_tci().
5. Remove unused net_device::min_header_len.
Testing (under vng):
- tools/testing/selftests/net: psock_snd.sh, psock_tpacket, and
txring_overwrite.
- Custom tests for short/zero header validation (SOCK_RAW, SOCK_DGRAM,
SOCK_PACKET, TX_RING), SOCK_PACKET retry device swap via userfaultfd
(tun -> veth), non-offloaded outgoing VLAN TCI capture (AUXDATA with
non-zero TCI, TCI 0, TP_STATUS_COPY, and tun; TPACKET_V2; TPACKET_V3),
and SOCK_RAW network header offset over PPP (40B/100B IPv4, with and
without TX_RING).
Link: https://patch.msgid.link/willemdebruijn.kernel.251660d5aa3e@gmail.com
Changes
v1 -> v2
- rebase on net-next
- cover letter: add Link: to the thread where this cleanup was
proposed
- cover letter: correct the summary of the network header change
- cover letter: update the summary of the VLAN change and the list
of custom tests to match v2
- patch 1/5: add Acked-by from Alex Elder
- patch 1/5: replace <linux/etherdevice.h> with <linux/if_ether.h>
for ETH_P_MAP and ETH_MIN_MTU
- patch 2/5: compare against live READ_ONCE(dev->hard_header_len) in
all three af_packet callers instead of the snapshotted value. In
packet_sendmsg_spkt() the snapshot could come from a different
device than the one transmitted on (Sashiko)
- drop v1 patch 3/6 ("packet: validate TX header length before skb
allocation"): not needed to remove min_header_len. This keeps the
TX header length checks against the live hard_header_len, after
the skb is built, which also addresses the Sashiko report on that
patch
- patch 3/5: no code change; clarify commit message (needed_headroom
vs hard_header_len, scope of the 6in4 workaround, why
tpacket_fill_skb() is changed as well, and list hdlc_null_ops as a
second header_ops without ->create)
- patch 4/5: have vlan_get_tci() return bool so callers only set
TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID when a VLAN
header is extracted, avoiding false VLAN flags on TP_STATUS_COPY
skbs (zeroed sll_hatype; Sashiko), non-Ethernet devices, and
truncated frames
- patch 4/5: update commit message to match
v1: https://lore.kernel.org/netdev/20261124170551.1874487-1-willemdebruijn.kernel@gmail.com/
Willem de Bruijn (5):
net: ipa: remove ethernet-specific artifacts from modem netdev setup
net: remove header_ops->validate and dev_validate_header()
packet: reset network header on all headerless devices
packet: use Ethernet header length in vlan_get_tci()
net: remove unused net_device::min_header_len
.../networking/net_cachelines/net_device.rst | 1 -
drivers/net/ipa/ipa_modem.c | 5 +-
drivers/net/loopback.c | 1 -
include/linux/netdevice.h | 18 -----
net/ethernet/eth.c | 1 -
net/packet/af_packet.c | 78 +++++++++----------
6 files changed, 36 insertions(+), 68 deletions(-)
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH net-next v2 1/5] net: ipa: remove ethernet-specific artifacts from modem netdev setup
2026-11-29 16:30 [PATCH net-next v2 0/5] net: remove dev_validate_header() and net_device::min_header_len Willem de Bruijn
@ 2026-11-29 16:30 ` Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 2/5] net: remove header_ops->validate and dev_validate_header() Willem de Bruijn
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Willem de Bruijn @ 2026-11-29 16:30 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, elder,
Willem de Bruijn, Alex Elder
Commit 75944b040bbc ("net: ipa: open-code ether_setup()") open-coded
ether_setup(), including fields that do not apply to this headerless
ARPHRD_RAWIP device:
- min_header_len = ETH_HLEN, while hard_header_len is 0
- an Ethernet broadcast address, while addr_len is 0
- clearing IFF_BROADCAST | IFF_MULTICAST, which are never set
Remove these and replace the etherdevice.h include with if_ether.h for
ETH_P_MAP and ETH_MIN_MTU.
With min_header_len left at 0, the device behaves like other headerless
devices (such as tun and rmnet) in af_packet's vlan_get_tci(), where
min_header_len == hard_header_len instead of returning early on the
mismatch. Normal IPA traffic uses ETH_P_MAP rather than a VLAN
ethertype, so it is unaffected.
Cc: Alex Elder <elder@kernel.org>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Acked-by: Alex Elder <elder@riscstar.com>
---
drivers/net/ipa/ipa_modem.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/net/ipa/ipa_modem.c b/drivers/net/ipa/ipa_modem.c
index d84c1dbd3b1a..d7892fcb0ef4 100644
--- a/drivers/net/ipa/ipa_modem.c
+++ b/drivers/net/ipa/ipa_modem.c
@@ -5,8 +5,8 @@
*/
#include <linux/errno.h>
-#include <linux/etherdevice.h>
#include <linux/if_arp.h>
+#include <linux/if_ether.h>
#include <linux/if_rmnet.h>
#include <linux/netdevice.h>
#include <linux/pm_runtime.h>
@@ -223,15 +223,12 @@ static void ipa_modem_netdev_setup(struct net_device *netdev)
netdev->header_ops = NULL;
netdev->type = ARPHRD_RAWIP;
netdev->hard_header_len = 0;
- netdev->min_header_len = ETH_HLEN;
netdev->min_mtu = ETH_MIN_MTU;
netdev->max_mtu = IPA_MTU;
netdev->mtu = netdev->max_mtu;
netdev->addr_len = 0;
netdev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
- netdev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
netdev->priv_flags |= IFF_TX_SKB_SHARING;
- eth_broadcast_addr(netdev->broadcast);
/* The endpoint is configured for QMAP */
netdev->needed_headroom = sizeof(struct rmnet_map_header);
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next v2 2/5] net: remove header_ops->validate and dev_validate_header()
2026-11-29 16:30 [PATCH net-next v2 0/5] net: remove dev_validate_header() and net_device::min_header_len Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 1/5] net: ipa: remove ethernet-specific artifacts from modem netdev setup Willem de Bruijn
@ 2026-11-29 16:30 ` Willem de Bruijn
2026-11-30 17:36 ` netdev-bot+sashiko
2026-11-29 16:30 ` [PATCH net-next v2 3/5] packet: reset network header on all headerless devices Willem de Bruijn
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Willem de Bruijn @ 2026-11-29 16:30 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, elder,
Willem de Bruijn
header_ops->validate was added in commit 2793a23aacbd ("net: validate
variable length ll headers") for AX.25, its only implementation. AX.25
was removed in commit dd8d4bc28ad7 ("net: remove ax25 and amateur radio
(hamradio) subsystem"), and the CAP_SYS_RAWIO bypass in
dev_validate_header() was removed in commit 3b9a324e646d ("net: remove
CAP_SYS_RAWIO zero-padding in dev_validate_header").
With both gone, dev_validate_header() only checks
len >= dev->hard_header_len. Remove header_ops->validate and
dev_validate_header(), and replace the only callers in af_packet with
direct checks against READ_ONCE(dev->hard_header_len).
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
include/linux/netdevice.h | 16 ----------------
net/packet/af_packet.c | 6 +++---
2 files changed, 3 insertions(+), 19 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 694b6d29f680..930899a7a577 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -326,7 +326,6 @@ struct header_ops {
void (*cache_update)(struct hh_cache *hh,
const struct net_device *dev,
const unsigned char *haddr);
- bool (*validate)(const char *ll_header, unsigned int len);
__be16 (*parse_protocol)(const struct sk_buff *skb);
};
@@ -3587,21 +3586,6 @@ static inline __be16 dev_parse_header_protocol(const struct sk_buff *skb)
return dev->header_ops->parse_protocol(skb);
}
-/* ll_header must have at least hard_header_len allocated */
-static inline bool dev_validate_header(const struct net_device *dev,
- char *ll_header, int len)
-{
- if (likely(len >= dev->hard_header_len))
- return true;
- if (len < dev->min_header_len)
- return false;
-
- if (dev->header_ops && dev->header_ops->validate)
- return dev->header_ops->validate(ll_header, len);
-
- return false;
-}
-
static inline bool dev_has_header(const struct net_device *dev)
{
return dev->header_ops && dev->header_ops->create;
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 037b4e55ca3d..0ea3036bee24 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2080,7 +2080,7 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
goto retry;
}
- if (!dev_validate_header(dev, skb->data, len) || !skb->len) {
+ if (len < READ_ONCE(dev->hard_header_len) || !skb->len) {
err = -EINVAL;
goto out_unlock;
}
@@ -2664,7 +2664,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
err = skb_store_bits(skb, 0, data, hdrlen);
if (unlikely(err))
return err;
- if (!dev_validate_header(dev, skb->data, hdrlen))
+ if (hdrlen < READ_ONCE(dev->hard_header_len))
return -EINVAL;
data += hdrlen;
@@ -3136,7 +3136,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
goto out_free;
if ((sock->type == SOCK_RAW &&
- !dev_validate_header(dev, skb->data, len)) || !skb->len) {
+ len < READ_ONCE(dev->hard_header_len)) || !skb->len) {
err = -EINVAL;
goto out_free;
}
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next v2 3/5] packet: reset network header on all headerless devices
2026-11-29 16:30 [PATCH net-next v2 0/5] net: remove dev_validate_header() and net_device::min_header_len Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 1/5] net: ipa: remove ethernet-specific artifacts from modem netdev setup Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 2/5] net: remove header_ops->validate and dev_validate_header() Willem de Bruijn
@ 2026-11-29 16:30 ` Willem de Bruijn
2026-11-30 17:36 ` netdev-bot+sashiko
2026-11-29 16:30 ` [PATCH net-next v2 4/5] packet: use Ethernet header length in vlan_get_tci() Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 5/5] net: remove unused net_device::min_header_len Willem de Bruijn
4 siblings, 1 reply; 9+ messages in thread
From: Willem de Bruijn @ 2026-11-29 16:30 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, elder,
Willem de Bruijn
Devices without a userspace-visible link layer header (!dev_has_header())
should leave hard_header_len at 0 and use needed_headroom for headers
prepended in ndo_start_xmit(), but some still set hard_header_len > 0
instead (e.g., PPP, mctp-usb, routed br2684, and previously sit). On
SOCK_RAW sends, af_packet reserves hard_header_len and leaves
skb->network_header pointing that many bytes into the L3 header.
Commit 88a8121dc1d3 ("af_packet: fix raw sockets over 6in4 tunnel")
added a workaround in packet_snd() only for short IPv6 packets on 6in4
tunnels, explicitly noting that it was temporary and left to be cleaned
up in net-next. That heuristic misses longer packets and misfires on
non-Ethernet devices with a link layer header where min_header_len is 0.
Replace it with !dev_has_header(dev) in packet_snd(). Apply the same in
tpacket_fill_skb(), which has the same problem but never had the
workaround, so that SOCK_RAW sends behave the same with and without a
TX ring.
For consistency, also switch packet_sendmsg_spkt() from dev->header_ops
to dev_has_header(dev). This has no effect today: the only header_ops
without ->create are ip_tunnel_header_ops and hdlc_null_ops, and all
devices using them have hard_header_len 0.
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
net/packet/af_packet.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 0ea3036bee24..4ff7a2cc11e5 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2054,7 +2054,7 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
if (!skb) {
size_t reserved = LL_RESERVED_SPACE_EX(dev, hard_header_len);
int tlen = dev->needed_tailroom;
- unsigned int hhlen = dev->header_ops ? hard_header_len : 0;
+ unsigned int hhlen = dev_has_header(dev) ? hard_header_len : 0;
rcu_read_unlock();
skb = sock_wmalloc(sk, len + reserved + tlen, 0, GFP_KERNEL);
@@ -2661,6 +2661,8 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
skb_push(skb, hard_header_len);
skb_put(skb, copylen - hard_header_len);
+ if (!dev_has_header(dev))
+ skb_reset_network_header(skb);
err = skb_store_bits(skb, 0, data, hdrlen);
if (unlikely(err))
return err;
@@ -3125,8 +3127,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
goto out_free;
} else if (reserve) {
skb_reserve(skb, -reserve);
- if (len < reserve + sizeof(struct ipv6hdr) &&
- dev->min_header_len != hard_header_len)
+ if (!dev_has_header(dev))
skb_reset_network_header(skb);
}
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next v2 4/5] packet: use Ethernet header length in vlan_get_tci()
2026-11-29 16:30 [PATCH net-next v2 0/5] net: remove dev_validate_header() and net_device::min_header_len Willem de Bruijn
` (2 preceding siblings ...)
2026-11-29 16:30 ` [PATCH net-next v2 3/5] packet: reset network header on all headerless devices Willem de Bruijn
@ 2026-11-29 16:30 ` Willem de Bruijn
2026-11-30 17:36 ` netdev-bot+sashiko
2026-11-29 16:30 ` [PATCH net-next v2 5/5] net: remove unused net_device::min_header_len Willem de Bruijn
4 siblings, 1 reply; 9+ messages in thread
From: Willem de Bruijn @ 2026-11-29 16:30 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, elder,
Willem de Bruijn
vlan_get_tci() uses dev->min_header_len to locate the outer 802.1Q/AD
header on SOCK_DGRAM captures, with an is_vlan_dev() fallback that has
been obsolete since commit 447cbe95ebb9 ("vlan: fix skb_under_panic and
races when toggling HW VLAN offload") stopped adding VLAN_HLEN to
vlandev->hard_header_len.
Only Ethernet and loopback devices set min_header_len (to ETH_HLEN).
Check ARPHRD_ETHER / ARPHRD_LOOPBACK and read at ETH_HLEN directly
instead, removing the last min_header_len reader and letting
packet_recvmsg() use sll->sll_hatype without an RCU device lookup.
Have vlan_get_tci() return whether a VLAN header was extracted, so
callers only set TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID when
the TCI is valid. This avoids setting false VLAN flags on non-Ethernet
devices, truncated frames, and TP_STATUS_COPY skbs queued by
tpacket_rcv() whose sockaddr_ll (including sll_hatype) is zeroed.
This changes the reported VLAN metadata in three cases:
- Ethernet devices with hard_header_len != ETH_HLEN (e.g., smsc95xx,
rndis_host) previously failed the min_header_len == hard_header_len
test and reported TCI 0. They now report the actual TCI.
- Non-Ethernet devices and frames without an extractable VLAN header
previously still set TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID:
headerless devices (e.g., tun, rmnet) matched 0 == 0 and read payload
bytes at offset 0 as TCI, while other non-Ethernet devices and
truncated frames reported TCI 0. They now omit VLAN metadata and flags.
- packet_recvmsg() previously omitted the VLAN fields if the device
had been unregistered since the packet was queued. It now fills
them from the queued skb.
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
net/packet/af_packet.c | 65 ++++++++++++++++++------------------------
1 file changed, 28 insertions(+), 37 deletions(-)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 4ff7a2cc11e5..7b02fd6b63eb 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -547,34 +547,25 @@ static void *packet_current_frame(struct packet_sock *po,
return packet_lookup_frame(po, rb, rb->head, status);
}
-static u16 vlan_get_tci(const struct sk_buff *skb, struct net_device *dev)
+static bool vlan_get_tci(const struct sk_buff *skb, unsigned short type,
+ u16 *tci)
{
struct vlan_hdr vhdr, *vh;
- unsigned int header_len;
- if (!dev)
- return 0;
+ if (type != ARPHRD_ETHER && type != ARPHRD_LOOPBACK)
+ return false;
/* In the SOCK_DGRAM scenario, skb data starts at the network
* protocol, which is after the VLAN headers. The outer VLAN
- * header is at the hard_header_len offset in non-variable
- * length link layer headers. If it's a VLAN device, the
- * min_header_len should be used to exclude the VLAN header
- * size.
+ * header is at the ETH_HLEN offset from the MAC header.
*/
- if (dev->min_header_len == dev->hard_header_len)
- header_len = dev->hard_header_len;
- else if (is_vlan_dev(dev))
- header_len = dev->min_header_len;
- else
- return 0;
-
- vh = skb_header_pointer(skb, skb_mac_offset(skb) + header_len,
+ vh = skb_header_pointer(skb, skb_mac_offset(skb) + ETH_HLEN,
sizeof(vhdr), &vhdr);
if (unlikely(!vh))
- return 0;
+ return false;
- return ntohs(vh->h_vlan_TCI);
+ *tci = ntohs(vh->h_vlan_TCI);
+ return true;
}
static __be16 vlan_get_protocol_dgram(const struct sk_buff *skb)
@@ -1025,13 +1016,17 @@ static void prb_fill_vlan_info(struct tpacket_kbdq_core *pkc,
struct tpacket3_hdr *ppd)
{
struct packet_sock *po = container_of(pkc, struct packet_sock, rx_ring.prb_bdqc);
+ u16 tci;
if (skb_vlan_tag_present(pkc->skb)) {
ppd->hv1.tp_vlan_tci = skb_vlan_tag_get(pkc->skb);
ppd->hv1.tp_vlan_tpid = ntohs(pkc->skb->vlan_proto);
ppd->tp_status = TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
- } else if (unlikely(po->sk.sk_type == SOCK_DGRAM && eth_type_vlan(pkc->skb->protocol))) {
- ppd->hv1.tp_vlan_tci = vlan_get_tci(pkc->skb, pkc->skb->dev);
+ } else if (unlikely(po->sk.sk_type == SOCK_DGRAM &&
+ eth_type_vlan(pkc->skb->protocol) &&
+ vlan_get_tci(pkc->skb, pkc->skb->dev->type,
+ &tci))) {
+ ppd->hv1.tp_vlan_tci = tci;
ppd->hv1.tp_vlan_tpid = ntohs(pkc->skb->protocol);
ppd->tp_status = TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
} else {
@@ -2294,6 +2289,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
__u32 ts_status;
unsigned int slot_id = 0;
int vnet_hdr_sz = 0;
+ u16 tci;
/* struct tpacket{2,3}_hdr is aligned to a multiple of TPACKET_ALIGNMENT.
* We may add members to them until current aligned size without forcing
@@ -2474,8 +2470,10 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
h.h2->tp_vlan_tci = skb_vlan_tag_get(skb);
h.h2->tp_vlan_tpid = ntohs(skb->vlan_proto);
status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
- } else if (unlikely(sk->sk_type == SOCK_DGRAM && eth_type_vlan(skb->protocol))) {
- h.h2->tp_vlan_tci = vlan_get_tci(skb, skb->dev);
+ } else if (unlikely(sk->sk_type == SOCK_DGRAM &&
+ eth_type_vlan(skb->protocol) &&
+ vlan_get_tci(skb, dev->type, &tci))) {
+ h.h2->tp_vlan_tci = tci;
h.h2->tp_vlan_tpid = ntohs(skb->protocol);
status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
} else {
@@ -3622,7 +3620,9 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
}
if (packet_sock_flag(pkt_sk(sk), PACKET_SOCK_AUXDATA)) {
+ const struct sockaddr_ll *sll = &PACKET_SKB_CB(skb)->sa.ll;
struct tpacket_auxdata aux;
+ u16 tci;
aux.tp_status = TP_STATUS_USER;
if (skb->ip_summed == CHECKSUM_PARTIAL)
@@ -3641,21 +3641,12 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
aux.tp_vlan_tci = skb_vlan_tag_get(skb);
aux.tp_vlan_tpid = ntohs(skb->vlan_proto);
aux.tp_status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
- } else if (unlikely(sock->type == SOCK_DGRAM && eth_type_vlan(skb->protocol))) {
- struct sockaddr_ll *sll = &PACKET_SKB_CB(skb)->sa.ll;
- struct net_device *dev;
-
- rcu_read_lock();
- dev = dev_get_by_index_rcu(sock_net(sk), sll->sll_ifindex);
- if (dev) {
- aux.tp_vlan_tci = vlan_get_tci(skb, dev);
- aux.tp_vlan_tpid = ntohs(skb->protocol);
- aux.tp_status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
- } else {
- aux.tp_vlan_tci = 0;
- aux.tp_vlan_tpid = 0;
- }
- rcu_read_unlock();
+ } else if (unlikely(sock->type == SOCK_DGRAM &&
+ eth_type_vlan(skb->protocol) &&
+ vlan_get_tci(skb, sll->sll_hatype, &tci))) {
+ aux.tp_vlan_tci = tci;
+ aux.tp_vlan_tpid = ntohs(skb->protocol);
+ aux.tp_status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
} else {
aux.tp_vlan_tci = 0;
aux.tp_vlan_tpid = 0;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH net-next v2 5/5] net: remove unused net_device::min_header_len
2026-11-29 16:30 [PATCH net-next v2 0/5] net: remove dev_validate_header() and net_device::min_header_len Willem de Bruijn
` (3 preceding siblings ...)
2026-11-29 16:30 ` [PATCH net-next v2 4/5] packet: use Ethernet header length in vlan_get_tci() Willem de Bruijn
@ 2026-11-29 16:30 ` Willem de Bruijn
4 siblings, 0 replies; 9+ messages in thread
From: Willem de Bruijn @ 2026-11-29 16:30 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, horms, elder,
Willem de Bruijn
dev->min_header_len was introduced in commit 217e6fa24ce2 ("net:
introduce device min_header_len") for dev_validate_header() when
header_ops->validate and the CAP_SYS_RAWIO bypass could accept frames
shorter than hard_header_len.
Now that dev_validate_header() and the remaining workarounds in
af_packet have been removed, dev->min_header_len has no readers left.
Remove the field from struct net_device along with its remaining
assignments in ether_setup() and loopback setup.
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
Documentation/networking/net_cachelines/net_device.rst | 1 -
drivers/net/loopback.c | 1 -
include/linux/netdevice.h | 2 --
net/ethernet/eth.c | 1 -
4 files changed, 5 deletions(-)
diff --git a/Documentation/networking/net_cachelines/net_device.rst b/Documentation/networking/net_cachelines/net_device.rst
index 7620d3fcb8dc..f73ea0069432 100644
--- a/Documentation/networking/net_cachelines/net_device.rst
+++ b/Documentation/networking/net_cachelines/net_device.rst
@@ -46,7 +46,6 @@ netdev_features_t gso_partial_features read_mostly
unsigned_int min_mtu
unsigned_int max_mtu
unsigned_short type
-unsigned_char min_header_len
unsigned_char name_assign_type
int group
struct net_device_stats stats
diff --git a/drivers/net/loopback.c b/drivers/net/loopback.c
index 1e6d1b7d71ba..6fdf00c223b9 100644
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -173,7 +173,6 @@ static void gen_lo_setup(struct net_device *dev,
{
dev->mtu = mtu;
dev->hard_header_len = ETH_HLEN; /* 14 */
- dev->min_header_len = ETH_HLEN; /* 14 */
dev->addr_len = ETH_ALEN; /* 6 */
dev->type = ARPHRD_LOOPBACK; /* 0x0001*/
dev->flags = IFF_LOOPBACK;
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 930899a7a577..2a1b3f48bed5 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1929,7 +1929,6 @@ enum netdev_reg_state {
* @max_mtu: Interface Maximum MTU value
* @type: Interface hardware type
* @hard_header_len: Maximum hardware header length.
- * @min_header_len: Minimum hardware header length
*
* @needed_headroom: Extra headroom the hardware may need, but not in all
* cases can this be guaranteed
@@ -2292,7 +2291,6 @@ struct net_device {
unsigned int min_mtu;
unsigned int max_mtu;
unsigned short type;
- unsigned char min_header_len;
unsigned char name_assign_type;
int group;
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 39aab0f8035a..db39527d4704 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -330,7 +330,6 @@ void ether_setup(struct net_device *dev)
dev->header_ops = ð_header_ops;
dev->type = ARPHRD_ETHER;
dev->hard_header_len = ETH_HLEN;
- dev->min_header_len = ETH_HLEN;
dev->mtu = ETH_DATA_LEN;
dev->min_mtu = ETH_MIN_MTU;
dev->max_mtu = ETH_DATA_LEN;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 2/5] net: remove header_ops->validate and dev_validate_header()
2026-11-29 16:30 ` [PATCH net-next v2 2/5] net: remove header_ops->validate and dev_validate_header() Willem de Bruijn
@ 2026-11-30 17:36 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 17:36 UTC (permalink / raw)
To: willemb; +Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, horms,
elder
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 (1) · 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] packet: re-reading hard_header_len in packet_snd() and
tpacket_fill_skb()
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch
rewrites the exact comparison involved and keeps it inconsistent.
--
net: remove header_ops->validate and dev_validate_header()
This commit removes header_ops->validate and dev_validate_header(). AX.25
was the only validate implementation and has been removed, and the
CAP_SYS_RAWIO bypass is also gone. The three af_packet callers now compare
directly against READ_ONCE(dev->hard_header_len).
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 037b4e55ca3df..0ea3036bee249 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
[ ... ]
> @@ -2664,7 +2664,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
> err = skb_store_bits(skb, 0, data, hdrlen);
> if (unlikely(err))
> return err;
> - if (!dev_validate_header(dev, skb->data, hdrlen))
> + if (hdrlen < READ_ONCE(dev->hard_header_len))
> return -EINVAL;
[Severity: Medium]
This patch did not introduce this issue, because the removed
dev_validate_header() read dev->hard_header_len the same way. Since
these three checks are being rewritten anyway, could they compare
against the local hard_header_len snapshot rather than doing a second
READ_ONCE()?
packet_snd() takes the snapshot once and lays out the skb from it:
packet_snd()
hard_header_len = READ_ONCE(dev->hard_header_len);
if (sock->type == SOCK_RAW)
reserve = hard_header_len;
...
linear = max(linear, min_t(int, len, hard_header_len));
skb = packet_alloc_skb(sk, hlen + tlen, hlen, len, linear, ...);
skb_reset_network_header(skb);
...
skb_reserve(skb, -reserve);
Take a SOCK_RAW socket on a device that has header_ops. The network
header stays at offset reserve from skb->data. Suppose
dev->hard_header_len shrinks between the snapshot and this check, for
example through ipgre_link_update() when GRE key/csum/seq flags are
dropped. A frame with len below the snapshot, but at or above the new
value, then passes. skb_network_offset(skb) ends up larger than
skb->len and points past skb_tail_pointer(skb). Is everything after
packet_parse_headers() and packet_xmit() prepared for a network header
that sits beyond the end of the packet?
packet_sendmsg_spkt() has the same pattern. It keeps hard_header_len
across the unlocked sock_wmalloc() and the retry lookup, and it uses
that value for the headroom and the MTU checks. The retry lookup by
name may resolve to a different net_device. Even so, the length check
re-reads dev->hard_header_len. The layout there resets the network
header when len < hhlen, so the effect looks limited to the check not
matching how the skb was built.
The tpacket_fill_skb() hunk has the same mismatch. There it is worse,
because the skb can go out with linear bytes that skb_store_bits()
never wrote.
Triggering this needs CAP_NET_RAW to send, plus CAP_NET_ADMIN to
reconfigure the device concurrently. Would something like this be
enough?
if ((sock->type == SOCK_RAW && len < hard_header_len) ||
!skb->len) {
and in packet_sendmsg_spkt():
if (len < hard_header_len || !skb->len) {
That would make all three checks match the value used to size and lay
out the skb, which is what the earlier "packet: use consistent
hard_header_len" changes seem to have intended.
[Severity: High]
This is a pre-existing issue that this patch did not introduce. Since this
line is being rewritten anyway, should it compare against the
hard_header_len parameter instead of reading dev->hard_header_len again?
The linear area just above is sized from a snapshot that tpacket_snd()
takes once, before its frame loop:
tpacket_snd()
hard_header_len = READ_ONCE(dev->hard_header_len);
...
do {
...
copylen = max_t(int, copylen, hard_header_len);
...
tp_len = tpacket_fill_skb(po, skb, dev, data, tp_len, proto,
addr, hlen, copylen, hard_header_len,
&sockc);
In tpacket_fill_skb(), skb_push() and skb_put() set skb->len to copylen.
However, skb_store_bits() only writes hdrlen = min(copylen, tp_len) bytes.
Suppose dev->hard_header_len shrinks after the snapshot. A SOCK_RAW
TX_RING frame with tp_len between the new value and the snapshot value
then passes this check. to_write becomes 0, so no frags are added. The skb
is sent with bytes [tp_len, copylen) never written, and those bytes come
from sock_alloc_send_skb(), which does not zero memory.
One way to shrink it at runtime is ipgre_changelink()->ipgre_link_update()
on a GRE device that has header_ops, when key/csum/seq flags are removed:
net/ipv4/ip_gre.c:ipgre_link_update() {
...
if (dev->header_ops)
dev->hard_header_len += len;
...
}
In that case len is negative. ipgre_xmit() then pulls only the current
tunnel->hlen + sizeof(struct iphdr). Couldn't the leftover uninitialized
bytes then be sent as GRE payload, and also be visible to packet taps?
The race window can be wide, because tpacket_snd() keeps using the
snapshot across wait_for_completion_interruptible_timeout(). The trigger
needs CAP_NET_RAW and CAP_NET_ADMIN in the netns, and an unprivileged user
namespace provides both.
The removed dev_validate_header() read dev->hard_header_len the same way,
so this patch does not change the behavior. The snapshot parameter has
been in scope here since commit 21b5953e7494 ("packet: use consistent
hard_header_len in TX_RING send path"). Would something like this close
it?
if (hdrlen < hard_header_len)
return -EINVAL;
This check is still unchanged at the end of the series, after "net: remove
unused net_device::min_header_len".
packet_snd() and packet_sendmsg_spkt() have the same mismatch between the
snapshot and the second read. They copy the whole payload, though, so the
effect there looks limited to an inconsistent network header offset rather
than uninitialized bytes.
>
> data += hdrlen;
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129163327.893403-1-willemb%40google.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 3/5] packet: reset network header on all headerless devices
2026-11-29 16:30 ` [PATCH net-next v2 3/5] packet: reset network header on all headerless devices Willem de Bruijn
@ 2026-11-30 17:36 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 17:36 UTC (permalink / raw)
To: willemb; +Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, horms,
elder
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · 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).
- [High] packet_snd() (net/packet/af_packet.c) can build an skb whose
network header lies past the end of the packet, on devices that have a…
--
packet: reset network header on all headerless devices
This replaces the min_header_len based heuristic in packet_snd() with a
!dev_has_header(dev) check before resetting the network header on
SOCK_RAW sends. It adds the same check to tpacket_fill_skb(). It also
switches packet_sendmsg_spkt() from dev->header_ops to
dev_has_header(dev).
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index 0ea3036bee249..4ff7a2cc11e54 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
[ ... ]
> @@ -3125,8 +3127,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
> goto out_free;
> } else if (reserve) {
> skb_reserve(skb, -reserve);
> - if (len < reserve + sizeof(struct ipv6hdr) &&
> - dev->min_header_len != hard_header_len)
> + if (!dev_has_header(dev))
> skb_reset_network_header(skb);
> }
>
[Severity: High]
Can this leave skb->network_header past the tail of the skb on devices
that have header_ops->create? GRE with ipgre_header_ops is one example.
packet_snd() reads the header length once and uses it for reserve:
hard_header_len = READ_ONCE(dev->hard_header_len);
if (sock->type == SOCK_RAW)
reserve = hard_header_len;
The later short packet check reads the device field again:
if ((sock->type == SOCK_RAW &&
len < READ_ONCE(dev->hard_header_len)) || !skb->len) {
On GRE, hard_header_len can shrink at runtime under RTNL, and
packet_snd() does not hold RTNL:
net/ipv4/ip_gre.c:ipgre_link_update() {
...
if (dev->header_ops)
dev->hard_header_len += len;
else
dev->needed_headroom += len;
...
}
This runs from ipgre_changelink() and ipgre_tunnel_ctl() when the
okey/csum/seq flags are cleared.
Take a saved value of 28 (GRE with key) and a user len of 24. If the
device value changes to 24 between the two reads, the 24 < 24 check
passes. The skb then has len 24 with network_header at data + 28.
The window between the two reads includes packet_alloc_skb(), which can
block on sndbuf. It also includes skb_copy_datagram_from_iter(), which
can fault.
Before this patch, the old condition reset the network header in this
case, because GRE leaves min_header_len at 0:
if (len < reserve + sizeof(struct ipv6hdr) &&
dev->min_header_len != hard_header_len)
That is the same protection commit 993675a3100b ("packet: reset network
header if packet shorter than ll reserved space") added for the case
where "skb->mac_len may exceed skb->len".
Suppose a clsact egress filter with a mirred ingress action is installed
on the GRE device. The skb would then reach:
__dev_queue_xmit()
sch_handle_egress()
tcf_mirred_to_dev()
net/sched/act_mirred.c:tcf_mirred_to_dev() {
...
expects_nh = want_ingress || !m_mac_header_xmit;
at_nh = skb->data == skb_network_header(skb);
if (at_nh != expects_nh) {
mac_len = at_ingress ? skb->mac_len :
skb_network_offset(skb);
if (expects_nh) {
skb_pull_rcsum(skb_to_send, mac_len);
...
}
Here mac_len is 28 and the clone has len 24, so skb_pull_rcsum() hits:
BUG_ON(len > skb->len);
On other paths, dev_queue_xmit_nit() would log "protocol %04x is buggy"
for this skb, and ipgre_xmit() would drop it in pskb_inet_may_pull().
The trigger needs CAP_NET_RAW and CAP_NET_ADMIN. An unprivileged user
can get both in a user namespace with its own netns.
The final state of the series ("net: remove unused
net_device::min_header_len") seems to have the same code here, so no
later patch fixes it.
Could len be checked against the saved hard_header_len, the value used
for reserve and linear, instead of re-reading dev->hard_header_len?
Alternatively, could the network header still be reset when
len < reserve?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129163327.893403-1-willemb%40google.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH net-next v2 4/5] packet: use Ethernet header length in vlan_get_tci()
2026-11-29 16:30 ` [PATCH net-next v2 4/5] packet: use Ethernet header length in vlan_get_tci() Willem de Bruijn
@ 2026-11-30 17:36 ` netdev-bot+sashiko
0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 17:36 UTC (permalink / raw)
To: willemb; +Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, horms,
elder
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch fixes VLAN metadata that userspace sees, but the commit
has no Fixes: tag.
- [Low] The commit message says the is_vlan_dev() fallback in
vlan_get_tci() 'has been obsolete since commit 447cbe95ebb9'.
--
packet: use Ethernet header length in vlan_get_tci()
This commit makes vlan_get_tci() read the outer VLAN header at ETH_HLEN,
and only for ARPHRD_ETHER and ARPHRD_LOOPBACK devices. The helper now
returns whether a TCI was extracted. tpacket_rcv(), prb_fill_vlan_info()
and packet_recvmsg() only set the VLAN valid flags when it was, and
packet_recvmsg() no longer looks up the device under RCU.
> vlan_get_tci() uses dev->min_header_len to locate the outer 802.1Q/AD
> header on SOCK_DGRAM captures, with an is_vlan_dev() fallback that has
> been obsolete since commit 447cbe95ebb9 ("vlan: fix skb_under_panic and
> races when toggling HW VLAN offload") stopped adding VLAN_HLEN to
> vlandev->hard_header_len.
[Severity: Low]
Is the is_vlan_dev() fallback really obsolete since 447cbe95ebb9? A VLAN
device still inherits hard_header_len from its lower device:
net/8021q/vlan_dev.c:vlan_dev_init() {
...
dev->hard_header_len = real_dev->hard_header_len;
...
}
vlan_transfer_features() does the same thing:
vlandev->hard_header_len = dev->hard_header_len;
vlan_setup() calls ether_setup(), so min_header_len stays at ETH_HLEN.
Some lower Ethernet devices have a hard_header_len larger than ETH_HLEN.
smsc95xx is one:
drivers/net/usb/smsc95xx.c:smsc95xx_bind() {
...
dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
...
}
rndis_host is another. For a VLAN device on top of one of these,
min_header_len != hard_header_len, so the old vlan_get_tci() still took
the is_vlan_dev() branch to get header_len = ETH_HLEN.
The new code that reads at ETH_HLEN gives the right result either way,
so only the explanation is affected. Could the wording be changed so
backporters don't read it as a dependency on 447cbe95ebb9?
[ ... ]
> This changes the reported VLAN metadata in three cases:
>
> - Ethernet devices with hard_header_len != ETH_HLEN (e.g., smsc95xx,
> rndis_host) previously failed the min_header_len == hard_header_len
> test and reported TCI 0. They now report the actual TCI.
> - Non-Ethernet devices and frames without an extractable VLAN header
> previously still set TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID:
> headerless devices (e.g., tun, rmnet) matched 0 == 0 and read payload
> bytes at offset 0 as TCI, while other non-Ethernet devices and
> truncated frames reported TCI 0. They now omit VLAN metadata and flags.
> - packet_recvmsg() previously omitted the VLAN fields if the device
> had been unregistered since the packet was queued. It now fills
> them from the queued skb.
>
> Signed-off-by: Willem de Bruijn <willemb@google.com>
[Severity: Low]
The first two cases fix wrong VLAN metadata that userspace sees, so
should this have a Fixes: tag?
Two pieces of code come from 79eecf631c14. One is the min_header_len /
hard_header_len / is_vlan_dev() logic in vlan_get_tci(). The other is
the code in tpacket_rcv(), prb_fill_vlan_info() and packet_recvmsg() that
sets TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID whatever
vlan_get_tci() returns. The old return value of 0 could not be told apart
from a valid TCI of 0.
Fixes: 79eecf631c14 ("af_packet: Handle outgoing VLAN packets without hardware offloading")
Since that commit, a SOCK_DGRAM capture of software-tagged VLAN traffic on
smsc95xx reports TCI 0 with the valid flags set. Headerless devices report
payload bytes as the TCI, also with the valid flags set.
Without the tag, stable trees that carry 79eecf631c14 have nothing
pointing them at this fix. The subject "use Ethernet header length in
vlan_get_tci()" and the "removing the last min_header_len reader" framing
also read like a refactor rather than a fix for wrong output.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129163327.893403-1-willemb%40google.com
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-30 17:36 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 16:30 [PATCH net-next v2 0/5] net: remove dev_validate_header() and net_device::min_header_len Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 1/5] net: ipa: remove ethernet-specific artifacts from modem netdev setup Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 2/5] net: remove header_ops->validate and dev_validate_header() Willem de Bruijn
2026-11-30 17:36 ` netdev-bot+sashiko
2026-11-29 16:30 ` [PATCH net-next v2 3/5] packet: reset network header on all headerless devices Willem de Bruijn
2026-11-30 17:36 ` netdev-bot+sashiko
2026-11-29 16:30 ` [PATCH net-next v2 4/5] packet: use Ethernet header length in vlan_get_tci() Willem de Bruijn
2026-11-30 17:36 ` netdev-bot+sashiko
2026-11-29 16:30 ` [PATCH net-next v2 5/5] net: remove unused net_device::min_header_len Willem de Bruijn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox