From 088bb8a6dae682c51581cda73dfe291f625df827 Mon Sep 17 00:00:00 2001 From: Ankit Goyal Date: Fri, 2 Sep 2022 15:45:32 -0700 Subject: Add a max limit to reserved regions Bug: 239415718 Test: VtsHalGraphicsMapperV4_0TargetTest Test: VtsHalGraphicsAllocatorAidl_TargetTest Change-Id: Ie827ab7663317418224d7a95db959290f1f060cf --- gralloc4/src/hidl_common/Allocator.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gralloc4/src/hidl_common/Allocator.cpp b/gralloc4/src/hidl_common/Allocator.cpp index 6ca758a..3b8e62a 100644 --- a/gralloc4/src/hidl_common/Allocator.cpp +++ b/gralloc4/src/hidl_common/Allocator.cpp @@ -77,7 +77,17 @@ void allocate(const buffer_descriptor_t &bufferDescriptor, uint32_t count, IAllo auto hnd = const_cast(reinterpret_cast(tmpBuffer)); hnd->imapper_version = HIDL_MAPPER_VERSION_SCALED; + // 4k is rougly 7.9 MB with one byte per pixel. We are + // assuming that the reserved region might be needed for + // dynamic HDR and that represents the largest size. + uint64_t max_reserved_region_size = 8ull * 1024 * 1024; hnd->reserved_region_size = bufferDescriptor.reserved_size; + if (hnd->reserved_region_size > max_reserved_region_size) { + MALI_GRALLOC_LOGE("%s, Requested reserved region size (%" PRIu64 ") is larger than allowed (%" PRIu64 ")", + __func__, hnd->reserved_region_size, max_reserved_region_size); + error = Error::BAD_VALUE; + break; + } hnd->attr_size = mapper::common::shared_metadata_size() + hnd->reserved_region_size; if (hnd->get_usage() & GRALLOC_USAGE_ROIINFO) -- cgit v1.2.3