Skip to content

Commit 1f50012

Browse files
raven-aubrauner
authored andcommitted
autofs: validate protocol version
Move the protocol parameter validation into a seperate function. Signed-off-by: Ian Kent <raven@themaw.net> Reviewed-by: Bill O'Donnell <bodonnel@redhat.com> Message-Id: <20230922041215.13675-7-raven@themaw.net> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 9b27316 commit 1f50012

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

fs/autofs/inode.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,28 @@ static struct autofs_sb_info *autofs_alloc_sbi(void)
287287
return sbi;
288288
}
289289

290+
static int autofs_validate_protocol(struct autofs_sb_info *sbi)
291+
{
292+
/* Test versions first */
293+
if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
294+
sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
295+
pr_err("kernel does not match daemon version "
296+
"daemon (%d, %d) kernel (%d, %d)\n",
297+
sbi->min_proto, sbi->max_proto,
298+
AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
299+
return -EINVAL;
300+
}
301+
302+
/* Establish highest kernel protocol version */
303+
if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
304+
sbi->version = AUTOFS_MAX_PROTO_VERSION;
305+
else
306+
sbi->version = sbi->max_proto;
307+
sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
308+
309+
return 0;
310+
}
311+
290312
int autofs_fill_super(struct super_block *s, void *data, int silent)
291313
{
292314
struct inode *root_inode;
@@ -335,22 +357,8 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
335357
goto fail_dput;
336358
}
337359

338-
/* Test versions first */
339-
if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
340-
sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
341-
pr_err("kernel does not match daemon version "
342-
"daemon (%d, %d) kernel (%d, %d)\n",
343-
sbi->min_proto, sbi->max_proto,
344-
AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
360+
if (autofs_validate_protocol(sbi))
345361
goto fail_dput;
346-
}
347-
348-
/* Establish highest kernel protocol version */
349-
if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
350-
sbi->version = AUTOFS_MAX_PROTO_VERSION;
351-
else
352-
sbi->version = sbi->max_proto;
353-
sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
354362

355363
if (pgrp_set) {
356364
sbi->oz_pgrp = find_get_pid(pgrp);

0 commit comments

Comments
 (0)