From 90e828489772f705fcd54b562e3dbf9ba312b4a6 Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Tue, 14 Apr 2020 12:03:41 -0700 Subject: [PATCH] ion: Forbid multi-VMID allocation requests for the secure system heap The secure system heap does not support multi-VMID allocations, so do not allow them. Also, fortify the secure allocation check for the system heap allocation path. Change-Id: I51d53274c2374632db778461ba7505de4d723439 Signed-off-by: Isaac J. Manjarres --- drivers/staging/android/ion/heaps/ion_system_heap.c | 2 +- drivers/staging/android/ion/heaps/ion_system_secure_heap.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/staging/android/ion/heaps/ion_system_heap.c b/drivers/staging/android/ion/heaps/ion_system_heap.c index 4885702f5d16..e0cc4bab86b8 100644 --- a/drivers/staging/android/ion/heaps/ion_system_heap.c +++ b/drivers/staging/android/ion/heaps/ion_system_heap.c @@ -288,7 +288,7 @@ static int ion_system_heap_allocate(struct ion_heap *heap, return -ENOMEM; if (ion_heap_is_system_heap_type(buffer->heap->type) && - is_secure_vmid_valid(vmid)) { + is_secure_allocation(buffer->flags)) { pr_info("%s: System heap doesn't support secure allocations\n", __func__); return -EINVAL; diff --git a/drivers/staging/android/ion/heaps/ion_system_secure_heap.c b/drivers/staging/android/ion/heaps/ion_system_secure_heap.c index 188b28f6c5d5..7b252d7ad169 100644 --- a/drivers/staging/android/ion/heaps/ion_system_secure_heap.c +++ b/drivers/staging/android/ion/heaps/ion_system_secure_heap.c @@ -79,9 +79,10 @@ static int ion_system_secure_heap_allocate(struct ion_heap *heap, struct ion_system_secure_heap *secure_heap = to_system_secure_heap(heap); enum ion_heap_type type = secure_heap->heap.ion_heap.type; + unsigned long cp_flags = buffer->flags & ION_FLAGS_CP_MASK; if (!ion_heap_is_system_secure_heap_type(type) || - !is_cp_flag_present(flags)) { + !is_cp_flag_present(flags) || (hweight_long(cp_flags) != 1)) { pr_info("%s: Incorrect heap type or incorrect flags\n", __func__); return -EINVAL;