summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnkit Goyal <layog@google.com>2022-05-12 10:51:56 -0700
committerAnkit Goyal <layog@google.com>2022-05-12 14:08:47 -0700
commit1c6b60178941ac3804caa8addeb96cbdb3e41bad (patch)
tree9bf2ab0215ec0437f6de3c1e4c90fdd62592b528
parent793e03473fc71b224d7a09bfc6e427f5a9a3f664 (diff)
downloadgchips-1c6b60178941ac3804caa8addeb96cbdb3e41bad.tar.gz
Revert "Revert "Validate alloc_size while mapping a buffer""
This reverts commit f7650a2d092ea056771dae5dbdc69329376f009c. Bug: 212804042 Test: VtsHalGraphicsMapperV4_0TargetTest Change-Id: If983551c6a2a1de62df55024ff26d1a0adb3680f
-rw-r--r--gralloc4/src/core/mali_gralloc_reference.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/gralloc4/src/core/mali_gralloc_reference.cpp b/gralloc4/src/core/mali_gralloc_reference.cpp
index 954c2b3..b73c08b 100644
--- a/gralloc4/src/core/mali_gralloc_reference.cpp
+++ b/gralloc4/src/core/mali_gralloc_reference.cpp
@@ -76,6 +76,16 @@ private:
return 0;
}
+ for (auto i = 0; i < MAX_BUFFER_FDS; i++) {
+ auto size = get_buffer_size(hnd->fds[i]);
+ auto size_padding = size - (off_t)hnd->alloc_sizes[i];
+ if ((size != -1) && ((size_padding < 0) || (size_padding > PAGE_SIZE))){
+ MALI_GRALLOC_LOGE("Found an imported buffer with out-of-bounds size %" PRIu64 "",
+ hnd->alloc_sizes[i]);
+ return -EINVAL;
+ }
+ }
+
int error = mali_gralloc_ion_map(hnd);
if (error != 0) {
return error;
@@ -115,7 +125,7 @@ private:
} else {
for (auto i = 0; i < MAX_BUFFER_FDS; i++) {
if (hnd->bases[i] != 0 || data.bases[i] != nullptr) {
- MALI_GRALLOC_LOGE("Validation failed: Expected nullptr for unmaped buffer");
+ MALI_GRALLOC_LOGE("Validation failed: Expected nullptr for unmapped buffer");
return -EINVAL;
}
}
@@ -124,6 +134,13 @@ private:
return 0;
}
+ off_t get_buffer_size(unsigned int fd) {
+ off_t current = lseek(fd, 0, SEEK_CUR);
+ off_t size = lseek(fd, 0, SEEK_END);
+ lseek(fd, current, SEEK_SET);
+ return size;
+ }
+
public:
static BufferManager &getInstance() {
static BufferManager instance;