Commit b4ad9a32 authored by Arnd Bergmann's avatar Arnd Bergmann

Merge tag 'tee-subsys-for-5.8' of...

Merge tag 'tee-subsys-for-5.8' of git://git.linaro.org/people/jens.wiklander/linux-tee into arm/drivers

TEE subsystem work
- Reserve GlobalPlatform implementation defined logon method range
- Add support to register kernel memory with TEE to allow TEE bus drivers
  to register memory references.

* tag 'tee-subsys-for-5.8' of git://git.linaro.org/people/jens.wiklander/linux-tee:
  tee: add private login method for kernel clients
  tee: enable support to register kernel memory

Link: https://lore.kernel.org/r/20200504181049.GA10860@jadeSigned-off-by: default avatarArnd Bergmann <arnd@arndb.de>
parents acb09eca 104edb94
......@@ -333,6 +333,13 @@ static int tee_ioctl_open_session(struct tee_context *ctx,
goto out;
}
if (arg.clnt_login >= TEE_IOCTL_LOGIN_REE_KERNEL_MIN &&
arg.clnt_login <= TEE_IOCTL_LOGIN_REE_KERNEL_MAX) {
pr_debug("login method not allowed for user-space client\n");
rc = -EPERM;
goto out;
}
rc = ctx->teedev->desc->ops->open_session(ctx, &arg, params);
if (rc)
goto out;
......
......@@ -9,6 +9,7 @@
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/tee_drv.h>
#include <linux/uio.h>
#include "tee_private.h"
static void tee_shm_release(struct tee_shm *shm)
......@@ -185,14 +186,15 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr,
size_t length, u32 flags)
{
struct tee_device *teedev = ctx->teedev;
const u32 req_flags = TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED;
const u32 req_user_flags = TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED;
const u32 req_kernel_flags = TEE_SHM_DMA_BUF | TEE_SHM_KERNEL_MAPPED;
struct tee_shm *shm;
void *ret;
int rc;
int num_pages;
unsigned long start;
if (flags != req_flags)
if (flags != req_user_flags && flags != req_kernel_flags)
return ERR_PTR(-ENOTSUPP);
if (!tee_device_get(teedev))
......@@ -226,7 +228,27 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr,
goto err;
}
rc = get_user_pages_fast(start, num_pages, FOLL_WRITE, shm->pages);
if (flags & TEE_SHM_USER_MAPPED) {
rc = get_user_pages_fast(start, num_pages, FOLL_WRITE,
shm->pages);
} else {
struct kvec *kiov;
int i;
kiov = kcalloc(num_pages, sizeof(*kiov), GFP_KERNEL);
if (!kiov) {
ret = ERR_PTR(-ENOMEM);
goto err;
}
for (i = 0; i < num_pages; i++) {
kiov[i].iov_base = (void *)(start + i * PAGE_SIZE);
kiov[i].iov_len = PAGE_SIZE;
}
rc = get_kernel_pages(kiov, num_pages, 0, shm->pages);
kfree(kiov);
}
if (rc > 0)
shm->num_pages = rc;
if (rc != num_pages) {
......
......@@ -26,6 +26,7 @@
#define TEE_SHM_REGISTER BIT(3) /* Memory registered in secure world */
#define TEE_SHM_USER_MAPPED BIT(4) /* Memory mapped in user space */
#define TEE_SHM_POOL BIT(5) /* Memory allocated from pool */
#define TEE_SHM_KERNEL_MAPPED BIT(6) /* Memory mapped in kernel space */
struct device;
struct tee_device;
......
......@@ -173,6 +173,15 @@ struct tee_ioctl_buf_data {
#define TEE_IOCTL_LOGIN_APPLICATION 4
#define TEE_IOCTL_LOGIN_USER_APPLICATION 5
#define TEE_IOCTL_LOGIN_GROUP_APPLICATION 6
/*
* Disallow user-space to use GP implementation specific login
* method range (0x80000000 - 0xBFFFFFFF). This range is rather
* being reserved for REE kernel clients or TEE implementation.
*/
#define TEE_IOCTL_LOGIN_REE_KERNEL_MIN 0x80000000
#define TEE_IOCTL_LOGIN_REE_KERNEL_MAX 0xBFFFFFFF
/* Private login method for REE kernel clients */
#define TEE_IOCTL_LOGIN_REE_KERNEL 0x80000000
/**
* struct tee_ioctl_param - parameter
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment