From patchwork Wed Nov 8 12:47:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 118251 Delivered-To: patches@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5242602qgn; Wed, 8 Nov 2017 04:48:03 -0800 (PST) X-Received: by 10.46.43.69 with SMTP id q66mr194234lje.104.1510145283847; Wed, 08 Nov 2017 04:48:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510145283; cv=none; d=google.com; s=arc-20160816; b=XyF83UsT900NUZVxBOB4D/Ap90T2ihlVLh5RuySxQ/uqAbZ85oLGWdy6fctWh30VSh 0KC0lvriwUx8viSVWW4wum+JpgxOmIl4GnPE9drBCk4prRi7IYlZzeqarhlEt/4dFJjR p73mczEoHi0zAcIJAJm6LbtqVw5+P7lmAeNaqgNWbFGxqVRrTyWDDh51wxml8jU3qKjB QzCAWfxpYolyVLeHjAthjigf5urRF4978BrkKLoIr8eCk0LnhonkjNW48V4KqlxI2hea 9vtNVcDKxkVMfzq25k8+fcQB+zt3bHw/iJJPBTgzPUaDzUNtpzSp/SzYfKnKhFkw93b5 WYnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=ykIrWsbzHRtB9yN7jykoSPMPKWQypeiKJLlvSxF+1mk=; b=b4sJjlArPdlGJJfishvqitSylBSePoxRUxA3IfQ8YZuzr8ypS6ni52ZfroZFi7cYjg roUa4lDhQOSglhaJFXfy5gYYE3oR16+Lk5jcxyvZwpAJ2k40eQpOVhMMbEBV5qcsbv42 TwEOcJb8sXrNXLGglEBjUHdy6jW2zY5Vh2v/enAOPelziJ4X2pqKcdw9O/9M3sLQSpyB vRkE8K24fyyZFknD+PfZxI31L+xqHQrcWq1UTILFLWLlCr889ZJMrONiWnOLzxtYsd8o r0D0wnXuG/wVtNz7/Iz4uAhQorIffGcRuXlMeY5Vn6Ba6VV56GPSu3KZrT+oo1a6wpf3 VwgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gNKgH/1q; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id e73sor146587lfi.105.2017.11.08.04.48.03 for (Google Transport Security); Wed, 08 Nov 2017 04:48:03 -0800 (PST) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gNKgH/1q; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ykIrWsbzHRtB9yN7jykoSPMPKWQypeiKJLlvSxF+1mk=; b=gNKgH/1qh5UyqAZwgvow8LnumZAtmD1wfHjIH69XnLf/ermgaRzPnt0f4xu1g2UUDm O46f2ng0e1NlBwPEaI+IqmTb5xY4+/4D8nib/7bpP/HLV89H15vyUVNU2JaGRv3h8qc4 yvQ9/wrTUp23fObYkAFb/gzZVFdLm5aYBkJmQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ykIrWsbzHRtB9yN7jykoSPMPKWQypeiKJLlvSxF+1mk=; b=oKIeDkKMf9HqtkIfZhiv5Um78kSbujgDlUC64S/K8y548ZvIaua1fVCZyIpZSzcnjb rvnsrcJBDaDeULA2i/Dh60H5f/GxPJ2RUUvhcsdPWbOLGGGNq59TeA38ttIa1KQqg2Sn h4iTexuhFx4HlGClEEEJ4dFnLX62EYHlBxFG+iqOB0/QT0yVsM6gtB16Pt0tkV/8b+eU eFRZkRZ42MnVpMSMoEMmbWQI4PNyu/dZoSPEsM6nY8YsZuHiqW+MP1pBfDcP+cBfdOpN txNjeosEN95AzLS/1Akx1BuXrHDHCpQVOpmwBKzi7Fm3O2pnsPy/QO8mqZOP9zAlNbH2 kiFA== X-Gm-Message-State: AJaThX6Tan4S0DCmw9/amFoW0s0TU7a/TIfNdfvbm5BEr+AnxTkbTlu6 P7jSYV6S8VjfmSBaTyitdB+O4j3X X-Google-Smtp-Source: ABhQp+RKcbrmaxOBbPOMSrT+obfneMzijImwDJDLxik3+Rp558d5E/AWBbHHYGb21FhITd+K//M/TQ== X-Received: by 10.25.20.167 with SMTP id 39mr132153lfu.261.1510145283480; Wed, 08 Nov 2017 04:48:03 -0800 (PST) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x7sm658479lff.91.2017.11.08.04.48.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Nov 2017 04:48:02 -0800 (PST) From: Jens Wiklander To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, tee-dev@lists.linaro.org Cc: Jens Wiklander Subject: [PATCH 2/3] tee: add TEE_IOCTL_PARAM_ATTR_META Date: Wed, 8 Nov 2017 13:47:51 +0100 Message-Id: <1510145272-14842-3-git-send-email-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510145272-14842-1-git-send-email-jens.wiklander@linaro.org> References: <1510145272-14842-1-git-send-email-jens.wiklander@linaro.org> Adds TEE_IOCTL_PARAM_ATTR_META which can be used to indicate meta parameters when communicating with user space. These meta parameters can be used by supplicant support multiple parallel requests at a time. Reviewed-by: Etienne Carriere Signed-off-by: Jens Wiklander --- drivers/tee/optee/supp.c | 25 +++++++++++++++++++++++++ drivers/tee/tee_core.c | 16 ++++++++++------ include/uapi/linux/tee.h | 7 +++++++ 3 files changed, 42 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/drivers/tee/optee/supp.c b/drivers/tee/optee/supp.c index b4ea0678a436..56aa8b929b8c 100644 --- a/drivers/tee/optee/supp.c +++ b/drivers/tee/optee/supp.c @@ -119,6 +119,27 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params, return ret; } +static int supp_check_recv_params(size_t num_params, struct tee_param *params) +{ + size_t n; + + /* + * If there's memrefs we need to decrease those as they where + * increased earlier and we'll even refuse to accept any below. + */ + for (n = 0; n < num_params; n++) + if (tee_param_is_memref(params + n) && params[n].u.memref.shm) + tee_shm_put(params[n].u.memref.shm); + + /* + * We only expect parameters as TEE_IOCTL_PARAM_ATTR_TYPE_NONE (0). + */ + for (n = 0; n < num_params; n++) + if (params[n].attr) + return -EINVAL; + return 0; +} + /** * optee_supp_recv() - receive request for supplicant * @ctx: context receiving the request @@ -137,6 +158,10 @@ int optee_supp_recv(struct tee_context *ctx, u32 *func, u32 *num_params, struct optee_supp *supp = &optee->supp; int rc; + rc = supp_check_recv_params(*num_params, param); + if (rc) + return rc; + /* * In case two threads in one supplicant is calling this function * simultaneously we need to protect the data with a mutex which diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index c78104589e42..4d0ce606f0fc 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -152,11 +152,11 @@ static int params_from_user(struct tee_context *ctx, struct tee_param *params, return -EFAULT; /* All unused attribute bits has to be zero */ - if (ip.attr & ~TEE_IOCTL_PARAM_ATTR_TYPE_MASK) + if (ip.attr & ~TEE_IOCTL_PARAM_ATTR_MASK) return -EINVAL; params[n].attr = ip.attr; - switch (ip.attr) { + switch (ip.attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) { case TEE_IOCTL_PARAM_ATTR_TYPE_NONE: case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT: break; @@ -394,8 +394,8 @@ static int params_to_supp(struct tee_context *ctx, struct tee_ioctl_param ip; struct tee_param *p = params + n; - ip.attr = p->attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK; - switch (p->attr) { + ip.attr = p->attr; + switch (p->attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) { case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT: ip.a = p->u.value.a; @@ -459,6 +459,10 @@ static int tee_ioctl_supp_recv(struct tee_context *ctx, if (!params) return -ENOMEM; + rc = params_from_user(ctx, params, num_params, uarg->params); + if (rc) + goto out; + rc = ctx->teedev->desc->ops->supp_recv(ctx, &func, &num_params, params); if (rc) goto out; @@ -488,11 +492,11 @@ static int params_from_supp(struct tee_param *params, size_t num_params, return -EFAULT; /* All unused attribute bits has to be zero */ - if (ip.attr & ~TEE_IOCTL_PARAM_ATTR_TYPE_MASK) + if (ip.attr & ~TEE_IOCTL_PARAM_ATTR_MASK) return -EINVAL; p->attr = ip.attr; - switch (ip.attr) { + switch (ip.attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) { case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT: /* Only out and in/out values can be updated */ diff --git a/include/uapi/linux/tee.h b/include/uapi/linux/tee.h index 688782e90140..267c12e7fd79 100644 --- a/include/uapi/linux/tee.h +++ b/include/uapi/linux/tee.h @@ -154,6 +154,13 @@ struct tee_ioctl_buf_data { */ #define TEE_IOCTL_PARAM_ATTR_TYPE_MASK 0xff +/* Meta parameter carrying extra information about the message. */ +#define TEE_IOCTL_PARAM_ATTR_META 0x100 + +/* Mask of all known attr bits */ +#define TEE_IOCTL_PARAM_ATTR_MASK \ + (TEE_IOCTL_PARAM_ATTR_TYPE_MASK | TEE_IOCTL_PARAM_ATTR_META) + /* * Matches TEEC_LOGIN_* in GP TEE Client API * Are only defined for GP compliant TEEs