From 5dd538cace2718584c51d52c1f7ce9ce294bb58e Mon Sep 17 00:00:00 2001 From: David Marcec Date: Thu, 11 Oct 2018 20:32:21 +1100 Subject: [PATCH 1/2] Passing an invalid nmap handle to Remap should throw an error Added error for invalid nmap handles --- .../hle/service/nvdrv/devices/nvhost_as_gpu.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index 7555bbe7d..7424fa72f 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp @@ -15,6 +15,11 @@ #include "video_core/renderer_base.h" namespace Service::Nvidia::Devices { +namespace NvErrCodes { +enum { + InvalidNmapHandle = -22, +}; +} nvhost_as_gpu::nvhost_as_gpu(std::shared_ptr nvmap_dev) : nvmap_dev(std::move(nvmap_dev)) {} nvhost_as_gpu::~nvhost_as_gpu() = default; @@ -79,14 +84,17 @@ u32 nvhost_as_gpu::Remap(const std::vector& input, std::vector& output) std::memcpy(entries.data(), input.data(), input.size()); auto& gpu = Core::System::GetInstance().GPU(); - + bool failed_remap{}; for (const auto& entry : entries) { LOG_WARNING(Service_NVDRV, "remap entry, offset=0x{:X} handle=0x{:X} pages=0x{:X}", entry.offset, entry.nvmap_handle, entry.pages); Tegra::GPUVAddr offset = static_cast(entry.offset) << 0x10; - auto object = nvmap_dev->GetObject(entry.nvmap_handle); - ASSERT(object); + if (!object) { + LOG_CRITICAL(Service_NVDRV, "nvmap {} is an invalid handle!", entry.nvmap_handle); + failed_remap = true; + continue; + } ASSERT(object->status == nvmap::Object::Status::Allocated); @@ -97,6 +105,9 @@ u32 nvhost_as_gpu::Remap(const std::vector& input, std::vector& output) ASSERT(returned == offset); } std::memcpy(output.data(), entries.data(), output.size()); + if (failed_remap) { + return static_cast(NvErrCodes::InvalidNmapHandle); + } return 0; } From 4d2de6564f6361f8732f734afdc8cfa74d7530ff Mon Sep 17 00:00:00 2001 From: David Marcec Date: Fri, 12 Oct 2018 17:10:41 +1100 Subject: [PATCH 2/2] Returned an error before processing other remaps --- src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index 7424fa72f..884837b17 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp @@ -84,7 +84,6 @@ u32 nvhost_as_gpu::Remap(const std::vector& input, std::vector& output) std::memcpy(entries.data(), input.data(), input.size()); auto& gpu = Core::System::GetInstance().GPU(); - bool failed_remap{}; for (const auto& entry : entries) { LOG_WARNING(Service_NVDRV, "remap entry, offset=0x{:X} handle=0x{:X} pages=0x{:X}", entry.offset, entry.nvmap_handle, entry.pages); @@ -92,8 +91,8 @@ u32 nvhost_as_gpu::Remap(const std::vector& input, std::vector& output) auto object = nvmap_dev->GetObject(entry.nvmap_handle); if (!object) { LOG_CRITICAL(Service_NVDRV, "nvmap {} is an invalid handle!", entry.nvmap_handle); - failed_remap = true; - continue; + std::memcpy(output.data(), entries.data(), output.size()); + return static_cast(NvErrCodes::InvalidNmapHandle); } ASSERT(object->status == nvmap::Object::Status::Allocated); @@ -105,9 +104,6 @@ u32 nvhost_as_gpu::Remap(const std::vector& input, std::vector& output) ASSERT(returned == offset); } std::memcpy(output.data(), entries.data(), output.size()); - if (failed_remap) { - return static_cast(NvErrCodes::InvalidNmapHandle); - } return 0; }