From patchwork Fri Jun 29 18:58:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1133151 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 05F0FDFFEB for ; Fri, 29 Jun 2012 18:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932806Ab2F2S6e (ORCPT ); Fri, 29 Jun 2012 14:58:34 -0400 Received: from mail-gg0-f174.google.com ([209.85.161.174]:45936 "EHLO mail-gg0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932794Ab2F2S6b (ORCPT ); Fri, 29 Jun 2012 14:58:31 -0400 Received: by mail-gg0-f174.google.com with SMTP id u4so3043915ggl.19 for ; Fri, 29 Jun 2012 11:58:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=Krmsfxb2l30up9MMzyi0ZwSU9a3PUXF/hE9oS77SHOA=; b=je/Z3bu4EpEIjGkWLfu9y2An2mj3zdjZ0kTvV735zgEhhqwcCMjbyziXYW49sjH1Ms iJLJdn5b9qAxyxTEs6JRDNMg5/I8si4JmGqHzEBHlTOJPBH2vTQ+J2K3FnAmLVlPtlqZ wiYGkEjmi3nYcBwomvOjh6uoGxGB2c8hSh202iQHYyIuGav8JYpwt6o0Z2EB3b3x7NFg e+F05wx4xZYhzMEwafeptPFiHERumYyFwYXaYK2ytxDCQdk0o0UVTVDtlBGe/T9N506D /5ZIV9WNIuW/yvCVS8QLt2wmcmOwJ6SUnEDb5noS7L3+JgXviGvliYuw5ijZOf7poho3 tZxQ== Received: by 10.236.152.97 with SMTP id c61mr4523960yhk.130.1340996311423; Fri, 29 Jun 2012 11:58:31 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-076-182-054-194.nc.res.rr.com. [76.182.54.194]) by mx.google.com with ESMTPS id l13sm3936309ann.2.2012.06.29.11.58.30 (version=SSLv3 cipher=OTHER); Fri, 29 Jun 2012 11:58:30 -0700 (PDT) From: Jeff Layton To: viro@ZenIV.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, michael.brantley@deshaw.com, hch@infradead.org, miklos@szeredi.hu, pstaubach@exagrid.com Subject: [PATCH v3 17/17] vfs: have faccessat retry once on an ESTALE error Date: Fri, 29 Jun 2012 14:58:00 -0400 Message-Id: <1340996280-27123-18-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1340996280-27123-1-git-send-email-jlayton@redhat.com> References: <1340996280-27123-1-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQmLNo1LUPoA0+1M7CYnAAOv98LoZ9oNIgwAMBwMtTRu5ry+eNrp7yYLgDUy8YcSOHfinchf Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Signed-off-by: Jeff Layton --- fs/open.c | 70 ++++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 40 insertions(+), 30 deletions(-) diff --git a/fs/open.c b/fs/open.c index e813d90..2bdc531 100644 --- a/fs/open.c +++ b/fs/open.c @@ -313,6 +313,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode) struct path path; struct inode *inode; int res; + unsigned int lookup_flags = LOOKUP_FOLLOW; + unsigned int try = 0; + char *name; if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */ return -EINVAL; @@ -334,44 +337,51 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode) override_cred->cap_permitted; } + name = getname_flags(filename, lookup_flags, NULL); + if (IS_ERR(name)) + return PTR_ERR(name); + old_cred = override_creds(override_cred); - res = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path); - if (res) - goto out; + do { + res = kern_path_at(dfd, name, lookup_flags, &path); + if (res) + break; - inode = path.dentry->d_inode; + inode = path.dentry->d_inode; - if ((mode & MAY_EXEC) && S_ISREG(inode->i_mode)) { + if ((mode & MAY_EXEC) && S_ISREG(inode->i_mode)) { + /* + * MAY_EXEC on regular files is denied if the fs is + * mounted with the "noexec" flag. + */ + res = -EACCES; + if (path.mnt->mnt_flags & MNT_NOEXEC) + goto out_path_release; + } + + res = inode_permission(inode, mode | MAY_ACCESS); + /* SuS v2 requires we report a read only fs too */ + if (res || !(mode & S_IWOTH) || special_file(inode->i_mode)) + goto out_path_release; /* - * MAY_EXEC on regular files is denied if the fs is mounted - * with the "noexec" flag. + * This is a rare case where using __mnt_is_readonly() + * is OK without a mnt_want/drop_write() pair. Since + * no actual write to the fs is performed here, we do + * not need to telegraph to that to anyone. + * + * By doing this, we accept that this access is + * inherently racy and know that the fs may change + * state before we even see this result. */ - res = -EACCES; - if (path.mnt->mnt_flags & MNT_NOEXEC) - goto out_path_release; - } - - res = inode_permission(inode, mode | MAY_ACCESS); - /* SuS v2 requires we report a read only fs too */ - if (res || !(mode & S_IWOTH) || special_file(inode->i_mode)) - goto out_path_release; - /* - * This is a rare case where using __mnt_is_readonly() - * is OK without a mnt_want/drop_write() pair. Since - * no actual write to the fs is performed here, we do - * not need to telegraph to that to anyone. - * - * By doing this, we accept that this access is - * inherently racy and know that the fs may change - * state before we even see this result. - */ - if (__mnt_is_readonly(path.mnt)) - res = -EROFS; + if (__mnt_is_readonly(path.mnt)) + res = -EROFS; out_path_release: - path_put(&path); -out: + path_put(&path); + lookup_flags |= LOOKUP_REVAL; + } while (retry_estale(res, try++)); + putname(name); revert_creds(old_cred); put_cred(override_cred); return res;