summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-11 17:52:07 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-11 17:52:07 +0200
commitaf8c74a328b80b09a6e948ab2e9dc4e54ad91cec (patch)
treed8813fb6bf5a9cfe524f6208f9085b021cf0ec3a /Kernel/Syscalls
parent59049ae4b760ae0f5cdad0d326eeaca9d2192fb9 (diff)
downloadserenity-af8c74a328b80b09a6e948ab2e9dc4e54ad91cec.zip
Kernel: Make SharedInodeVMObject allocation OOM-safe
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r--Kernel/Syscalls/execve.cpp13
1 files changed, 11 insertions, 2 deletions
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<RequiredLoadRange> 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<LoadResult> load_elf_object(NonnullOwnPtr<Space> 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;