{"id":2221787,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2221787/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/20260410112352.23599-12-fw@strlen.de/","project":{"id":26,"url":"http://patchwork.ozlabs.org/api/1.2/projects/26/?format=json","name":"Netfilter Development","link_name":"netfilter-devel","list_id":"netfilter-devel.vger.kernel.org","list_email":"netfilter-devel@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260410112352.23599-12-fw@strlen.de>","list_archive_url":null,"date":"2026-04-10T11:23:52","name":"[net-next,11/11] netfilter: require Ethernet MAC header before using eth_hdr()","commit_ref":null,"pull_url":null,"state":"handled-elsewhere","archived":true,"hash":"c6d360fd0e001cb42b986bbc5f7a2690f8cc49e2","submitter":{"id":1025,"url":"http://patchwork.ozlabs.org/api/1.2/people/1025/?format=json","name":"Florian Westphal","email":"fw@strlen.de"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/netfilter-devel/patch/20260410112352.23599-12-fw@strlen.de/mbox/","series":[{"id":499444,"url":"http://patchwork.ozlabs.org/api/1.2/series/499444/?format=json","web_url":"http://patchwork.ozlabs.org/project/netfilter-devel/list/?series=499444","date":"2026-04-10T11:23:46","name":"[net-next,01/11] ipvs: show the current conn_tab size to users","version":1,"mbox":"http://patchwork.ozlabs.org/series/499444/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2221787/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2221787/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <netfilter-devel+bounces-11807-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","netfilter-devel@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=netfilter-devel+bounces-11807-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=91.216.245.30","smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=strlen.de","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=Chamillionaire.breakpoint.cc"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fsZTd00Qvz1yGS\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 21:34:44 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id E6DAC3069554\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 11:24:50 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 769FB3ACA6F;\n\tFri, 10 Apr 2026 11:24:47 +0000 (UTC)","from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc\n [91.216.245.30])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B0EF39EF0E;\n\tFri, 10 Apr 2026 11:24:45 +0000 (UTC)","by Chamillionaire.breakpoint.cc (Postfix, from userid 1003)\n\tid D50CC60C9C; Fri, 10 Apr 2026 13:24:43 +0200 (CEST)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775820287; cv=none;\n b=VVYoye3wOoiBYZTRIvOsIbdgp8rh1JTDFxpu1OIDOE2XV4efaZtHlpFrk4/N6ukpiIYF6JdkdrLg0KvpTmSf0gtP0bT5Y3aTqaSC5QMBjZM7cbRfc39N3hmqMLR8p5sGWvYUFQaqylRGYnAOQqKnkeucLC72n4jggEwiFvzvRB4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775820287; c=relaxed/simple;\n\tbh=l8eqKPw4VBFkae+sqDnJAoR0w1YLMWEY7HtRpB6fItI=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=TuxHYTAiAgPO2JwNwqSP1XXeA5zMpesmifTixjGCAj/zD/cHh3iGaht28DCYs8IwXUJnBWL2Ncke7ySvureGi1atmpThrGVRStN6xoJMIXxL3abeE+qmv+iEsO7iJayV8RtJVCDbIDytSY64i/ZgixVcgpRLJkk/FayLr8pTRjA=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=strlen.de;\n spf=pass smtp.mailfrom=Chamillionaire.breakpoint.cc;\n arc=none smtp.client-ip=91.216.245.30","From":"Florian Westphal <fw@strlen.de>","To":"<netdev@vger.kernel.org>","Cc":"Paolo Abeni <pabeni@redhat.com>,\n\t\"David S. Miller\" <davem@davemloft.net>,\n\tEric Dumazet <edumazet@google.com>,\n\tJakub Kicinski <kuba@kernel.org>,\n\t<netfilter-devel@vger.kernel.org>,\n\tpablo@netfilter.org","Subject":"[PATCH net-next 11/11] netfilter: require Ethernet MAC header before\n using eth_hdr()","Date":"Fri, 10 Apr 2026 13:23:52 +0200","Message-ID":"<20260410112352.23599-12-fw@strlen.de>","X-Mailer":"git-send-email 2.52.0","In-Reply-To":"<20260410112352.23599-1-fw@strlen.de>","References":"<20260410112352.23599-1-fw@strlen.de>","Precedence":"bulk","X-Mailing-List":"netfilter-devel@vger.kernel.org","List-Id":"<netfilter-devel.vger.kernel.org>","List-Subscribe":"<mailto:netfilter-devel+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:netfilter-devel+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"From: Zhengchuan Liang <zcliangcn@gmail.com>\n\n`ip6t_eui64`, `xt_mac`, the `bitmap:ip,mac`, `hash:ip,mac`, and\n`hash:mac` ipset types, and `nf_log_syslog` access `eth_hdr(skb)`\nafter either assuming that the skb is associated with an Ethernet\ndevice or checking only that the `ETH_HLEN` bytes at\n`skb_mac_header(skb)` lie between `skb->head` and `skb->data`.\n\nMake these paths first verify that the skb is associated with an\nEthernet device, that the MAC header was set, and that it spans at\nleast a full Ethernet header before accessing `eth_hdr(skb)`.\n\nSuggested-by: Florian Westphal <fw@strlen.de>\nTested-by: Ren Wei <enjou1224z@gmail.com>\nSigned-off-by: Zhengchuan Liang <zcliangcn@gmail.com>\nSigned-off-by: Ren Wei <n05ec@lzu.edu.cn>\nSigned-off-by: Florian Westphal <fw@strlen.de>\n---\n net/ipv6/netfilter/ip6t_eui64.c           | 7 +++++--\n net/netfilter/ipset/ip_set_bitmap_ipmac.c | 5 +++--\n net/netfilter/ipset/ip_set_hash_ipmac.c   | 9 +++++----\n net/netfilter/ipset/ip_set_hash_mac.c     | 5 +++--\n net/netfilter/nf_log_syslog.c             | 8 +++++++-\n net/netfilter/xt_mac.c                    | 4 +---\n 6 files changed, 24 insertions(+), 14 deletions(-)","diff":"diff --git a/net/ipv6/netfilter/ip6t_eui64.c b/net/ipv6/netfilter/ip6t_eui64.c\nindex da69a27e8332..bbb684f9964c 100644\n--- a/net/ipv6/netfilter/ip6t_eui64.c\n+++ b/net/ipv6/netfilter/ip6t_eui64.c\n@@ -7,6 +7,7 @@\n #include <linux/module.h>\n #include <linux/skbuff.h>\n #include <linux/ipv6.h>\n+#include <linux/if_arp.h>\n #include <linux/if_ether.h>\n \n #include <linux/netfilter/x_tables.h>\n@@ -21,8 +22,10 @@ eui64_mt6(const struct sk_buff *skb, struct xt_action_param *par)\n {\n \tunsigned char eui64[8];\n \n-\tif (!(skb_mac_header(skb) >= skb->head &&\n-\t      skb_mac_header(skb) + ETH_HLEN <= skb->data)) {\n+\tif (!skb->dev || skb->dev->type != ARPHRD_ETHER)\n+\t\treturn false;\n+\n+\tif (!skb_mac_header_was_set(skb) || skb_mac_header_len(skb) < ETH_HLEN) {\n \t\tpar->hotdrop = true;\n \t\treturn false;\n \t}\ndiff --git a/net/netfilter/ipset/ip_set_bitmap_ipmac.c b/net/netfilter/ipset/ip_set_bitmap_ipmac.c\nindex 2c625e0f49ec..752f59ef8744 100644\n--- a/net/netfilter/ipset/ip_set_bitmap_ipmac.c\n+++ b/net/netfilter/ipset/ip_set_bitmap_ipmac.c\n@@ -11,6 +11,7 @@\n #include <linux/etherdevice.h>\n #include <linux/skbuff.h>\n #include <linux/errno.h>\n+#include <linux/if_arp.h>\n #include <linux/if_ether.h>\n #include <linux/netlink.h>\n #include <linux/jiffies.h>\n@@ -220,8 +221,8 @@ bitmap_ipmac_kadt(struct ip_set *set, const struct sk_buff *skb,\n \t\treturn -IPSET_ERR_BITMAP_RANGE;\n \n \t/* Backward compatibility: we don't check the second flag */\n-\tif (skb_mac_header(skb) < skb->head ||\n-\t    (skb_mac_header(skb) + ETH_HLEN) > skb->data)\n+\tif (!skb->dev || skb->dev->type != ARPHRD_ETHER ||\n+\t    !skb_mac_header_was_set(skb) || skb_mac_header_len(skb) < ETH_HLEN)\n \t\treturn -EINVAL;\n \n \te.id = ip_to_id(map, ip);\ndiff --git a/net/netfilter/ipset/ip_set_hash_ipmac.c b/net/netfilter/ipset/ip_set_hash_ipmac.c\nindex 467c59a83c0a..b9a2681e2488 100644\n--- a/net/netfilter/ipset/ip_set_hash_ipmac.c\n+++ b/net/netfilter/ipset/ip_set_hash_ipmac.c\n@@ -11,6 +11,7 @@\n #include <linux/skbuff.h>\n #include <linux/errno.h>\n #include <linux/random.h>\n+#include <linux/if_arp.h>\n #include <linux/if_ether.h>\n #include <net/ip.h>\n #include <net/ipv6.h>\n@@ -89,8 +90,8 @@ hash_ipmac4_kadt(struct ip_set *set, const struct sk_buff *skb,\n \tstruct hash_ipmac4_elem e = { .ip = 0, { .foo[0] = 0, .foo[1] = 0 } };\n \tstruct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);\n \n-\tif (skb_mac_header(skb) < skb->head ||\n-\t    (skb_mac_header(skb) + ETH_HLEN) > skb->data)\n+\tif (!skb->dev || skb->dev->type != ARPHRD_ETHER ||\n+\t    !skb_mac_header_was_set(skb) || skb_mac_header_len(skb) < ETH_HLEN)\n \t\treturn -EINVAL;\n \n \tif (opt->flags & IPSET_DIM_TWO_SRC)\n@@ -205,8 +206,8 @@ hash_ipmac6_kadt(struct ip_set *set, const struct sk_buff *skb,\n \t};\n \tstruct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);\n \n-\tif (skb_mac_header(skb) < skb->head ||\n-\t    (skb_mac_header(skb) + ETH_HLEN) > skb->data)\n+\tif (!skb->dev || skb->dev->type != ARPHRD_ETHER ||\n+\t    !skb_mac_header_was_set(skb) || skb_mac_header_len(skb) < ETH_HLEN)\n \t\treturn -EINVAL;\n \n \tif (opt->flags & IPSET_DIM_TWO_SRC)\ndiff --git a/net/netfilter/ipset/ip_set_hash_mac.c b/net/netfilter/ipset/ip_set_hash_mac.c\nindex 718814730acf..41a122591fe2 100644\n--- a/net/netfilter/ipset/ip_set_hash_mac.c\n+++ b/net/netfilter/ipset/ip_set_hash_mac.c\n@@ -8,6 +8,7 @@\n #include <linux/etherdevice.h>\n #include <linux/skbuff.h>\n #include <linux/errno.h>\n+#include <linux/if_arp.h>\n #include <linux/if_ether.h>\n #include <net/netlink.h>\n \n@@ -77,8 +78,8 @@ hash_mac4_kadt(struct ip_set *set, const struct sk_buff *skb,\n \tstruct hash_mac4_elem e = { { .foo[0] = 0, .foo[1] = 0 } };\n \tstruct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);\n \n-\tif (skb_mac_header(skb) < skb->head ||\n-\t    (skb_mac_header(skb) + ETH_HLEN) > skb->data)\n+\tif (!skb->dev || skb->dev->type != ARPHRD_ETHER ||\n+\t    !skb_mac_header_was_set(skb) || skb_mac_header_len(skb) < ETH_HLEN)\n \t\treturn -EINVAL;\n \n \tif (opt->flags & IPSET_DIM_ONE_SRC)\ndiff --git a/net/netfilter/nf_log_syslog.c b/net/netfilter/nf_log_syslog.c\nindex 0507d67cad27..7a8952b049d1 100644\n--- a/net/netfilter/nf_log_syslog.c\n+++ b/net/netfilter/nf_log_syslog.c\n@@ -78,7 +78,10 @@ dump_arp_packet(struct nf_log_buf *m,\n \telse\n \t\tlogflags = NF_LOG_DEFAULT_MASK;\n \n-\tif (logflags & NF_LOG_MACDECODE) {\n+\tif ((logflags & NF_LOG_MACDECODE) &&\n+\t    skb->dev && skb->dev->type == ARPHRD_ETHER &&\n+\t    skb_mac_header_was_set(skb) &&\n+\t    skb_mac_header_len(skb) >= ETH_HLEN) {\n \t\tnf_log_buf_add(m, \"MACSRC=%pM MACDST=%pM \",\n \t\t\t       eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest);\n \t\tnf_log_dump_vlan(m, skb);\n@@ -797,6 +800,9 @@ static void dump_mac_header(struct nf_log_buf *m,\n \n \tswitch (dev->type) {\n \tcase ARPHRD_ETHER:\n+\t\tif (!skb_mac_header_was_set(skb) || skb_mac_header_len(skb) < ETH_HLEN)\n+\t\t\treturn;\n+\n \t\tnf_log_buf_add(m, \"MACSRC=%pM MACDST=%pM \",\n \t\t\t       eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest);\n \t\tnf_log_dump_vlan(m, skb);\ndiff --git a/net/netfilter/xt_mac.c b/net/netfilter/xt_mac.c\nindex 81649da57ba5..4798cd2ca26e 100644\n--- a/net/netfilter/xt_mac.c\n+++ b/net/netfilter/xt_mac.c\n@@ -29,9 +29,7 @@ static bool mac_mt(const struct sk_buff *skb, struct xt_action_param *par)\n \n \tif (skb->dev == NULL || skb->dev->type != ARPHRD_ETHER)\n \t\treturn false;\n-\tif (skb_mac_header(skb) < skb->head)\n-\t\treturn false;\n-\tif (skb_mac_header(skb) + ETH_HLEN > skb->data)\n+\tif (!skb_mac_header_was_set(skb) || skb_mac_header_len(skb) < ETH_HLEN)\n \t\treturn false;\n \tret  = ether_addr_equal(eth_hdr(skb)->h_source, info->srcaddr);\n \tret ^= info->invert;\n","prefixes":["net-next","11/11"]}