summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chris Forbes <chrisforbes@google.com> 2022-01-26 18:48:55 +1300
committer Chris Forbes <chrisforbes@google.com> 2022-01-29 06:56:27 +1300
commit6c09ee7f4ec0c38766f6de2ad922d85a5035f565 (patch)
tree117f8f4f0a8d46800ec5ba86c3e567746d6d94c7
parenta9ff73831c26cb01e5164f3dd19c4c5b6307f9ae (diff)
gralloc: Move validation of non-blob/gpu_data_buffer down to libui
AIDL gralloc implementations may choose to support this combination. Existing implementations of HIDL gralloc 2/3/4 do not support it, and do not reliably reject it due to having been previously protected by validation at the AHardwareBuffer layer. Move the check down to the gralloc layer, and defer to the HAL only in the AIDL case. Bug: b/195944622 Test: build; real CTS/VTS to land soon after. Change-Id: I7b0b9de005a9b0f564915f9c71cc8aea3ef0618a
-rw-r--r--libs/nativewindow/AHardwareBuffer.cpp4
-rw-r--r--libs/ui/Gralloc2.cpp9
-rw-r--r--libs/ui/Gralloc3.cpp9
-rw-r--r--libs/ui/Gralloc4.cpp11
4 files changed, 29 insertions, 4 deletions
diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp
index cb3361b431..2578ee8467 100644
--- a/libs/nativewindow/AHardwareBuffer.cpp
+++ b/libs/nativewindow/AHardwareBuffer.cpp
@@ -509,10 +509,6 @@ bool AHardwareBuffer_isValidDescription(const AHardwareBuffer_Desc* desc, bool l
ALOGE_IF(log, "AHARDWAREBUFFER_USAGE_SENSOR_DIRECT_DATA requires AHARDWAREBUFFER_FORMAT_BLOB");
return false;
}
- if (desc->usage & AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER) {
- ALOGE_IF(log, "AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER requires AHARDWAREBUFFER_FORMAT_BLOB");
- return false;
- }
}
if ((desc->usage & (AHARDWAREBUFFER_USAGE_CPU_READ_MASK | AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK)) &&
diff --git a/libs/ui/Gralloc2.cpp b/libs/ui/Gralloc2.cpp
index 040a62b542..f23f10a1a9 100644
--- a/libs/ui/Gralloc2.cpp
+++ b/libs/ui/Gralloc2.cpp
@@ -110,6 +110,15 @@ status_t Gralloc2Mapper::validateBufferDescriptorInfo(
descriptorInfo->usage & ~validUsageBits);
return BAD_VALUE;
}
+
+ // Gralloc2 implementations never understand non-BLOB with GPU_DATA_BUFFER
+ // and do not reliably reject it.
+ if (descriptorInfo->usage & BufferUsage::GPU_DATA_BUFFER &&
+ descriptorInfo->format != hardware::graphics::common::V1_1::PixelFormat::BLOB) {
+ ALOGE("gralloc2 does not support non-BLOB pixel formats with GPU_DATA_BUFFER usage");
+ return BAD_VALUE;
+ }
+
return NO_ERROR;
}
diff --git a/libs/ui/Gralloc3.cpp b/libs/ui/Gralloc3.cpp
index 882674f479..15c60bcadf 100644
--- a/libs/ui/Gralloc3.cpp
+++ b/libs/ui/Gralloc3.cpp
@@ -101,6 +101,15 @@ status_t Gralloc3Mapper::validateBufferDescriptorInfo(
descriptorInfo->usage & ~validUsageBits);
return BAD_VALUE;
}
+
+ // Gralloc3 implementations never understand non-BLOB with GPU_DATA_BUFFER
+ // and do not reliably reject it.
+ if (descriptorInfo->usage & BufferUsage::GPU_DATA_BUFFER &&
+ descriptorInfo->format != hardware::graphics::common::V1_2::PixelFormat::BLOB) {
+ ALOGE("gralloc3 does not support non-BLOB pixel formats with GPU_DATA_BUFFER usage");
+ return BAD_VALUE;
+ }
+
return NO_ERROR;
}
diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp
index e02632460f..9922d6afaf 100644
--- a/libs/ui/Gralloc4.cpp
+++ b/libs/ui/Gralloc4.cpp
@@ -41,6 +41,7 @@ using aidl::android::hardware::graphics::common::StandardMetadataType;
using android::hardware::hidl_vec;
using android::hardware::graphics::allocator::V4_0::IAllocator;
using android::hardware::graphics::common::V1_2::BufferUsage;
+using android::hardware::graphics::common::V1_2::PixelFormat;
using android::hardware::graphics::mapper::V4_0::BufferDescriptor;
using android::hardware::graphics::mapper::V4_0::Error;
using android::hardware::graphics::mapper::V4_0::IMapper;
@@ -120,6 +121,16 @@ static status_t validateBufferDescriptorInfo(IMapper::BufferDescriptorInfo* desc
descriptorInfo->usage & ~validUsageBits);
return BAD_VALUE;
}
+
+ // Combinations that are only allowed with gralloc 4.1.
+ // Previous grallocs must be protected from this.
+ if (!hasIAllocatorAidl() &&
+ descriptorInfo->format != hardware::graphics::common::V1_2::PixelFormat::BLOB &&
+ descriptorInfo->usage & BufferUsage::GPU_DATA_BUFFER) {
+ ALOGE("non-BLOB pixel format with GPU_DATA_BUFFER usage is not supported prior to gralloc 4.1");
+ return BAD_VALUE;
+ }
+
return NO_ERROR;
}