xref: /linux/include/linux/uts_namespace.h (revision 18b19abc3709b109676ffd1f48dcd332c2e477d4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_UTS_NAMESPACE_H
3 #define _LINUX_UTS_NAMESPACE_H
4 
5 #include <linux/ns_common.h>
6 #include <uapi/linux/utsname.h>
7 
8 struct user_namespace;
9 extern struct user_namespace init_user_ns;
10 
11 struct uts_namespace {
12 	struct new_utsname name;
13 	struct user_namespace *user_ns;
14 	struct ucounts *ucounts;
15 	struct ns_common ns;
16 } __randomize_layout;
17 
18 extern struct uts_namespace init_uts_ns;
19 
20 #ifdef CONFIG_UTS_NS
to_uts_ns(struct ns_common * ns)21 static inline struct uts_namespace *to_uts_ns(struct ns_common *ns)
22 {
23 	return container_of(ns, struct uts_namespace, ns);
24 }
25 
get_uts_ns(struct uts_namespace * ns)26 static inline void get_uts_ns(struct uts_namespace *ns)
27 {
28 	ns_ref_inc(ns);
29 }
30 
31 extern struct uts_namespace *copy_utsname(u64 flags,
32 	struct user_namespace *user_ns, struct uts_namespace *old_ns);
33 extern void free_uts_ns(struct uts_namespace *ns);
34 
put_uts_ns(struct uts_namespace * ns)35 static inline void put_uts_ns(struct uts_namespace *ns)
36 {
37 	if (ns_ref_put(ns))
38 		free_uts_ns(ns);
39 }
40 
41 void uts_ns_init(void);
42 #else
get_uts_ns(struct uts_namespace * ns)43 static inline void get_uts_ns(struct uts_namespace *ns)
44 {
45 }
46 
put_uts_ns(struct uts_namespace * ns)47 static inline void put_uts_ns(struct uts_namespace *ns)
48 {
49 }
50 
copy_utsname(u64 flags,struct user_namespace * user_ns,struct uts_namespace * old_ns)51 static inline struct uts_namespace *copy_utsname(u64 flags,
52 	struct user_namespace *user_ns, struct uts_namespace *old_ns)
53 {
54 	if (flags & CLONE_NEWUTS)
55 		return ERR_PTR(-EINVAL);
56 
57 	return old_ns;
58 }
59 
uts_ns_init(void)60 static inline void uts_ns_init(void)
61 {
62 }
63 #endif
64 
65 #endif /* _LINUX_UTS_NAMESPACE_H */
66