]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.54/ipv6-flowlabel-fl6_sock_lookup-must-use-atomic_inc_not_zero.patch
Linux 4.19.54
[thirdparty/kernel/stable-queue.git] / releases / 4.19.54 / ipv6-flowlabel-fl6_sock_lookup-must-use-atomic_inc_not_zero.patch
1 From foo@baz Wed 19 Jun 2019 02:34:37 PM CEST
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Thu, 6 Jun 2019 14:32:34 -0700
4 Subject: ipv6: flowlabel: fl6_sock_lookup() must use atomic_inc_not_zero
5
6 From: Eric Dumazet <edumazet@google.com>
7
8 [ Upstream commit 65a3c497c0e965a552008db8bc2653f62bc925a1 ]
9
10 Before taking a refcount, make sure the object is not already
11 scheduled for deletion.
12
13 Same fix is needed in ipv6_flowlabel_opt()
14
15 Fixes: 18367681a10b ("ipv6 flowlabel: Convert np->ipv6_fl_list to RCU.")
16 Signed-off-by: Eric Dumazet <edumazet@google.com>
17 Cc: Willem de Bruijn <willemb@google.com>
18 Signed-off-by: David S. Miller <davem@davemloft.net>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
20 ---
21 net/ipv6/ip6_flowlabel.c | 7 ++++---
22 1 file changed, 4 insertions(+), 3 deletions(-)
23
24 --- a/net/ipv6/ip6_flowlabel.c
25 +++ b/net/ipv6/ip6_flowlabel.c
26 @@ -254,9 +254,9 @@ struct ip6_flowlabel *fl6_sock_lookup(st
27 rcu_read_lock_bh();
28 for_each_sk_fl_rcu(np, sfl) {
29 struct ip6_flowlabel *fl = sfl->fl;
30 - if (fl->label == label) {
31 +
32 + if (fl->label == label && atomic_inc_not_zero(&fl->users)) {
33 fl->lastuse = jiffies;
34 - atomic_inc(&fl->users);
35 rcu_read_unlock_bh();
36 return fl;
37 }
38 @@ -622,7 +622,8 @@ int ipv6_flowlabel_opt(struct sock *sk,
39 goto done;
40 }
41 fl1 = sfl->fl;
42 - atomic_inc(&fl1->users);
43 + if (!atomic_inc_not_zero(&fl1->users))
44 + fl1 = NULL;
45 break;
46 }
47 }