zhang / rpms / kernel

Forked from rpms/kernel 5 years ago
Clone
e293be
From 21a46cb1e668aa27756e6858512a0eb48b37f588 Mon Sep 17 00:00:00 2001
e293be
From: Pablo Greco <pablo@fliagreco.com.ar>
e293be
Date: Wed, 10 Oct 2018 13:03:14 -0300
e293be
Subject: [PATCH 1/5] https://bugs.centos.org/view.php?id=7369
e293be
 http://kozlex.blogspot.com/2015/05/building-ecryptfs-on-redhat-7_19.html
e293be
e293be
To fix ecryptfs and build it in the kernel follow is the partial fix:
e293be
This is a fix that will not be proposed to upstream cause it is not
e293be
compatible with other kernels; instead it is a patch to make ecryptfs
e293be
work on Rhel7 only.
e293be
---
e293be
 fs/ecryptfs/main.c | 5 +++--
e293be
 1 file changed, 3 insertions(+), 2 deletions(-)
e293be
e293be
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
e293be
index 8b0957e..b07cee6 100644
e293be
--- a/fs/ecryptfs/main.c
e293be
+++ b/fs/ecryptfs/main.c
e293be
@@ -500,6 +500,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
e293be
 	struct path path;
e293be
 	uid_t check_ruid;
e293be
 	int rc;
e293be
+	int *s_stack_depth;
e293be
 
e293be
 	sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL);
