1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +00:00

Kernel+LibELF: Enable SMAP protection during non-syscall exec()

When loading a new executable, we now map the ELF image in kernel-only
memory and parse it there. Then we use copy_to_user() when initializing
writable regions with data from the executable.

Note that the exec() syscall still disables SMAP protection and will
require additional work. This patch only affects kernel-originated
process spawns.
This commit is contained in:
Andreas Kling 2020-01-10 06:57:18 +01:00
parent 66b0002acb
commit 197e73ee31
5 changed files with 20 additions and 10 deletions

View file

@ -5,6 +5,9 @@
#ifdef KERNEL
#include <Kernel/VM/MemoryManager.h>
#define do_memcpy copy_to_user
#else
#define do_memcpy memcpy
#endif
//#define ELFLOADER_DEBUG
@ -48,7 +51,7 @@ bool ELFLoader::layout()
failed = true;
return;
}
memcpy(tls_image, program_header.raw_data(), program_header.size_in_image());
do_memcpy(tls_image, program_header.raw_data(), program_header.size_in_image());
#endif
return;
}
@ -75,7 +78,7 @@ bool ELFLoader::layout()
failed = true;
return;
}
memcpy(program_header.vaddr().as_ptr(), program_header.raw_data(), program_header.size_in_image());
do_memcpy(program_header.vaddr().as_ptr(), program_header.raw_data(), program_header.size_in_image());
} else {
auto* mapped_section = map_section_hook(
program_header.vaddr(),