Skip to content

Commit 2f36db7

Browse files
thejhtorvalds
authored andcommitted
ecryptfs: forbid opening files without mmap handler
This prevents users from triggering a stack overflow through a recursive invocation of pagefault handling that involves mapping procfs files into virtual memory. Signed-off-by: Jann Horn <jannh@google.com> Acked-by: Tyler Hicks <tyhicks@canonical.com> Cc: stable@vger.kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e54ad7f commit 2f36db7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: fs/ecryptfs/kthread.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/slab.h>
2626
#include <linux/wait.h>
2727
#include <linux/mount.h>
28+
#include <linux/file.h>
2829
#include "ecryptfs_kernel.h"
2930

3031
struct ecryptfs_open_req {
@@ -147,7 +148,7 @@ int ecryptfs_privileged_open(struct file **lower_file,
147148
flags |= IS_RDONLY(d_inode(lower_dentry)) ? O_RDONLY : O_RDWR;
148149
(*lower_file) = dentry_open(&req.path, flags, cred);
149150
if (!IS_ERR(*lower_file))
150-
goto out;
151+
goto have_file;
151152
if ((flags & O_ACCMODE) == O_RDONLY) {
152153
rc = PTR_ERR((*lower_file));
153154
goto out;
@@ -165,8 +166,16 @@ int ecryptfs_privileged_open(struct file **lower_file,
165166
mutex_unlock(&ecryptfs_kthread_ctl.mux);
166167
wake_up(&ecryptfs_kthread_ctl.wait);
167168
wait_for_completion(&req.done);
168-
if (IS_ERR(*lower_file))
169+
if (IS_ERR(*lower_file)) {
169170
rc = PTR_ERR(*lower_file);
171+
goto out;
172+
}
173+
have_file:
174+
if ((*lower_file)->f_op->mmap == NULL) {
175+
fput(*lower_file);
176+
*lower_file = NULL;
177+
rc = -EMEDIUMTYPE;
178+
}
170179
out:
171180
return rc;
172181
}

0 commit comments

Comments
 (0)