From patchwork Fri Sep 22 04:12:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 13394903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3E6AE7D0C2 for ; Fri, 22 Sep 2023 04:13:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230440AbjIVENp (ORCPT ); Fri, 22 Sep 2023 00:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230461AbjIVENX (ORCPT ); Fri, 22 Sep 2023 00:13:23 -0400 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90BA41A3; Thu, 21 Sep 2023 21:12:58 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 061345C0222; Fri, 22 Sep 2023 00:12:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 22 Sep 2023 00:12:58 -0400 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== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudekjedgjeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepkfgrnhcu mfgvnhhtuceorhgrvhgvnhesthhhvghmrgifrdhnvghtqeenucggtffrrghtthgvrhhnpe duleegueffgfehudeufedtffeiudfghfejgeehvdffgefgjeetvdfffeeihfdvveenucev lhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehrrghvvghnse hthhgvmhgrfidrnhgvth X-ME-Proxy: Feedback-ID: i31e841b0:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Sep 2023 00:12:53 -0400 (EDT) From: Ian Kent To: Al Viro , Christian Brauner Cc: autofs mailing list , linux-fsdevel , Kernel Mailing List , Bill O'Donnell , Miklos Szeredi , David Howells , 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> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230922041215.13675-1-raven@themaw.net> References: <20230922041215.13675-1-raven@themaw.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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);