Skip to content

Commit b4ad9a3

Browse files
committed
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@jade Signed-off-by: Arnd Bergmann <[email protected]>
2 parents acb09ec + 104edb9 commit b4ad9a3

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

drivers/tee/tee_core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ static int tee_ioctl_open_session(struct tee_context *ctx,
333333
goto out;
334334
}
335335

336+
if (arg.clnt_login >= TEE_IOCTL_LOGIN_REE_KERNEL_MIN &&
337+
arg.clnt_login <= TEE_IOCTL_LOGIN_REE_KERNEL_MAX) {
338+
pr_debug("login method not allowed for user-space client\n");
339+
rc = -EPERM;
340+
goto out;
341+
}
342+
336343
rc = ctx->teedev->desc->ops->open_session(ctx, &arg, params);
337344
if (rc)
338345
goto out;

drivers/tee/tee_shm.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/sched.h>
1010
#include <linux/slab.h>
1111
#include <linux/tee_drv.h>
12+
#include <linux/uio.h>
1213
#include "tee_private.h"
1314

1415
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,
185186
size_t length, u32 flags)
186187
{
187188
struct tee_device *teedev = ctx->teedev;
188-
const u32 req_flags = TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED;
189+
const u32 req_user_flags = TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED;
190+
const u32 req_kernel_flags = TEE_SHM_DMA_BUF | TEE_SHM_KERNEL_MAPPED;
189191
struct tee_shm *shm;
190192
void *ret;
191193
int rc;
192194
int num_pages;
193195
unsigned long start;
194196

195-
if (flags != req_flags)
197+
if (flags != req_user_flags && flags != req_kernel_flags)
196198
return ERR_PTR(-ENOTSUPP);
197199

198200
if (!tee_device_get(teedev))
@@ -226,7 +228,27 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr,
226228
goto err;
227229
}
228230

229-
rc = get_user_pages_fast(start, num_pages, FOLL_WRITE, shm->pages);
231+
if (flags & TEE_SHM_USER_MAPPED) {
232+
rc = get_user_pages_fast(start, num_pages, FOLL_WRITE,
233+
shm->pages);
234+
} else {
235+
struct kvec *kiov;
236+
int i;
237+
238+
kiov = kcalloc(num_pages, sizeof(*kiov), GFP_KERNEL);
239+
if (!kiov) {
240+
ret = ERR_PTR(-ENOMEM);
241+
goto err;
242+
}
243+
244+
for (i = 0; i < num_pages; i++) {
245+
kiov[i].iov_base = (void *)(start + i * PAGE_SIZE);
246+
kiov[i].iov_len = PAGE_SIZE;
247+
}
248+
249+
rc = get_kernel_pages(kiov, num_pages, 0, shm->pages);
250+
kfree(kiov);
251+
}
230252
if (rc > 0)
231253
shm->num_pages = rc;
232254
if (rc != num_pages) {

include/linux/tee_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define TEE_SHM_REGISTER BIT(3) /* Memory registered in secure world */
2727
#define TEE_SHM_USER_MAPPED BIT(4) /* Memory mapped in user space */
2828
#define TEE_SHM_POOL BIT(5) /* Memory allocated from pool */
29+
#define TEE_SHM_KERNEL_MAPPED BIT(6) /* Memory mapped in kernel space */
2930

3031
struct device;
3132
struct tee_device;

include/uapi/linux/tee.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ struct tee_ioctl_buf_data {
173173
#define TEE_IOCTL_LOGIN_APPLICATION 4
174174
#define TEE_IOCTL_LOGIN_USER_APPLICATION 5
175175
#define TEE_IOCTL_LOGIN_GROUP_APPLICATION 6
176+
/*
177+
* Disallow user-space to use GP implementation specific login
178+
* method range (0x80000000 - 0xBFFFFFFF). This range is rather
179+
* being reserved for REE kernel clients or TEE implementation.
180+
*/
181+
#define TEE_IOCTL_LOGIN_REE_KERNEL_MIN 0x80000000
182+
#define TEE_IOCTL_LOGIN_REE_KERNEL_MAX 0xBFFFFFFF
183+
/* Private login method for REE kernel clients */
184+
#define TEE_IOCTL_LOGIN_REE_KERNEL 0x80000000
176185

177186
/**
178187
* struct tee_ioctl_param - parameter

0 commit comments

Comments
 (0)