kern: fix svc bounds checking for main memory size 4GB -> 8GB (closes #1320)

This commit is contained in:
Michael Scire 2021-01-07 03:43:09 -08:00
parent b21f8a5043
commit 1c9d6b4d90
3 changed files with 6 additions and 6 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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());