Blame SOURCES/0004-eCryptfs-fix-permission-denied-with-ecryptfs_xattr-m.patch

Kmods SIG c540c3
From d43388dea04b18f516bd7c837d9222fe7309b12d Mon Sep 17 00:00:00 2001
Kmods SIG c540c3
From: Robbie Ko <robbieko@synology.com>
Kmods SIG c540c3
Date: Tue, 21 Aug 2018 16:17:40 +0800
Kmods SIG c540c3
Subject: [Backport d43388dea04b] eCryptfs: fix permission denied with
Kmods SIG c540c3
 ecryptfs_xattr mount option when create readonly file
Kmods SIG c540c3
Kmods SIG c540c3
When the ecryptfs_xattr mount option is turned on, the ecryptfs
Kmods SIG c540c3
metadata will be written to xattr via vfs_setxattr, which will
Kmods SIG c540c3
check the WRITE permissions.
Kmods SIG c540c3
Kmods SIG c540c3
However, this will cause denial of permission when creating a
Kmods SIG c540c3
file withoug write permission.
Kmods SIG c540c3
Kmods SIG c540c3
So fix this by calling __vfs_setxattr directly to skip permission
Kmods SIG c540c3
check.
Kmods SIG c540c3
Kmods SIG c540c3
Signed-off-by: Robbie Ko <robbieko@synology.com>
Kmods SIG c540c3
[tyhicks: Copy up lower inode attributes when successful]
Kmods SIG c540c3
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Kmods SIG c540c3
---
Kmods SIG c540c3
 src/crypto.c | 17 +++++++++++++++--
Kmods SIG c540c3
 1 file changed, 15 insertions(+), 2 deletions(-)
Kmods SIG c540c3
Kmods SIG c540c3
diff --git a/src/crypto.c b/src/crypto.c
Kmods SIG c540c3
index 708f931c36f14adace91af82229a6043386c9baf..bc2376726090b403ed3fa8d043efa07c6b45c23a 100644
Kmods SIG c540c3
--- a/src/crypto.c
Kmods SIG c540c3
+++ b/src/crypto.c
Kmods SIG c540c3
@@ -37,6 +37,7 @@
Kmods SIG c540c3
 #include <linux/slab.h>
Kmods SIG c540c3
 #include <asm/unaligned.h>
Kmods SIG c540c3
 #include <linux/kernel.h>
Kmods SIG c540c3
+#include <linux/xattr.h>
Kmods SIG c540c3
 #include "ecryptfs_kernel.h"
Kmods SIG c540c3
 
Kmods SIG c540c3
 #define DECRYPT		0
Kmods SIG c540c3
@@ -1131,9 +1132,21 @@ ecryptfs_write_metadata_to_xattr(struct dentry *ecryptfs_dentry,
Kmods SIG c540c3
 				 char *page_virt, size_t size)
Kmods SIG c540c3
 {
Kmods SIG c540c3
 	int rc;
Kmods SIG c540c3
+	struct dentry *lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
Kmods SIG c540c3
+	struct inode *lower_inode = d_inode(lower_dentry);
Kmods SIG c540c3
 
Kmods SIG c540c3
-	rc = ecryptfs_setxattr(ecryptfs_dentry, ecryptfs_inode,
Kmods SIG c540c3
-			       ECRYPTFS_XATTR_NAME, page_virt, size, 0);
Kmods SIG c540c3
+	if (!(lower_inode->i_opflags & IOP_XATTR)) {
Kmods SIG c540c3
+		rc = -EOPNOTSUPP;
Kmods SIG c540c3
+		goto out;
Kmods SIG c540c3
+	}
Kmods SIG c540c3
+
Kmods SIG c540c3
+	inode_lock(lower_inode);
Kmods SIG c540c3
+	rc = __vfs_setxattr(lower_dentry, lower_inode, ECRYPTFS_XATTR_NAME,
Kmods SIG c540c3
+			    page_virt, size, 0);
Kmods SIG c540c3
+	if (!rc && ecryptfs_inode)
Kmods SIG c540c3
+		fsstack_copy_attr_all(ecryptfs_inode, lower_inode);
Kmods SIG c540c3
+	inode_unlock(lower_inode);
Kmods SIG c540c3
+out:
Kmods SIG c540c3
 	return rc;
Kmods SIG c540c3
 }
Kmods SIG c540c3
 
Kmods SIG c540c3
-- 
Kmods SIG c540c3
2.31.1
Kmods SIG c540c3