19
19
#include <linux/proc_ns.h>
20
20
#include <linux/sched/task.h>
21
21
22
+ static struct kmem_cache * uts_ns_cache __ro_after_init ;
23
+
22
24
static struct ucounts * inc_uts_namespaces (struct user_namespace * ns )
23
25
{
24
26
return inc_ucount (ns , current_euid (), UCOUNT_UTS_NAMESPACES );
@@ -33,7 +35,7 @@ static struct uts_namespace *create_uts_ns(void)
33
35
{
34
36
struct uts_namespace * uts_ns ;
35
37
36
- uts_ns = kmalloc ( sizeof ( struct uts_namespace ) , GFP_KERNEL );
38
+ uts_ns = kmem_cache_alloc ( uts_ns_cache , GFP_KERNEL );
37
39
if (uts_ns )
38
40
kref_init (& uts_ns -> kref );
39
41
return uts_ns ;
@@ -42,7 +44,7 @@ static struct uts_namespace *create_uts_ns(void)
42
44
/*
43
45
* Clone a new ns copying an original utsname, setting refcount to 1
44
46
* @old_ns: namespace to clone
45
- * Return ERR_PTR(-ENOMEM) on error (failure to kmalloc ), new ns otherwise
47
+ * Return ERR_PTR(-ENOMEM) on error (failure to allocate ), new ns otherwise
46
48
*/
47
49
static struct uts_namespace * clone_uts_ns (struct user_namespace * user_ns ,
48
50
struct uts_namespace * old_ns )
@@ -75,7 +77,7 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns,
75
77
return ns ;
76
78
77
79
fail_free :
78
- kfree ( ns );
80
+ kmem_cache_free ( uts_ns_cache , ns );
79
81
fail_dec :
80
82
dec_uts_namespaces (ucounts );
81
83
fail :
@@ -113,7 +115,7 @@ void free_uts_ns(struct kref *kref)
113
115
dec_uts_namespaces (ns -> ucounts );
114
116
put_user_ns (ns -> user_ns );
115
117
ns_free_inum (& ns -> ns );
116
- kfree ( ns );
118
+ kmem_cache_free ( uts_ns_cache , ns );
117
119
}
118
120
119
121
static inline struct uts_namespace * to_uts_ns (struct ns_common * ns )
@@ -169,3 +171,13 @@ const struct proc_ns_operations utsns_operations = {
169
171
.install = utsns_install ,
170
172
.owner = utsns_owner ,
171
173
};
174
+
175
+ void __init uts_ns_init (void )
176
+ {
177
+ uts_ns_cache = kmem_cache_create_usercopy (
178
+ "uts_namespace" , sizeof (struct uts_namespace ), 0 ,
179
+ SLAB_PANIC |SLAB_ACCOUNT ,
180
+ offsetof(struct uts_namespace , name ),
181
+ sizeof_field (struct uts_namespace , name ),
182
+ NULL );
183
+ }
0 commit comments