Skip to content

Commit c9c5d92

Browse files
Sukadev BhattiproluLinus Torvalds
authored andcommitted
pid namespaces: create a slab-cache for 'struct pid_namespace'
This will help fixing memory leaks due to bad reference counting. Signed-off-by: Sukadev Bhattiprolu <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Sukadev Bhattiprolu <[email protected]> Cc: Paul Menage <[email protected]> Cc: "Eric W. Biederman" <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6f4e643 commit c9c5d92

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

kernel/pid.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
static struct hlist_head *pid_hash;
4141
static int pidhash_shift;
4242
struct pid init_struct_pid = INIT_STRUCT_PID;
43+
static struct kmem_cache *pid_ns_cachep;
4344

4445
int pid_max = PID_MAX_DEFAULT;
4546

@@ -486,7 +487,7 @@ static struct pid_namespace *create_pid_namespace(int level)
486487
struct pid_namespace *ns;
487488
int i;
488489

489-
ns = kmalloc(sizeof(struct pid_namespace), GFP_KERNEL);
490+
ns = kmem_cache_alloc(pid_ns_cachep, GFP_KERNEL);
490491
if (ns == NULL)
491492
goto out;
492493

@@ -516,7 +517,7 @@ static struct pid_namespace *create_pid_namespace(int level)
516517
out_free_map:
517518
kfree(ns->pidmap[0].page);
518519
out_free:
519-
kfree(ns);
520+
kmem_cache_free(pid_ns_cachep, ns);
520521
out:
521522
return ERR_PTR(-ENOMEM);
522523
}
@@ -527,7 +528,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns)
527528

528529
for (i = 0; i < PIDMAP_ENTRIES; i++)
529530
kfree(ns->pidmap[i].page);
530-
kfree(ns);
531+
kmem_cache_free(pid_ns_cachep, ns);
531532
}
532533

533534
struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *old_ns)
@@ -601,4 +602,6 @@ void __init pidmap_init(void)
601602
init_pid_ns.pid_cachep = create_pid_cachep(1);
602603
if (init_pid_ns.pid_cachep == NULL)
603604
panic("Can't create pid_1 cachep\n");
605+
606+
pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC);
604607
}

0 commit comments

Comments
 (0)