From patchwork Thu Jul 7 05:53:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Drokin X-Patchwork-Id: 9217823 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 5A3DA607D9 for ; Thu, 7 Jul 2016 05:55:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CE6C2870C for ; Thu, 7 Jul 2016 05:55:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41DA828711; Thu, 7 Jul 2016 05:55: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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 CE9BD2870C for ; Thu, 7 Jul 2016 05:55:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750993AbcGGFzA (ORCPT ); Thu, 7 Jul 2016 01:55:00 -0400 Received: from linuxhacker.ru ([217.76.32.60]:58982 "EHLO fiona.linuxhacker.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751278AbcGGFy7 (ORCPT ); Thu, 7 Jul 2016 01:54:59 -0400 Received: from intelbox2.localnet (c-73-190-129-164.hsd1.tn.comcast.net [73.190.129.164]) (authenticated bits=0) by fiona.linuxhacker.ru (8.15.2/8.14.7) with ESMTPSA id u675shXY3551205 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 7 Jul 2016 08:54:48 +0300 From: Oleg Drokin To: Trond Myklebust , Jeff Layton , Al Viro Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, Oleg Drokin Subject: [PATCH 1/2] nfs: Fix spurios EPERM when mkdir of existing dentry Date: Thu, 7 Jul 2016 01:53:46 -0400 Message-Id: <1467870827-2959489-2-git-send-email-green@linuxhacker.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467870827-2959489-1-git-send-email-green@linuxhacker.ru> References: <1467870827-2959489-1-git-send-email-green@linuxhacker.ru> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It's great when we can shave an extra RPC, but not at the expense of correctness. We should not return EPERM (from vfs_create/mknod/mkdir) if the name already exists, even if we have no write access in parent. Since the check in nfs_permission is clearly not enough to stave off this, just throw in the extra READ access to actually go through. Signed-off-by: Oleg Drokin --- fs/nfs/dir.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index d8015a0..8c7835b 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1383,8 +1383,10 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in /* * If we're doing an exclusive create, optimize away the lookup * but don't hash the dentry. + * This optimization only works if we can write in the parent. */ - if (nfs_is_exclusive_create(dir, flags)) + if (nfs_is_exclusive_create(dir, flags) && + (inode_permission(dir, MAY_WRITE | MAY_READ | MAY_EXEC) == 0)) return NULL; res = ERR_PTR(-ENOMEM);