Skip to content

Commit 69879c0

Browse files
committed
proc: Remove the now unnecessary internal mount of proc
There remains no more code in the kernel using pids_ns->proc_mnt, therefore remove it from the kernel. The big benefit of this change is that one of the most error prone and tricky parts of the pid namespace implementation, maintaining kernel mounts of proc is removed. In addition removing the unnecessary complexity of the kernel mount fixes a regression that caused the proc mount options to be ignored. Now that the initial mount of proc comes from userspace, those mount options are again honored. This fixes Android's usage of the proc hidepid option. Reported-by: Alistair Strachan <[email protected]> Fixes: e94591d ("proc: Convert proc_mount to use mount_ns.") Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 76313c7 commit 69879c0

File tree

5 files changed

+0
-58
lines changed

5 files changed

+0
-58
lines changed

fs/proc/root.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -292,39 +292,3 @@ struct proc_dir_entry proc_root = {
292292
.subdir = RB_ROOT,
293293
.name = "/proc",
294294
};
295-
296-
int pid_ns_prepare_proc(struct pid_namespace *ns)
297-
{
298-
struct proc_fs_context *ctx;
299-
struct fs_context *fc;
300-
struct vfsmount *mnt;
301-
302-
fc = fs_context_for_mount(&proc_fs_type, SB_KERNMOUNT);
303-
if (IS_ERR(fc))
304-
return PTR_ERR(fc);
305-
306-
if (fc->user_ns != ns->user_ns) {
307-
put_user_ns(fc->user_ns);
308-
fc->user_ns = get_user_ns(ns->user_ns);
309-
}
310-
311-
ctx = fc->fs_private;
312-
if (ctx->pid_ns != ns) {
313-
put_pid_ns(ctx->pid_ns);
314-
get_pid_ns(ns);
315-
ctx->pid_ns = ns;
316-
}
317-
318-
mnt = fc_mount(fc);
319-
put_fs_context(fc);
320-
if (IS_ERR(mnt))
321-
return PTR_ERR(mnt);
322-
323-
ns->proc_mnt = mnt;
324-
return 0;
325-
}
326-
327-
void pid_ns_release_proc(struct pid_namespace *ns)
328-
{
329-
kern_unmount(ns->proc_mnt);
330-
}

include/linux/pid_namespace.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ struct pid_namespace {
3333
unsigned int level;
3434
struct pid_namespace *parent;
3535
#ifdef CONFIG_PROC_FS
36-
struct vfsmount *proc_mnt;
3736
struct dentry *proc_self;
3837
struct dentry *proc_thread_self;
3938
#endif
@@ -42,7 +41,6 @@ struct pid_namespace {
4241
#endif
4342
struct user_namespace *user_ns;
4443
struct ucounts *ucounts;
45-
struct work_struct proc_work;
4644
kgid_t pid_gid;
4745
int hide_pid;
4846
int reboot; /* group exit code if this pidns was rebooted */

include/linux/proc_ns.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,11 @@ enum {
5050

5151
#ifdef CONFIG_PROC_FS
5252

53-
extern int pid_ns_prepare_proc(struct pid_namespace *ns);
54-
extern void pid_ns_release_proc(struct pid_namespace *ns);
5553
extern int proc_alloc_inum(unsigned int *pino);
5654
extern void proc_free_inum(unsigned int inum);
5755

5856
#else /* CONFIG_PROC_FS */
5957

60-
static inline int pid_ns_prepare_proc(struct pid_namespace *ns) { return 0; }
61-
static inline void pid_ns_release_proc(struct pid_namespace *ns) {}
62-
6358
static inline int proc_alloc_inum(unsigned int *inum)
6459
{
6560
*inum = 1;

kernel/pid.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ void free_pid(struct pid *pid)
144144
/* Handle a fork failure of the first process */
145145
WARN_ON(ns->child_reaper);
146146
ns->pid_allocated = 0;
147-
/* fall through */
148-
case 0:
149-
schedule_work(&ns->proc_work);
150147
break;
151148
}
152149

@@ -247,11 +244,6 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
247244
tmp = tmp->parent;
248245
}
249246

250-
if (unlikely(is_child_reaper(pid))) {
251-
if (pid_ns_prepare_proc(ns))
252-
goto out_free;
253-
}
254-
255247
get_pid_ns(ns);
256248
refcount_set(&pid->count, 1);
257249
for (type = 0; type < PIDTYPE_MAX; ++type)

kernel/pid_namespace.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ static struct kmem_cache *create_pid_cachep(unsigned int level)
5757
return READ_ONCE(*pkc);
5858
}
5959

60-
static void proc_cleanup_work(struct work_struct *work)
61-
{
62-
struct pid_namespace *ns = container_of(work, struct pid_namespace, proc_work);
63-
pid_ns_release_proc(ns);
64-
}
65-
6660
static struct ucounts *inc_pid_namespaces(struct user_namespace *ns)
6761
{
6862
return inc_ucount(ns, current_euid(), UCOUNT_PID_NAMESPACES);
@@ -114,7 +108,6 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
114108
ns->user_ns = get_user_ns(user_ns);
115109
ns->ucounts = ucounts;
116110
ns->pid_allocated = PIDNS_ADDING;
117-
INIT_WORK(&ns->proc_work, proc_cleanup_work);
118111

119112
return ns;
120113

0 commit comments

Comments
 (0)