From patchwork Wed May 10 04:18:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 9719217 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 5DBB2601E7 for ; Wed, 10 May 2017 04:19:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DAD328552 for ; Wed, 10 May 2017 04:19:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DD6F28558; Wed, 10 May 2017 04:19:09 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 E115528552 for ; Wed, 10 May 2017 04:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751936AbdEJESy (ORCPT ); Wed, 10 May 2017 00:18:54 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:48977 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751901AbdEJESw (ORCPT ); Wed, 10 May 2017 00:18:52 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 543CA20A35; Wed, 10 May 2017 00:18:51 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute1.internal (MEProxy); Wed, 10 May 2017 00:18:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=themaw.net; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=S1F+XydPslgv0zFO/i gMr8MEBffMLSvxuyPJCJryMYA=; b=KpdZ68qgBFj3DEwES1ywX/kVBnqD1NSkDM iOdic4GtbfMGvXIKKiqtFI76tJzMmAcK8Tt8+5ZoGRVVDl/6SFTuhbf9xouMVpIL pFgD2RUrlS3hthS5doqW6UhXuVI5J84ZcZ0w2q25UIQIHT/jvhKCKk1dqY2jQjx9 i2G8NDejPLW7ptY1Z6Q08jHiCCqY1QvAMflsAwHh6TucSQS7Weor14eDAVcqQp7v /TCeaLk11LB+7dK46g0zU3PcHFwmjHNSd+3j/RbLucu2bjURPb74XaqYZnxxnGpP myeDbhthMw1BOGGiCZNZiLMdbxAH7em0Hj/tsa0WT1qH4OPMq4XQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=S1F+XydPslgv0zFO/igMr8MEBffMLSvxuyPJCJryMYA=; b=MY3Sh6yf D93JyVTbkOlPyyFUOrKHQkQ5CAdJPX1Kf0oCevEDQMZ+ndEOe6tpYiknij5CeBHg YjZQt0i6riXWg9EfYYwk+UyL25mvBlaNtsGRD7m8MCfAoN8jdJ28wcUadzxNp5dr 2Q5ByBKWpZDHhP8XQYbPxsbIK2PvPzBd7kkzS8iACh+ey1fikQdKE7A1KkWTc9ES hKI2JY3bn8YdM9KC/79p8Al6L68nQ45u7nrSxmwN+EGR7ozZAifxHuixxs+pJeFL 83rxsQjjMG5TlHYvHn2WLzsvAF+dxRGRU8IFJIh5qLEf5nGz3wZ3scq8UDyDqEwQ ObZf9igcTYqC0Q== X-ME-Sender: X-Sasl-enc: EiGf+ER2J8f06E2oyJ2Q65tQNGhpJpX+g4OTehI1rxeY 1494389930 Received: from pluto.themaw.net (220-253-147-189.dyn.iinet.net.au [220.253.147.189]) by mail.messagingengine.com (Postfix) with ESMTPA id B97987E86A; Wed, 10 May 2017 00:18:50 -0400 (EDT) Received: from pluto.themaw.net (localhost [127.0.0.1]) by pluto.themaw.net (Postfix) with ESMTP id 84287A00C2; Wed, 10 May 2017 12:18:48 +0800 (AWST) Subject: [PATCH 3/3] autofs - fix AT_NO_AUTOMOUNT not being honored From: Ian Kent To: Al Viro Cc: Colin Walters , Ondrej Holy , autofs mailing list , Kernel Mailing List , David Howells , linux-fsdevel Date: Wed, 10 May 2017 12:18:48 +0800 Message-ID: <149438992850.26550.14370272866390445786.stgit@pluto.themaw.net> In-Reply-To: <149438991819.26550.11290804420751932707.stgit@pluto.themaw.net> References: <149438991819.26550.11290804420751932707.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 Cc: stable@vger.kernel.org --- 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 7286f87..cd74838 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 26488b4..be09684 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2935,8 +2935,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) {