From: Ian Kent Subject: [PATCH 6/8] autofs: validate protocol version Date: Fri, 22 Sep 2023 12:12:13 +0800 Message-ID: <20230922041215.13675-7-raven@themaw.net> References: <20230922041215.13675-1-raven@themaw.net> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=themaw.net; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1695355978; x= 1695442378; bh=1rBf/tENa8Po/M99DgSqwjUd7A6nMFydxVLGoW1DBxw=; b=m Zr0GwKdhkpe1LLNAYPe/pVq2UTvLZ0nFT4U5r4Rkk8bcpkT3T+aYfSEnMrk008uQ PLanhuWeVexXiwIzYYEpL9mQk0alBM6Y38DxJyGeisbJVsWYdA4FNqAQ9SqdM3Rb BDXnL6abA37CcV0xLnUnNZI3vcYV4pmvzWnBvGOwcyi5qKlh5whKhRMYZEGUMMXI TEz/cwbwvwN4gFvE1RLYR2j2vO5McwXkhifYpqJIm70+jgnKoecpNe2gIuCSCxnt xjhgM3yZ0cPJHvAQzzuzh/zgsevzGLuJcwSpVzBtDHrOFABM+yXKsMgMTukVubjQ dh3u6ZyF2FuShML9Ns2lQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1695355978; x= 1695442378; bh=1rBf/tENa8Po/M99DgSqwjUd7A6nMFydxVLGoW1DBxw=; b=L Cj7AFu6VB8QYslobSLTvwCkrvIZn6n4zN60yexHUeBwRJcTn/Cf2hU/9M/k2/heD iw3mM/gsCFV8R+N85xcR47mbtU4lwe38WyDcyCLIdLnH/UVzh3w58Kuvs4EDAPAh f9t0wM3lDIiZ7TV5sAHi++UP308NgjqknXOEbdjZfNUI0GutCRFHXcFs7oG/WzGv TkE1VLhnz4O/ETOD0YD02x94Nzxg+RZylN+blTowT67Z6kOkvO/RyjYqpWIlAzGb YtfLbfABQcLyfZlZdFLsDv9ZDQldAqh+u905kGMlHMfTFsC1Svoe3r268mO2Z0QV rAXZpurAlvt1zck2HuNlw== In-Reply-To: <20230922041215.13675-1-raven@themaw.net> List-ID: Content-Type: text/plain; charset="us-ascii" To: Al Viro , Christian Brauner Cc: autofs mailing list , linux-fsdevel , Kernel Mailing List , Bill O'Donnell , Miklos Szeredi , David Howells , Ian Kent Move the protocol parameter validation into a seperate function. Signed-off-by: Ian Kent --- fs/autofs/inode.c | 38 +++++++++++++++++++++++--------------- 1 file 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); -- 2.41.0