1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_UTSNAME_H 3 #define _LINUX_UTSNAME_H 4 5 6 #include <linux/sched.h> 7 #include <linux/nsproxy.h> 8 #include <linux/ns_common.h> 9 #include <linux/err.h> 10 #include <uapi/linux/utsname.h> 11 12 enum uts_proc { 13 UTS_PROC_ARCH, 14 UTS_PROC_OSTYPE, 15 UTS_PROC_OSRELEASE, 16 UTS_PROC_VERSION, 17 UTS_PROC_HOSTNAME, 18 UTS_PROC_DOMAINNAME, 19 }; 20 21 struct user_namespace; 22 extern struct user_namespace init_user_ns; 23 24 struct uts_namespace { 25 struct new_utsname name; 26 struct user_namespace *user_ns; 27 struct ucounts *ucounts; 28 struct ns_common ns; 29 } __randomize_layout; 30 extern struct uts_namespace init_uts_ns; 31 32 #ifdef CONFIG_UTS_NS 33 static inline void get_uts_ns(struct uts_namespace *ns) 34 { 35 refcount_inc(&ns->ns.count); 36 } 37 38 extern struct uts_namespace *copy_utsname(unsigned long flags, 39 struct user_namespace *user_ns, struct uts_namespace *old_ns); 40 extern void free_uts_ns(struct uts_namespace *ns); 41 42 static inline void put_uts_ns(struct uts_namespace *ns) 43 { 44 if (refcount_dec_and_test(&ns->ns.count)) 45 free_uts_ns(ns); 46 } 47 48 void uts_ns_init(void); 49 #else 50 static inline void get_uts_ns(struct uts_namespace *ns) 51 { 52 } 53 54 static inline void put_uts_ns(struct uts_namespace *ns) 55 { 56 } 57 58 static inline struct uts_namespace *copy_utsname(unsigned long flags, 59 struct user_namespace *user_ns, struct uts_namespace *old_ns) 60 { 61 if (flags & CLONE_NEWUTS) 62 return ERR_PTR(-EINVAL); 63 64 return old_ns; 65 } 66 67 static inline void uts_ns_init(void) 68 { 69 } 70 #endif 71 72 #ifdef CONFIG_PROC_SYSCTL 73 extern void uts_proc_notify(enum uts_proc proc); 74 #else 75 static inline void uts_proc_notify(enum uts_proc proc) 76 { 77 } 78 #endif 79 80 static inline struct new_utsname *utsname(void) 81 { 82 return ¤t->nsproxy->uts_ns->name; 83 } 84 85 static inline struct new_utsname *init_utsname(void) 86 { 87 return &init_uts_ns.name; 88 } 89 90 extern struct rw_semaphore uts_sem; 91 92 #endif /* _LINUX_UTSNAME_H */ 93