Article View: linux.kernel.netdev
Article #21843[PATCH net v3] net: xdp: fix generic XDP on skbs without an Ethernet header
From: Jiayuan Chen
Date: Tue, 24 Nov 2026 14:25
Date: Tue, 24 Nov 2026 14:25
96 lines
12489 bytes
12489 bytes
Kenneth Lee reported a bug [1]:
skb_vlan_push got skb with skb->data not at mac header (offset 14)
WARNING: net/core/skbuff.c:6474 at skb_vlan_push+0x5ec/0x8a0
____bpf_skb_vlan_push net/core/filter.c:3239 [inline]
bpf_skb_vlan_push+0x216/0x8b0 net/core/filter.c:3229
bpf_prog_run_data_pointers+0x17c/0x240 include/linux/filter.h:917
tcf_bpf_act+0x31c/0x940 net/sched/act_bpf.c:50
tcf_action_exec+0x2c1/0x720 net/sched/act_api.c:1147
tcf_classify+0x6e4/0x1080 net/sched/cls_api.c:1860
tc_run+0x31c/0x5d0 net/core/dev.c:4411
sch_handle_ingress net/core/dev.c:4486 [inline]
__netif_receive_skb_core+0x141b/0x2ec0 net/core/dev.c:6054
bpf_prog_run_generic_xdp() reads xdp->data as an Ethernet header. On an
L3 device like sit0 there is none, so the "did the program change the
header" check compares garbage, and the fixup:
__skb_push(skb, ETH_HLEN);
skb->pkt_type = PACKET_HOST;
skb->protocol = eth_type_trans(skb, skb->dev);
leaves mac_len == 0 with skb_mac_header(skb) == skb->data - ETH_HLEN.
tc ingress then can't get skb->data back onto the mac header.
XDP is Ethernet only, so refuse to attach a generic XDP program to a
device that is not ARPHRD_ETHER.
The one exception is lo. Its type is ARPHRD_LOOPBACK, but it uses
eth_header_ops and eth_type_trans() like any Ethernet device, so its
skbs do carry an Ethernet header. Generic XDP on lo works today and the
BPF selftests rely on it (xdp_attach, xdp_devmap_attach, check_mtu,
...), so keep allowing it.
Rejecting the attach is not enough on its own, dev->type can change
after the program is attached. An empty bond or team takes the type of
its first port, and TUNSETLINK lets a tun device change its type.
dev->hard_header_len is no help either, it is what the driver wants
reserved on TX and many Ethernet drivers make it larger than ETH_HLEN.
So also skip the program for skbs that have no ETH_HLEN sized mac
header.
[1]: https://lore.kernel.org/bpf/20260812043643.808295-1-kennethbwlee@snu.ac.kr/
Fixes: 297249569932 ("net: fix generic XDP to handle if eth header was mangled")
Reported-by: Kenneth Lee <kennethbwlee@snu.ac.kr>
Closes: https://lore.kernel.org/bpf/20260812043643.808295-1-kennethbwlee@snu.ac.kr/
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
v2 -> v3:
- Only handle skbs with an ETH_HLEN mac header in generic XDP. This
also skips VLAN devices with reorder_hdr off.
v1 -> v2:
- Generic XDP does not support L3 devices, as discussed on v1. Reject
the attach and skip skbs without an Ethernet header, instead of
running the program on them.
- Target net instead of net-next.
v2: https://lore.kernel.org/netdev/20261123121540.275576-1-jiayuan.chen@linux.dev/
v1: https://lore.kernel.org/netdev/20260813113229.381136-1-jiayuan.chen@linux.dev/
---
net/core/dev.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/net/core/dev.c b/net/core/dev.c
index 1a63f6b939f7..4a4e030d93b6 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5844,6 +5844,10 @@ static u32 netif_receive_generic_xdp(struct sk_buff **pskb,
if (skb_is_redirected(skb))
return XDP_PASS;
+ /* XDP is Ethernet only, skip skbs without an Ethernet header. */
+ if (skb->data - skb_mac_header(skb) != ETH_HLEN)
+ return XDP_PASS;
+
/* XDP packets must have sufficient headroom of XDP_PACKET_HEADROOM
* bytes. This is the guarantee that also native XDP provides,
* thus we need to do it here as well.
@@ -10869,6 +10873,12 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack
NL_SET_ERR_MSG(extack, "XDP program already attached");
return -EBUSY;
}
+ /* lo is ARPHRD_LOOPBACK but uses Ethernet framing. */
+ if (mode == XDP_MODE_SKB && dev->type != ARPHRD_ETHER &&
+ dev->type != ARPHRD_LOOPBACK) {
+ NL_SET_ERR_MSG(extack, "Generic XDP only supports Ethernet devices");
+ return -EOPNOTSUPP;
+ }
}
/* don't call drivers if the effective program didn't change */
--
2.43.0
Technical Details
Message-ID:
<20261124142545.221584-1-jiayuan.chen@linux.dev>Path:
mbox-mo1.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370436-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370436-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: [PATCH net v3] net: xdp: fix generic XDP on skbs without an Ethernet header Date: Tue, 24 Nov 2026 22:25:39 +0800 Organization: Usenet Network Message-ID: <20261124142545.221584-1-jiayuan.chen@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="4156399"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:b5yu08e/Sg0n7nHM6KmjOp9/+5Y= sha256:DY0WTvUN+zKsKTmwDuxgUtpa/joFbYA3eOS8Dm7UWW0= sha1:RtEwxOktrhubbGExGblt7xlCoSg= sha256:r2Uygio0tnSeaIYJ6aomr/bwXKlYS7Z806edLJCf9Ts= 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 8731E125E1A; Tue, 24 Nov 2026 17:26:15 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.05 X-Spam-Status: No, score=-2.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, HK_RANDOM_FROM=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 (1024-bit key) header.d=linux.dev 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 PXPEoJlvFHaF; Tue, 24 Nov 2026 17:26:11 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-370436-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 73FD6125E18; Tue, 24 Nov 2026 17:26:02 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 42165273CA; Tue, 24 Nov 2026 14:26:00 +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=1795530359; b=4QWmY1rnbT6ryeyaEulEtZXtTzvM4aA+zu2dOk37S2OBAvieHwi6nSEuXZyOTHeyzerJ 2VwMAyD5fb16gOqCwnpt8KTHD+DQr9q3wMzbX9s9KFeVNImkT2wPlJs0ROe2ycA9+7FoU //7wFMwhvaLE0X7M260OFqodbmmiGleeNHEKADhIiaoiGmihJ4L6IHCHJWXggByx9vLQT E28cnU3uJCZUa+Rdb8J6ElCvKKpVoLrnlSNk/YnI7TWfobnFimg8wyRNRSrQEOSMNrNbU 9xe36T6cOI3l/KucaK3+b6o4H/UdjOX6kpyQhuzo19p7P6CLMi68v6DzsFARBYKvnvg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795530359; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc: Subject:Date:Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Transfer-Encoding; bh=h2pLve9CfbYUk4h9BNGefRcEfHbuM+avbXOhKVZvFdU=; b=bcXIWyIGn2UuTY20ON3RJxcmgoDhG7Bnc4k/m7GAJy0Zvxi6bU2QE62fjMW1kxnGKtbN KrlibW9vuIiIoCwr22z3IBEYbOKOMHlWEByVnRxAgp88lpty29jLfs/GPmOeIPur2TWN1 Jdseoop9qlApIbQ3galHfIKqgOZ1cs69JM4B6OS7LSNx1eLR11AbMKPI1u8hZZ1BaBr73 pmMVwXWLFzvEGgdlks+m6GdpSH2ppeYDoh8pk5EWqomvQsVoqjQQbFHZOFh9qdrqQmLV5 vGT5llAZSTUj+tzEzQeczWXF3rM9Ht9EbDO5jQnSZymlSZbIbdSeaCw/eIF3gBKa4cg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=oWj94Es+; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; 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 AA887606A336; Tue, 24 Nov 2026 14:25:59 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=oWj94Es+ X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.195 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795530358; b=XOGtOQZQguhQ/seQGANjIc+Sib5A9pVUpqfHzeTL0y9qwlqEctpaq7U7Plpvbt2G5yi9 AkxJGCe81wNDaWG1rvu6MyDYuxpYDTs35ajvjRZslccnGlwijKMS/Vnddh3pL2vCp+5c/ J/UlOPjIcF57PcAcIkVQmF/o/sfRFR4N92HlyI1p5nkhayIlcT7bKSqNSgl7lrC9p/MC4 TNlSySBBfDWxDjUDWEs27IgAKts65zk4ZJoD/K+T1wNwC60zItpUD+ncGWt7Z7fhROAlc sPbg8gOac59dxYXPvHVN2vE3bQnjaGS8hmcsh9l0Ppy8WJQ0dOtpW3CGituWn51jfiw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795530358; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=h2pLve9CfbYUk4h9BNGefRcEfHbuM+avbXOhKVZvFdU=; b=ce7exwkguv3RTENpMA68ElEEAtYkbEfkezxoUqS8OoX5jv4plsh4E1DVPJMCQM2rf8kS wNhDY29jDikXpjioiN5FufE9ZfNIyU7WYizlP1mQVCPVTdutLtIeTvFaVauy1Ql/fxSTJ m8JMMADJJLgQsawpA3A5ydC3EIPxY1ZhW8H8K00V7vfCEz0nwMislhhQ06UQDYQWI1JXg xkCBrvwAX8NJZct1xBMW/cos6FsVud93QDBGoB00zv/g9/PaM+DRKn6SCuBRXFezmFacl fCDW3DZin9XecFwGFV8hITsdKg+isS2L0oscyT4Sb/HgzCukAdxZnPPgoxrF5Pr/M8w== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=oWj94Es+; arc=none smtp.remote-ip=95.215.58.195 X-Received: from mta1.migadu.com (out-195.mta1.migadu.com [95.215.58.195]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B016C606A321 for <netdev@vger.kernel.org>; Tue, 24 Nov 2026 14:25:57 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B016C606A321 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=wtciEf4k1Kp/fzHfdEXxKaqAhqAQ0xFfSaOuMZuKKiQ=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1795530355; v=1; x=1796135155; b=oWj94Es+UZrjTPx0iYjnwSS2OgB3YOINseLV7PztbqWHNGsyighPuCIStvofjcSny1+YmqkA 4I2KFQVfQvg9wzwDV8edtaerxiyEWLkAJo0ubnWi9kWf6aeCKq3mxCdygkH1LERwb3uPRGHyt8Y UbKgC7jAAyQA82xeIvr7FiKg= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 55d229cec49dac67; Tue, 24 Nov 2026 14:25:55 +0000 X-Mizu-Trace-ID: 55d229cec49dac67 X-Migadu-Flow: FLOW_OUT X-Cc: Jiayuan Chen <jiayuan.chen@linux.dev>, Kenneth Lee <kennethbwlee@snu.ac.kr>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Jesper Dangaard Brouer <hawk@kernel.org>, John Fastabend <john.fastabend@gmail.com>, Stanislav Fomichev <sdf@fomichev.me>, Kuniyuki Iwashima <kuniyu@google.com>, Wang Zhan <wang.zhan@smartx.com>, Martin Karsten <mkarsten@uwaterloo.ca>, bpf@vger.kernel.org X-Mailer: git-send-email 2.43.0 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