From 1c9d6b4d90a85360a569239bc681f31d8d07a831 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 7 Jan 2021 03:43:09 -0800 Subject: [PATCH] kern: fix svc bounds checking for main memory size 4GB -> 8GB (closes #1320) --- .../libmesosphere/source/svc/kern_svc_physical_memory.cpp | 2 +- libraries/libmesosphere/source/svc/kern_svc_process.cpp | 6 +++--- .../libmesosphere/source/svc/kern_svc_shared_memory.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/libmesosphere/source/svc/kern_svc_physical_memory.cpp b/libraries/libmesosphere/source/svc/kern_svc_physical_memory.cpp index 8ffcbd402..ec7334c0d 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_physical_memory.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_physical_memory.cpp @@ -24,7 +24,7 @@ namespace ams::kern::svc { Result SetHeapSize(uintptr_t *out_address, size_t size) { /* Validate size. */ R_UNLESS(util::IsAligned(size, ams::svc::HeapSizeAlignment), svc::ResultInvalidSize()); - R_UNLESS(size < ams::kern::MainMemorySize, svc::ResultInvalidSize()); + R_UNLESS(size < ams::kern::MainMemorySizeMax, svc::ResultInvalidSize()); /* Set the heap size. */ KProcessAddress address; diff --git a/libraries/libmesosphere/source/svc/kern_svc_process.cpp b/libraries/libmesosphere/source/svc/kern_svc_process.cpp index 2d517f471..33c8d8926 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_process.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_process.cpp @@ -175,9 +175,9 @@ namespace ams::kern::svc { R_UNLESS(params.code_address + code_size - 1 <= map_end - 1, svc::ResultInvalidMemoryRegion()); /* Check that the number of pages is valid for the kernel address space. */ - R_UNLESS(code_num_pages < (kern::MainMemorySize / PageSize), svc::ResultOutOfMemory()); - R_UNLESS(system_resource_num_pages < (kern::MainMemorySize / PageSize), svc::ResultOutOfMemory()); - R_UNLESS(total_pages < (kern::MainMemorySize / PageSize), svc::ResultOutOfMemory()); + R_UNLESS(code_num_pages < (kern::MainMemorySizeMax / PageSize), svc::ResultOutOfMemory()); + R_UNLESS(system_resource_num_pages < (kern::MainMemorySizeMax / PageSize), svc::ResultOutOfMemory()); + R_UNLESS(total_pages < (kern::MainMemorySizeMax / PageSize), svc::ResultOutOfMemory()); /* Check that optimized memory allocation is used only for applications. */ const bool optimize_allocs = (params.flags & ams::svc::CreateProcessFlag_OptimizeMemoryAllocation) != 0; diff --git a/libraries/libmesosphere/source/svc/kern_svc_shared_memory.cpp b/libraries/libmesosphere/source/svc/kern_svc_shared_memory.cpp index d971fe85a..b7c4d9b49 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_shared_memory.cpp +++ b/libraries/libmesosphere/source/svc/kern_svc_shared_memory.cpp @@ -99,8 +99,8 @@ namespace ams::kern::svc { Result CreateSharedMemory(ams::svc::Handle *out, size_t size, ams::svc::MemoryPermission owner_perm, ams::svc::MemoryPermission remote_perm) { /* Validate the size. */ - R_UNLESS(0 < size && size < kern::MainMemorySize, svc::ResultInvalidSize()); - R_UNLESS(util::IsAligned(size, PageSize), svc::ResultInvalidSize()); + R_UNLESS(0 < size && size < kern::MainMemorySizeMax, svc::ResultInvalidSize()); + R_UNLESS(util::IsAligned(size, PageSize), svc::ResultInvalidSize()); /* Validate the permissions. */ R_UNLESS(IsValidSharedMemoryPermission(owner_perm), svc::ResultInvalidNewMemoryPermission());