Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[NETNS]: Inet control socket should not hold a namespace.

This is a generic requirement, so make inet_ctl_sock_create namespace
aware and create a inet_ctl_sock_destroy wrapper around
sk_release_kernel.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Denis V. Lunev and committed by
David S. Miller
5677242f eee4fe4d

+22 -21
+7 -1
include/net/inet_common.h
··· 42 42 extern int inet_ctl_sock_create(struct sock **sk, 43 43 unsigned short family, 44 44 unsigned short type, 45 - unsigned char protocol); 45 + unsigned char protocol, 46 + struct net *net); 47 + 48 + static inline void inet_ctl_sock_destroy(struct sock *sk) 49 + { 50 + sk_release_kernel(sk); 51 + } 46 52 47 53 #endif 48 54
+2 -2
net/dccp/ipv4.c
··· 1003 1003 inet_register_protosw(&dccp_v4_protosw); 1004 1004 1005 1005 err = inet_ctl_sock_create(&dccp_v4_ctl_sk, PF_INET, 1006 - SOCK_DCCP, IPPROTO_DCCP); 1006 + SOCK_DCCP, IPPROTO_DCCP, &init_net); 1007 1007 if (err) 1008 1008 goto out_unregister_protosw; 1009 1009 out: ··· 1018 1018 1019 1019 static void __exit dccp_v4_exit(void) 1020 1020 { 1021 - sock_release(dccp_v4_ctl_sk->sk_socket); 1021 + inet_ctl_sock_destroy(dccp_v4_ctl_sk); 1022 1022 inet_unregister_protosw(&dccp_v4_protosw); 1023 1023 inet_del_protocol(&dccp_v4_protocol, IPPROTO_DCCP); 1024 1024 proto_unregister(&dccp_v4_prot);
+2 -2
net/dccp/ipv6.c
··· 1185 1185 inet6_register_protosw(&dccp_v6_protosw); 1186 1186 1187 1187 err = inet_ctl_sock_create(&dccp_v6_ctl_sk, PF_INET6, 1188 - SOCK_DCCP, IPPROTO_DCCP); 1188 + SOCK_DCCP, IPPROTO_DCCP, &init_net); 1189 1189 if (err != 0) 1190 1190 goto out_unregister_protosw; 1191 1191 out: ··· 1200 1200 1201 1201 static void __exit dccp_v6_exit(void) 1202 1202 { 1203 - sock_release(dccp_v6_ctl_sk->sk_socket); 1203 + inet_ctl_sock_destroy(dccp_v6_ctl_sk); 1204 1204 inet6_del_protocol(&dccp_v6_protocol, IPPROTO_DCCP); 1205 1205 inet6_unregister_protosw(&dccp_v6_protosw); 1206 1206 proto_unregister(&dccp_v6_prot);
+4 -1
net/ipv4/af_inet.c
··· 1251 1251 } 1252 1252 1253 1253 int inet_ctl_sock_create(struct sock **sk, unsigned short family, 1254 - unsigned short type, unsigned char protocol) 1254 + unsigned short type, unsigned char protocol, 1255 + struct net *net) 1255 1256 { 1256 1257 struct socket *sock; 1257 1258 int rc = sock_create_kern(family, type, protocol, &sock); ··· 1266 1265 * we do not wish this socket to see incoming packets. 1267 1266 */ 1268 1267 (*sk)->sk_prot->unhash(*sk); 1268 + 1269 + sk_change_net(*sk, net); 1269 1270 } 1270 1271 return rc; 1271 1272 }
+1 -1
net/ipv4/tcp_ipv4.c
··· 2491 2491 void __init tcp_v4_init(void) 2492 2492 { 2493 2493 if (inet_ctl_sock_create(&tcp_sock, PF_INET, SOCK_RAW, 2494 - IPPROTO_TCP) < 0) 2494 + IPPROTO_TCP, &init_net) < 0) 2495 2495 panic("Failed to create the TCP control socket.\n"); 2496 2496 } 2497 2497
+3 -11
net/ipv6/tcp_ipv6.c
··· 2199 2199 2200 2200 static int tcpv6_net_init(struct net *net) 2201 2201 { 2202 - int err; 2203 - struct sock *sk; 2204 - 2205 - err = inet_ctl_sock_create(&sk, PF_INET6, SOCK_RAW, IPPROTO_TCP); 2206 - if (err) 2207 - return err; 2208 - 2209 - net->ipv6.tcp_sk = sk; 2210 - sk_change_net(sk, net); 2211 - return err; 2202 + return inet_ctl_sock_create(&net->ipv6.tcp_sk, PF_INET6, 2203 + SOCK_RAW, IPPROTO_TCP, net); 2212 2204 } 2213 2205 2214 2206 static void tcpv6_net_exit(struct net *net) 2215 2207 { 2216 - sk_release_kernel(net->ipv6.tcp_sk); 2208 + inet_ctl_sock_destroy(net->ipv6.tcp_sk); 2217 2209 } 2218 2210 2219 2211 static struct pernet_operations tcpv6_net_ops = {
+3 -3
net/sctp/protocol.c
··· 681 681 family = PF_INET; 682 682 683 683 err = inet_ctl_sock_create(&sctp_ctl_sock, family, 684 - SOCK_SEQPACKET, IPPROTO_SCTP); 684 + SOCK_SEQPACKET, IPPROTO_SCTP, &init_net); 685 685 if (err < 0) { 686 686 printk(KERN_ERR 687 687 "SCTP: Failed to create the SCTP control socket.\n"); ··· 1284 1284 sctp_v6_del_protocol(); 1285 1285 err_add_protocol: 1286 1286 sctp_v4_del_protocol(); 1287 - sock_release(sctp_ctl_sock->sk_socket); 1287 + inet_ctl_sock_destroy(sctp_ctl_sock); 1288 1288 err_ctl_sock_init: 1289 1289 sctp_v6_protosw_exit(); 1290 1290 err_v6_protosw_init: ··· 1328 1328 sctp_v4_del_protocol(); 1329 1329 1330 1330 /* Free the control endpoint. */ 1331 - sock_release(sctp_ctl_sock->sk_socket); 1331 + inet_ctl_sock_destroy(sctp_ctl_sock); 1332 1332 1333 1333 /* Free protosw registrations */ 1334 1334 sctp_v6_protosw_exit();