[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211025190939.588455709@linuxfoundation.org>
Date: Mon, 25 Oct 2021 21:14:24 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: linux-kernel@...r.kernel.org
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
stable@...r.kernel.org,
"Matthew Wilcox (Oracle)" <willy@...radead.org>,
Hao Sun <sunhao.th@...il.com>,
Kees Cook <keescook@...omium.org>,
Christian Brauner <christian.brauner@...ntu.com>,
Al Viro <viro@...iv.linux.org.uk>,
Mimi Zohar <zohar@...ux.ibm.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Linus Torvalds <torvalds@...ux-foundation.org>
Subject: [PATCH 4.9 37/50] vfs: check fd has read access in kernel_read_file_from_fd()
From: Matthew Wilcox (Oracle) <willy@...radead.org>
commit 032146cda85566abcd1c4884d9d23e4e30a07e9a upstream.
If we open a file without read access and then pass the fd to a syscall
whose implementation calls kernel_read_file_from_fd(), we get a warning
from __kernel_read():
if (WARN_ON_ONCE(!(file->f_mode & FMODE_READ)))
This currently affects both finit_module() and kexec_file_load(), but it
could affect other syscalls in the future.
Link: https://lkml.kernel.org/r/20211007220110.600005-1-willy@infradead.org
Fixes: b844f0ecbc56 ("vfs: define kernel_copy_file_from_fd()")
Signed-off-by: Matthew Wilcox (Oracle) <willy@...radead.org>
Reported-by: Hao Sun <sunhao.th@...il.com>
Reviewed-by: Kees Cook <keescook@...omium.org>
Acked-by: Christian Brauner <christian.brauner@...ntu.com>
Cc: Al Viro <viro@...iv.linux.org.uk>
Cc: Mimi Zohar <zohar@...ux.ibm.com>
Cc: <stable@...r.kernel.org>
Signed-off-by: Andrew Morton <akpm@...ux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@...ux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
---
fs/exec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -994,7 +994,7 @@ int kernel_read_file_from_fd(int fd, voi
struct fd f = fdget(fd);
int ret = -EBADF;
- if (!f.file)
+ if (!f.file || !(f.file->f_mode & FMODE_READ))
goto out;
ret = kernel_read_file(f.file, buf, size, max_size, id);
Powered by blists - more mailing lists