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: 10048451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7123D60247 for ; Wed, 8 Nov 2017 12:49:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6046E28D04 for ; Wed, 8 Nov 2017 12:49:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51BAA295C5; Wed, 8 Nov 2017 12:49:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C45F228D04 for ; Wed, 8 Nov 2017 12:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7iy4t0NrUbrgJ9j3+0/GLhnlgQkpu+ETY9LXgdwXgEc=; b=T1aSUr3RTMIYrjJ9LRt0eu4voO 8nZcUAhudVII8e+ETc2vGPQc11RfAdM7/YhOf3dhWiE5hGxcocLLmnYeuJJbYgaJzIbkJYhXhhLR4 9JMTxf+qR74U6UxWLUu2jmvZg+IL/u9b+whcRQTZkJDB/peRY6QicBsx6HVIr25ezFgL2mfYMAQQW fHxIFuI6MNhQKAED0PI+TThCbfbqRvYcBU/a47XtUzNF2Ozloap4VLuy/YKP7/E5dek49i2B+PDTY y4LlmPJLF9BwH5zsWZKLG5DaB8Pxx5PMoaRCQholZye1LRaKwCdYKpDS/rB0d1/wILzM7ptHjCjC5 Hma2lvaQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eCPnH-0000Sh-Rg; Wed, 08 Nov 2017 12:49:23 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eCPmJ-0007mN-9k for linux-arm-kernel@lists.infradead.org; Wed, 08 Nov 2017 12:48:28 +0000 Received: by mail-lf0-x241.google.com with SMTP id a16so3011586lfk.0 for ; Wed, 08 Nov 2017 04:48:04 -0800 (PST) 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=s00v+DOtzerlIjOi3O3xtuCaFRTWWJVPb15DdJcbLhCh+m/nb2Manf0Lq1WHbtZbNk Fb81aTB3md+h6VWdAqf9HdhkhVGF+6TK91jrHRP8Jz3AASI0tAIENnCZvvdP7syoaCUi e8WezV05rg5BlST1rDKegwWehtud471RU7ygyMJ31uryF2ex46br4vsFYLnSz3kW5EGK vOXHqA746kHsxpLkCiZIcRruaSoeSLHSE039zwjHkqFT5N/w5VqCw+CbJ0WWS1RsqxnQ daKVGujUvMl2lI1ZHTjc0CCd19PaV31AisSrDnBiB+rpJS+a9slCKMIrWxYr9UKdbWrL NULA== X-Gm-Message-State: AJaThX7r1+gScLevk3zxE+SgYL5J2TwQS9HjL7tGutexTJdqjULvO/SK 8D8igfVw9SyOBUpjl9b4xU6RVQ== 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) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171108_044823_617955_AD28314A X-CRM114-Status: GOOD ( 16.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jens Wiklander MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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