From patchwork Tue Aug 8 04:26:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 9886521 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BD47660352 for ; Tue, 8 Aug 2017 04:36:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF2022846D for ; Tue, 8 Aug 2017 04:36:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3082286FF; Tue, 8 Aug 2017 04:36:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5678D2846D for ; Tue, 8 Aug 2017 04:36:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751982AbdHHEgN (ORCPT ); Tue, 8 Aug 2017 00:36:13 -0400 Received: from icp-osb-irony-out3.external.iinet.net.au ([203.59.1.153]:63891 "EHLO icp-osb-irony-out3.external.iinet.net.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751971AbdHHEgM (ORCPT ); Tue, 8 Aug 2017 00:36:12 -0400 X-Greylist: delayed 555 seconds by postgrey-1.27 at vger.kernel.org; Tue, 08 Aug 2017 00:36:11 EDT X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2BHBgD0PIlZ/3GhBzpcHQEFAQsBg1qBeJ4WOQEBAQEBBoEIM5YEghIchSuEXkEWAQIBAQEBAQEBayiFQgRSKAEMAhgOAkkWE4oiDKwRgWw6IgKLb4ELgh2CAoEFgmCKOgwxgmEFkHSBDY4NiyWJEItXhnZIlUElATGBClMvCoUQAYJfMzaJZAEBAQ X-IPAS-Result: A2BHBgD0PIlZ/3GhBzpcHQEFAQsBg1qBeJ4WOQEBAQEBBoEIM5YEghIchSuEXkEWAQIBAQEBAQEBayiFQgRSKAEMAhgOAkkWE4oiDKwRgWw6IgKLb4ELgh2CAoEFgmCKOgwxgmEFkHSBDY4NiyWJEItXhnZIlUElATGBClMvCoUQAYJfMzaJZAEBAQ X-IronPort-AV: E=Sophos;i="5.41,341,1498492800"; d="scan'208";a="411532749" Received: from unknown (HELO pluto.themaw.net) ([58.7.161.113]) by icp-osb-irony-out3.iinet.net.au with ESMTP; 08 Aug 2017 12:26:53 +0800 Subject: [PATCH 1/3] autofs - fix AT_NO_AUTOMOUNT not being honored From: Ian Kent To: Andrew Morton Cc: autofs mailing list , Ondrej Holy , Colin Walters , Kernel Mailing List , David Howells , linux-fsdevel Date: Tue, 08 Aug 2017 12:26:52 +0800 Message-ID: <150216641255.11652.4204561328197919771.stgit@pluto.themaw.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The fstatat(2) and statx() calls can pass the flag AT_NO_AUTOMOUNT which is meant to clear the LOOKUP_AUTOMOUNT flag and prevent triggering of an automount by the call. But this flag is unconditionally cleared for all stat family system calls except statx(). stat family system calls have always triggered mount requests for the negative dentry case in follow_automount() which is intended but prevents the fstatat(2) and statx() AT_NO_AUTOMOUNT case from being handled. In order to handle the AT_NO_AUTOMOUNT for both system calls the negative dentry case in follow_automount() needs to be changed to return ENOENT when the LOOKUP_AUTOMOUNT flag is clear (and the other required flags are clear). AFAICT this change doesn't have any noticable side effects and may, in some use cases (although I didn't see it in testing) prevent unnecessary callbacks to the automount daemon. It's also possible that a stat family call has been made with a path that is in the process of being mounted by some other process. But stat family calls should return the automount state of the path as it is "now" so it shouldn't wait for mount completion. This is the same semantic as the positive dentry case already handled. Signed-off-by: Ian Kent Cc: David Howells Cc: Colin Walters Cc: Ondrej Holy --- fs/namei.c | 15 ++++++++++++--- include/linux/fs.h | 3 +-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index ddb6a7c2b3d4..1180f9c58093 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1129,9 +1129,18 @@ static int follow_automount(struct path *path, struct nameidata *nd, * of the daemon to instantiate them before they can be used. */ if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY | - LOOKUP_OPEN | LOOKUP_CREATE | LOOKUP_AUTOMOUNT)) && - path->dentry->d_inode) - return -EISDIR; + LOOKUP_OPEN | LOOKUP_CREATE | + LOOKUP_AUTOMOUNT))) { + /* Positive dentry that isn't meant to trigger an + * automount, EISDIR will allow it to be used, + * otherwise there's no mount here "now" so return + * ENOENT. + */ + if (path->dentry->d_inode) + return -EISDIR; + else + return -ENOENT; + } if (path->dentry->d_sb->s_user_ns != &init_user_ns) return -EACCES; diff --git a/include/linux/fs.h b/include/linux/fs.h index 6e1fd5d21248..37c96f52e48e 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3022,8 +3022,7 @@ static inline int vfs_lstat(const char __user *name, struct kstat *stat) static inline int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, int flags) { - return vfs_statx(dfd, filename, flags | AT_NO_AUTOMOUNT, - stat, STATX_BASIC_STATS); + return vfs_statx(dfd, filename, flags, stat, STATX_BASIC_STATS); } static inline int vfs_fstat(int fd, struct kstat *stat) {