aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-10-09 08:14:51 -0400
committerDavid S. Miller <davem@davemloft.net>2017-10-09 13:27:49 -0400
commit41c87425a1ac9b633e0fcc78eb1f19640c8fb5a0 (patch)
treec91239da85b6dabccc4c3be54bafa71d181de790 /net
parent6df4d17c442f39137026bce387b0100eef8a25ba (diff)
netlink: do not set cb_running if dump's start() errs
It turns out that multiple places can call netlink_dump(), which means it's still possible to dereference partially initialized values in dump() that were the result of a faulty returned start(). This fixes the issue by calling start() _before_ setting cb_running to true, so that there's no chance at all of hitting the dump() function through any indirect paths. It also moves the call to start() to be when the mutex is held. This has the nice side effect of serializing invocations to start(), which is likely desirable anyway. It also prevents any possible other races that might come out of this logic. In testing this with several different pieces of tricky code to trigger these issues, this commit fixes all avenues that I'm aware of. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Cc: Johannes Berg <johannes@sipsolutions.net> Reviewed-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/netlink/af_netlink.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 94c11cf0459d..f34750691c5c 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2266,16 +2266,17 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
2266 cb->min_dump_alloc = control->min_dump_alloc; 2266 cb->min_dump_alloc = control->min_dump_alloc;
2267 cb->skb = skb; 2267 cb->skb = skb;
2268 2268
2269 if (cb->start) {
2270 ret = cb->start(cb);
2271 if (ret)
2272 goto error_unlock;
2273 }
2274
2269 nlk->cb_running = true; 2275 nlk->cb_running = true;
2270 2276
2271 mutex_unlock(nlk->cb_mutex); 2277 mutex_unlock(nlk->cb_mutex);
2272 2278
2273 ret = 0; 2279 ret = netlink_dump(sk);
2274 if (cb->start)
2275 ret = cb->start(cb);
2276
2277 if (!ret)
2278 ret = netlink_dump(sk);
2279 2280
2280 sock_put(sk); 2281 sock_put(sk);
2281 2282