aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/core/net_namespace.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index f2f756ce99d7..97f4dc2132ad 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -347,7 +347,7 @@ struct net *get_net_ns_by_fd(int fd)
347 347
348 ei = get_proc_ns(file_inode(file)); 348 ei = get_proc_ns(file_inode(file));
349 if (ei->ns_ops == &netns_operations) 349 if (ei->ns_ops == &netns_operations)
350 net = get_net(ei->ns); 350 net = get_net(container_of(ei->ns, struct net, ns));
351 else 351 else
352 net = ERR_PTR(-EINVAL); 352 net = ERR_PTR(-EINVAL);
353 353
@@ -640,17 +640,22 @@ static void *netns_get(struct task_struct *task)
640 net = get_net(nsproxy->net_ns); 640 net = get_net(nsproxy->net_ns);
641 task_unlock(task); 641 task_unlock(task);
642 642
643 return net; 643 return net ? &net->ns : NULL;
644}
645
646static inline struct net *to_net_ns(struct ns_common *ns)
647{
648 return container_of(ns, struct net, ns);
644} 649}
645 650
646static void netns_put(void *ns) 651static void netns_put(void *ns)
647{ 652{
648 put_net(ns); 653 put_net(to_net_ns(ns));
649} 654}
650 655
651static int netns_install(struct nsproxy *nsproxy, void *ns) 656static int netns_install(struct nsproxy *nsproxy, void *ns)
652{ 657{
653 struct net *net = ns; 658 struct net *net = to_net_ns(ns);
654 659
655 if (!ns_capable(net->user_ns, CAP_SYS_ADMIN) || 660 if (!ns_capable(net->user_ns, CAP_SYS_ADMIN) ||
656 !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) 661 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
@@ -663,8 +668,7 @@ static int netns_install(struct nsproxy *nsproxy, void *ns)
663 668
664static unsigned int netns_inum(void *ns) 669static unsigned int netns_inum(void *ns)
665{ 670{
666 struct net *net = ns; 671 return ((struct ns_common *)ns)->inum;
667 return net->ns.inum;
668} 672}
669 673
670const struct proc_ns_operations netns_operations = { 674const struct proc_ns_operations netns_operations = {