user_namespace.c (3c0411846118a578de3a979faf2da3ab5fb81179) user_namespace.c (64964528b24ea390824f0e5ce9d34b8d39b28cde)
1/*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation, version 2 of the
5 * License.
6 */
7
8#include <linux/export.h>

--- 832 unchanged lines hidden (view full) ---

841 return false;
842}
843
844static inline struct user_namespace *to_user_ns(struct ns_common *ns)
845{
846 return container_of(ns, struct user_namespace, ns);
847}
848
1/*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation, version 2 of the
5 * License.
6 */
7
8#include <linux/export.h>

--- 832 unchanged lines hidden (view full) ---

841 return false;
842}
843
844static inline struct user_namespace *to_user_ns(struct ns_common *ns)
845{
846 return container_of(ns, struct user_namespace, ns);
847}
848
849static void *userns_get(struct task_struct *task)
849static struct ns_common *userns_get(struct task_struct *task)
850{
851 struct user_namespace *user_ns;
852
853 rcu_read_lock();
854 user_ns = get_user_ns(__task_cred(task)->user_ns);
855 rcu_read_unlock();
856
857 return user_ns ? &user_ns->ns : NULL;
858}
859
850{
851 struct user_namespace *user_ns;
852
853 rcu_read_lock();
854 user_ns = get_user_ns(__task_cred(task)->user_ns);
855 rcu_read_unlock();
856
857 return user_ns ? &user_ns->ns : NULL;
858}
859
860static void userns_put(void *ns)
860static void userns_put(struct ns_common *ns)
861{
862 put_user_ns(to_user_ns(ns));
863}
864
861{
862 put_user_ns(to_user_ns(ns));
863}
864
865static int userns_install(struct nsproxy *nsproxy, void *ns)
865static int userns_install(struct nsproxy *nsproxy, struct ns_common *ns)
866{
867 struct user_namespace *user_ns = to_user_ns(ns);
868 struct cred *cred;
869
870 /* Don't allow gaining capabilities by reentering
871 * the same user namespace.
872 */
873 if (user_ns == current_user_ns())

--- 14 unchanged lines hidden (view full) ---

888 return -ENOMEM;
889
890 put_user_ns(cred->user_ns);
891 set_cred_user_ns(cred, get_user_ns(user_ns));
892
893 return commit_creds(cred);
894}
895
866{
867 struct user_namespace *user_ns = to_user_ns(ns);
868 struct cred *cred;
869
870 /* Don't allow gaining capabilities by reentering
871 * the same user namespace.
872 */
873 if (user_ns == current_user_ns())

--- 14 unchanged lines hidden (view full) ---

888 return -ENOMEM;
889
890 put_user_ns(cred->user_ns);
891 set_cred_user_ns(cred, get_user_ns(user_ns));
892
893 return commit_creds(cred);
894}
895
896static unsigned int userns_inum(void *ns)
897{
898 return ((struct ns_common *)ns)->inum;
899}
900
901const struct proc_ns_operations userns_operations = {
902 .name = "user",
903 .type = CLONE_NEWUSER,
904 .get = userns_get,
905 .put = userns_put,
906 .install = userns_install,
896const struct proc_ns_operations userns_operations = {
897 .name = "user",
898 .type = CLONE_NEWUSER,
899 .get = userns_get,
900 .put = userns_put,
901 .install = userns_install,
907 .inum = userns_inum,
908};
909
910static __init int user_namespaces_init(void)
911{
912 user_ns_cachep = KMEM_CACHE(user_namespace, SLAB_PANIC);
913 return 0;
914}
915subsys_initcall(user_namespaces_init);
902};
903
904static __init int user_namespaces_init(void)
905{
906 user_ns_cachep = KMEM_CACHE(user_namespace, SLAB_PANIC);
907 return 0;
908}
909subsys_initcall(user_namespaces_init);