81d4cffb6cbf2faac5d77a51174ff24e0bb7aec3
[linux-2.6.git] / linux-2.6-595-vserver-new-netns.patch
1 --- linux-i686-2.6.22/kernel/vserver/space.c.orig       2008-03-11 20:14:21.000000000 -0400
2 +++ linux-i686-2.6.22/kernel/vserver/space.c    2008-03-11 20:13:53.000000000 -0400
3 @@ -15,12 +15,15 @@
4  #include <linux/utsname.h>
5  #include <linux/nsproxy.h>
6  #include <linux/err.h>
7 +#include <net/net_namespace.h>
8  #include <asm/uaccess.h>
9  
10  #include <linux/vs_context.h>
11  #include <linux/vserver/space.h>
12  #include <linux/vserver/space_cmd.h>
13  
14 +#include <linux/capability.h>
15 +
16  
17  atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
18  atomic_t vs_global_fs          = ATOMIC_INIT(0);
19 @@ -55,9 +58,21 @@
20         struct mnt_namespace *old_ns;
21         struct uts_namespace *old_uts;
22         struct ipc_namespace *old_ipc;
23 +       struct net *old_net;
24         struct nsproxy *nsproxy;
25  
26 +       /* Dunno if task_lock is really needed */
27 +       task_lock(current);
28 +       if (!cap_raised(current->cap_effective, CAP_SYS_ADMIN)) {
29 +               current->cap_effective = cap_raise(current->cap_effective, CAP_SYS_ADMIN);
30 +       }
31         nsproxy = copy_nsproxy(old_nsproxy);
32 +       if (cap_raised(current->cap_effective, CAP_SYS_ADMIN)) {
33 +               current->cap_effective = cap_lower(current->cap_effective, CAP_SYS_ADMIN);
34 +       }
35 +       task_unlock(current);
36 +       /* <- */
37 +
38         if (!nsproxy)
39                 goto out;
40  
41 @@ -84,6 +99,16 @@
42                         get_ipc_ns(nsproxy->ipc_ns);
43         } else
44                 old_ipc = NULL;
45 +       
46 +       if (mask & CLONE_NEWNET) {
47 +               old_net = nsproxy->net_ns;
48 +               nsproxy->net_ns = new_nsproxy->net_ns;
49 +               if (nsproxy->net_ns) {
50 +                       get_net(nsproxy->net_ns);
51 +               }       
52 +       } else
53 +               old_net = NULL;
54 +
55  
56         if (old_ns)
57                 put_mnt_ns(old_ns);
58 @@ -91,6 +116,9 @@
59                 put_uts_ns(old_uts);
60         if (old_ipc)
61                 put_ipc_ns(old_ipc);
62 +       if (old_net)
63 +               put_net(old_net);
64 +
65  out:
66         return nsproxy;
67  }
68 @@ -251,7 +279,8 @@
69  
70  int vc_enter_space(struct vx_info *vxi, void __user *data)
71  {
72 -       struct vcmd_space_mask vc_data = { .mask = 0 };
73 +       /* Ask dhozac how to pass this flag from user space - Sapan*/
74 +       struct vcmd_space_mask vc_data = { .mask = CLONE_NEWNET };
75  
76         if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
77                 return -EFAULT;