Skip to contentSkip to conversation

ipv6: flowlabel: fl6_sock_lookup() must use atomic_inc_not_zero

PATCH In review Eric Dumazet 2 participants 2 messages Jun 6, 2019 – Jun 9, 2019

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

PATCH v2 1/1 ipv6: flowlabel: fl6_sock_lookup() must use atomic_inc_not_zero

Before taking a refcount, make sure the object is not already scheduled for deletion.

Same fix is needed in ipv6_flowlabel_opt()

Fixes 18367681a10b ("ipv6 flowlabel: Convert np->ipv6_fl_list to RCU.")
Cc Willem de Bruijn <[email protected]>
---
 net/ipv6/ip6_flowlabel.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv6/ip6_flowlabel.c +4 -3
index be5f3d7ceb966d609121f89a6cc5dcc605834c89..f994f50e1516226c88101f901f71647514ad580b 100644
@@ -254,9 +254,9 @@ struct ip6_flowlabel *fl6_sock_lookup(struct sock *sk, __be32 label)
 	rcu_read_lock_bh();
 	for_each_sk_fl_rcu(np, sfl) {
 		struct ip6_flowlabel *fl = sfl->fl;
-		if (fl->label == label) {
+
+		if (fl->label == label && atomic_inc_not_zero(&fl->users)) {
 			fl->lastuse = jiffies;
-			atomic_inc(&fl->users);
 			rcu_read_unlock_bh();
 			return fl;
 		}
@@ -622,7 +622,8 @@ int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen)
 						goto done;
 					}
 					fl1 = sfl->fl;
-					atomic_inc(&fl1->users);
+					if (!atomic_inc_not_zero(&fl1->users))
+						fl1 = NULL;
 					break;
 				}
 			}
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
maintainer
#1 lore raw

From: Eric Dumazet <[email protected]>
Date: Thu, 6 Jun 2019 14:32:34 -0700

Quoted 7 lines

Before taking a refcount, make sure the object is not already scheduled for deletion.

Same fix is needed in ipv6_flowlabel_opt()

Fixes 18367681a10b ("ipv6 flowlabel: Convert np->ipv6_fl_list to RCU.")

Applied and queued up for -stable.