Skip to contentSkip to conversation

ipv6: Properly check reference count flag before taking reference

PATCH In review Jason A. Donenfeld 3 participants 4 messages Sep 23, 2019 – Sep 25, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv6: Properly check reference count flag before taking reference

People are reporting that WireGuard experiences erratic crashes on 5.3, and bisected it down to 7d30a7f6424e. Casually flipping through that commit I noticed that a flag is checked using | instead of &, which in this current case, means that a reference is never incremented, which would result in the use-after-free users are seeing. This commit changes the | to the proper & test.

Fixes 7d30a7f6424e ("Merge branch 'ipv6-avoid-taking-refcnt-on-dst-during-route-lookup'")
---
 net/ipv6/ip6_fib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ip6_fib.c +1 -1
index 87f47bc55c5e..6e2af411cd9c 100644
@@ -318,7 +318,7 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
 	if (rt->dst.error == -EAGAIN) {
 		ip6_rt_put_flags(rt, flags);
 		rt = net->ipv6.ip6_null_entry;
-		if (!(flags | RT6_LOOKUP_F_DST_NOREF))
+		if (!(flags & RT6_LOOKUP_F_DST_NOREF))
 			dst_hold(&rt->dst);
 	}
 
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 10 lines

People are reporting that WireGuard experiences erratic crashes on 5.3, and bisected it down to 7d30a7f6424e. Casually flipping through that commit I noticed that a flag is checked using | instead of &, which in this current case, means that a reference is never incremented, which would result in the use-after-free users are seeing. This commit changes the | to the proper & test.

Fixes 7d30a7f6424e ("Merge branch 'ipv6-avoid-taking-refcnt-on-dst-during-route-lookup'")

NOTE: this change was added in d64a1f574a29 ("ipv6: honor RT6_LOOKUP_F_DST_NOREF in rule lookup logic")

Kind regards,
Petr

Quoted 16 lines
---
 net/ipv6/ip6_fib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ip6_fib.c +1 -1
index 87f47bc55c5e..6e2af411cd9c 100644
@@ -318,7 +318,7 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
 	if (rt->dst.error == -EAGAIN) {
 		ip6_rt_put_flags(rt, flags);
 		rt = net->ipv6.ip6_null_entry;
-		if (!(flags | RT6_LOOKUP_F_DST_NOREF))
+		if (!(flags & RT6_LOOKUP_F_DST_NOREF))
 			dst_hold(&rt->dst);
 	}
#2 lore raw

Apparently even with this (certainly correct) patch attached, users are still experiencing problems. Bug hunting continues, and I'll report back if I figure something out.

#3 lore raw
In reply to Petr Vorel
Quoted 13 lines · Petr Vorel

Hi,

Quoted 10 lines

People are reporting that WireGuard experiences erratic crashes on 5.3, and bisected it down to 7d30a7f6424e. Casually flipping through that commit I noticed that a flag is checked using | instead of &, which in this current case, means that a reference is never incremented, which would result in the use-after-free users are seeing. This commit changes the | to the proper & test.

Fixes 7d30a7f6424e ("Merge branch 'ipv6-avoid-taking-refcnt-on-dst-during-route-lookup'")
Quoted 7 lines

NOTE: this change was added in d64a1f574a29 ("ipv6: honor RT6_LOOKUP_F_DST_NOREF in rule lookup logic")

Kind regards,
Petr

This was fixed earlier I think

https://git.kernel.org/pub/scm/linux/kernel/git/davem/net.git/commit/?id=7b09c2d052db4b4ad0b27b97918b46a7746966fa

Quoted 16 lines
Quoted 16 lines
---
 net/ipv6/ip6_fib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ip6_fib.c +1 -1
index 87f47bc55c5e..6e2af411cd9c 100644
@@ -318,7 +318,7 @@ struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
 	if (rt->dst.error == -EAGAIN) {
 		ip6_rt_put_flags(rt, flags);
 		rt = net->ipv6.ip6_null_entry;
-		if (!(flags | RT6_LOOKUP_F_DST_NOREF))
+		if (!(flags & RT6_LOOKUP_F_DST_NOREF))
 			dst_hold(&rt->dst);
 	}