diff options
-rw-r--r-- | ipc/namespace.c | 15 | ||||
-rw-r--r-- | kernel/pid_namespace.c | 14 | ||||
-rw-r--r-- | kernel/user_namespace.c | 14 | ||||
-rw-r--r-- | kernel/utsname.c | 15 |
4 files changed, 36 insertions, 22 deletions
diff --git a/ipc/namespace.c b/ipc/namespace.c index 177fa9db391d..3c1e8d3bd7d3 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c | |||
@@ -149,6 +149,11 @@ void put_ipc_ns(struct ipc_namespace *ns) | |||
149 | } | 149 | } |
150 | } | 150 | } |
151 | 151 | ||
152 | static inline struct ipc_namespace *to_ipc_ns(struct ns_common *ns) | ||
153 | { | ||
154 | return container_of(ns, struct ipc_namespace, ns); | ||
155 | } | ||
156 | |||
152 | static void *ipcns_get(struct task_struct *task) | 157 | static void *ipcns_get(struct task_struct *task) |
153 | { | 158 | { |
154 | struct ipc_namespace *ns = NULL; | 159 | struct ipc_namespace *ns = NULL; |
@@ -160,17 +165,17 @@ static void *ipcns_get(struct task_struct *task) | |||
160 | ns = get_ipc_ns(nsproxy->ipc_ns); | 165 | ns = get_ipc_ns(nsproxy->ipc_ns); |
161 | task_unlock(task); | 166 | task_unlock(task); |
162 | 167 | ||
163 | return ns; | 168 | return ns ? &ns->ns : NULL; |
164 | } | 169 | } |
165 | 170 | ||
166 | static void ipcns_put(void *ns) | 171 | static void ipcns_put(void *ns) |
167 | { | 172 | { |
168 | return put_ipc_ns(ns); | 173 | return put_ipc_ns(to_ipc_ns(ns)); |
169 | } | 174 | } |
170 | 175 | ||
171 | static int ipcns_install(struct nsproxy *nsproxy, void *new) | 176 | static int ipcns_install(struct nsproxy *nsproxy, void *new) |
172 | { | 177 | { |
173 | struct ipc_namespace *ns = new; | 178 | struct ipc_namespace *ns = to_ipc_ns(new); |
174 | if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) || | 179 | if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) || |
175 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) | 180 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) |
176 | return -EPERM; | 181 | return -EPERM; |
@@ -184,9 +189,7 @@ static int ipcns_install(struct nsproxy *nsproxy, void *new) | |||
184 | 189 | ||
185 | static unsigned int ipcns_inum(void *vp) | 190 | static unsigned int ipcns_inum(void *vp) |
186 | { | 191 | { |
187 | struct ipc_namespace *ns = vp; | 192 | return ((struct ns_common *)vp)->inum; |
188 | |||
189 | return ns->ns.inum; | ||
190 | } | 193 | } |
191 | 194 | ||
192 | const struct proc_ns_operations ipcns_operations = { | 195 | const struct proc_ns_operations ipcns_operations = { |
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 99e27e5bf906..dd961ad86fbd 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c | |||
@@ -313,6 +313,11 @@ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) | |||
313 | return 0; | 313 | return 0; |
314 | } | 314 | } |
315 | 315 | ||
316 | static inline struct pid_namespace *to_pid_ns(struct ns_common *ns) | ||
317 | { | ||
318 | return container_of(ns, struct pid_namespace, ns); | ||
319 | } | ||
320 | |||
316 | static void *pidns_get(struct task_struct *task) | 321 | static void *pidns_get(struct task_struct *task) |
317 | { | 322 | { |
318 | struct pid_namespace *ns; | 323 | struct pid_namespace *ns; |
@@ -323,18 +328,18 @@ static void *pidns_get(struct task_struct *task) | |||
323 | get_pid_ns(ns); | 328 | get_pid_ns(ns); |
324 | rcu_read_unlock(); | 329 | rcu_read_unlock(); |
325 | 330 | ||
326 | return ns; | 331 | return ns ? &ns->ns : NULL; |
327 | } | 332 | } |
328 | 333 | ||
329 | static void pidns_put(void *ns) | 334 | static void pidns_put(void *ns) |
330 | { | 335 | { |
331 | put_pid_ns(ns); | 336 | put_pid_ns(to_pid_ns(ns)); |
332 | } | 337 | } |
333 | 338 | ||
334 | static int pidns_install(struct nsproxy *nsproxy, void *ns) | 339 | static int pidns_install(struct nsproxy *nsproxy, void *ns) |
335 | { | 340 | { |
336 | struct pid_namespace *active = task_active_pid_ns(current); | 341 | struct pid_namespace *active = task_active_pid_ns(current); |
337 | struct pid_namespace *ancestor, *new = ns; | 342 | struct pid_namespace *ancestor, *new = to_pid_ns(ns); |
338 | 343 | ||
339 | if (!ns_capable(new->user_ns, CAP_SYS_ADMIN) || | 344 | if (!ns_capable(new->user_ns, CAP_SYS_ADMIN) || |
340 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) | 345 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) |
@@ -364,8 +369,7 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns) | |||
364 | 369 | ||
365 | static unsigned int pidns_inum(void *ns) | 370 | static unsigned int pidns_inum(void *ns) |
366 | { | 371 | { |
367 | struct pid_namespace *pid_ns = ns; | 372 | return ((struct ns_common *)ns)->inum; |
368 | return pid_ns->ns.inum; | ||
369 | } | 373 | } |
370 | 374 | ||
371 | const struct proc_ns_operations pidns_operations = { | 375 | const struct proc_ns_operations pidns_operations = { |
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index fde584082673..1ab2209228ff 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c | |||
@@ -841,6 +841,11 @@ static bool new_idmap_permitted(const struct file *file, | |||
841 | return false; | 841 | return false; |
842 | } | 842 | } |
843 | 843 | ||
844 | static inline struct user_namespace *to_user_ns(struct ns_common *ns) | ||
845 | { | ||
846 | return container_of(ns, struct user_namespace, ns); | ||
847 | } | ||
848 | |||
844 | static void *userns_get(struct task_struct *task) | 849 | static void *userns_get(struct task_struct *task) |
845 | { | 850 | { |
846 | struct user_namespace *user_ns; | 851 | struct user_namespace *user_ns; |
@@ -849,17 +854,17 @@ static void *userns_get(struct task_struct *task) | |||
849 | user_ns = get_user_ns(__task_cred(task)->user_ns); | 854 | user_ns = get_user_ns(__task_cred(task)->user_ns); |
850 | rcu_read_unlock(); | 855 | rcu_read_unlock(); |
851 | 856 | ||
852 | return user_ns; | 857 | return user_ns ? &user_ns->ns : NULL; |
853 | } | 858 | } |
854 | 859 | ||
855 | static void userns_put(void *ns) | 860 | static void userns_put(void *ns) |
856 | { | 861 | { |
857 | put_user_ns(ns); | 862 | put_user_ns(to_user_ns(ns)); |
858 | } | 863 | } |
859 | 864 | ||
860 | static int userns_install(struct nsproxy *nsproxy, void *ns) | 865 | static int userns_install(struct nsproxy *nsproxy, void *ns) |
861 | { | 866 | { |
862 | struct user_namespace *user_ns = ns; | 867 | struct user_namespace *user_ns = to_user_ns(ns); |
863 | struct cred *cred; | 868 | struct cred *cred; |
864 | 869 | ||
865 | /* Don't allow gaining capabilities by reentering | 870 | /* Don't allow gaining capabilities by reentering |
@@ -890,8 +895,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns) | |||
890 | 895 | ||
891 | static unsigned int userns_inum(void *ns) | 896 | static unsigned int userns_inum(void *ns) |
892 | { | 897 | { |
893 | struct user_namespace *user_ns = ns; | 898 | return ((struct ns_common *)ns)->inum; |
894 | return user_ns->ns.inum; | ||
895 | } | 899 | } |
896 | 900 | ||
897 | const struct proc_ns_operations userns_operations = { | 901 | const struct proc_ns_operations userns_operations = { |
diff --git a/kernel/utsname.c b/kernel/utsname.c index b1cd00b828f2..1917f74be8ec 100644 --- a/kernel/utsname.c +++ b/kernel/utsname.c | |||
@@ -88,6 +88,11 @@ void free_uts_ns(struct kref *kref) | |||
88 | kfree(ns); | 88 | kfree(ns); |
89 | } | 89 | } |
90 | 90 | ||
91 | static inline struct uts_namespace *to_uts_ns(struct ns_common *ns) | ||
92 | { | ||
93 | return container_of(ns, struct uts_namespace, ns); | ||
94 | } | ||
95 | |||
91 | static void *utsns_get(struct task_struct *task) | 96 | static void *utsns_get(struct task_struct *task) |
92 | { | 97 | { |
93 | struct uts_namespace *ns = NULL; | 98 | struct uts_namespace *ns = NULL; |
@@ -101,17 +106,17 @@ static void *utsns_get(struct task_struct *task) | |||
101 | } | 106 | } |
102 | task_unlock(task); | 107 | task_unlock(task); |
103 | 108 | ||
104 | return ns; | 109 | return ns ? &ns->ns : NULL; |
105 | } | 110 | } |
106 | 111 | ||
107 | static void utsns_put(void *ns) | 112 | static void utsns_put(void *ns) |
108 | { | 113 | { |
109 | put_uts_ns(ns); | 114 | put_uts_ns(to_uts_ns(ns)); |
110 | } | 115 | } |
111 | 116 | ||
112 | static int utsns_install(struct nsproxy *nsproxy, void *new) | 117 | static int utsns_install(struct nsproxy *nsproxy, void *new) |
113 | { | 118 | { |
114 | struct uts_namespace *ns = new; | 119 | struct uts_namespace *ns = to_uts_ns(new); |
115 | 120 | ||
116 | if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) || | 121 | if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) || |
117 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) | 122 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) |
@@ -125,9 +130,7 @@ static int utsns_install(struct nsproxy *nsproxy, void *new) | |||
125 | 130 | ||
126 | static unsigned int utsns_inum(void *vp) | 131 | static unsigned int utsns_inum(void *vp) |
127 | { | 132 | { |
128 | struct uts_namespace *ns = vp; | 133 | return ((struct ns_common *)vp)->inum; |
129 | |||
130 | return ns->ns.inum; | ||
131 | } | 134 | } |
132 | 135 | ||
133 | const struct proc_ns_operations utsns_operations = { | 136 | const struct proc_ns_operations utsns_operations = { |