Revert "ecryptfs: forbid opening files without mmap handler"
Subsystems (2)
PATCH 1/2 Revert "ecryptfs: forbid opening files without mmap handler"
From: Jeff Mahoney <[email protected]>
This reverts commit 2f36db71009304b3f0b95afacd8eba1f9f046b87.
It fixed a local root exploit but also introduced a dependency on the lower file system implementing an mmap operation just to open a file, which is a bit of a heavy hammer. The right fix is to have mmap depend on the existence of the mmap handler instead.
--- fs/ecryptfs/kthread.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
fs/ecryptfs/kthread.c +2 -11
@@ -25,7 +25,6 @@#include <linux/slab.h> #include <linux/wait.h> #include <linux/mount.h> -#include <linux/file.h> #include "ecryptfs_kernel.h" struct ecryptfs_open_req {
@@ -148,7 +147,7 @@ int ecryptfs_privileged_open(struct file **lower_file, flags |=IS_RDONLY (d_inode (lower_dentry)) ?O_RDONLY :O_RDWR ; (*lower_file) =dentry_open (&req.path, flags, cred);if (!IS_ERR (*lower_file)) - goto have_file; + goto out;if ((flags &O_ACCMODE ) ==O_RDONLY ) { rc =PTR_ERR ((*lower_file)); goto out;
@@ -166,16 +165,8 @@ int ecryptfs_privileged_open(struct file **lower_file,mutex_unlock (&ecryptfs_kthread_ctl.mux);wake_up (&ecryptfs_kthread_ctl.wait);wait_for_completion (&req.done); -if (IS_ERR (*lower_file)) { +if (IS_ERR (*lower_file)) rc =PTR_ERR (*lower_file); - goto out; - } -have_file: -if ((*lower_file)->f_op->mmap ==NULL ) { -fput (*lower_file); - *lower_file =NULL ; - rc = -EMEDIUMTYPE ; - } out:return rc; }
Signature · 1 line
2.7.1
PATCH 2/2 ecryptfs: don't allow mmap when the lower fs doesn't support it
From: Jeff Mahoney <[email protected]>
There are legitimate reasons to disallow mmap on certain files, notably in sysfs or procfs. We shouldn't emulate mmap support on file systems that don't offer support natively.
--- fs/ecryptfs/file.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
fs/ecryptfs/file.c +15 -1
@@ -169,6 +169,20 @@ out:return rc; } + +static int ecryptfs_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct dentry *dentry =ecryptfs_dentry_to_lower (file_dentry (file)); +/* +* Don't allow mmap on top of file systems that don't support it +* natively. If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs +* allows recursive mounting, this will need to be extended. +*/ +if (!d_inode (dentry)->i_fop->mmap) +return -ENODEV ; +return generic_file_mmap (file, vma); +} +/** * ecryptfs_open * @inode: inode speciying file to open
@@ -403,7 +417,7 @@ const struct file_operations ecryptfs_main_fops = {#ifdef CONFIG_COMPAT .compat_ioctl = ecryptfs_compat_ioctl, #endif - .mmap = generic_file_mmap, + .mmap = ecryptfs_mmap, .open = ecryptfs_open, .flush = ecryptfs_flush, .release = ecryptfs_release,
Signature · 1 line
2.7.1
Re: [PATCH 2/2] ecryptfs: don't allow mmap when the lower fs doesn't support it
Quoted 17 lines · On Tue, Jul 05, 2016 at 05:32:30PM -0400, [email protected] wrote:
From: Jeff Mahoney <[email protected]>
There are legitimate reasons to disallow mmap on certain files, notably in sysfs or procfs. We shouldn't emulate mmap support on file systems that don't offer support natively.
Signed-off-by Jeff Mahoney <[email protected]>--- fs/ecryptfs/file.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)fs/ecryptfs/file.c +0
-0@@ -169,6 +169,20 @@ out:return rc;
fs/ecryptfs/file.c out: · line 179
Quoted 10 lines
fs/ecryptfs/file.c +8
-0} + +static int ecryptfs_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct dentry *dentry =ecryptfs_dentry_to_lower (file_dentry (file)); +/* +* Don't allow mmap on top of file systems that don't support it +* natively. If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs +* allows recursive mounting, this will need to be extended.
Or if another new stacking filesystem appears whose f_op->mmap just forwards to lower_f_op->mmap - but thinking about it, in that scenario, my patch would stop working, too.
At this point, I dislike both this patch and my own one because of their lack of robustness. Well, at least e54ad7f1ee263ffa5a2de9c609d58dfa27b21cd9 should be solid. :/
Quoted 21 lines
fs/ecryptfs/file.c +7
-1+*/ +if (!d_inode (dentry)->i_fop->mmap) +return -ENODEV ; +return generic_file_mmap (file, vma); +} +/** * ecryptfs_open * @inode: inode speciying file to open @@ -403,7 +417,7 @@ const struct file_operations ecryptfs_main_fops = {#ifdef CONFIG_COMPAT .compat_ioctl = ecryptfs_compat_ioctl, #endif - .mmap = generic_file_mmap, + .mmap = ecryptfs_mmap, .open = ecryptfs_open, .flush = ecryptfs_flush, .release = ecryptfs_release,Signature · 1 line
2.7.1
Re: [PATCH 2/2] ecryptfs: don't allow mmap when the lower fs doesn't support it
Quoted 33 lines · Jann Horn
Quoted 17 lines · On Tue, Jul 05, 2016 at 05:32:30PM -0400, [email protected] wrote:
From: Jeff Mahoney <[email protected]>
There are legitimate reasons to disallow mmap on certain files, notably in sysfs or procfs. We shouldn't emulate mmap support on file systems that don't offer support natively.
Signed-off-by Jeff Mahoney <[email protected]>--- fs/ecryptfs/file.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)fs/ecryptfs/file.c +0
-0@@ -169,6 +169,20 @@ out:return rc;fs/ecryptfs/file.c out: · line 179
Quoted 10 lines
fs/ecryptfs/file.c +8
-0} + +static int ecryptfs_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct dentry *dentry =ecryptfs_dentry_to_lower (file_dentry (file)); +/* +* Don't allow mmap on top of file systems that don't support it +* natively. If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs +* allows recursive mounting, this will need to be extended. Or if another new stacking filesystem appears whose
f_op->mmapjust forwards tolower_f_op->mmap- but thinking about it, in that scenario, my patch would stop working, too.
Quoted 3 lines
At this point, I dislike both this patch and my own one because of their lack of robustness. Well, at least
e54ad7f1ee263ffa5a2de9c609d58dfa27b21cd9should be solid. :/
I agree that neither approach provides long term protection from the attack but they fix the immediate issue at hand. Therefore, I think we need to move forward with what we have now.
Tyler
Quoted 23 lines
Quoted 23 lines
fs/ecryptfs/file.c +7
-1+*/ +if (!d_inode (dentry)->i_fop->mmap) +return -ENODEV ; +return generic_file_mmap (file, vma); +} +/** * ecryptfs_open * @inode: inode speciying file to open @@ -403,7 +417,7 @@ const struct file_operations ecryptfs_main_fops = {#ifdef CONFIG_COMPAT .compat_ioctl = ecryptfs_compat_ioctl, #endif - .mmap = generic_file_mmap, + .mmap = ecryptfs_mmap, .open = ecryptfs_open, .flush = ecryptfs_flush, .release = ecryptfs_release,Signature · 1 line
2.7.1
Re: [PATCH 2/2] ecryptfs: don't allow mmap when the lower fs doesn't support it
In reply to [email protected]Quoted 16 lines · On 07/05/2016 04:32 PM, [email protected] wrote:
From: Jeff Mahoney <[email protected]>
There are legitimate reasons to disallow mmap on certain files, notably in sysfs or procfs. We shouldn't emulate mmap support on file systems that don't offer support natively.
Signed-off-by Jeff Mahoney <[email protected]>--- fs/ecryptfs/file.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)fs/ecryptfs/file.c +0
-0
fs/ecryptfs/file.c out: · line 175
Quoted 7 lines
fs/ecryptfs/file.c +4
-0@@ -169,6 +169,20 @@ out:return rc; } + +static int ecryptfs_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct dentry *dentry =ecryptfs_dentry_to_lower (file_dentry (file));
This should be:
struct file *lower_file = ecryptfs_file_to_lower(file);
fs/ecryptfs/file.c out: · line 181
Quoted 6 lines
fs/ecryptfs/file.c +6
-0+/* +* Don't allow mmap on top of file systems that don't support it +* natively. If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs +* allows recursive mounting, this will need to be extended. +*/ +if (!d_inode (dentry)->i_fop->mmap)
and then:
if (!lower_file->f_op->mmap)
I'll make these simple changes, add stable to cc in the patch tags, and push to Linus.
Thanks again!
Tyler
Quoted 17 lines
fs/ecryptfs/file.c +5
-1+return -ENODEV ; +return generic_file_mmap (file, vma); +} +/** * ecryptfs_open * @inode: inode speciying file to open @@ -403,7 +417,7 @@ const struct file_operations ecryptfs_main_fops = {#ifdef CONFIG_COMPAT .compat_ioctl = ecryptfs_compat_ioctl, #endif - .mmap = generic_file_mmap, + .mmap = ecryptfs_mmap, .open = ecryptfs_open, .flush = ecryptfs_flush, .release = ecryptfs_release,
Re: [PATCH 2/2] ecryptfs: don't allow mmap when the lower fs doesn't support it
Quoted 38 lines · Tyler Hicks
Quoted 16 lines · On 07/05/2016 04:32 PM, [email protected] wrote:
From: Jeff Mahoney <[email protected]>
There are legitimate reasons to disallow mmap on certain files, notably in sysfs or procfs. We shouldn't emulate mmap support on file systems that don't offer support natively.
Signed-off-by Jeff Mahoney <[email protected]>--- fs/ecryptfs/file.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)fs/ecryptfs/file.c +0
-0fs/ecryptfs/file.c out: · line 175
Quoted 7 lines
fs/ecryptfs/file.c +4
-0@@ -169,6 +169,20 @@ out:return rc; } + +static int ecryptfs_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct dentry *dentry =ecryptfs_dentry_to_lower (file_dentry (file));This should be:
struct file *lower_file = ecryptfs_file_to_lower(file);fs/ecryptfs/file.c out: · line 181
Quoted 6 lines
fs/ecryptfs/file.c +6
-0+/* +* Don't allow mmap on top of file systems that don't support it +* natively. If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs +* allows recursive mounting, this will need to be extended. +*/ +if (!d_inode (dentry)->i_fop->mmap)and then:
Quoted 5 lines
if (!lower_file->f_op->mmap)I'll make these simple changes, add stable to cc in the patch tags, and push to Linus.
Oh, whoops. Yeah, that's better.
Thanks,
-Jeff
Quoted 23 lines
Thanks again!
Tyler
Quoted 17 lines
fs/ecryptfs/file.c +5
-1+return -ENODEV ; +return generic_file_mmap (file, vma); +} +/** * ecryptfs_open * @inode: inode speciying file to open @@ -403,7 +417,7 @@ const struct file_operations ecryptfs_main_fops = {#ifdef CONFIG_COMPAT .compat_ioctl = ecryptfs_compat_ioctl, #endif - .mmap = generic_file_mmap, + .mmap = ecryptfs_mmap, .open = ecryptfs_open, .flush = ecryptfs_flush, .release = ecryptfs_release,
Signature · 2 lines
Jeff Mahoney SUSE Labs
Re: [PATCH 2/2] ecryptfs: don't allow mmap when the lower fs doesn't support it
Hello,
is there any new status? We are meanwhile at kernel 4.4.16 LTS and ecryptfs is still broken there.
Regards,
Henry
Quoted 80 lines · On Thu, 7 Jul 2016 20:46:34 -0400 Jeff Mahoney <[email protected]> wrote:
Quoted 38 lines · Tyler Hicks
Quoted 16 lines · On 07/05/2016 04:32 PM, [email protected] wrote:
From: Jeff Mahoney <[email protected]>
There are legitimate reasons to disallow mmap on certain files, notably in sysfs or procfs. We shouldn't emulate mmap support on file systems that don't offer support natively.
Signed-off-by Jeff Mahoney <[email protected]>--- fs/ecryptfs/file.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)fs/ecryptfs/file.c +0
-0fs/ecryptfs/file.c out: · line 175
Quoted 7 lines
fs/ecryptfs/file.c +4
-0@@ -169,6 +169,20 @@ out:return rc; } + +static int ecryptfs_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct dentry *dentry =ecryptfs_dentry_to_lower (file_dentry (file));This should be:
struct file *lower_file = ecryptfs_file_to_lower(file);fs/ecryptfs/file.c out: · line 181
Quoted 6 lines
fs/ecryptfs/file.c +6
-0+/* +* Don't allow mmap on top of file systems that don't support it +* natively. If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs +* allows recursive mounting, this will need to be extended. +*/ +if (!d_inode (dentry)->i_fop->mmap)and then:
Quoted 5 lines
if (!lower_file->f_op->mmap)I'll make these simple changes, add stable to cc in the patch tags, and push to Linus.
Oh, whoops. Yeah, that's better.
Thanks,
-Jeff
Quoted 23 lines
Thanks again!
Tyler
Quoted 17 lines
fs/ecryptfs/file.c +5
-1+return -ENODEV ; +return generic_file_mmap (file, vma); +} +/** * ecryptfs_open * @inode: inode speciying file to open @@ -403,7 +417,7 @@ const struct file_operations ecryptfs_main_fops = {#ifdef CONFIG_COMPAT .compat_ioctl = ecryptfs_compat_ioctl, #endif - .mmap = generic_file_mmap, + .mmap = ecryptfs_mmap, .open = ecryptfs_open, .flush = ecryptfs_flush, .release = ecryptfs_release,Signature · 2 lines
Jeff Mahoney SUSE Labs
Re: [PATCH 2/2] ecryptfs: don't allow mmap when the lower fs doesn't support it
Quoted 4 lines · Henry Jensen
Hello,
is there any new status? We are meanwhile at kernel 4.4.16 LTS and ecryptfs is still broken there.
The revert and the fix below, plus Tyler's cleanup, landed in 4.7. Both were tagged for inclusion in -stable but haven't landed there yet. I'm afraid that's the limit of my tracking of it.
-Jeff
Quoted 89 lines
Regards,
Henry
Quoted 80 lines · On Thu, 7 Jul 2016 20:46:34 -0400 Jeff Mahoney <[email protected]> wrote:
Quoted 38 lines · Tyler Hicks
Quoted 16 lines · On 07/05/2016 04:32 PM, [email protected] wrote:
From: Jeff Mahoney <[email protected]>
There are legitimate reasons to disallow mmap on certain files, notably in sysfs or procfs. We shouldn't emulate mmap support on file systems that don't offer support natively.
Signed-off-by Jeff Mahoney <[email protected]>--- fs/ecryptfs/file.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)fs/ecryptfs/file.c +0
-0fs/ecryptfs/file.c out: · line 175
Quoted 7 lines
fs/ecryptfs/file.c +4
-0@@ -169,6 +169,20 @@ out:return rc; } + +static int ecryptfs_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct dentry *dentry =ecryptfs_dentry_to_lower (file_dentry (file));This should be:
struct file *lower_file = ecryptfs_file_to_lower(file);fs/ecryptfs/file.c out: · line 181
Quoted 6 lines
fs/ecryptfs/file.c +6
-0+/* +* Don't allow mmap on top of file systems that don't support it +* natively. If FILESYSTEM_MAX_STACK_DEPTH > 2 or ecryptfs +* allows recursive mounting, this will need to be extended. +*/ +if (!d_inode (dentry)->i_fop->mmap)and then:
Quoted 5 lines
if (!lower_file->f_op->mmap)I'll make these simple changes, add stable to cc in the patch tags, and push to Linus.
Oh, whoops. Yeah, that's better.
Thanks,
-Jeff
Quoted 23 lines
Thanks again!
Tyler
Quoted 17 lines
fs/ecryptfs/file.c +5
-1+return -ENODEV ; +return generic_file_mmap (file, vma); +} +/** * ecryptfs_open * @inode: inode speciying file to open @@ -403,7 +417,7 @@ const struct file_operations ecryptfs_main_fops = {#ifdef CONFIG_COMPAT .compat_ioctl = ecryptfs_compat_ioctl, #endif - .mmap = generic_file_mmap, + .mmap = ecryptfs_mmap, .open = ecryptfs_open, .flush = ecryptfs_flush, .release = ecryptfs_release,Signature · 2 lines
Jeff Mahoney SUSE Labs
Signature · 2 lines
Jeff Mahoney SUSE Labs
Re: [PATCH 2/2] ecryptfs: don't allow mmap when the lower fs doesn't support it
Quoted 9 lines · Jeff Mahoney
Quoted 4 lines · Henry Jensen
Hello,
is there any new status? We are meanwhile at kernel 4.4.16 LTS and ecryptfs is still broken there.
The revert and the fix below, plus Tyler's cleanup, landed in 4.7. Both were tagged for inclusion in -stable but haven't landed there yet. I'm afraid that's the limit of my tracking of it.
Yes, that's all you need to do. I'll be queueing these up soon, I have 200+ stable patches to process at this point in time.
Henry, there's nothing preventing you from adding these to your local trees if you need them.
thanks,
greg k-h