summaryrefslogtreecommitdiff
path: root/fs/autofs
diff options
context:
space:
mode:
authorIan Kent <raven@themaw.net>2023-09-22 07:12:09 +0300
committerChristian Brauner <brauner@kernel.org>2023-09-22 11:14:58 +0300
commit546694b8f65807427a0104154abd8cdc633b36e3 (patch)
tree7ee63479f3b432e8bc626e21e3d360d35998cc0b /fs/autofs
parentbc69fdde0ae1aff595590d802b6ef39114f2b260 (diff)
downloadlinux-546694b8f65807427a0104154abd8cdc633b36e3.tar.xz
autofs: add autofs_parse_fd()
Factor out the fd mount option handling. Signed-off-by: Ian Kent <raven@themaw.net> Reviewed-by: Bill O'Donnell <bodonnel@redhat.com> Message-Id: <20230922041215.13675-3-raven@themaw.net> Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'fs/autofs')
-rw-r--r--fs/autofs/inode.c48
1 files changed, 31 insertions, 17 deletions
diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c
index 2b49662ed237..e279e275b0a5 100644
--- a/fs/autofs/inode.c
+++ b/fs/autofs/inode.c
@@ -129,6 +129,33 @@ static const match_table_t tokens = {
{Opt_err, NULL}
};
+static int autofs_parse_fd(struct autofs_sb_info *sbi, int fd)
+{
+ struct file *pipe;
+ int ret;
+
+ pipe = fget(fd);
+ if (!pipe) {
+ pr_err("could not open pipe file descriptor\n");
+ return -EBADF;
+ }
+
+ ret = autofs_check_pipe(pipe);
+ if (ret < 0) {
+ pr_err("Invalid/unusable pipe\n");
+ fput(pipe);
+ return -EBADF;
+ }
+
+ if (sbi->pipe)
+ fput(sbi->pipe);
+
+ sbi->pipefd = fd;
+ sbi->pipe = pipe;
+
+ return 0;
+}
+
static int parse_options(char *options,
struct inode *root, int *pgrp, bool *pgrp_set,
struct autofs_sb_info *sbi)
@@ -139,6 +166,7 @@ static int parse_options(char *options,
int pipefd = -1;
kuid_t uid;
kgid_t gid;
+ int ret;
root->i_uid = current_uid();
root->i_gid = current_gid();
@@ -162,7 +190,9 @@ static int parse_options(char *options,
case Opt_fd:
if (match_int(args, &pipefd))
return 1;
- sbi->pipefd = pipefd;
+ ret = autofs_parse_fd(sbi, pipefd);
+ if (ret)
+ return 1;
break;
case Opt_uid:
if (match_int(args, &option))
@@ -222,7 +252,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
{
struct inode *root_inode;
struct dentry *root;
- struct file *pipe;
struct autofs_sb_info *sbi;
struct autofs_info *ino;
int pgrp = 0;
@@ -275,7 +304,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
ret = -ENOMEM;
goto fail_ino;
}
- pipe = NULL;
root->d_fsdata = ino;
@@ -321,16 +349,7 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
pr_debug("pipe fd = %d, pgrp = %u\n",
sbi->pipefd, pid_nr(sbi->oz_pgrp));
- pipe = fget(sbi->pipefd);
- if (!pipe) {
- pr_err("could not open pipe file descriptor\n");
- goto fail_put_pid;
- }
- ret = autofs_prepare_pipe(pipe);
- if (ret < 0)
- goto fail_fput;
- sbi->pipe = pipe;
sbi->flags &= ~AUTOFS_SBI_CATATONIC;
/*
@@ -342,11 +361,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
/*
* Failure ... clean up.
*/
-fail_fput:
- pr_err("pipe file descriptor does not contain proper ops\n");
- fput(pipe);
-fail_put_pid:
- put_pid(sbi->oz_pgrp);
fail_dput:
dput(root);
goto fail_free;