blob: 44429d9142ca3d08309435d7fe27e4ade7038103 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_UTSNAME_H
3#define _LINUX_UTSNAME_H
4
Cedric Le Goaterb119f132006-10-04 02:15:19 -07005
6#include <linux/sched.h>
7#include <linux/kref.h>
8#include <linux/nsproxy.h>
Al Viro435d5f42014-10-31 22:56:04 -04009#include <linux/ns_common.h>
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080010#include <linux/err.h>
David Howells607ca462012-10-13 10:46:48 +010011#include <uapi/linux/utsname.h>
Cedric Le Goaterb119f132006-10-04 02:15:19 -070012
Lucas De Marchif1ecf062011-11-02 13:39:22 -070013enum uts_proc {
14 UTS_PROC_OSTYPE,
15 UTS_PROC_OSRELEASE,
16 UTS_PROC_VERSION,
17 UTS_PROC_HOSTNAME,
18 UTS_PROC_DOMAINNAME,
19};
20
Serge E. Hallyn59607db2011-03-23 16:43:16 -070021struct user_namespace;
22extern struct user_namespace init_user_ns;
23
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070024struct uts_namespace {
25 struct kref kref;
26 struct new_utsname name;
Serge E. Hallyn59607db2011-03-23 16:43:16 -070027 struct user_namespace *user_ns;
Eric W. Biedermanf7af3d12016-08-08 14:11:25 -050028 struct ucounts *ucounts;
Al Viro435d5f42014-10-31 22:56:04 -040029 struct ns_common ns;
Kees Cook3859a272016-10-28 01:22:25 -070030} __randomize_layout;
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070031extern struct uts_namespace init_uts_ns;
32
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080033#ifdef CONFIG_UTS_NS
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070034static inline void get_uts_ns(struct uts_namespace *ns)
35{
36 kref_get(&ns->kref);
37}
38
Eric W. Biederman213dd262007-07-15 23:41:15 -070039extern struct uts_namespace *copy_utsname(unsigned long flags,
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070040 struct user_namespace *user_ns, struct uts_namespace *old_ns);
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070041extern void free_uts_ns(struct kref *kref);
42
43static inline void put_uts_ns(struct uts_namespace *ns)
44{
45 kref_put(&ns->kref, free_uts_ns);
46}
Alexey Dobriyan3ea056c2018-04-10 16:32:36 -070047
48void uts_ns_init(void);
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080049#else
50static inline void get_uts_ns(struct uts_namespace *ns)
51{
52}
53
54static inline void put_uts_ns(struct uts_namespace *ns)
55{
56}
57
58static inline struct uts_namespace *copy_utsname(unsigned long flags,
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070059 struct user_namespace *user_ns, struct uts_namespace *old_ns)
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080060{
61 if (flags & CLONE_NEWUTS)
62 return ERR_PTR(-EINVAL);
63
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070064 return old_ns;
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080065}
Alexey Dobriyan3ea056c2018-04-10 16:32:36 -070066
67static inline void uts_ns_init(void)
68{
69}
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080070#endif
71
Lucas De Marchif1ecf062011-11-02 13:39:22 -070072#ifdef CONFIG_PROC_SYSCTL
73extern void uts_proc_notify(enum uts_proc proc);
74#else
75static inline void uts_proc_notify(enum uts_proc proc)
76{
77}
78#endif
79
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070080static inline struct new_utsname *utsname(void)
81{
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070082 return &current->nsproxy->uts_ns->name;
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070083}
84
85static inline struct new_utsname *init_utsname(void)
86{
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070087 return &init_uts_ns.name;
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070088}
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090extern struct rw_semaphore uts_sem;
Cedric Le Goaterb119f132006-10-04 02:15:19 -070091
Cedric Le Goaterb119f132006-10-04 02:15:19 -070092#endif /* _LINUX_UTSNAME_H */