Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dad57f02 authored by qctecmdr Service's avatar qctecmdr Service Committed by Gerrit - the friendly Code Review server
Browse files

Merge "ion: Ensure non-HLOS memory cannot be mapped by CPU"

parents 4820bede 31142010
Loading
Loading
Loading
Loading
+25 −2
Original line number Diff line number Diff line
@@ -232,11 +232,34 @@ static int ion_secure_cma_allocate(
	return ret;
}

static void *ion_secure_cma_map_kernel(struct ion_heap *heap,
				       struct ion_buffer *buffer)
{
	if (!hlos_accessible_buffer(buffer)) {
		pr_info("%s: Mapping non-HLOS accessible buffer disallowed\n",
			__func__);
		return NULL;
	}
	return ion_heap_map_kernel(heap, buffer);
}

static int ion_secure_cma_map_user(struct ion_heap *mapper,
				   struct ion_buffer *buffer,
				   struct vm_area_struct *vma)
{
	if (!hlos_accessible_buffer(buffer)) {
		pr_info("%s: Mapping non-HLOS accessible buffer disallowed\n",
			__func__);
		return -EINVAL;
	}
	return ion_heap_map_user(mapper, buffer, vma);
}

static struct ion_heap_ops ion_secure_cma_ops = {
	.allocate = ion_secure_cma_allocate,
	.free = ion_secure_cma_free,
	.map_user = ion_heap_map_user,
	.map_kernel = ion_heap_map_kernel,
	.map_user = ion_secure_cma_map_user,
	.map_kernel = ion_secure_cma_map_kernel,
	.unmap_kernel = ion_heap_unmap_kernel,
};

+12 −0
Original line number Diff line number Diff line
@@ -56,6 +56,11 @@ struct pages_mem {
	u32 size;
};

int ion_heap_is_system_heap_type(enum ion_heap_type type)
{
	return type == ((enum ion_heap_type)ION_HEAP_TYPE_SYSTEM);
}

static struct page *alloc_buffer_page(struct ion_system_heap *heap,
				      struct ion_buffer *buffer,
				      unsigned long order,
@@ -280,6 +285,13 @@ static int ion_system_heap_allocate(struct ion_heap *heap,
	if (size / PAGE_SIZE > totalram_pages / 2)
		return -ENOMEM;

	if (ion_heap_is_system_heap_type(buffer->heap->type) &&
	    is_secure_vmid_valid(vmid)) {
		pr_info("%s: System heap doesn't support secure allocations\n",
			__func__);
		return -EINVAL;
	}

	data.size = 0;
	INIT_LIST_HEAD(&pages);
	INIT_LIST_HEAD(&pages_from_pool);