* [PATCH] vfs: Check fd has read access in kernel_read_file_from_fd()
@ 2021-10-07 22:01 Matthew Wilcox (Oracle)
2021-10-07 23:39 ` Kees Cook
2021-10-11 8:54 ` Christian Brauner
0 siblings, 2 replies; 3+ messages in thread
From: Matthew Wilcox (Oracle) @ 2021-10-07 22:01 UTC (permalink / raw)
To: Kees Cook
Cc: Matthew Wilcox (Oracle),
Al Viro, Mimi Zohar, Andrew Morton, linux-fsdevel, Hao Sun,
stable
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.
Reported-by: Hao Sun <sunhao.th@gmail.com>
Fixes: b844f0ecbc56 ("vfs: define kernel_copy_file_from_fd()")
Cc: stable@vger.kernel.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/kernel_read_file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/kernel_read_file.c b/fs/kernel_read_file.c
index 87aac4c72c37..1b07550485b9 100644
--- a/fs/kernel_read_file.c
+++ b/fs/kernel_read_file.c
@@ -178,7 +178,7 @@ int kernel_read_file_from_fd(int fd, loff_t offset, void **buf,
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, offset, buf, buf_size, file_size, id);
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] vfs: Check fd has read access in kernel_read_file_from_fd()
2021-10-07 22:01 [PATCH] vfs: Check fd has read access in kernel_read_file_from_fd() Matthew Wilcox (Oracle)
@ 2021-10-07 23:39 ` Kees Cook
2021-10-11 8:54 ` Christian Brauner
1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2021-10-07 23:39 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: Al Viro, Mimi Zohar, Andrew Morton, linux-fsdevel, Hao Sun, stable
On Thu, Oct 07, 2021 at 11:01:10PM +0100, Matthew Wilcox (Oracle) wrote:
> 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.
>
> Reported-by: Hao Sun <sunhao.th@gmail.com>
> Fixes: b844f0ecbc56 ("vfs: define kernel_copy_file_from_fd()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Thanks for chasing this down!
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] vfs: Check fd has read access in kernel_read_file_from_fd()
2021-10-07 22:01 [PATCH] vfs: Check fd has read access in kernel_read_file_from_fd() Matthew Wilcox (Oracle)
2021-10-07 23:39 ` Kees Cook
@ 2021-10-11 8:54 ` Christian Brauner
1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2021-10-11 8:54 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: Kees Cook, Al Viro, Mimi Zohar, Andrew Morton, linux-fsdevel,
Hao Sun, stable
On Thu, Oct 07, 2021 at 11:01:10PM +0100, Matthew Wilcox wrote:
> 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.
>
> Reported-by: Hao Sun <sunhao.th@gmail.com>
> Fixes: b844f0ecbc56 ("vfs: define kernel_copy_file_from_fd()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
Thanks!
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-11 8:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-07 22:01 [PATCH] vfs: Check fd has read access in kernel_read_file_from_fd() Matthew Wilcox (Oracle)
2021-10-07 23:39 ` Kees Cook
2021-10-11 8:54 ` Christian Brauner
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.