aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/diag.c
diff options
context:
space:
mode:
authorCong Wang <xiyou.wangcong@gmail.com>2018-08-24 12:28:06 -0700
committerDavid S. Miller <davem@davemloft.net>2018-08-29 18:04:54 -0700
commit9a07efa9aea2f4a59f35da0785a4e6a6b5a96192 (patch)
treef557853b702648e5497483065b96bc332e9d68de /net/tipc/diag.c
parentRevert "net: stmmac: Do not keep rearming the coalesce timer in stmmac_xmit" (diff)
downloadlinux-dev-9a07efa9aea2f4a59f35da0785a4e6a6b5a96192.tar.xz
linux-dev-9a07efa9aea2f4a59f35da0785a4e6a6b5a96192.zip
tipc: switch to rhashtable iterator
syzbot reported a use-after-free in tipc_group_fill_sock_diag(), where tipc_group_fill_sock_diag() still reads tsk->group meanwhile tipc_group_delete() just deletes it in tipc_release(). tipc_nl_sk_walk() aims to lock this sock when walking each sock in the hash table to close race conditions with sock changes like this one, by acquiring tsk->sk.sk_lock.slock spinlock, unfortunately this doesn't work at all. All non-BH call path should take lock_sock() instead to make it work. tipc_nl_sk_walk() brutally iterates with raw rht_for_each_entry_rcu() where RCU read lock is required, this is the reason why lock_sock() can't be taken on this path. This could be resolved by switching to rhashtable iterator API's, where taking a sleepable lock is possible. Also, the iterator API's are friendly for restartable calls like diag dump, the last position is remembered behind the scence, all we need to do here is saving the iterator into cb->args[]. I tested this with parallel tipc diag dump and thousands of tipc socket creation and release, no crash or memory leak. Reported-by: syzbot+b9c8f3ab2994b7cd1625@syzkaller.appspotmail.com Cc: Jon Maloy <jon.maloy@ericsson.com> Cc: Ying Xue <ying.xue@windriver.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/diag.c')
-rw-r--r--net/tipc/diag.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/net/tipc/diag.c b/net/tipc/diag.c
index aaabb0b776dd..73137f4aeb68 100644
--- a/net/tipc/diag.c
+++ b/net/tipc/diag.c
@@ -84,7 +84,9 @@ static int tipc_sock_diag_handler_dump(struct sk_buff *skb,
if (h->nlmsg_flags & NLM_F_DUMP) {
struct netlink_dump_control c = {
+ .start = tipc_dump_start,
.dump = tipc_diag_dump,
+ .done = tipc_dump_done,
};
netlink_dump_start(net->diag_nlsk, skb, h, &c);
return 0;