From patchwork Thu Sep 21 07:03:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 142840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5071076vqi; Thu, 21 Sep 2023 12:02:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEh4UXXDl7NjTY59J38h8OK8Y90oU6fdv3Yo0fcjIxW1ZiVe5DMZD0kV3cVliv6GRssJeG X-Received: by 2002:a17:902:c211:b0:1c5:64aa:b97a with SMTP id 17-20020a170902c21100b001c564aab97amr5645922pll.38.1695322920974; Thu, 21 Sep 2023 12:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695322920; cv=none; d=google.com; s=arc-20160816; b=WovFBKpkUaGEwc9HcrHR0dBFXkYIQiDoLPzIx6QyEOSbJYvzuZfn80SqOoYJspNnK9 KJYcbXgu3J7ACtJhlDVYBjtemLnV6/QQMI6aVyrHmqUGg8QQxZeEZrBp1sUmCpuzP7oT OH0RMnION1y9uuVSCsHQ1MFqgGGnq6PzW4f++PRse5gSkbaWotQNl8e9gH7i1MoE68Vb uY3jWA3XjqqSejPdRCtyPtPNa2CnSMVW0rI6zramEBYAKpQlOpAtMrW7jWmPREPhPs5/ BnBNz5iRpfsak3yY2Vjhjzh5fqhDe6MKJKFWGoyPttfAfa4Ky2uT1+jw5lAunDCeBlt+ 4pKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject; bh=TilKPE80wE2QqhUWBtHW/6QHdOup1I94px7hcoTlf7A=; fh=Vd00GRLUNDtgftEBzBaifz0ZIGFRdtawsvTRUw5VTu8=; b=CyscepAOQGVTg13eGvgDhOcxFX8QDn2G20ka33Zx62BcLV+We4Be0Lq6UCCFnjE3ff Hwd2GvhCxzB7O2bmIYN3meESQd72LckriffyEWsAvMjxvOZaHnF3/Mfe7+GOGbxCB87g PdwLcSH4E37IIsJ+vkBA1BTdU6wVsSejrwZzGaazHWL4qqe3uuUotUJbj3UOQdi5hcwC WP86/fqxTarQ0nUpRRNX63AMQRmIZGj9AkH3PbrsK6Y1sUA6cbPCXYuw2FfipumirM2q thw06RigpLyEoH+Hlu4yZm+JQMob3xB/0BAlnOdMnavUinAFpX1jUDe9GqIV21Fir5t4 8q1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id ju22-20020a170903429600b001c5a8815fd7si1917769plb.150.2023.09.21.12.02.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 12:02:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 964F080427AF; Thu, 21 Sep 2023 11:57:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230491AbjIUS5Y (ORCPT + 28 others); Thu, 21 Sep 2023 14:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbjIUS5A (ORCPT ); Thu, 21 Sep 2023 14:57:00 -0400 Received: from smtp01.aussiebb.com.au (smtp01.aussiebb.com.au [IPv6:2403:5800:3:25::1001]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F1258DEFE; Thu, 21 Sep 2023 11:51:05 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id 70527100580; Thu, 21 Sep 2023 17:03:40 +1000 (AEST) X-Virus-Scanned: Debian amavisd-new at smtp01.aussiebb.com.au Received: from smtp01.aussiebb.com.au ([127.0.0.1]) by localhost (smtp01.aussiebb.com.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AAGMtsSZ3NHu; Thu, 21 Sep 2023 17:03:40 +1000 (AEST) Received: by smtp01.aussiebb.com.au (Postfix, from userid 116) id 67A5C10057F; Thu, 21 Sep 2023 17:03:40 +1000 (AEST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from donald.themaw.net (180-150-90-198.b4965a.per.nbn.aussiebb.net [180.150.90.198]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id 8AFA9100265; Thu, 21 Sep 2023 17:03:39 +1000 (AEST) Subject: [PATCH 2/8] autofs: add autofs_parse_fd() From: Ian Kent To: Al Viro , Christian Brauner Cc: autofs mailing list , linux-fsdevel , Kernel Mailing List , Bill O'Donnell , Miklos Szeredi , David Howells Date: Thu, 21 Sep 2023 15:03:39 +0800 Message-ID: <169527981914.27328.15182386732807940466.stgit@donald.themaw.net> In-Reply-To: <169527971702.27328.16272807830250040704.stgit@donald.themaw.net> References: <169527971702.27328.16272807830250040704.stgit@donald.themaw.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 11:57:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777674927133988056 X-GMAIL-MSGID: 1777674927133988056 Factor out the fd mount option handling. Signed-off-by: Ian Kent --- fs/autofs/inode.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c index 2b49662ed237..e279e275b0a5 100644 --- a/fs/autofs/inode.c +++ b/fs/autofs/inode.c @@ -129,6 +129,33 @@ static const match_table_t tokens = { {Opt_err, NULL} }; +static int autofs_parse_fd(struct autofs_sb_info *sbi, int fd) +{ + struct file *pipe; + int ret; + + pipe = fget(fd); + if (!pipe) { + pr_err("could not open pipe file descriptor\n"); + return -EBADF; + } + + ret = autofs_check_pipe(pipe); + if (ret < 0) { + pr_err("Invalid/unusable pipe\n"); + fput(pipe); + return -EBADF; + } + + if (sbi->pipe) + fput(sbi->pipe); + + sbi->pipefd = fd; + sbi->pipe = pipe; + + return 0; +} + static int parse_options(char *options, struct inode *root, int *pgrp, bool *pgrp_set, struct autofs_sb_info *sbi) @@ -139,6 +166,7 @@ static int parse_options(char *options, int pipefd = -1; kuid_t uid; kgid_t gid; + int ret; root->i_uid = current_uid(); root->i_gid = current_gid(); @@ -162,7 +190,9 @@ static int parse_options(char *options, case Opt_fd: if (match_int(args, &pipefd)) return 1; - sbi->pipefd = pipefd; + ret = autofs_parse_fd(sbi, pipefd); + if (ret) + return 1; break; case Opt_uid: if (match_int(args, &option)) @@ -222,7 +252,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) { struct inode *root_inode; struct dentry *root; - struct file *pipe; struct autofs_sb_info *sbi; struct autofs_info *ino; int pgrp = 0; @@ -275,7 +304,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) ret = -ENOMEM; goto fail_ino; } - pipe = NULL; root->d_fsdata = ino; @@ -321,16 +349,7 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) pr_debug("pipe fd = %d, pgrp = %u\n", sbi->pipefd, pid_nr(sbi->oz_pgrp)); - pipe = fget(sbi->pipefd); - if (!pipe) { - pr_err("could not open pipe file descriptor\n"); - goto fail_put_pid; - } - ret = autofs_prepare_pipe(pipe); - if (ret < 0) - goto fail_fput; - sbi->pipe = pipe; sbi->flags &= ~AUTOFS_SBI_CATATONIC; /* @@ -342,11 +361,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) /* * Failure ... clean up. */ -fail_fput: - pr_err("pipe file descriptor does not contain proper ops\n"); - fput(pipe); -fail_put_pid: - put_pid(sbi->oz_pgrp); fail_dput: dput(root); goto fail_free;