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

Commit f5266ee4 authored by Kamal Agrawal's avatar Kamal Agrawal Committed by Gerrit - the friendly Code Review server
Browse files

msm: kgsl: Fail import if secure buffer is not accessible to CP_PIXEL



It is possible that userspace can request import for secure dma buffer
that is not accessible to CP_PIXEL. There is no need to import such
buffers in KGSL. Go through the list of VMIDs for secure dma buffer
and fail import if it is not accessible to CP_PIXEL.

Change-Id: I7584ad00a964c9c40ac4c0c9b1c83a21c03c48fd
Signed-off-by: default avatarKamal Agrawal <kamaagra@codeaurora.org>
parent 1cda180c
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
 * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved.
 */

#include <uapi/linux/msm_ion.h>
#include <uapi/linux/sched/types.h>
#include <linux/ctype.h>
#include <linux/debugfs.h>
@@ -3008,6 +3009,29 @@ static int kgsl_setup_dma_buf(struct kgsl_device *device,
	entry->priv_data = meta;
	entry->memdesc.sgt = sg_table;

	if (entry->memdesc.priv & KGSL_MEMDESC_SECURE) {
		unsigned long dma_buf_flags;

		ret = dma_buf_get_flags(dmabuf, &dma_buf_flags);
		if (ret) {
			dev_info(device->dev,
				"Unable to get dma buf flags, err = %d. Skipped access check\n",
				ret);
			ret = 0;
			goto skip_access_check;
		}

		/*
		 * Secure buffer is not accessible to CP_PIXEL, there is no point
		 * in importing this buffer.
		 */
		if (!(dma_buf_flags & ION_FLAG_CP_PIXEL)) {
			ret = -EPERM;
			goto out;
		}
	}

skip_access_check:
	/* Calculate the size of the memdesc from the sglist */
	for (s = entry->memdesc.sgt->sgl; s != NULL; s = sg_next(s)) {
		int priv = (entry->memdesc.priv & KGSL_MEMDESC_SECURE) ? 1 : 0;