Skip to content

vfs: check fd has read access in kernel_read_file_from_fd()

Carlos Maiolino requested to merge cmaiolino/centos-stream-9:bz2022893_CS9 into main

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2022893 Tested: ltp test

Conflicts: There is no real conflict with this patch, but, it does change the error some syscalls (read finit_module and kexec_file_load) returns. It does change the error to its correct (and expected) value according to their manpages, but users checking for the wrong error values may need to be updated.

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: b844f0ec ("vfs: define kernel_copy_file_from_fd()") Signed-off-by: Matthew Wilcox (Oracle) willy@infradead.org Reported-by: Hao Sun sunhao.th@gmail.com Reviewed-by: Kees Cook keescook@chromium.org Acked-by: Christian Brauner christian.brauner@ubuntu.com Cc: Al Viro viro@zeniv.linux.org.uk Cc: Mimi Zohar zohar@linux.ibm.com Cc: stable@vger.kernel.org Signed-off-by: Andrew Morton akpm@linux-foundation.org Signed-off-by: Linus Torvalds torvalds@linux-foundation.org (cherry picked from commit 032146cda85566abcd1c4884d9d23e4e30a07e9a)

Signed-off-by: Carlos Maiolino cmaiolino@redhat.com

Edited by Carlos Maiolino

Merge request reports