Message ID | 20220429154257.2054294-1-eric.dumazet@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Commit | dba5bdd57bea587ea4f0b79b03c71135f84a7e8b |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net] net: igmp: respect RCU rules in ip_mc_source() and ip_mc_msfilter() | expand |
Hello: This patch was applied to netdev/net.git (master) by David S. Miller <davem@davemloft.net>: On Fri, 29 Apr 2022 08:42:57 -0700 you wrote: > From: Eric Dumazet <edumazet@google.com> > > syzbot reported an UAF in ip_mc_sf_allow() [1] > > 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() > > [...] Here is the summary with links: - [net] net: igmp: respect RCU rules in ip_mc_source() and ip_mc_msfilter() https://git.kernel.org/netdev/net/c/dba5bdd57bea You are awesome, thank you!
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 2ad3c7b42d6d271baf941e7f74feaf981dff8036..1d9e6d5e9a76c5c22d78d7da5b0efbf61d8feb88 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c @@ -2403,9 +2403,10 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct /* decrease mem now to avoid the memleak warning */ atomic_sub(struct_size(psl, sl_addr, psl->sl_max), &sk->sk_omem_alloc); - kfree_rcu(psl, rcu); } rcu_assign_pointer(pmc->sflist, newpsl); + if (psl) + kfree_rcu(psl, rcu); psl = newpsl; } rv = 1; /* > 0 for insert logic below if sl_count is 0 */ @@ -2507,11 +2508,13 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex) /* decrease mem now to avoid the memleak warning */ atomic_sub(struct_size(psl, sl_addr, psl->sl_max), &sk->sk_omem_alloc); - kfree_rcu(psl, rcu); - } else + } else { (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode, 0, NULL, 0); + } rcu_assign_pointer(pmc->sflist, newpsl); + if (psl) + kfree_rcu(psl, rcu); pmc->sfmode = msf->imsf_fmode; err = 0; done: