module: Don't ignore errors from set_memory_XX()
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Fri, 16 Feb 2024 08:14:27 +0000 (09:14 +0100)
committerLuis Chamberlain <mcgrof@kernel.org>
Fri, 16 Feb 2024 19:30:43 +0000 (11:30 -0800)
commitd1909c0221739356f31c721de4743e7d219a56cc
tree17fef68d60f0e59ab3697324b5f361caf255b4d6
parent157285397f6a7b35d8f7f115e1be24f49e947ba3
module: Don't ignore errors from set_memory_XX()

set_memory_ro(), set_memory_nx(), set_memory_x() and other helpers
can fail and return an error. In that case the memory might not be
protected as expected and the module loading has to be aborted to
avoid security issues.

Check return value of all calls to set_memory_XX() and handle
error if any.

Add a check to not call set_memory_XX() on NULL pointers as some
architectures may not like it allthough numpages is always 0 in that
case. This also avoid a useless call to set_vm_flush_reset_perms().

Link: https://github.com/KSPP/linux/issues/7
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
kernel/module/internal.h
kernel/module/main.c
kernel/module/strict_rwx.c