Skip to content

Commit

Permalink
pidfs: allow bind-mounts
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
brauner committed Dec 22, 2024
1 parent 16ecd47 commit ef4144a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <linux/fs_context.h>
#include <linux/shmem_fs.h>
#include <linux/mnt_idmapping.h>
#include <linux/pidfs.h>
#include <linux/nospec.h>

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

if (!check_mnt(old) && old_path->dentry->d_op != &ns_dentry_operations)
return mnt;
if (!check_mnt(old)) {
const struct dentry_operations *d_op = old_path->dentry->d_op;

if (d_op != &ns_dentry_operations &&
d_op != &pidfs_dentry_operations)
return mnt;
}

if (!recurse && has_locked_children(old, old_path->dentry))
return mnt;
Expand Down
2 changes: 1 addition & 1 deletion fs/pidfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ static char *pidfs_dname(struct dentry *dentry, char *buffer, int buflen)
return dynamic_dname(buffer, buflen, "anon_inode:[pidfd]");
}

static const struct dentry_operations pidfs_dentry_operations = {
const struct dentry_operations pidfs_dentry_operations = {
.d_delete = always_delete_dentry,
.d_dname = pidfs_dname,
.d_prune = stashed_dentry_prune,
Expand Down
1 change: 1 addition & 0 deletions include/linux/pidfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags);
void __init pidfs_init(void);
void pidfs_add_pid(struct pid *pid);
void pidfs_remove_pid(struct pid *pid);
extern const struct dentry_operations pidfs_dentry_operations;

#endif /* _LINUX_PID_FS_H */

0 comments on commit ef4144a

Please sign in to comment.