Skip to content

Commit 546694b

Browse files
raven-aubrauner
authored andcommitted
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>
1 parent bc69fdd commit 546694b

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

fs/autofs/inode.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,33 @@ static const match_table_t tokens = {
129129
{Opt_err, NULL}
130130
};
131131

132+
static int autofs_parse_fd(struct autofs_sb_info *sbi, int fd)
133+
{
134+
struct file *pipe;
135+
int ret;
136+
137+
pipe = fget(fd);
138+
if (!pipe) {
139+
pr_err("could not open pipe file descriptor\n");
140+
return -EBADF;
141+
}
142+
143+
ret = autofs_check_pipe(pipe);
144+
if (ret < 0) {
145+
pr_err("Invalid/unusable pipe\n");
146+
fput(pipe);
147+
return -EBADF;
148+
}
149+
150+
if (sbi->pipe)
151+
fput(sbi->pipe);
152+
153+
sbi->pipefd = fd;
154+
sbi->pipe = pipe;
155+
156+
return 0;
157+
}
158+
132159
static int parse_options(char *options,
133160
struct inode *root, int *pgrp, bool *pgrp_set,
134161
struct autofs_sb_info *sbi)
@@ -139,6 +166,7 @@ static int parse_options(char *options,
139166
int pipefd = -1;
140167
kuid_t uid;
141168
kgid_t gid;
169+
int ret;
142170

143171
root->i_uid = current_uid();
144172
root->i_gid = current_gid();
@@ -162,7 +190,9 @@ static int parse_options(char *options,
162190
case Opt_fd:
163191
if (match_int(args, &pipefd))
164192
return 1;
165-
sbi->pipefd = pipefd;
193+
ret = autofs_parse_fd(sbi, pipefd);
194+
if (ret)
195+
return 1;
166196
break;
167197
case Opt_uid:
168198
if (match_int(args, &option))
@@ -222,7 +252,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
222252
{
223253
struct inode *root_inode;
224254
struct dentry *root;
225-
struct file *pipe;
226255
struct autofs_sb_info *sbi;
227256
struct autofs_info *ino;
228257
int pgrp = 0;
@@ -275,7 +304,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
275304
ret = -ENOMEM;
276305
goto fail_ino;
277306
}
278-
pipe = NULL;
279307

280308
root->d_fsdata = ino;
281309

@@ -321,16 +349,7 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
321349

322350
pr_debug("pipe fd = %d, pgrp = %u\n",
323351
sbi->pipefd, pid_nr(sbi->oz_pgrp));
324-
pipe = fget(sbi->pipefd);
325352

326-
if (!pipe) {
327-
pr_err("could not open pipe file descriptor\n");
328-
goto fail_put_pid;
329-
}
330-
ret = autofs_prepare_pipe(pipe);
331-
if (ret < 0)
332-
goto fail_fput;
333-
sbi->pipe = pipe;
334353
sbi->flags &= ~AUTOFS_SBI_CATATONIC;
335354

336355
/*
@@ -342,11 +361,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
342361
/*
343362
* Failure ... clean up.
344363
*/
345-
fail_fput:
346-
pr_err("pipe file descriptor does not contain proper ops\n");
347-
fput(pipe);
348-
fail_put_pid:
349-
put_pid(sbi->oz_pgrp);
350364
fail_dput:
351365
dput(root);
352366
goto fail_free;

0 commit comments

Comments
 (0)