Skip to content

Commit ef4144a

Browse files
committed
pidfs: allow bind-mounts
Allow bind-mounting pidfds. Similar to nsfs let's allow bind-mounts for pidfds. This allows pidfds to be safely recovered and checked for process recycling. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 16ecd47 commit ef4144a

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

fs/namespace.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/fs_context.h>
3333
#include <linux/shmem_fs.h>
3434
#include <linux/mnt_idmapping.h>
35+
#include <linux/pidfs.h>
3536
#include <linux/nospec.h>
3637

3738
#include "pnode.h"
@@ -2732,8 +2733,13 @@ static struct mount *__do_loopback(struct path *old_path, int recurse)
27322733
if (IS_MNT_UNBINDABLE(old))
27332734
return mnt;
27342735

2735-
if (!check_mnt(old) && old_path->dentry->d_op != &ns_dentry_operations)
2736-
return mnt;
2736+
if (!check_mnt(old)) {
2737+
const struct dentry_operations *d_op = old_path->dentry->d_op;
2738+
2739+
if (d_op != &ns_dentry_operations &&
2740+
d_op != &pidfs_dentry_operations)
2741+
return mnt;
2742+
}
27372743

27382744
if (!recurse && has_locked_children(old, old_path->dentry))
27392745
return mnt;

fs/pidfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ static char *pidfs_dname(struct dentry *dentry, char *buffer, int buflen)
510510
return dynamic_dname(buffer, buflen, "anon_inode:[pidfd]");
511511
}
512512

513-
static const struct dentry_operations pidfs_dentry_operations = {
513+
const struct dentry_operations pidfs_dentry_operations = {
514514
.d_delete = always_delete_dentry,
515515
.d_dname = pidfs_dname,
516516
.d_prune = stashed_dentry_prune,

include/linux/pidfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags);
66
void __init pidfs_init(void);
77
void pidfs_add_pid(struct pid *pid);
88
void pidfs_remove_pid(struct pid *pid);
9+
extern const struct dentry_operations pidfs_dentry_operations;
910

1011
#endif /* _LINUX_PID_FS_H */

0 commit comments

Comments
 (0)