diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/nsproxy.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index 15a6015a849d..4b7fcc8f9a48 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c | |||
| @@ -21,6 +21,8 @@ | |||
| 21 | #include <linux/utsname.h> | 21 | #include <linux/utsname.h> |
| 22 | #include <linux/pid_namespace.h> | 22 | #include <linux/pid_namespace.h> |
| 23 | 23 | ||
| 24 | static struct kmem_cache *nsproxy_cachep; | ||
| 25 | |||
| 24 | struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy); | 26 | struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy); |
| 25 | 27 | ||
| 26 | static inline void get_nsproxy(struct nsproxy *ns) | 28 | static inline void get_nsproxy(struct nsproxy *ns) |
| @@ -43,9 +45,11 @@ static inline struct nsproxy *clone_nsproxy(struct nsproxy *orig) | |||
| 43 | { | 45 | { |
| 44 | struct nsproxy *ns; | 46 | struct nsproxy *ns; |
| 45 | 47 | ||
| 46 | ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL); | 48 | ns = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL); |
| 47 | if (ns) | 49 | if (ns) { |
| 50 | memcpy(ns, orig, sizeof(struct nsproxy)); | ||
| 48 | atomic_set(&ns->count, 1); | 51 | atomic_set(&ns->count, 1); |
| 52 | } | ||
| 49 | return ns; | 53 | return ns; |
| 50 | } | 54 | } |
| 51 | 55 | ||
| @@ -109,7 +113,7 @@ out_uts: | |||
| 109 | if (new_nsp->mnt_ns) | 113 | if (new_nsp->mnt_ns) |
| 110 | put_mnt_ns(new_nsp->mnt_ns); | 114 | put_mnt_ns(new_nsp->mnt_ns); |
| 111 | out_ns: | 115 | out_ns: |
| 112 | kfree(new_nsp); | 116 | kmem_cache_free(nsproxy_cachep, new_nsp); |
| 113 | return ERR_PTR(err); | 117 | return ERR_PTR(err); |
| 114 | } | 118 | } |
| 115 | 119 | ||
| @@ -160,7 +164,7 @@ void free_nsproxy(struct nsproxy *ns) | |||
| 160 | put_pid_ns(ns->pid_ns); | 164 | put_pid_ns(ns->pid_ns); |
| 161 | if (ns->user_ns) | 165 | if (ns->user_ns) |
| 162 | put_user_ns(ns->user_ns); | 166 | put_user_ns(ns->user_ns); |
| 163 | kfree(ns); | 167 | kmem_cache_free(nsproxy_cachep, ns); |
| 164 | } | 168 | } |
| 165 | 169 | ||
| 166 | /* | 170 | /* |
| @@ -185,3 +189,12 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags, | |||
| 185 | err = PTR_ERR(*new_nsp); | 189 | err = PTR_ERR(*new_nsp); |
| 186 | return err; | 190 | return err; |
| 187 | } | 191 | } |
| 192 | |||
| 193 | static int __init nsproxy_cache_init(void) | ||
| 194 | { | ||
| 195 | nsproxy_cachep = kmem_cache_create("nsproxy", sizeof(struct nsproxy), | ||
| 196 | 0, SLAB_PANIC, NULL, NULL); | ||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | |||
| 200 | module_init(nsproxy_cache_init); | ||
