Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2230296rdb; Thu, 21 Sep 2023 12:12:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE71m0hoVRVWq5TLhADDWmqpiYUgLrggvNd+QgsuoGJqnSg+kLzKzQGmcA9T9emBdDvpSW/ X-Received: by 2002:a05:6a00:84e:b0:690:3abc:8043 with SMTP id q14-20020a056a00084e00b006903abc8043mr6883156pfk.8.1695323540905; Thu, 21 Sep 2023 12:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695323540; cv=none; d=google.com; s=arc-20160816; b=O041hZ2C9e3/zxEmEPMPMlZoWRO7BK+GHxY9J2o97m7YYwpnI+XoJyEG9d9F7EQfsg IDQMVQUZ2ap2LXjatned6yNN2ftcQU6I+Z0uVX2je7Pctwm733f37N/ma2PnHbsaPG6j Xln0pp5MbXXRYFN3DhtRkv4ucCBeJEvdVRZsEoCpkl3NFS8HTXy6svcfoNxgET6bppdF 6+TKHEmjRVntsbbdembo7nAAnKIAIEWEOIyqriDlKwxky0MGP6rqxauMVF+lyQiWe34I HMY8p7g7uii5g/s5+JVef3OAKMjr69xEYoDKaSCjTvMntea9Ec1LXqFc8NkMwq33e1Er o/DQ== 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:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id n49-20020a056a000d7100b0069102c864c5si1907748pfv.218.2023.09.21.12.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 12:12:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id E7FE1809C41A; Thu, 21 Sep 2023 11:57:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230488AbjIUS5X (ORCPT + 99 others); Thu, 21 Sep 2023 14:57:23 -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 morse.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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 11:57:35 -0700 (PDT) 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;