diff options
author | Oleg Nesterov <oleg@redhat.com> | 2013-08-08 12:55:32 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-08-08 16:11:39 -0400 |
commit | 8742f229b635bf1c1c84a3dfe5e47c814c20b5c8 (patch) | |
tree | 3d9f64cf0c9d705b9f422d137c8067fa2d41f3c8 | |
parent | 55f5bfd4c94b923d965d47f5c1889ef8f98fcef1 (diff) |
userns: limit the maximum depth of user_namespace->parent chain
Ensure that user_namespace->parent chain can't grow too much.
Currently we use the hardroded 32 as limit.
Reported-by: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/user_namespace.h | 1 | ||||
-rw-r--r-- | kernel/user_namespace.c | 4 |
2 files changed, 5 insertions, 0 deletions
diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index b6b215f13b45..14105c26a836 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h | |||
@@ -23,6 +23,7 @@ struct user_namespace { | |||
23 | struct uid_gid_map projid_map; | 23 | struct uid_gid_map projid_map; |
24 | atomic_t count; | 24 | atomic_t count; |
25 | struct user_namespace *parent; | 25 | struct user_namespace *parent; |
26 | int level; | ||
26 | kuid_t owner; | 27 | kuid_t owner; |
27 | kgid_t group; | 28 | kgid_t group; |
28 | unsigned int proc_inum; | 29 | unsigned int proc_inum; |
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 6e50a44610ee..9064b919a406 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c | |||
@@ -62,6 +62,9 @@ int create_user_ns(struct cred *new) | |||
62 | kgid_t group = new->egid; | 62 | kgid_t group = new->egid; |
63 | int ret; | 63 | int ret; |
64 | 64 | ||
65 | if (parent_ns->level > 32) | ||
66 | return -EUSERS; | ||
67 | |||
65 | /* | 68 | /* |
66 | * Verify that we can not violate the policy of which files | 69 | * Verify that we can not violate the policy of which files |
67 | * may be accessed that is specified by the root directory, | 70 | * may be accessed that is specified by the root directory, |
@@ -92,6 +95,7 @@ int create_user_ns(struct cred *new) | |||
92 | atomic_set(&ns->count, 1); | 95 | atomic_set(&ns->count, 1); |
93 | /* Leave the new->user_ns reference with the new user namespace. */ | 96 | /* Leave the new->user_ns reference with the new user namespace. */ |
94 | ns->parent = parent_ns; | 97 | ns->parent = parent_ns; |
98 | ns->level = parent_ns->level + 1; | ||
95 | ns->owner = owner; | 99 | ns->owner = owner; |
96 | ns->group = group; | 100 | ns->group = group; |
97 | 101 | ||