Skip to content

Commit a9384a4

Browse files
edumazetdavem330
authored andcommitted
mld: respect RCU rules in ip6_mc_source() and ip6_mc_msfilter()
Whenever RCU protected list replaces an object, the pointer to the new object needs to be updated _before_ the call to kfree_rcu() or call_rcu() Also ip6_mc_msfilter() needs to update the pointer before releasing the mc_lock mutex. Note that linux-5.13 was supporting kfree_rcu(NULL, rcu), so this fix does not need the conditional test I was forced to use in the equivalent patch for IPv4. Fixes: 882ba1f ("mld: convert ipv6_mc_socklist->sflist to RCU") Signed-off-by: Eric Dumazet <[email protected]> Cc: Taehee Yoo <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent dba5bdd commit a9384a4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/ipv6/mcast.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,10 @@ int ip6_mc_source(int add, int omode, struct sock *sk,
460460
newpsl->sl_addr[i] = psl->sl_addr[i];
461461
atomic_sub(struct_size(psl, sl_addr, psl->sl_max),
462462
&sk->sk_omem_alloc);
463-
kfree_rcu(psl, rcu);
464463
}
464+
rcu_assign_pointer(pmc->sflist, newpsl);
465+
kfree_rcu(psl, rcu);
465466
psl = newpsl;
466-
rcu_assign_pointer(pmc->sflist, psl);
467467
}
468468
rv = 1; /* > 0 for insert logic below if sl_count is 0 */
469469
for (i = 0; i < psl->sl_count; i++) {
@@ -565,12 +565,12 @@ int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf,
565565
psl->sl_count, psl->sl_addr, 0);
566566
atomic_sub(struct_size(psl, sl_addr, psl->sl_max),
567567
&sk->sk_omem_alloc);
568-
kfree_rcu(psl, rcu);
569568
} else {
570569
ip6_mc_del_src(idev, group, pmc->sfmode, 0, NULL, 0);
571570
}
572-
mutex_unlock(&idev->mc_lock);
573571
rcu_assign_pointer(pmc->sflist, newpsl);
572+
mutex_unlock(&idev->mc_lock);
573+
kfree_rcu(psl, rcu);
574574
pmc->sfmode = gsf->gf_fmode;
575575
err = 0;
576576
done:

0 commit comments

Comments
 (0)