Thread (30 messages) flat view 30 messages, 6 authors, 2011-03-22

Re: [held lock freed] Re: [GIT] Networking

From: Arnd Bergmann <arnd@arndb.de>
Date: 2011-03-21 14:50:18
Also in: lkml
Subsystem: networking [general], the rest, x.25 stack · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds, Martin Schiller

On Monday 21 March 2011, Eric Dumazet wrote:
[PATCH] ipx: fix ipx_release()

Commit b0d0d915d1d1a0 (remove the BKL) added a regression, because
sock_put() can free memory while we are going to use it later.

Fix is to delay sock_put() after release_sock().

Reported-by: Ingo Molnar <redacted>
Signed-off-by: Eric Dumazet <redacted>
Cc: Arnd Bergmann <arnd@arndb.de>
Your fix looks good, thanks Eric!

Acked-by: Arnd Bergmann <arnd@arndb.de>

I believe I made the same mistake in atalk_release and x25_release:

8<------------
net: fix atalk_release and x25_release

The recent BKL removal has introduced a use-after-free problem
in multiple network protocols. This fixes the problem in appletalk
and x25 by ensuring that we call the final sock_put() after
releasing the socket lock.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c
index 3d4f4b0..206e771 100644
--- a/net/appletalk/ddp.c
+++ b/net/appletalk/ddp.c
@@ -1051,6 +1051,7 @@ static int atalk_release(struct socket *sock)
 {
 	struct sock *sk = sock->sk;
 
+	sock_hold(sk);
 	lock_sock(sk);
 	if (sk) {
 		sock_orphan(sk);
@@ -1058,6 +1059,8 @@ static int atalk_release(struct socket *sock)
 		atalk_destroy_socket(sk);
 	}
 	release_sock(sk);
+	sock_put(sk);
+
 	return 0;
 }
 
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index 4680b1e..b2cf1db 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -669,8 +669,8 @@ static int x25_release(struct socket *sock)
 
 	sock_orphan(sk);
 out:
-	release_sock(sk);
 	sock_put(sk);
+	release_sock(sk);
 	return 0;
 }
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help