From patchwork Fri Sep 7 14:18:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1422911 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 55057DF283 for ; Fri, 7 Sep 2012 14:24:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760721Ab2IGOXf (ORCPT ); Fri, 7 Sep 2012 10:23:35 -0400 Received: from mail-vb0-f46.google.com ([209.85.212.46]:48299 "EHLO mail-vb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760725Ab2IGOS6 (ORCPT ); Fri, 7 Sep 2012 10:18:58 -0400 Received: by mail-vb0-f46.google.com with SMTP id ff1so3363912vbb.19 for ; Fri, 07 Sep 2012 07:18:58 -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=xah0OZk6C2HJv9FLraUL3ANaPJkdnSj+9A6pGL8v6cg=; b=VjLkSSLqbO1T2OXNpyL3Gm0/ugFmGHh/kkfoZXANIYsSfzGLltMCDmIgbzTAk7tmCt G+g5tgTi19jEPy220ortQ1WtWr51gr3KUB8ufjmd7UE3puW+hTR9o4EZlOw+uMTbSWCV UXqlsvW9K4vy+Ecka6Hb0NiQOCdg5FClK7Xufzql8e5djBLWNHKyGWyCCKiMK879UAKP R7EAlBH73RYhm/yIzXFS4pg9cQ46wfBlNpzfYp9FgOPYucL4BUA6VX33ObWXfkT+FX5X PzazpCK/LDT4cQZ5Jgi+N63ZAU7yLJd8QhVv2gJMldIMl+qTMw7qw/rV0xhP6XE/38vo Ouqw== Received: by 10.52.16.239 with SMTP id j15mr5904640vdd.7.1347027537582; Fri, 07 Sep 2012 07:18:57 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-069-134-145-027.nc.res.rr.com. [69.134.145.27]) by mx.google.com with ESMTPS id v9sm3207113ves.8.2012.09.07.07.18.56 (version=SSLv3 cipher=OTHER); Fri, 07 Sep 2012 07:18:56 -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 v6 14/20] vfs: have faccessat retry once on an ESTALE error Date: Fri, 7 Sep 2012 10:18:21 -0400 Message-Id: <1347027507-20956-15-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1347027507-20956-1-git-send-email-jlayton@redhat.com> References: <1347027507-20956-1-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQmDHM357X4TStWwNW1r2bcsDht9zHKq1YiwfxnhE6q+vxEvvNHGzQez8xMwW2oCnvydKTwA 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 | 64 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/fs/open.c b/fs/open.c index 5dcee00..a5a5c9a 100644 --- a/fs/open.c +++ b/fs/open.c @@ -312,6 +312,8 @@ 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; if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */ return -EINVAL; @@ -335,42 +337,44 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode) old_cred = override_creds(override_cred); - res = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path); - if (res) - goto out; + do { + res = user_path_at(dfd, filename, 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)) { + /* + * 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; + } - if ((mode & MAY_EXEC) && S_ISREG(inode->i_mode)) { + 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++)); revert_creds(old_cred); put_cred(override_cred); return res;