Skip to content

Commit 1adfcb0

Browse files
author
Al Viro
committed
pid_namespace: make freeing struct pid_namespace rcu-delayed
makes procfs ->premission() instances safety in RCU mode independent from vfsmount_lock. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 1dcddd4 commit 1adfcb0

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎include/linux/pid_namespace.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct bsd_acct_struct;
2323
struct pid_namespace {
2424
struct kref kref;
2525
struct pidmap pidmap[PIDMAP_ENTRIES];
26+
struct rcu_head rcu;
2627
int last_pid;
2728
unsigned int nr_hashed;
2829
struct task_struct *child_reaper;

‎kernel/pid_namespace.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
132132
return ERR_PTR(err);
133133
}
134134

135+
static void delayed_free_pidns(struct rcu_head *p)
136+
{
137+
kmem_cache_free(pid_ns_cachep,
138+
container_of(p, struct pid_namespace, rcu));
139+
}
140+
135141
static void destroy_pid_namespace(struct pid_namespace *ns)
136142
{
137143
int i;
@@ -140,7 +146,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns)
140146
for (i = 0; i < PIDMAP_ENTRIES; i++)
141147
kfree(ns->pidmap[i].page);
142148
put_user_ns(ns->user_ns);
143-
kmem_cache_free(pid_ns_cachep, ns);
149+
call_rcu(&ns->rcu, delayed_free_pidns);
144150
}
145151

146152
struct pid_namespace *copy_pid_ns(unsigned long flags,

0 commit comments

Comments
 (0)