From af8c74a328b80b09a6e948ab2e9dc4e54ad91cec Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 11 Jul 2021 17:52:07 +0200 Subject: Kernel: Make SharedInodeVMObject allocation OOM-safe --- Kernel/Syscalls/execve.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Kernel/Syscalls') diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 6c8b93424c..3c79f34069 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -162,7 +162,11 @@ struct RequiredLoadRange { static KResultOr get_required_load_range(FileDescription& program_description) { auto& inode = *(program_description.inode()); - auto vmobject = SharedInodeVMObject::create_with_inode(inode); + auto vmobject = SharedInodeVMObject::try_create_with_inode(inode); + if (!vmobject) { + dbgln("get_required_load_range: Unable to allocate SharedInodeVMObject"); + return ENOMEM; + } size_t executable_size = inode.size(); @@ -263,7 +267,12 @@ static KResultOr load_elf_object(NonnullOwnPtr new_space, Fil FlatPtr load_offset, ShouldAllocateTls should_allocate_tls, ShouldAllowSyscalls should_allow_syscalls) { auto& inode = *(object_description.inode()); - auto vmobject = SharedInodeVMObject::create_with_inode(inode); + auto vmobject = SharedInodeVMObject::try_create_with_inode(inode); + if (!vmobject) { + dbgln("load_elf_object: Unable to allocate SharedInodeVMObject"); + return ENOMEM; + } + if (vmobject->writable_mappings()) { dbgln("Refusing to execute a write-mapped program"); return ETXTBSY; -- cgit v1.2.3