e293be
 	if (!sbi) {
e293be
@@ -567,10 +568,10 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
e293be
 	s->s_maxbytes = path.dentry->d_sb->s_maxbytes;
e293be
 	s->s_blocksize = path.dentry->d_sb->s_blocksize;
e293be
 	s->s_magic = ECRYPTFS_SUPER_MAGIC;
e293be
-	s->s_stack_depth = path.dentry->d_sb->s_stack_depth + 1;
e293be
+	s_stack_depth = get_s_stack_depth(path.dentry->d_sb);
e293be
 
e293be
 	rc = -EINVAL;
e293be
-	if (s->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
e293be
+	if ( *s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
e293be
 		pr_err("eCryptfs: maximum fs stacking depth exceeded\n");
e293be
 		goto out_free;
e293be
 	}
e293be
-- 
e293be
1.8.3.1
e293be
e293be
From 8eff0cda21d01242dd4b580a041fcb7f064d52a7 Mon Sep 17 00:00:00 2001
e293be
From: Pablo Greco <pablo@fliagreco.com.ar>
e293be
Date: Wed, 10 Oct 2018 13:04:36 -0300
e293be
Subject: [PATCH 2/5] https://bugs.centos.org/view.php?id=15353 Update ecryptfs
e293be
 to 3.10.108, fixes some null pointer dereference
e293be
e293be
---
e293be
 fs/ecryptfs/crypto.c |  1 -
e293be
 fs/ecryptfs/file.c   | 27 ++++++++++++++-------------
e293be
 fs/ecryptfs/inode.c  |  2 +-
e293be
 fs/ecryptfs/main.c   | 16 +++++++++++++---
e293be
 4 files changed, 28 insertions(+), 18 deletions(-)
e293be
e293be
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
e293be
index f71ec12..1da2446 100644
e293be
--- a/fs/ecryptfs/crypto.c
e293be
+++ b/fs/ecryptfs/crypto.c
e293be
@@ -2102,7 +2102,6 @@ ecryptfs_decode_from_filename(unsigned char *dst, size_t *dst_size,
e293be
 			break;
e293be
 		case 2:
e293be
 			dst[dst_byte_offset++] |= (src_byte);
e293be
-			dst[dst_byte_offset] = 0;
e293be
 			current_bit_offset = 0;
e293be
 			break;
e293be
 		}
e293be
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
e293be
index 041379a..fac9d01 100644
e293be
--- a/fs/ecryptfs/file.c
e293be
+++ b/fs/ecryptfs/file.c
e293be
@@ -185,6 +185,19 @@ out:
e293be
 	return rc;
e293be
 }
e293be
 
e293be
+static int ecryptfs_mmap(struct file *file, struct vm_area_struct *vma)
e293be
+{
e293be
+	struct file *lower_file = ecryptfs_file_to_lower(file);
e293be
+	/*
e293be
+	 * Don't allow mmap on top of file systems that don't support it
e293be
+	 * natively.  If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs
e293be
+	 * allows recursive mounting, this will need to be extended.
e293be
+	 */
e293be
+	if (!lower_file->f_op->mmap)
e293be
+		return -ENODEV;
e293be
+	return generic_file_mmap(file, vma);
e293be
+}
e293be
+
e293be
 /**
e293be
  * ecryptfs_open
e293be
  * @inode: inode speciying file to open
e293be
@@ -198,23 +211,11 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
e293be
 {
e293be
 	int rc = 0;
e293be
 	struct ecryptfs_crypt_stat *crypt_stat = NULL;
e293be
-	struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
e293be
 	struct dentry *ecryptfs_dentry = file->f_path.dentry;
e293be
 	/* Private value of ecryptfs_dentry allocated in
e293be
 	 * ecryptfs_lookup() */
e293be
 	struct ecryptfs_file_info *file_info;
e293be
 
e293be
-	mount_crypt_stat = &ecryptfs_superblock_to_private(
e293be
-		ecryptfs_dentry->d_sb)->mount_crypt_stat;
e293be
-	if ((mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
e293be
-	    && ((file->f_flags & O_WRONLY) || (file->f_flags & O_RDWR)
e293be
-		|| (file->f_flags & O_CREAT) || (file->f_flags & O_TRUNC)
e293be
-		|| (file->f_flags & O_APPEND))) {
e293be
-		printk(KERN_WARNING "Mount has encrypted view enabled; "
e293be
-		       "files may only be read\n");
e293be
-		rc = -EPERM;
e293be
-		goto out;
e293be
-	}
e293be
 	/* Released in ecryptfs_release or end of function if failure */
e293be
 	file_info = kmem_cache_zalloc(ecryptfs_file_info_cache, GFP_KERNEL);
e293be
 	ecryptfs_set_file_private(file, file_info);
e293be
@@ -372,7 +373,7 @@ const struct file_operations ecryptfs_main_fops = {
e293be
 #ifdef CONFIG_COMPAT
e293be
 	.compat_ioctl = ecryptfs_compat_ioctl,
e293be
 #endif
e293be
-	.mmap = generic_file_mmap,
e293be
+	.mmap = ecryptfs_mmap,
e293be
 	.open = ecryptfs_open,
e293be
 	.flush = ecryptfs_flush,
e293be
 	.release = ecryptfs_release,
e293be
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
e293be
index 1648908..d3d47e7 100644
e293be
--- a/fs/ecryptfs/inode.c
e293be
+++ b/fs/ecryptfs/inode.c
e293be
@@ -1042,7 +1042,7 @@ ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
e293be
 	}
e293be
 
e293be
 	rc = vfs_setxattr(lower_dentry, name, value, size, flags);
e293be
-	if (!rc)
e293be
+	if (!rc && dentry->d_inode)
e293be
 		fsstack_copy_attr_all(dentry->d_inode, lower_dentry->d_inode);
e293be
 out:
e293be
 	return rc;
e293be
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
e293be
index b07cee6..01b209d 100644
e293be
--- a/fs/ecryptfs/main.c
e293be
+++ b/fs/ecryptfs/main.c
e293be
@@ -494,6 +494,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
e293be
 {
e293be
 	struct super_block *s;
e293be
 	struct ecryptfs_sb_info *sbi;
e293be
+	struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
e293be
 	struct ecryptfs_dentry_info *root_info;
e293be
 	const char *err = "Getting sb failed";
e293be
 	struct inode *inode;
e293be
@@ -513,6 +514,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
e293be
 		err = "Error parsing options";
e293be
 		goto out;
e293be
 	}
e293be
+	mount_crypt_stat = &sbi->mount_crypt_stat;
e293be
 
e293be
 	s = sget(fs_type, NULL, set_anon_super, flags, NULL);
e293be
 	if (IS_ERR(s)) {
e293be
@@ -559,11 +561,19 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
e293be
 
e293be
 	/**
e293be
 	 * Set the POSIX ACL flag based on whether they're enabled in the lower
e293be
-	 * mount. Force a read-only eCryptfs mount if the lower mount is ro.
e293be
-	 * Allow a ro eCryptfs mount even when the lower mount is rw.
e293be
+	 * mount.
e293be
 	 */
e293be
 	s->s_flags = flags & ~MS_POSIXACL;
e293be
-	s->s_flags |= path.dentry->d_sb->s_flags & (MS_RDONLY | MS_POSIXACL);
e293be
+	s->s_flags |= path.dentry->d_sb->s_flags & MS_POSIXACL;
e293be
+
e293be
+	/**
e293be
+	 * Force a read-only eCryptfs mount when:
e293be
+	 *   1) The lower mount is ro
e293be
+	 *   2) The ecryptfs_encrypted_view mount option is specified
e293be
+	 */
e293be
+	if (path.dentry->d_sb->s_flags & MS_RDONLY ||
e293be
+	    mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED)
e293be
+		s->s_flags |= MS_RDONLY;
e293be
 
e293be
 	s->s_maxbytes = path.dentry->d_sb->s_maxbytes;
e293be
 	s->s_blocksize = path.dentry->d_sb->s_blocksize;
e293be
-- 
e293be
1.8.3.1
e293be
e293be
From b14c0c55ccb3a77172d35bda6c3b1e1af8daed16 Mon Sep 17 00:00:00 2001
e293be
From: Dan Carpenter <dan.carpenter@oracle.com>
e293be
Date: Tue, 22 Aug 2017 23:41:28 +0300
e293be
Subject: [PATCH 3/5] eCryptfs: use after free in ecryptfs_release_messaging()
e293be
e293be
commit db86be3a12d0b6e5c5b51c2ab2a48f06329cb590 upstream.
e293be
e293be
We're freeing the list iterator so we should be using the _safe()
e293be
version of hlist_for_each_entry().
e293be
e293be
Fixes: 88b4a07e6610 ("[PATCH] eCryptfs: Public key transport mechanism")
e293be
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
e293be
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
e293be
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
e293be
---
e293be
 fs/ecryptfs/messaging.c | 7 ++++---
e293be
 1 file changed, 4 insertions(+), 3 deletions(-)
e293be
e293be
diff --git a/fs/ecryptfs/messaging.c b/fs/ecryptfs/messaging.c
e293be
index 49ff8ea..331f502 100644
e293be
--- a/fs/ecryptfs/messaging.c
e293be
+++ b/fs/ecryptfs/messaging.c
e293be
@@ -444,15 +444,16 @@ void ecryptfs_release_messaging(void)
e293be
 	}
e293be
 	if (ecryptfs_daemon_hash) {
e293be
 		struct ecryptfs_daemon *daemon;
e293be
+		struct hlist_node *n;
e293be
 		int i;
e293be
 
e293be
 		mutex_lock(&ecryptfs_daemon_hash_mux);
e293be
 		for (i = 0; i < (1 << ecryptfs_hash_bits); i++) {
e293be
 			int rc;
e293be
 
e293be
-			hlist_for_each_entry(daemon,
e293be
-					     &ecryptfs_daemon_hash[i],
e293be
-					     euid_chain) {
e293be
+			hlist_for_each_entry_safe(daemon, n,
e293be
+						  &ecryptfs_daemon_hash[i],
e293be
+						  euid_chain) {
e293be
 				rc = ecryptfs_exorcise_daemon(daemon);
e293be
 				if (rc)
e293be
 					printk(KERN_ERR "%s: Error whilst "
e293be
-- 
e293be
1.8.3.1
e293be
e293be
From e67495775579bdb7f70dddcc28d44cbb2e09d782 Mon Sep 17 00:00:00 2001
e293be
From: Al Viro <viro@zeniv.linux.org.uk>
e293be
Date: Fri, 29 Nov 2013 22:51:47 -0500
e293be
Subject: [PATCH 4/5] ecryptfs: fix failure handling in ->readlink()
e293be
e293be
If ecryptfs_readlink_lower() fails, buf remains an uninitialized
e293be
pointer and passing it nd_set_link() won't do anything good.
e293be
e293be
Fixed by switching ecryptfs_readlink_lower() to saner API - make it
e293be
return buf or ERR_PTR(...) and update callers.
e293be
e293be
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
e293be
---
e293be
 fs/ecryptfs/inode.c | 29 +++++++++++++----------------
e293be
 1 file changed, 13 insertions(+), 16 deletions(-)
e293be
e293be
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
e293be
index d3d47e7..4052e41 100644
e293be
--- a/fs/ecryptfs/inode.c
e293be
+++ b/fs/ecryptfs/inode.c
e293be
@@ -659,19 +659,17 @@ out_lock:
e293be
 	return rc;
e293be
 }
e293be
 
e293be
-static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
e293be
-				   size_t *bufsiz)
e293be
+static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
e293be
 {
e293be
 	struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
e293be
 	char *lower_buf;
e293be
+	char *buf;
e293be
 	mm_segment_t old_fs;
e293be
 	int rc;
e293be
 
e293be
 	lower_buf = kmalloc(PATH_MAX, GFP_KERNEL);
e293be
-	if (!lower_buf) {
e293be
-		rc = -ENOMEM;
e293be
-		goto out;
e293be
-	}
e293be
+	if (!lower_buf)
e293be
+		return ERR_PTR(-ENOMEM);
e293be
 	old_fs = get_fs();
e293be
 	set_fs(get_ds());
e293be
 	rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
e293be
@@ -680,21 +678,18 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
e293be
 	set_fs(old_fs);
e293be
 	if (rc < 0)
e293be
 		goto out;
e293be
-	rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry,
e293be
+	rc = ecryptfs_decode_and_decrypt_filename(&buf, bufsiz, dentry,
e293be
 						  lower_buf, rc);
e293be
 out:
e293be
 	kfree(lower_buf);
e293be
-	return rc;
e293be
+	return rc ? ERR_PTR(rc) : buf;
e293be
 }
e293be
 
e293be
 static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
e293be
 {
e293be
-	char *buf;
e293be
-	size_t len = PATH_MAX;
e293be
-	int rc;
e293be
-
e293be
-	rc = ecryptfs_readlink_lower(dentry, &buf, &len;;
e293be
-	if (rc)
e293be
+	size_t len;
e293be
+	char *buf = ecryptfs_readlink_lower(dentry, &len;;
e293be
+	if (IS_ERR(buf))
e293be
 		goto out;
e293be
 	fsstack_copy_attr_atime(dentry->d_inode,
e293be
 				ecryptfs_dentry_to_lower(dentry)->d_inode);
e293be
@@ -1003,10 +998,12 @@ static int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
e293be
 		char *target;
e293be
 		size_t targetsiz;
e293be
 
e293be
-		rc = ecryptfs_readlink_lower(dentry, &target, &targetsiz);
e293be
-		if (!rc) {
e293be
+		target = ecryptfs_readlink_lower(dentry, &targetsiz);
e293be
+		if (!IS_ERR(target)) {
e293be
 			kfree(target);
e293be
 			stat->size = targetsiz;
e293be
+		} else {
e293be
+			rc = PTR_ERR(target);
e293be
 		}
e293be
 	}
e293be
 	return rc;
e293be
-- 
e293be
1.8.3.1
e293be
e293be
From 7f59ba91ad4d6547a12493131833d4c89017f7ab Mon Sep 17 00:00:00 2001
e293be
From: Pablo Greco <pablo@fliagreco.com.ar>
e293be
Date: Wed, 10 Oct 2018 13:10:09 -0300
e293be
Subject: [PATCH 5/5] https://bugs.centos.org/view.php?id=15353 Update ecryptfs
e293be
 to the use rename2 in inode_operations. Needed for the changes made between
e293be
 7.0 and 7.1
e293be
e293be
---
e293be
 fs/ecryptfs/ecryptfs_kernel.h |  2 +-
e293be
 fs/ecryptfs/inode.c           | 27 ++++++++++++++++++++++-----
e293be
 2 files changed, 23 insertions(+), 6 deletions(-)
e293be
e293be
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
e293be
index 07b4757..8ebcd40 100644
e293be
--- a/fs/ecryptfs/ecryptfs_kernel.h
e293be
+++ b/fs/ecryptfs/ecryptfs_kernel.h
e293be
@@ -545,7 +545,7 @@ void __ecryptfs_printk(const char *fmt, ...);
e293be
 extern const struct file_operations ecryptfs_main_fops;
e293be
 extern const struct file_operations ecryptfs_dir_fops;
e293be
 extern const struct inode_operations ecryptfs_main_iops;
e293be
-extern const struct inode_operations ecryptfs_dir_iops;
e293be
+extern const struct inode_operations_wrapper ecryptfs_dir_iops;
e293be
 extern const struct inode_operations ecryptfs_symlink_iops;
e293be
 extern const struct super_operations ecryptfs_sops;
e293be
 extern const struct dentry_operations ecryptfs_dops;
e293be
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
e293be
index 4052e41..6e5cb89 100644
e293be
--- a/fs/ecryptfs/inode.c
e293be
+++ b/fs/ecryptfs/inode.c
e293be
@@ -71,12 +71,16 @@ static int ecryptfs_inode_set(struct inode *inode, void *opaque)
e293be
 	inode->i_mapping->a_ops = &ecryptfs_aops;
e293be
 	inode->i_mapping->backing_dev_info = inode->i_sb->s_bdi;
e293be
 
e293be
-	if (S_ISLNK(inode->i_mode))
e293be
+	if (S_ISLNK(inode->i_mode)) {
e293be
 		inode->i_op = &ecryptfs_symlink_iops;
e293be
-	else if (S_ISDIR(inode->i_mode))
e293be
-		inode->i_op = &ecryptfs_dir_iops;
e293be
-	else
e293be
+	}
e293be
+	else if (S_ISDIR(inode->i_mode)) {
e293be
+		inode->i_op = &ecryptfs_dir_iops.ops;
e293be
+		inode->i_flags |= S_IOPS_WRAPPER;
e293be
+	}
e293be
+	else {
e293be
 		inode->i_op = &ecryptfs_main_iops;
e293be
+	}
e293be
 
e293be
 	if (S_ISDIR(inode->i_mode))
e293be
 		inode->i_fop = &ecryptfs_dir_fops;
e293be
@@ -659,6 +663,16 @@ out_lock:
e293be
 	return rc;
e293be
 }
e293be
 
e293be
+static int ecryptfs_rename2(struct inode *old_dir, struct dentry *old_dentry,
e293be
+			 struct inode *new_dir, struct dentry *new_dentry,
e293be
+			 unsigned int flags)
e293be
+{
e293be
+	if (flags & ~RENAME_NOREPLACE)
e293be
+		return -EINVAL;
e293be
+
e293be
+	return ecryptfs_rename(old_dir, old_dentry, new_dir, new_dentry);
e293be
+}
e293be
+
e293be
 static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
e293be
 {
e293be
 	struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
e293be
@@ -1119,7 +1133,8 @@ const struct inode_operations ecryptfs_symlink_iops = {
e293be
 	.removexattr = ecryptfs_removexattr
e293be
 };
e293be
 
e293be
-const struct inode_operations ecryptfs_dir_iops = {
e293be
+const struct inode_operations_wrapper ecryptfs_dir_iops = {
e293be
+	.ops = {
e293be
 	.create = ecryptfs_create,
e293be
 	.lookup = ecryptfs_lookup,
e293be
 	.link = ecryptfs_link,
e293be
@@ -1135,6 +1150,8 @@ const struct inode_operations ecryptfs_dir_iops = {
e293be
 	.getxattr = ecryptfs_getxattr,
e293be
 	.listxattr = ecryptfs_listxattr,
e293be
 	.removexattr = ecryptfs_removexattr
e293be
+	},
e293be
+	.rename2 = ecryptfs_rename2,
e293be
 };
e293be
 
e293be
 const struct inode_operations ecryptfs_main_iops = {
e293be
-- 
e293be
1.8.3.1
e293be