Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2649653rdb; Fri, 22 Sep 2023 05:07:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IETcFqCBs9axHQP39dh4Ayir/jpiBqCVXimtpwxzoddVAnn7lEfqn9L8NxCZuqD0zy0o+x3 X-Received: by 2002:a05:6a20:7348:b0:15b:c800:48af with SMTP id v8-20020a056a20734800b0015bc80048afmr8805124pzc.23.1695384456881; Fri, 22 Sep 2023 05:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695384456; cv=none; d=google.com; s=arc-20160816; b=zd/Wwep8SnPDJ8tO6Rf2GmL5odH8ZVk28Ccv8sD7FcUpx6bJy5EmD2+U1VwwPENgkm mctPaCZB0j0BukKnXwsmOmyKBlfX3z3wVNB5vMvoMcyO0/E9yt+SkNP3YSaDo9YMwYz5 fGRbsyL7U5gS3Fzre/McPnq76ofAzE4j4BzDO4tXgjq6FCKDLsIHn7Kmty71DGecfyHa 1oQZVSzoUdpj3cigThs7sixTlkZ37owxagFgIeaZlRfKTpt49p+hQ0G0+IbQQAYXTYWF eUDfqTnzpyR9PWeQH+jdsQcuOgWFq0UTZdUw2CEnR4cDh6fAvzUzSBBxLQqHNI04sj9T GeRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2NRm9vxw9TCpKYGQruTUw6CjtcmwCcHUFFI59OOIEdk=; fh=qM8Rte8O6Vf1Y331HKtY/EJtdYfopYd+QVHDrN7Qnn8=; b=gWvB2TkbcQ1nt6mdGQMDJhrvW9N0KHfnlmjaGIq+VmH2ZD1wZVwkMcUot6GI6sxEnG OHmQmLbNhpj6ZrKxs7c9AmUTeb4CJw3R5zh1jbqVXRfufGqF7aatKHw8BD0fjuQD2GXv WUG+JmCa+CjHyRvy2nNT/a7SOLrFbuiBBtE0Y0N7M5RcvWWYg5rpGhikMHDhz+LKIkv0 Nz7D8bxAbZ6C9llhH7aKT7bMMRqzukB/3Wc31Pgh/dSl+Oxhbq8z6y5Vais4vsooS22T jktNEl167CBhQFInijoQnKgUWxwUaeM90oV+YaFdaoeRCjRV1qjN89+o7xWR8PpaYNel KzGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fbA9AsP6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id e21-20020a656895000000b0056da0ae25a0si3593746pgt.441.2023.09.22.05.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 05:07:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fbA9AsP6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 8A0F782E078A; Fri, 22 Sep 2023 04:59:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233835AbjIVL7q (ORCPT + 99 others); Fri, 22 Sep 2023 07:59:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229644AbjIVL7j (ORCPT ); Fri, 22 Sep 2023 07:59:39 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A24E0FB; Fri, 22 Sep 2023 04:59:33 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 733CFC433C7; Fri, 22 Sep 2023 11:59:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695383973; bh=ORzIDixyYNN/jJb/Sxa5K2h12YMiO0mDofirvWtUYDU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fbA9AsP6p4xsjJaKQy9RAcs3SFDkJUxohUtLbQfIivmE20XLy+RMcYpcwNxR+Y33d mqGSO32J30z4pjw1IUvNWnfU27xq7uksjaYhXUpPOzTrlR8fj/8lcNE5GBZZHyX7FU IlNnm93Nhzzs2RpERpkh0yqFoR/fGKcvMtM1/0MRy3LDIvcf4ikJIq4xpiEiCKEzBE Rk9bUkaKnEhyaCzWgSKEEHX5OHCLPshTO8ueyaJAnF5VLtlDn0euzEvuOvhFaEEdJs 9oGHb78rRcxDQa57tYaUDigbJtw8Dqg+8QptH5vNcKT+bSHL8RP+XPGV2McBFYXCDC KbjE0uN4eFWnA== Date: Fri, 22 Sep 2023 13:59:28 +0200 From: Christian Brauner To: Ian Kent Cc: Al Viro , autofs mailing list , linux-fsdevel , Kernel Mailing List , Bill O'Donnell , Miklos Szeredi , David Howells Subject: Re: [PATCH 7/8] autofs: convert autofs to use the new mount api Message-ID: <20230922-vorbringen-spaghetti-946729122076@brauner> References: <20230922041215.13675-1-raven@themaw.net> <20230922041215.13675-8-raven@themaw.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230922041215.13675-8-raven@themaw.net> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Fri, 22 Sep 2023 04:59:46 -0700 (PDT) > + fsparam_fd ("fd", Opt_fd), > +/* > + * Open the fd. We do it here rather than in get_tree so that it's done in the > + * context of the system call that passed the data and not the one that > + * triggered the superblock creation, lest the fd gets reassigned. > + */ > +static int autofs_parse_fd(struct fs_context *fc, int fd) > { > + struct autofs_sb_info *sbi = fc->s_fs_info; > struct file *pipe; > int ret; > > pipe = fget(fd); > if (!pipe) { > - pr_err("could not open pipe file descriptor\n"); > + errorf(fc, "could not open pipe file descriptor"); > return -EBADF; > } > > ret = autofs_check_pipe(pipe); > if (ret < 0) { > - pr_err("Invalid/unusable pipe\n"); > + errorf(fc, "Invalid/unusable pipe"); > fput(pipe); > return -EBADF; > } > +static int autofs_parse_param(struct fs_context *fc, struct fs_parameter *param) > { > + return autofs_parse_fd(fc, result.int_32); Mah, so there's a difference between the new and the old mount api that we should probably hide on the VFS level for fsparam_fd. Basically, if you're coming through the new mount api via fsconfig(FSCONFIG_SET_FD, fd) then the vfs will have done param->file = fget(fd) for you already so there's no need to call fget() again. We can just take ownership of the reference that the vfs took for us. But if we're coming in through the old mount api then we need to call fget. There's nothing wrong with your code but it doesn't take advantage of the new mount api which would be unfortunate. So I folded a small extension into this see [1]. There's an unrelated bug in fs_param_is_fd() that I'm also fixing see [2]. I've tested both changes with the old and new mount api. [1]: diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c index 3f2dfed428f9..0477bce7d277 100644 --- a/fs/autofs/inode.c +++ b/fs/autofs/inode.c @@ -150,13 +150,20 @@ struct autofs_fs_context { * context of the system call that passed the data and not the one that * triggered the superblock creation, lest the fd gets reassigned. */ -static int autofs_parse_fd(struct fs_context *fc, int fd) +static int autofs_parse_fd(struct fs_context *fc, struct autofs_sb_info *sbi, + struct fs_parameter *param, + struct fs_parse_result *result) { - struct autofs_sb_info *sbi = fc->s_fs_info; struct file *pipe; int ret; - pipe = fget(fd); + if (param->type == fs_value_is_file) { + /* came through the new api */ + pipe = param->file; + param->file = NULL; + } else { + pipe = fget(result->uint_32); + } if (!pipe) { errorf(fc, "could not open pipe file descriptor"); return -EBADF; @@ -165,14 +172,15 @@ static int autofs_parse_fd(struct fs_context *fc, int fd) ret = autofs_check_pipe(pipe); if (ret < 0) { errorf(fc, "Invalid/unusable pipe"); - fput(pipe); + if (param->type != fs_value_is_file) + fput(pipe); return -EBADF; } if (sbi->pipe) fput(sbi->pipe); - sbi->pipefd = fd; + sbi->pipefd = result->uint_32; sbi->pipe = pipe; return 0; [2]: From 2f9171200505c82e744a235c85377e36ed190109 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 22 Sep 2023 13:49:05 +0200 Subject: [PATCH] fsconfig: ensure that dirfd is set to aux The code in fs_param_is_fd() expects param->dirfd to be set to the fd that was used to set param->file to initialize result->uint_32. So make sure it's set so users like autofs using FSCONFIG_SET_FD with the new mount api can rely on this to be set to the correct value. Signed-off-by: Christian Brauner --- fs/fsopen.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/fsopen.c b/fs/fsopen.c index ce03f6521c88..6593ae518115 100644 --- a/fs/fsopen.c +++ b/fs/fsopen.c @@ -465,6 +465,7 @@ SYSCALL_DEFINE5(fsconfig, param.file = fget(aux); if (!param.file) goto out_key; + param.dirfd = aux; break; default: break; -- 2.34.1