Skip to content

Commit ffbf700

Browse files
committed
Merge tag 'vfs-6.19-rc1.autofs' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull autofs update from Christian Brauner: "Prevent futile mount triggers in private mount namespaces. Fix a problematic loop in autofs when a mount namespace contains autofs mounts that are propagation private and there is no namespace-specific automount daemon to handle possible automounting. Previously, attempted path resolution would loop until MAXSYMLINKS was reached before failing, causing significant noise in the log. The fix adds a check in autofs ->d_automount() so that the VFS can immediately return EPERM in this case. Since the mount is propagation private, EPERM is the most appropriate error code" * tag 'vfs-6.19-rc1.autofs' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: autofs: dont trigger mount if it cant succeed
2 parents d0deeb8 + 922a6f3 commit ffbf700

6 files changed

Lines changed: 22 additions & 0 deletions

File tree

fs/autofs/autofs_i.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/wait.h>
1717
#include <linux/sched.h>
1818
#include <linux/sched/signal.h>
19+
#include <uapi/linux/mount.h>
1920
#include <linux/mount.h>
2021
#include <linux/namei.h>
2122
#include <linux/uaccess.h>
@@ -27,6 +28,9 @@
2728
#include <linux/magic.h>
2829
#include <linux/fs_context.h>
2930
#include <linux/fs_parser.h>
31+
#include "../mount.h"
32+
#include <linux/ns_common.h>
33+
3034

3135
/* This is the range of ioctl() numbers we claim as ours */
3236
#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
@@ -114,6 +118,7 @@ struct autofs_sb_info {
114118
int pipefd;
115119
struct file *pipe;
116120
struct pid *oz_pgrp;
121+
u64 mnt_ns_id;
117122
int version;
118123
int sub_version;
119124
int min_proto;

fs/autofs/dev-ioctl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ static int autofs_dev_ioctl_setpipefd(struct file *fp,
381381
swap(sbi->oz_pgrp, new_pid);
382382
sbi->pipefd = pipefd;
383383
sbi->pipe = pipe;
384+
sbi->mnt_ns_id = to_ns_common(current->nsproxy->mnt_ns)->ns_id;
384385
sbi->flags &= ~AUTOFS_SBI_CATATONIC;
385386
}
386387
out:

fs/autofs/inode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ static struct autofs_sb_info *autofs_alloc_sbi(void)
251251
sbi->min_proto = AUTOFS_MIN_PROTO_VERSION;
252252
sbi->max_proto = AUTOFS_MAX_PROTO_VERSION;
253253
sbi->pipefd = -1;
254+
sbi->mnt_ns_id = to_ns_common(current->nsproxy->mnt_ns)->ns_id;
254255

255256
set_autofs_type_indirect(&sbi->type);
256257
mutex_init(&sbi->wq_mutex);

fs/autofs/root.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ static struct vfsmount *autofs_d_automount(struct path *path)
341341
if (autofs_oz_mode(sbi))
342342
return NULL;
343343

344+
/* Refuse to trigger mount if current namespace is not the owner
345+
* and the mount is propagation private.
346+
*/
347+
if (sbi->mnt_ns_id != to_ns_common(current->nsproxy->mnt_ns)->ns_id) {
348+
if (vfsmount_to_propagation_flags(path->mnt) & MS_PRIVATE)
349+
return ERR_PTR(-EPERM);
350+
}
351+
344352
/*
345353
* If an expire request is pending everyone must wait.
346354
* If the expire fails we're still mounted so continue

fs/namespace.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5148,6 +5148,12 @@ static u64 mnt_to_propagation_flags(struct mount *m)
51485148
return propagation;
51495149
}
51505150

5151+
u64 vfsmount_to_propagation_flags(struct vfsmount *mnt)
5152+
{
5153+
return mnt_to_propagation_flags(real_mount(mnt));
5154+
}
5155+
EXPORT_SYMBOL_GPL(vfsmount_to_propagation_flags);
5156+
51515157
static void statmount_sb_basic(struct kstatmount *s)
51525158
{
51535159
struct super_block *sb = s->mnt->mnt_sb;

include/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2840,6 +2840,7 @@ extern struct file * open_exec(const char *);
28402840
/* fs/dcache.c -- generic fs support functions */
28412841
extern bool is_subdir(struct dentry *, struct dentry *);
28422842
extern bool path_is_under(const struct path *, const struct path *);
2843+
u64 vfsmount_to_propagation_flags(struct vfsmount *mnt);
28432844

28442845
extern char *file_path(struct file *, char *, int);
28452846

0 commit comments

Comments
 (0)