|
Kmods SIG |
1bd144 |
From e72b9dd6a5f17d0fb51f16f8685f3004361e83d0 Mon Sep 17 00:00:00 2001
|
|
Kmods SIG |
1bd144 |
From: Al Viro <viro@zeniv.linux.org.uk>
|
|
Kmods SIG |
1bd144 |
Date: Sun, 3 Nov 2019 13:45:04 -0500
|
|
Kmods SIG |
1bd144 |
Subject: [Backport e72b9dd6a5f1] ecryptfs_lookup_interpose():
|
|
Kmods SIG |
1bd144 |
lower_dentry->d_inode is not stable
|
|
Kmods SIG |
1bd144 |
|
|
Kmods SIG |
1bd144 |
lower_dentry can't go from positive to negative (we have it pinned),
|
|
Kmods SIG |
1bd144 |
but it *can* go from negative to positive. So fetching ->d_inode
|
|
Kmods SIG |
1bd144 |
into a local variable, doing a blocking allocation, checking that
|
|
Kmods SIG |
1bd144 |
now ->d_inode is non-NULL and feeding the value we'd fetched
|
|
Kmods SIG |
1bd144 |
earlier to a function that won't accept NULL is not a good idea.
|
|
Kmods SIG |
1bd144 |
|
|
Kmods SIG |
1bd144 |
Cc: stable@vger.kernel.org
|
|
Kmods SIG |
1bd144 |
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
|
|
Kmods SIG |
1bd144 |
---
|
|
Kmods SIG |
1bd144 |
src/inode.c | 12 ++++++++++--
|
|
Kmods SIG |
1bd144 |
1 file changed, 10 insertions(+), 2 deletions(-)
|
|
Kmods SIG |
1bd144 |
|
|
Kmods SIG |
1bd144 |
diff --git a/src/inode.c b/src/inode.c
|
|
Kmods SIG |
1bd144 |
index a905d5f4f3b0726303595e39ba40309d68baa422..3c229872135987fb4d0a1a36a910651d5f37a08b 100644
|
|
Kmods SIG |
1bd144 |
--- a/src/inode.c
|
|
Kmods SIG |
1bd144 |
+++ b/src/inode.c
|
|
Kmods SIG |
1bd144 |
@@ -319,7 +319,7 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
|
|
Kmods SIG |
1bd144 |
static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
|
|
Kmods SIG |
1bd144 |
struct dentry *lower_dentry)
|
|
Kmods SIG |
1bd144 |
{
|
|
Kmods SIG |
1bd144 |
- struct inode *inode, *lower_inode = d_inode(lower_dentry);
|
|
Kmods SIG |
1bd144 |
+ struct inode *inode, *lower_inode;
|
|
Kmods SIG |
1bd144 |
struct ecryptfs_dentry_info *dentry_info;
|
|
Kmods SIG |
1bd144 |
struct vfsmount *lower_mnt;
|
|
Kmods SIG |
1bd144 |
int rc = 0;
|
|
Kmods SIG |
1bd144 |
@@ -339,7 +339,15 @@ static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
|
|
Kmods SIG |
1bd144 |
dentry_info->lower_path.mnt = lower_mnt;
|
|
Kmods SIG |
1bd144 |
dentry_info->lower_path.dentry = lower_dentry;
|
|
Kmods SIG |
1bd144 |
|
|
Kmods SIG |
1bd144 |
- if (d_really_is_negative(lower_dentry)) {
|
|
Kmods SIG |
1bd144 |
+ /*
|
|
Kmods SIG |
1bd144 |
+ * negative dentry can go positive under us here - its parent is not
|
|
Kmods SIG |
1bd144 |
+ * locked. That's OK and that could happen just as we return from
|
|
Kmods SIG |
1bd144 |
+ * ecryptfs_lookup() anyway. Just need to be careful and fetch
|
|
Kmods SIG |
1bd144 |
+ * ->d_inode only once - it's not stable here.
|
|
Kmods SIG |
1bd144 |
+ */
|
|
Kmods SIG |
1bd144 |
+ lower_inode = READ_ONCE(lower_dentry->d_inode);
|
|
Kmods SIG |
1bd144 |
+
|
|
Kmods SIG |
1bd144 |
+ if (!lower_inode) {
|
|
Kmods SIG |
1bd144 |
/* We want to add because we couldn't find in lower */
|
|
Kmods SIG |
1bd144 |
d_add(dentry, NULL);
|
|
Kmods SIG |
1bd144 |
return NULL;
|
|
Kmods SIG |
1bd144 |
--
|
|
Kmods SIG |
1bd144 |
2.31.1
|
|
Kmods SIG |
1bd144 |
|