All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: viro@zeniv.linux.org.uk, miklos@szeredi.hu
Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org,
	linux-unionfs@vger.kernel.org
Subject: [PATCH 4/4] Overlayfs: Wrap RCU-mode accesses to ->d_inode on subordinate filesystems
Date: Thu, 16 Apr 2015 15:43:19 +0100	[thread overview]
Message-ID: <20150416144319.12620.61390.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20150416144241.12620.85836.stgit@warthog.procyon.org.uk>

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 <dhowells@redhat.com>
---

 fs/overlayfs/inode.c   |    2 +-
 include/linux/dcache.h |   18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

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
  *


      parent reply	other threads:[~2015-04-16 14:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-16 14:42 [PATCH 0/4] Overlayfs: Wrap ->d_inode David Howells
2015-04-16 14:42 ` [PATCH 1/4] Overlayfs: Convert S_ISDIR(dentry->d_inode) to d_is_dir()/d_can_lookup() David Howells
2015-04-16 14:43 ` [PATCH 2/4] Overlayfs: Convert own ->d_inode to d_inode() or d_really_is_positive/negative() David Howells
2015-04-16 14:43 ` [PATCH 3/4] Overlayfs: Wrap accesses to ->d_inode on subordinate filesystems David Howells
2015-04-17  8:53   ` Miklos Szeredi
2015-04-16 14:43 ` David Howells [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150416144319.12620.61390.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.