summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-04-08 01:07:25 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-04-08 01:07:25 +0000
commitcdbb7c0edc86f3c9ba97cb0cf06099a459686503 (patch)
treeedf23c1c6fc925495ed82ddf7cd65c1b85098f8a
parentf092faf7a30e7120b5346dd6392537d671e0f9ff (diff)
parentd3822f10ba32b67621d7d5be4681f57565f0af25 (diff)
downloadgchips-cdbb7c0edc86f3c9ba97cb0cf06099a459686503.tar.gz
Snap for 8422357 from d3822f10ba32b67621d7d5be4681f57565f0af25 to tm-d1-release
Change-Id: Icc5f51b1d89dcb96cf5cb810ce2760928306d4b7
-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;