From: Mazin Al Haddad <mazin@getstate.dev>
To: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Mazin Al Haddad <mazin@getstate.dev>,
syzbot+6023ea32e206eef7920a@syzkaller.appspotmail.com
Subject: [PATCH] ip6_tunnel: Fix uninit-value in ip6_tnl_xmit
Date: Tue, 17 Dec 2024 06:07:51 +0300 [thread overview]
Message-ID: <20241217030751.11226-1-mazin@getstate.dev> (raw)
When taking the branch with skb_realloc_headroom, pskb_expand_head is
called, as such, pointers referencing content within the new skb's header
are invalid. Currently, the assignment of hop_limit accesses the now
invalid pointer in the network header of this "new" skb. Fix this by
moving the logic to assign hop_limit earlier so that the assignment
references the original un-resized skb instead.
uninit-value in ip6table_mangle_hook+0x97d/0x9c0 net/ipv6/netfilter/ip6table_mangle.c:72
ip6t_mangle_out net/ipv6/netfilter/ip6table_mangle.c:56 [inline]
ip6table_mangle_hook+0x97d/0x9c0 net/ipv6/netfilter/ip6table_mangle.c:72
nf_hook_entry_hookfn include/linux/netfilter.h:154 [inline]
nf_hook_slow+0xf4/0x400 net/netfilter/core.c:626
nf_hook include/linux/netfilter.h:269 [inline]
__ip6_local_out+0x5ac/0x640 net/ipv6/output_core.c:143
ip6_local_out+0x4c/0x210 net/ipv6/output_core.c:153
ip6tunnel_xmit+0x129/0x460 include/net/ip6_tunnel.h:161
ip6_tnl_xmit+0x341a/0x3860 net/ipv6/ip6_tunnel.c:1281
Uninit was stored to memory at:
ip6_tnl_xmit+0x34f7/0x3860 net/ipv6/ip6_tunnel.c:1277
__gre6_xmit+0x14b9/0x1550 net/ipv6/ip6_gre.c:815
ip6gre_xmit_ipv4 net/ipv6/ip6_gre.c:839 [inline]
ip6gre_tunnel_xmit+0x18f7/0x2030 net/ipv6/ip6_gre.c:922
Uninit was created at:
slab_post_alloc_hook mm/slub.c:4091 [inline]
slab_alloc_node mm/slub.c:4134 [inline]
__do_kmalloc_node mm/slub.c:4263 [inline]
__kmalloc_node_track_caller_noprof+0x6c7/0xf90 mm/slub.c:4283
kmalloc_reserve+0x23e/0x4a0 net/core/skbuff.c:609
pskb_expand_head+0x226/0x1a60 net/core/skbuff.c:2275
skb_realloc_headroom+0x140/0x2b0 net/core/skbuff.c:2355
ip6_tnl_xmit+0x2106/0x3860 net/ipv6/ip6_tunnel.c:1227
__gre6_xmit+0x14b9/0x1550 net/ipv6/ip6_gre.c:815
ip6gre_xmit_ipv4 net/ipv6/ip6_gre.c:839 [inline]
ip6gre_tunnel_xmit+0x18f7/0x2030 net/ipv6/ip6_gre.c:922
Reported-by: syzbot+6023ea32e206eef7920a@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6023ea32e206eef7920a
Signed-off-by: Mazin Al Haddad <mazin@getstate.dev>
---
net/ipv6/ip6_tunnel.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 48fd53b98972..62a51f03360d 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1098,7 +1098,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
unsigned int max_headroom = psh_hlen;
__be16 payload_protocol;
bool use_cache = false;
- u8 hop_limit;
+ u8 hop_limit = 0;
int err = -1;
payload_protocol = skb_protocol(skb, true);
@@ -1215,6 +1215,15 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
skb_scrub_packet(skb, !net_eq(t->net, dev_net(dev)));
+ if (hop_limit == 0) {
+ if (payload_protocol == htons(ETH_P_IP))
+ hop_limit = ip_hdr(skb)->ttl;
+ else if (payload_protocol == htons(ETH_P_IPV6))
+ hop_limit = ipv6_hdr(skb)->hop_limit;
+ else
+ hop_limit = ip6_dst_hoplimit(dst);
+ }
+
/*
* Okay, now see if we can stuff it in the buffer as-is.
*/
@@ -1243,15 +1252,6 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
}
skb_dst_set(skb, dst);
- if (hop_limit == 0) {
- if (payload_protocol == htons(ETH_P_IP))
- hop_limit = ip_hdr(skb)->ttl;
- else if (payload_protocol == htons(ETH_P_IPV6))
- hop_limit = ipv6_hdr(skb)->hop_limit;
- else
- hop_limit = ip6_dst_hoplimit(dst);
- }
-
/* Calculate max headroom for all the headers and adjust
* needed_headroom if necessary.
*/
--
2.46.0
next reply other threads:[~2024-12-17 3:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-17 3:07 Mazin Al Haddad [this message]
2024-12-17 5:42 ` [PATCH] ip6_tunnel: Fix uninit-value in ip6_tnl_xmit Eric Dumazet
2024-12-17 10:28 ` Mazin Al haddad
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241217030751.11226-1-mazin@getstate.dev \
--to=mazin@getstate.dev \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+6023ea32e206eef7920a@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).