@@ -79,23 +79,36 @@ static void proc_cleanup_work(struct work_struct *work)
79
79
/* MAX_PID_NS_LEVEL is needed for limiting size of 'struct pid' */
80
80
#define MAX_PID_NS_LEVEL 32
81
81
82
+ static struct ucounts * inc_pid_namespaces (struct user_namespace * ns )
83
+ {
84
+ return inc_ucount (ns , current_euid (), UCOUNT_PID_NAMESPACES );
85
+ }
86
+
87
+ static void dec_pid_namespaces (struct ucounts * ucounts )
88
+ {
89
+ dec_ucount (ucounts , UCOUNT_PID_NAMESPACES );
90
+ }
91
+
82
92
static struct pid_namespace * create_pid_namespace (struct user_namespace * user_ns ,
83
93
struct pid_namespace * parent_pid_ns )
84
94
{
85
95
struct pid_namespace * ns ;
86
96
unsigned int level = parent_pid_ns -> level + 1 ;
97
+ struct ucounts * ucounts ;
87
98
int i ;
88
99
int err ;
89
100
90
- if (level > MAX_PID_NS_LEVEL ) {
91
- err = - EINVAL ;
101
+ err = - EINVAL ;
102
+ if (level > MAX_PID_NS_LEVEL )
103
+ goto out ;
104
+ ucounts = inc_pid_namespaces (user_ns );
105
+ if (!ucounts )
92
106
goto out ;
93
- }
94
107
95
108
err = - ENOMEM ;
96
109
ns = kmem_cache_zalloc (pid_ns_cachep , GFP_KERNEL );
97
110
if (ns == NULL )
98
- goto out ;
111
+ goto out_dec ;
99
112
100
113
ns -> pidmap [0 ].page = kzalloc (PAGE_SIZE , GFP_KERNEL );
101
114
if (!ns -> pidmap [0 ].page )
@@ -114,6 +127,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
114
127
ns -> level = level ;
115
128
ns -> parent = get_pid_ns (parent_pid_ns );
116
129
ns -> user_ns = get_user_ns (user_ns );
130
+ ns -> ucounts = ucounts ;
117
131
ns -> nr_hashed = PIDNS_HASH_ADDING ;
118
132
INIT_WORK (& ns -> proc_work , proc_cleanup_work );
119
133
@@ -129,6 +143,8 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
129
143
kfree (ns -> pidmap [0 ].page );
130
144
out_free :
131
145
kmem_cache_free (pid_ns_cachep , ns );
146
+ out_dec :
147
+ dec_pid_namespaces (ucounts );
132
148
out :
133
149
return ERR_PTR (err );
134
150
}
@@ -146,6 +162,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns)
146
162
ns_free_inum (& ns -> ns );
147
163
for (i = 0 ; i < PIDMAP_ENTRIES ; i ++ )
148
164
kfree (ns -> pidmap [i ].page );
165
+ dec_pid_namespaces (ns -> ucounts );
149
166
put_user_ns (ns -> user_ns );
150
167
call_rcu (& ns -> rcu , delayed_free_pidns );
151
168
}
0 commit comments