netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netlink: do not set cb_running if dump's start() errs
@ 2017-10-09 11:56 Jason A. Donenfeld
  2017-10-09 11:57 ` Jason A. Donenfeld
  2017-10-09 11:58 ` Johannes Berg
  0 siblings, 2 replies; 9+ messages in thread
From: Jason A. Donenfeld @ 2017-10-09 11:56 UTC (permalink / raw)
  To: johannes, davem, Netdev, linux-kernel; +Cc: Jason A. Donenfeld

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.

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>
---
 net/netlink/af_netlink.c | 13 +++++++------
 1 file 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,
 	cb->min_dump_alloc = control->min_dump_alloc;
 	cb->skb = skb;
 
+	if (cb->start) {
+		ret = cb->start(cb);
+		if (ret)
+			goto error_unlock;
+	}
+
 	nlk->cb_running = true;
 
 	mutex_unlock(nlk->cb_mutex);
 
-	ret = 0;
-	if (cb->start)
-		ret = cb->start(cb);
-
-	if (!ret)
-		ret = netlink_dump(sk);
+	ret = netlink_dump(sk);
 
 	sock_put(sk);
 
-- 
2.14.2

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-10-09 17:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-09 11:56 [PATCH] netlink: do not set cb_running if dump's start() errs Jason A. Donenfeld
2017-10-09 11:57 ` Jason A. Donenfeld
2017-10-09 11:58 ` Johannes Berg
2017-10-09 12:12   ` Jason A. Donenfeld
2017-10-09 12:14     ` [PATCH v2] " Jason A. Donenfeld
2017-10-09 12:31       ` Johannes Berg
2017-10-09 17:02         ` Jason A. Donenfeld
2017-10-09 17:29       ` David Miller
2017-10-09 12:27   ` [PATCH] " Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).