Skip to content

Commit 31d7d67

Browse files
edumazetkuba-moo
authored andcommitted
ipv6: annotate data-races around rt->fib6_nsiblings
rt->fib6_nsiblings can be read locklessly, add corresponding READ_ONCE() and WRITE_ONCE() annotations. Fixes: 66f5d6c ("ipv6: replace rwlock with rcu and spinlock in fib6_table") Signed-off-by: Eric Dumazet <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f8d8ce1 commit 31d7d67

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

net/ipv6/ip6_fib.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,17 @@ struct fib6_dump_arg {
445445
static int fib6_rt_dump(struct fib6_info *rt, struct fib6_dump_arg *arg)
446446
{
447447
enum fib_event_type fib_event = FIB_EVENT_ENTRY_REPLACE;
448+
unsigned int nsiblings;
448449
int err;
449450

450451
if (!rt || rt == arg->net->ipv6.fib6_null_entry)
451452
return 0;
452453

453-
if (rt->fib6_nsiblings)
454+
nsiblings = READ_ONCE(rt->fib6_nsiblings);
455+
if (nsiblings)
454456
err = call_fib6_multipath_entry_notifier(arg->nb, fib_event,
455457
rt,
456-
rt->fib6_nsiblings,
458+
nsiblings,
457459
arg->extack);
458460
else
459461
err = call_fib6_entry_notifier(arg->nb, fib_event, rt,
@@ -1138,7 +1140,7 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
11381140

11391141
if (rt6_duplicate_nexthop(iter, rt)) {
11401142
if (rt->fib6_nsiblings)
1141-
rt->fib6_nsiblings = 0;
1143+
WRITE_ONCE(rt->fib6_nsiblings, 0);
11421144
if (!(iter->fib6_flags & RTF_EXPIRES))
11431145
return -EEXIST;
11441146
if (!(rt->fib6_flags & RTF_EXPIRES)) {
@@ -1167,7 +1169,8 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
11671169
*/
11681170
if (rt_can_ecmp &&
11691171
rt6_qualify_for_ecmp(iter))
1170-
rt->fib6_nsiblings++;
1172+
WRITE_ONCE(rt->fib6_nsiblings,
1173+
rt->fib6_nsiblings + 1);
11711174
}
11721175

11731176
if (iter->fib6_metric > rt->fib6_metric)
@@ -1217,7 +1220,8 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
12171220
fib6_nsiblings = 0;
12181221
list_for_each_entry_safe(sibling, temp_sibling,
12191222
&rt->fib6_siblings, fib6_siblings) {
1220-
sibling->fib6_nsiblings++;
1223+
WRITE_ONCE(sibling->fib6_nsiblings,
1224+
sibling->fib6_nsiblings + 1);
12211225
BUG_ON(sibling->fib6_nsiblings != rt->fib6_nsiblings);
12221226
fib6_nsiblings++;
12231227
}
@@ -1264,7 +1268,8 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
12641268
list_for_each_entry_safe(sibling, next_sibling,
12651269
&rt->fib6_siblings,
12661270
fib6_siblings)
1267-
sibling->fib6_nsiblings--;
1271+
WRITE_ONCE(sibling->fib6_nsiblings,
1272+
sibling->fib6_nsiblings - 1);
12681273
WRITE_ONCE(rt->fib6_nsiblings, 0);
12691274
list_del_rcu(&rt->fib6_siblings);
12701275
rcu_read_lock();
@@ -2014,7 +2019,8 @@ static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn,
20142019
notify_del = true;
20152020
list_for_each_entry_safe(sibling, next_sibling,
20162021
&rt->fib6_siblings, fib6_siblings)
2017-
sibling->fib6_nsiblings--;
2022+
WRITE_ONCE(sibling->fib6_nsiblings,
2023+
sibling->fib6_nsiblings - 1);
20182024
WRITE_ONCE(rt->fib6_nsiblings, 0);
20192025
list_del_rcu(&rt->fib6_siblings);
20202026
rt6_multipath_rebalance(next_sibling);

net/ipv6/route.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5346,7 +5346,8 @@ static void ip6_route_mpath_notify(struct fib6_info *rt,
53465346
*/
53475347
rcu_read_lock();
53485348

5349-
if ((nlflags & NLM_F_APPEND) && rt_last && rt_last->fib6_nsiblings) {
5349+
if ((nlflags & NLM_F_APPEND) && rt_last &&
5350+
READ_ONCE(rt_last->fib6_nsiblings)) {
53505351
rt = list_first_or_null_rcu(&rt_last->fib6_siblings,
53515352
struct fib6_info,
53525353
fib6_siblings);
@@ -5856,7 +5857,7 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,
58565857
if (dst->lwtstate &&
58575858
lwtunnel_fill_encap(skb, dst->lwtstate, RTA_ENCAP, RTA_ENCAP_TYPE) < 0)
58585859
goto nla_put_failure;
5859-
} else if (rt->fib6_nsiblings) {
5860+
} else if (READ_ONCE(rt->fib6_nsiblings)) {
58605861
struct fib6_info *sibling;
58615862
struct nlattr *mp;
58625863

0 commit comments

Comments
 (0)