summaryrefslogtreecommitdiffstats
path: root/fs/autofs
diff options
context:
space:
mode:
authorIan Kent <raven@themaw.net>2023-09-22 12:12:13 +0800
committerChristian Brauner <brauner@kernel.org>2023-09-22 10:14:59 +0200
commit1f50012d9c63c690f25956239bd25d10236405f8 (patch)
tree00b4a7823463253caf20a0eb05fae0371e445114 /fs/autofs
parent9b2731666d1d46bb476df6e4f2ec9a776ad7a507 (diff)
downloadlinux-1f50012d9c63c690f25956239bd25d10236405f8.tar.gz
linux-1f50012d9c63c690f25956239bd25d10236405f8.tar.bz2
linux-1f50012d9c63c690f25956239bd25d10236405f8.zip
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>
Diffstat (limited to 'fs/autofs')
-rw-r--r--fs/autofs/inode.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c
index 5e061ce3ab8d..e2026e063d8c 100644
--- a/fs/autofs/inode.c
+++ b/fs/autofs/inode.c
@@ -287,6 +287,28 @@ static struct autofs_sb_info *autofs_alloc_sbi(void)
return sbi;
}
+static int autofs_validate_protocol(struct autofs_sb_info *sbi)
+{
+ /* Test versions first */
+ if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
+ sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
+ pr_err("kernel does not match daemon version "
+ "daemon (%d, %d) kernel (%d, %d)\n",
+ sbi->min_proto, sbi->max_proto,
+ AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
+ return -EINVAL;
+ }
+
+ /* Establish highest kernel protocol version */
+ if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
+ sbi->version = AUTOFS_MAX_PROTO_VERSION;
+ else
+ sbi->version = sbi->max_proto;
+ sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
+
+ return 0;
+}
+
int autofs_fill_super(struct super_block *s, void *data, int silent)
{
struct inode *root_inode;
@@ -335,22 +357,8 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
goto fail_dput;
}
- /* Test versions first */
- if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
- sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
- pr_err("kernel does not match daemon version "
- "daemon (%d, %d) kernel (%d, %d)\n",
- sbi->min_proto, sbi->max_proto,
- AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
+ if (autofs_validate_protocol(sbi))
goto fail_dput;
- }
-
- /* Establish highest kernel protocol version */
- if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
- sbi->version = AUTOFS_MAX_PROTO_VERSION;
- else
- sbi->version = sbi->max_proto;
- sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
if (pgrp_set) {
sbi->oz_pgrp = find_get_pid(pgrp);