diff options
| author | 2019-04-03 11:48:11 -0400 | |
|---|---|---|
| committer | 2019-04-03 11:48:11 -0400 | |
| commit | 580e3564c9f2cac47b39fc5c3214271cff0648fb (patch) | |
| tree | 88175f150482c61d8d53ef7813956455ce4aac5a /src | |
| parent | Merge pull request #2314 from lioncash/const (diff) | |
| parent | kernel/shared_memory: Remove unused core/memory.h include (diff) | |
| download | yuzu-580e3564c9f2cac47b39fc5c3214271cff0648fb.tar.gz yuzu-580e3564c9f2cac47b39fc5c3214271cff0648fb.tar.xz yuzu-580e3564c9f2cac47b39fc5c3214271cff0648fb.zip | |
Merge pull request #2305 from lioncash/shared
kernel/shared_memory: Sanitize supplied size when unmapping
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/shared_memory.cpp | 11 | ||||
| -rw-r--r-- | src/core/hle/kernel/shared_memory.h | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 2 |
3 files changed, 18 insertions, 5 deletions
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index 62861da36..f15c5ee36 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp | |||
| @@ -9,7 +9,6 @@ | |||
| 9 | #include "core/hle/kernel/errors.h" | 9 | #include "core/hle/kernel/errors.h" |
| 10 | #include "core/hle/kernel/kernel.h" | 10 | #include "core/hle/kernel/kernel.h" |
| 11 | #include "core/hle/kernel/shared_memory.h" | 11 | #include "core/hle/kernel/shared_memory.h" |
| 12 | #include "core/memory.h" | ||
| 13 | 12 | ||
| 14 | namespace Kernel { | 13 | namespace Kernel { |
| 15 | 14 | ||
| @@ -119,7 +118,15 @@ ResultCode SharedMemory::Map(Process& target_process, VAddr address, MemoryPermi | |||
| 119 | ConvertPermissions(permissions)); | 118 | ConvertPermissions(permissions)); |
| 120 | } | 119 | } |
| 121 | 120 | ||
| 122 | ResultCode SharedMemory::Unmap(Process& target_process, VAddr address) { | 121 | ResultCode SharedMemory::Unmap(Process& target_process, VAddr address, u64 unmap_size) { |
| 122 | if (unmap_size != size) { | ||
| 123 | LOG_ERROR(Kernel, | ||
| 124 | "Invalid size passed to Unmap. Size must be equal to the size of the " | ||
| 125 | "memory managed. Shared memory size=0x{:016X}, Unmap size=0x{:016X}", | ||
| 126 | size, unmap_size); | ||
| 127 | return ERR_INVALID_SIZE; | ||
| 128 | } | ||
| 129 | |||
| 123 | // TODO(Subv): Verify what happens if the application tries to unmap an address that is not | 130 | // TODO(Subv): Verify what happens if the application tries to unmap an address that is not |
| 124 | // mapped to a SharedMemory. | 131 | // mapped to a SharedMemory. |
| 125 | return target_process.VMManager().UnmapRange(address, size); | 132 | return target_process.VMManager().UnmapRange(address, size); |
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index dab2a6bea..37e18c443 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h | |||
| @@ -104,11 +104,17 @@ public: | |||
| 104 | 104 | ||
| 105 | /** | 105 | /** |
| 106 | * Unmaps a shared memory block from the specified address in system memory | 106 | * Unmaps a shared memory block from the specified address in system memory |
| 107 | * | ||
| 107 | * @param target_process Process from which to unmap the memory block. | 108 | * @param target_process Process from which to unmap the memory block. |
| 108 | * @param address Address in system memory where the shared memory block is mapped | 109 | * @param address Address in system memory where the shared memory block is mapped. |
| 110 | * @param unmap_size The amount of bytes to unmap from this shared memory instance. | ||
| 111 | * | ||
| 109 | * @return Result code of the unmap operation | 112 | * @return Result code of the unmap operation |
| 113 | * | ||
| 114 | * @pre The given size to unmap must be the same size as the amount of memory managed by | ||
| 115 | * the SharedMemory instance itself, otherwise ERR_INVALID_SIZE will be returned. | ||
| 110 | */ | 116 | */ |
| 111 | ResultCode Unmap(Process& target_process, VAddr address); | 117 | ResultCode Unmap(Process& target_process, VAddr address, u64 unmap_size); |
| 112 | 118 | ||
| 113 | /** | 119 | /** |
| 114 | * Gets a pointer to the shared memory block | 120 | * Gets a pointer to the shared memory block |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 23c768f57..ab10db3df 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -1140,7 +1140,7 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 | |||
| 1140 | return ERR_INVALID_MEMORY_RANGE; | 1140 | return ERR_INVALID_MEMORY_RANGE; |
| 1141 | } | 1141 | } |
| 1142 | 1142 | ||
| 1143 | return shared_memory->Unmap(*current_process, addr); | 1143 | return shared_memory->Unmap(*current_process, addr, size); |
| 1144 | } | 1144 | } |
| 1145 | 1145 | ||
| 1146 | static ResultCode QueryProcessMemory(VAddr memory_info_address, VAddr page_info_address, | 1146 | static ResultCode QueryProcessMemory(VAddr memory_info_address, VAddr page_info_address, |