diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2018-06-11 22:26:19 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2018-06-11 22:26:19 +0000 |
commit | 59df4f470046fc3897578f2755a9db43eba3675f (patch) | |
tree | 3307c0fd2951f5fc6ee32575c55c35814a89a270 | |
parent | d749b47414fac334c57a2c192dfff9316674bdcf (diff) | |
parent | 341b5f90d293f9745e59e4ebe2bec4cc74bb928b (diff) | |
download | libhidl-oreo-m2-s5-release.tar.gz |
Merge cherrypicks of [4314166, 4314167, 4314168, 4314169, 4314462, 4314463, 4314464, 4314465, 4314466, 4314643, 4314644, 4314185, 4314467, 4314468, 4315341, 4315342, 4315343, 4315344, 4315345, 4314469, 4314283, 4314186, 4314187, 4314188, 4314189, 4314190, 4314191, 4314192, 4315082, 4315083, 4315084, 4315085, 4315086, 4315087, 4315088, 4315089, 4315090, 4315091, 4315092, 4314170, 4314284, 4314285, 4314286, 4314287, 4314171, 4314172, 4315346, 4314288, 4315381, 4315401, 4315402, 4314289, 4314290, 4314291, 4314292, 4314293, 4314294, 4314295, 4314296, 4314297, 4314298, 4314299, 4314300, 4315421, 4315422, 4314034, 4314229, 4315347, 4315423, 4315424, 4315314, 4315348, 4315349, 4314470, 4315425, 4315426, 4315427, 4315428, 4315429] into sparse-4732990-L02900000181396755android-8.1.0_r36oreo-m2-s5-release
Change-Id: If3ea9e44108538cc8b385d6839f7d75b306f3b52
-rw-r--r-- | libhidlmemory/mapping.cpp | 10 | ||||
-rw-r--r-- | transport/memory/1.0/default/Android.bp | 1 | ||||
-rw-r--r-- | transport/memory/1.0/default/AshmemMapper.cpp | 13 |
3 files changed, 24 insertions, 0 deletions
diff --git a/libhidlmemory/mapping.cpp b/libhidlmemory/mapping.cpp index 3cb6485..8f0bcf4 100644 --- a/libhidlmemory/mapping.cpp +++ b/libhidlmemory/mapping.cpp @@ -24,6 +24,7 @@ #include <android-base/logging.h> #include <android/hidl/memory/1.0/IMapper.h> #include <hidl/HidlSupport.h> +#include <log/log.h> using android::sp; using android::hidl::memory::V1_0::IMemory; @@ -63,6 +64,15 @@ sp<IMemory> mapMemory(const hidl_memory& memory) { return nullptr; } + // hidl_memory's size is stored in uint64_t, but mapMemory's mmap will map + // size in size_t. If size is over SIZE_MAX, mapMemory could succeed + // but the mapped memory's actual size will be smaller than the reported size. + if (memory.size() > SIZE_MAX) { + LOG(ERROR) << "Cannot map " << memory.size() << " bytes of memory because it is too large."; + android_errorWriteLog(0x534e4554, "79376389"); + return nullptr; + } + Return<sp<IMemory>> ret = mapper->mapMemory(memory); if (!ret.isOk()) { diff --git a/transport/memory/1.0/default/Android.bp b/transport/memory/1.0/default/Android.bp index a4f45cf..470d3b8 100644 --- a/transport/memory/1.0/default/Android.bp +++ b/transport/memory/1.0/default/Android.bp @@ -32,6 +32,7 @@ cc_library_shared { "libhardware", "libhwbinder", "libbase", + "liblog", "libutils", "libhidlbase", "libhidltransport", diff --git a/transport/memory/1.0/default/AshmemMapper.cpp b/transport/memory/1.0/default/AshmemMapper.cpp index bef4767..cefaaa4 100644 --- a/transport/memory/1.0/default/AshmemMapper.cpp +++ b/transport/memory/1.0/default/AshmemMapper.cpp @@ -16,6 +16,9 @@ #include "AshmemMapper.h" +#include <inttypes.h> + +#include <log/log.h> #include <sys/mman.h> #include "AshmemMemory.h" @@ -32,6 +35,16 @@ Return<sp<IMemory>> AshmemMapper::mapMemory(const hidl_memory& mem) { return nullptr; } + // If ashmem service runs in 32-bit (size_t is uint32_t) and a 64-bit + // client process requests a memory > 2^32 bytes, the size would be + // converted to a 32-bit number in mmap. mmap could succeed but the + // mapped memory's actual size would be smaller than the reported size. + if (mem.size() > SIZE_MAX) { + ALOGE("Cannot map %" PRIu64 " bytes of memory because it is too large.", mem.size()); + android_errorWriteLog(0x534e4554, "79376389"); + return nullptr; + } + int fd = mem.handle()->data[0]; void* data = mmap(0, mem.size(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (data == MAP_FAILED) { |