From a304195ea8d5667f2409fb64075ac3ddae2566f6 Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Wed, 29 Sep 2021 17:49:25 -0700 Subject: osi: Prevent memory allocations with MSB set Limit allocations on 32bit to 2 GB Limit allocations on 64bit to 8 Exabyte Bug: 197868577 Tag: #refactor Test: gd/cert/run Ignore-AOSP-First: Security Change-Id: I1c347084d7617b1e364a3241f1b37b398a2a6c6a (cherry picked from commit ad3b69b15f6d5a1e8eb98572109668009f2f2468) --- osi/src/allocator.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osi/src/allocator.cc b/osi/src/allocator.cc index 1c0449e14..e2c356dd3 100644 --- a/osi/src/allocator.cc +++ b/osi/src/allocator.cc @@ -56,6 +56,7 @@ char* osi_strndup(const char* str, size_t len) { } void* osi_malloc(size_t size) { + CHECK(static_cast(size) >= 0); size_t real_size = allocation_tracker_resize_for_canary(size); void* ptr = malloc(real_size); CHECK(ptr); @@ -63,6 +64,7 @@ void* osi_malloc(size_t size) { } void* osi_calloc(size_t size) { + CHECK(static_cast(size) >= 0); size_t real_size = allocation_tracker_resize_for_canary(size); void* ptr = calloc(1, real_size); CHECK(ptr); -- cgit v1.2.3