user_namespace.h 2.1 KB
Newer Older
1 2 3 4 5 6
#ifndef _LINUX_USER_NAMESPACE_H
#define _LINUX_USER_NAMESPACE_H

#include <linux/kref.h>
#include <linux/nsproxy.h>
#include <linux/sched.h>
S
Serge E. Hallyn 已提交
7
#include <linux/err.h>
8

9 10 11 12 13 14 15 16 17 18 19
#define UID_GID_MAP_MAX_EXTENTS 5

struct uid_gid_map {	/* 64 bytes -- 1 cache line */
	u32 nr_extents;
	struct uid_gid_extent {
		u32 first;
		u32 lower_first;
		u32 count;
	} extent[UID_GID_MAP_MAX_EXTENTS];
};

20
struct user_namespace {
21 22
	struct uid_gid_map	uid_map;
	struct uid_gid_map	gid_map;
23
	struct uid_gid_map	projid_map;
24
	atomic_t		count;
25
	struct user_namespace	*parent;
26 27
	kuid_t			owner;
	kgid_t			group;
28
	unsigned int		proc_inum;
29 30
	bool			may_mount_sysfs;
	bool			may_mount_proc;
31 32 33 34 35 36 37 38 39
};

extern struct user_namespace init_user_ns;

#ifdef CONFIG_USER_NS

static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
{
	if (ns)
40
		atomic_inc(&ns->count);
41 42 43
	return ns;
}

44
extern int create_user_ns(struct cred *new);
45
extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
46
extern void free_user_ns(struct user_namespace *ns);
47 48 49

static inline void put_user_ns(struct user_namespace *ns)
{
50 51
	if (ns && atomic_dec_and_test(&ns->count))
		free_user_ns(ns);
52 53
}

54 55 56
struct seq_operations;
extern struct seq_operations proc_uid_seq_operations;
extern struct seq_operations proc_gid_seq_operations;
57
extern struct seq_operations proc_projid_seq_operations;
58 59
extern ssize_t proc_uid_map_write(struct file *, const char __user *, size_t, loff_t *);
extern ssize_t proc_gid_map_write(struct file *, const char __user *, size_t, loff_t *);
60
extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, loff_t *);
61 62 63 64 65 66 67
#else

static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
{
	return &init_user_ns;
}

68
static inline int create_user_ns(struct cred *new)
69
{
70
	return -EINVAL;
71 72
}

73 74 75 76 77 78 79 80
static inline int unshare_userns(unsigned long unshare_flags,
				 struct cred **new_cred)
{
	if (unshare_flags & CLONE_NEWUSER)
		return -EINVAL;
	return 0;
}

81 82 83 84
static inline void put_user_ns(struct user_namespace *ns)
{
}

85 86
#endif

87 88
void update_mnt_policy(struct user_namespace *userns);

89
#endif /* _LINUX_USER_H */