Skip to contentSkip to conversation

net: kernel socket should be released in init_net namespace

PATCH Applied Ying Xue 2 participants 2 messages Mar 16, 2015

Subsystems (3)
lore
Share & tools
lore

Ying Xue

author
#0 lore raw

PATCH 1/1 net: kernel socket should be released in init_net namespace

Creating a kernel socket with sock_create_kern() happens in "init_net" namespace, however, releasing it with sk_release_kernel() occurs in the current namespace which may be different with "init_net" namespace. Therefore, we should guarantee that the namespace in which a kernel socket is created is same as the socket is created.

---
 net/core/sock.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock.c +1 -1
index 4bc42ef..11e144e 100644
@@ -1454,8 +1454,8 @@ void sk_release_kernel(struct sock *sk)
 		return;
 
 	sock_hold(sk);
-	sock_release(sk->sk_socket);
 	sock_net_set(sk, get_net(&init_net));
+	sock_release(sk->sk_socket);
 	sock_put(sk);
 }
 EXPORT_SYMBOL(sk_release_kernel);
Signature · 1 line
1.7.9.5
maintainer Applied
#1 lore raw

From: Ying Xue <[email protected]>
Date: Mon, 16 Mar 2015 18:19:12 +0800

Quoted 7 lines

Creating a kernel socket with sock_create_kern() happens in "init_net" namespace, however, releasing it with sk_release_kernel() occurs in the current namespace which may be different with "init_net" namespace. Therefore, we should guarantee that the namespace in which a kernel socket is created is same as the socket is created.

Applied, thanks.