diff options
author | Presubmit Automerger Backend <android-build-presubmit-automerger-backend@system.gserviceaccount.com> | 2022-04-07 04:27:56 +0000 |
---|---|---|
committer | Presubmit Automerger Backend <android-build-presubmit-automerger-backend@system.gserviceaccount.com> | 2022-04-07 04:27:56 +0000 |
commit | 6af58d8abb7d006d1e4ce3b5b5507bc620dafefa (patch) | |
tree | b08608a23c7ef5f7abae691352d91fbda436b257 | |
parent | 00a23275e2341f29847d5e10afe8a886aa24dd9e (diff) | |
parent | e7e91d94d1fdd3320d7138c3e0ff56f989d4cf1c (diff) | |
download | gchips-6af58d8abb7d006d1e4ce3b5b5507bc620dafefa.tar.gz |
[automerge] Validate alloc_size while mapping a buffer 2p: e7e91d94d1
Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/google/gchips/+/17464220
Bug: 212804042
Change-Id: I4c9aa20ab409da0130b0b2359d5b5392062583e5
-rw-r--r-- | gralloc4/src/core/mali_gralloc_reference.cpp | 19 |
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; |