aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/utsname.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/utsname.c')
-rw-r--r--kernel/utsname.c41
1 files changed, 4 insertions, 37 deletions
diff --git a/kernel/utsname.c b/kernel/utsname.c
index c859164a6993..160c8c5136bd 100644
--- a/kernel/utsname.c
+++ b/kernel/utsname.c
@@ -32,58 +32,25 @@ static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns)
32} 32}
33 33
34/* 34/*
35 * unshare the current process' utsname namespace.
36 * called only in sys_unshare()
37 */
38int unshare_utsname(unsigned long unshare_flags, struct uts_namespace **new_uts)
39{
40 if (unshare_flags & CLONE_NEWUTS) {
41 if (!capable(CAP_SYS_ADMIN))
42 return -EPERM;
43
44 *new_uts = clone_uts_ns(current->nsproxy->uts_ns);
45 if (!*new_uts)
46 return -ENOMEM;
47 }
48
49 return 0;
50}
51
52/*
53 * Copy task tsk's utsname namespace, or clone it if flags 35 * Copy task tsk's utsname namespace, or clone it if flags
54 * specifies CLONE_NEWUTS. In latter case, changes to the 36 * specifies CLONE_NEWUTS. In latter case, changes to the
55 * utsname of this process won't be seen by parent, and vice 37 * utsname of this process won't be seen by parent, and vice
56 * versa. 38 * versa.
57 */ 39 */
58int copy_utsname(int flags, struct task_struct *tsk) 40struct uts_namespace *copy_utsname(int flags, struct uts_namespace *old_ns)
59{ 41{
60 struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
61 struct uts_namespace *new_ns; 42 struct uts_namespace *new_ns;
62 int err = 0;
63
64 if (!old_ns)
65 return 0;
66 43
44 BUG_ON(!old_ns);
67 get_uts_ns(old_ns); 45 get_uts_ns(old_ns);
68 46
69 if (!(flags & CLONE_NEWUTS)) 47 if (!(flags & CLONE_NEWUTS))
70 return 0; 48 return old_ns;
71
72 if (!capable(CAP_SYS_ADMIN)) {
73 err = -EPERM;
74 goto out;
75 }
76 49
77 new_ns = clone_uts_ns(old_ns); 50 new_ns = clone_uts_ns(old_ns);
78 if (!new_ns) {
79 err = -ENOMEM;
80 goto out;
81 }
82 tsk->nsproxy->uts_ns = new_ns;
83 51
84out:
85 put_uts_ns(old_ns); 52 put_uts_ns(old_ns);
86 return err; 53 return new_ns;
87} 54}
88 55
89void free_uts_ns(struct kref *kref) 56void free_uts_ns(struct kref *kref)