Skip to content

Commit 922a6f3

Browse files
raven-aubrauner
authored andcommitted
autofs: dont trigger mount if it cant succeed
If a mount namespace contains autofs mounts, and they are propagation private, and there is no namespace specific automount daemon to handle possible automounting then attempted path resolution will loop until MAXSYMLINKS is reached before failing causing quite a bit of noise in the log. Add a check for this in autofs ->d_automount() so that the VFS can immediately return an error in this case. Since the mount is propagation private an EPERM return seems most appropriate. Suggested by: Christian Brauner <brauner@kernel.org> Signed-off-by: Ian Kent <raven@themaw.net> Link: https://patch.msgid.link/20251118024631.10854-2-raven@themaw.net Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 3a86608 commit 922a6f3

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
@@ -5150,6 +5150,12 @@ static u64 mnt_to_propagation_flags(struct mount *m)
51505150
return propagation;
51515151
}
51525152

5153+
u64 vfsmount_to_propagation_flags(struct vfsmount *mnt)
5154+
{
5155+
return mnt_to_propagation_flags(real_mount(mnt));
5156+
}
5157+
EXPORT_SYMBOL_GPL(vfsmount_to_propagation_flags);
5158+
51535159
static void statmount_sb_basic(struct kstatmount *s)
51545160
{
51555161
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
@@ -3269,6 +3269,7 @@ extern struct file * open_exec(const char *);
32693269
/* fs/dcache.c -- generic fs support functions */
32703270
extern bool is_subdir(struct dentry *, struct dentry *);
32713271
extern bool path_is_under(const struct path *, const struct path *);
3272+
u64 vfsmount_to_propagation_flags(struct vfsmount *mnt);
32723273

32733274
extern char *file_path(struct file *, char *, int);
32743275

0 commit comments

Comments
 (0)