userns: Generalize the user namespace count into ucount

The same kind of recursive sane default limit and policy
countrol that has been implemented for the user namespace
is desirable for the other namespaces, so generalize
the user namespace refernce count into a ucount.

Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
This commit is contained in:
Eric W. Biederman 2016-08-08 14:41:52 -05:00
parent f6b2db1a3e
commit 25f9c0817c
4 changed files with 49 additions and 25 deletions

View file

@ -23,6 +23,12 @@ struct uid_gid_map { /* 64 bytes -- 1 cache line */
#define USERNS_INIT_FLAGS USERNS_SETGROUPS_ALLOWED
struct ucounts;
enum ucount_type {
UCOUNT_USER_NAMESPACES,
UCOUNT_COUNTS,
};
struct user_namespace {
struct uid_gid_map uid_map;
struct uid_gid_map gid_map;
@ -46,7 +52,7 @@ struct user_namespace {
struct ctl_table_header *sysctls;
#endif
struct ucounts *ucounts;
int max_user_namespaces;
int ucount_max[UCOUNT_COUNTS];
};
struct ucounts {
@ -54,15 +60,15 @@ struct ucounts {
struct user_namespace *ns;
kuid_t uid;
atomic_t count;
atomic_t user_namespaces;
atomic_t ucount[UCOUNT_COUNTS];
};
extern struct user_namespace init_user_ns;
bool setup_userns_sysctls(struct user_namespace *ns);
void retire_userns_sysctls(struct user_namespace *ns);
struct ucounts *inc_user_namespaces(struct user_namespace *ns, kuid_t uid);
void dec_user_namespaces(struct ucounts *ucounts);
struct ucounts *inc_ucount(struct user_namespace *ns, kuid_t uid, enum ucount_type type);
void dec_ucount(struct ucounts *ucounts, enum ucount_type type);
#ifdef CONFIG_USER_NS