FAILED: patch "[PATCH] netfilter: nf_reject: initialize IPCB at inet ingress" failed to apply to 5.15-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 73a73d442f9986353fe284bd1b504d0313d0f153
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 73a73d442f9986353fe284bd1b504d0313d0f153 Mon Sep 17 00:00:00 2001
From: Kyle Zeng <[email protected]>
Date: Wed, 7 Oct 2026 23:01:00 +0200
Subject: [PATCH] netfilter: nf_reject: initialize IPCB at inet ingress
The inet ingress hook runs before ip_rcv_core() and ip6_rcv_core(), so neither IPCB nor IP6CB has been initialized when nft_reject_inet passes a packet to nf_send_unreach() or nf_send_unreach6(). skb->cb can therefore retain metadata from an earlier protocol layer.
For IPv4, icmp_send() treats IPCB(skb)->opt as parsed IPv4 options. Stale option offsets can make __ip_options_echo() copy an attacker-controlled length into its 40-byte reply option buffer and overflow the stack. On an unpatched v7.2-rc5 kernel, the IPv4 reproducer produced:
BUG: KASAN: stack-out-of-bounds in __ip_options_echo() Write of size 255
For IPv6, icmpv6_send() consumes IP6CB(skb) as parsed IPv6 metadata. It always uses iif for source selection and, when MIP6 is enabled, uses dsthao as an extension-header offset. These fields must not be stale.
For NF_INET_INGRESS, clear the address-family-specific control block and restore its input interface before constructing the ICMP error. This matches similar initialization normally performed by ip_rcv_core() and ip6_rcv_core().
--- net/ipv4/netfilter/nf_reject_ipv4.c | 5 +++++ net/ipv6/netfilter/nf_reject_ipv6.c | 5 +++++ 2 files changed, 10 insertions(+)
net/ipv4/netfilter/nf_reject_ipv4.c +5 -0
@@ -357,6 +357,11 @@ void nf_send_unreach(struct sk_buff *skb_in, int code, int hook)if (!skb_valid_dst (skb_in) &&nf_reject_fill_skb_dst (skb_in) <0 )return ; +if (hook ==NF_INET_INGRESS ) { +memset (IPCB (skb_in),0 ,sizeof (*IPCB (skb_in))); +IPCB (skb_in)->iif = skb_in->skb_iif; + } +if (skb_csum_unnecessary (skb_in) || !nf_reject_verify_csum (skb_in, dataoff, proto)) {icmp_send (skb_in,ICMP_DEST_UNREACH , code,0 );
net/ipv6/netfilter/nf_reject_ipv6.c +5 -0
@@ -444,6 +444,11 @@ void nf_send_unreach6(struct net *net, struct sk_buff *skb_in,if (hooknum ==NF_INET_LOCAL_OUT && skb_in->dev ==NULL ) skb_in->dev = net->loopback_dev; +if (hooknum ==NF_INET_INGRESS ) { +memset (IP6CB (skb_in),0 ,sizeof (*IP6CB (skb_in))); +IP6CB (skb_in)->iif = skb_in->skb_iif; + } +if (!skb_valid_dst (skb_in) &&nf_reject6_fill_skb_dst (skb_in) <0 )return ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 netfilter: conntrack: skip verification of zero UDP checksum
From: Kevin Mitchell <[email protected]>
[ Upstream commit 4f9bd53084d18c2f9f1ec68fa56587b99a2cef00 ]
The checksum is optional for UDP packets. However nf_reject would previously require a valid checksum to elicit a response such as ICMP_DEST_UNREACH.
Add some logic to nf_reject_verify_csum to determine if a UDP packet has a zero checksum and should therefore not be verified.
Stable-dep-of: 73a73d442f99 ("netfilter: nf_reject: initialize IPCB at inet ingress")
--- include/net/netfilter/nf_reject.h | 21 +++++++++++++++++---- net/ipv4/netfilter/nf_reject_ipv4.c | 10 +++++++--- net/ipv6/netfilter/nf_reject_ipv6.c | 4 ++-- 3 files changed, 26 insertions(+), 9 deletions(-)
include/net/netfilter/nf_reject.h +17 -4
@@ -5,12 +5,28 @@#include <linux/types.h> #include <uapi/linux/in.h> -static inline bool nf_reject_verify_csum (__u8 proto) +static inline bool nf_reject_verify_csum (struct sk_buff *skb,int dataoff, +__u8 proto) {/* Skip protocols that don't use 16-bit one's complement checksum * of the entire payload. */ switch (proto) { +/* Protocols with optional checksums. */ +case IPPROTO_UDP : { +const struct udphdr *udp_hdr; +struct udphdr _udp_hdr; + + udp_hdr =skb_header_pointer (skb, dataoff, +sizeof (_udp_hdr), + &_udp_hdr); +if (!udp_hdr || udp_hdr->check) +return true; + +return false; + } +case IPPROTO_GRE : +/* Protocols with other integrity checks. */ case IPPROTO_AH :case IPPROTO_ESP :
@@ -19,9 +35,6 @@ static inline bool nf_reject_verify_csum(__u8 proto)/* Protocols with partial checksums. */ case IPPROTO_UDPLITE :case IPPROTO_DCCP : - -/* Protocols with optional checksums. */ -case IPPROTO_GRE :return false; }return true;
net/ipv4/netfilter/nf_reject_ipv4.c +7 -3
@@ -102,6 +102,7 @@ struct sk_buff *nf_reject_skb_v4_unreach(struct net *net,struct iphdr *niph;struct icmphdr *icmph;unsigned int len; +int dataoff;__wsum csum;u8 proto;
@@ -125,10 +126,11 @@ struct sk_buff *nf_reject_skb_v4_unreach(struct net *net,if (pskb_trim_rcsum (oldskb,ntohs (ip_hdr (oldskb)->tot_len)))return NULL ; + dataoff =ip_hdrlen (oldskb); proto =ip_hdr (oldskb)->protocol;if (!skb_csum_unnecessary (oldskb) && -nf_reject_verify_csum (proto) && +nf_reject_verify_csum (oldskb, dataoff, proto) &&nf_ip_checksum (oldskb, hook,ip_hdrlen (oldskb), proto))return NULL ;
@@ -338,6 +340,7 @@ EXPORT_SYMBOL_GPL(nf_send_reset);void nf_send_unreach (struct sk_buff *skb_in,int code,int hook) {struct iphdr *iph =ip_hdr (skb_in); +int dataoff =ip_hdrlen (skb_in);u8 proto = iph->protocol;if (iph->frag_off &htons (IP_OFFSET ))
@@ -346,12 +349,13 @@ void nf_send_unreach(struct sk_buff *skb_in, int code, int hook)if (!skb_valid_dst (skb_in) &&nf_reject_fill_skb_dst (skb_in) <0 )return ; -if (skb_csum_unnecessary (skb_in) || !nf_reject_verify_csum (proto)) { +if (skb_csum_unnecessary (skb_in) || + !nf_reject_verify_csum (skb_in, dataoff, proto)) {icmp_send (skb_in,ICMP_DEST_UNREACH , code,0 );return ; } -if (nf_ip_checksum (skb_in, hook,ip_hdrlen (skb_in), proto) ==0 ) +if (nf_ip_checksum (skb_in, hook, dataoff, proto) ==0 )icmp_send (skb_in,ICMP_DEST_UNREACH , code,0 ); }EXPORT_SYMBOL_GPL (nf_send_unreach);
net/ipv6/netfilter/nf_reject_ipv6.c +2 -2
@@ -32,7 +32,7 @@ static bool nf_reject_v6_csum_ok(struct sk_buff *skb, int hook)if (thoff <0 || thoff >= skb->len || (fo &htons (~0x7 )) !=0 )return false; -if (!nf_reject_verify_csum (proto)) +if (!nf_reject_verify_csum (skb, thoff, proto))return true;return nf_ip6_checksum (skb, hook, thoff, proto) ==0 ;
@@ -413,7 +413,7 @@ static bool reject6_csum_ok(struct sk_buff *skb, int hook)if (thoff <0 || thoff >= skb->len || (fo &htons (~0x7 )) !=0 )return false; -if (!nf_reject_verify_csum (proto)) +if (!nf_reject_verify_csum (skb, thoff, proto))return true;return nf_ip6_checksum (skb, hook, thoff, proto) ==0 ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 netfilter: nf_reject: initialize IPCB at inet ingress
From: Kyle Zeng <[email protected]>
[ Upstream commit 73a73d442f9986353fe284bd1b504d0313d0f153 ]
The inet ingress hook runs before ip_rcv_core() and ip6_rcv_core(), so neither IPCB nor IP6CB has been initialized when nft_reject_inet passes a packet to nf_send_unreach() or nf_send_unreach6(). skb->cb can therefore retain metadata from an earlier protocol layer.
For IPv4, icmp_send() treats IPCB(skb)->opt as parsed IPv4 options. Stale option offsets can make __ip_options_echo() copy an attacker-controlled length into its 40-byte reply option buffer and overflow the stack. On an unpatched v7.2-rc5 kernel, the IPv4 reproducer produced:
BUG: KASAN: stack-out-of-bounds in __ip_options_echo() Write of size 255
For IPv6, icmpv6_send() consumes IP6CB(skb) as parsed IPv6 metadata. It always uses iif for source selection and, when MIP6 is enabled, uses dsthao as an extension-header offset. These fields must not be stale.
For NF_INET_INGRESS, clear the address-family-specific control block and restore its input interface before constructing the ICMP error. This matches similar initialization normally performed by ip_rcv_core() and ip6_rcv_core().
--- net/ipv4/netfilter/nf_reject_ipv4.c | 5 +++++ net/ipv6/netfilter/nf_reject_ipv6.c | 5 +++++ 2 files changed, 10 insertions(+)
net/ipv4/netfilter/nf_reject_ipv4.c +5 -0
@@ -349,6 +349,11 @@ void nf_send_unreach(struct sk_buff *skb_in, int code, int hook)if (!skb_valid_dst (skb_in) &&nf_reject_fill_skb_dst (skb_in) <0 )return ; +if (hook ==NF_INET_INGRESS ) { +memset (IPCB (skb_in),0 ,sizeof (*IPCB (skb_in))); +IPCB (skb_in)->iif = skb_in->skb_iif; + } +if (skb_csum_unnecessary (skb_in) || !nf_reject_verify_csum (skb_in, dataoff, proto)) {icmp_send (skb_in,ICMP_DEST_UNREACH , code,0 );
net/ipv6/netfilter/nf_reject_ipv6.c +5 -0
@@ -428,6 +428,11 @@ void nf_send_unreach6(struct net *net, struct sk_buff *skb_in,if (hooknum ==NF_INET_LOCAL_OUT && skb_in->dev ==NULL ) skb_in->dev = net->loopback_dev; +if (hooknum ==NF_INET_INGRESS ) { +memset (IP6CB (skb_in),0 ,sizeof (*IP6CB (skb_in))); +IP6CB (skb_in)->iif = skb_in->skb_iif; + } +if (!skb_valid_dst (skb_in) &&nf_reject6_fill_skb_dst (skb_in) <0 )return ;
Signature · 1 line
2.53.0