From patchwork Thu Apr 16 14:43:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 6226651 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C7E7D9F54F for ; Thu, 16 Apr 2015 14:43:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E9023202FF for ; Thu, 16 Apr 2015 14:43:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4973320351 for ; Thu, 16 Apr 2015 14:43:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933630AbbDPOn3 (ORCPT ); Thu, 16 Apr 2015 10:43:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45873 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933614AbbDPOnY (ORCPT ); Thu, 16 Apr 2015 10:43:24 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3GEhNWo001239 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 16 Apr 2015 10:43:23 -0400 Received: from warthog.procyon.org.uk ([10.3.112.12]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3GEhK6V017144; Thu, 16 Apr 2015 10:43:21 -0400 Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 4/4] Overlayfs: Wrap RCU-mode accesses to ->d_inode on subordinate filesystems From: David Howells To: viro@zeniv.linux.org.uk, miklos@szeredi.hu Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org Date: Thu, 16 Apr 2015 15:43:19 +0100 Message-ID: <20150416144319.12620.61390.stgit@warthog.procyon.org.uk> In-Reply-To: <20150416144241.12620.85836.stgit@warthog.procyon.org.uk> References: <20150416144241.12620.85836.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is a place in overlayfs where it may touch a lower-layer inode during RCU-mode pathwalk. In this situation the combination of d_backing_inode() and ACCESS_ONCE() does not compile, so institute and use a d_backing_inode_rcu() function that combines these. Signed-off-by: David Howells --- fs/overlayfs/inode.c | 2 +- include/linux/dcache.h | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index ead6a7a6fe9d..7e3a7e3ff095 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -99,7 +99,7 @@ int ovl_permission(struct inode *inode, int mask) realdentry = ovl_entry_real(oe, &is_upper); /* Careful in RCU walk mode */ - realinode = ACCESS_ONCE(realdentry->d_inode); + realinode = d_backing_inode_rcu(realdentry); if (!realinode) { WARN_ON(!(mask & MAY_NOT_BLOCK)); err = -ENOENT; diff --git a/include/linux/dcache.h b/include/linux/dcache.h index df334cbacc6d..50004f2429a1 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -562,6 +562,24 @@ static inline struct inode *d_backing_inode(const struct dentry *upper) } /** + * d_backing_inode_rcu - Get upper or lower inode we should be using with ACCESS_ONCE() + * @upper: The upper layer + * + * This is the helper that should be used to get at the inode that will be used + * if this dentry were to be opened as a file. The inode may be on the upper + * dentry or it may be on a lower dentry pinned by the upper. Further, the + * upper dentry might not have an inode set. + * + * Normal filesystems should not use this to access their own inodes. + */ +static inline struct inode *d_backing_inode_rcu(const struct dentry *upper) +{ + struct inode *inode = ACCESS_ONCE(upper->d_inode); + + return inode; +} + +/** * d_backing_dentry - Get upper or lower dentry we should be using * @upper: The upper layer *