From patchwork Thu Jun 13 10:30:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166696 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp908699ilk; Thu, 13 Jun 2019 08:35:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyl5At8MMvCWsej8GCVhF4pWIc/sEVpYuVGRb9iMkf4RsSuZ2N3nRrbCVjkuPtN3Q8xBQid X-Received: by 2002:a65:500d:: with SMTP id f13mr30841019pgo.151.1560440109537; Thu, 13 Jun 2019 08:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440109; cv=none; d=google.com; s=arc-20160816; b=A5MY1t06genYo4atRsdxKbj4qKdQxKAQq0IVJmOAhIw1EcNx4yJtfZNVGCB3tJe0XS 0DSoiu3jAZc/z0WO78P1gTB0orOKb7paa0mZQ95+2gwUUHpdPgED57+3FJl9hZrKii9m jDu3pknRH90n3EjEM/z1889c/eUyusz5fTxiFTB0MF7AVwUX3R8V/qKO7pOjDWp+0wEK TxXBUd3yS6IJscVzS2tOXm6PN+CopoZEOkGXhMvQ+O7Y2WmMPNuRHqhnw2Jeo9dnjfID PNAlyye6PABq3g7T31Yswtqy2cGAwzeq5REVVDyWoeT644pEaaPAYFZy8JcbkqHBKF/s dwtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=zNYSDlioe1/7qDzUymWdeZ+QFAflos+mlnY8eEGg+0o=; b=zQa6l1g9bwSjccXfgRfkE60WRKY3YaxfLFM8T9PQ5n7ENap61N7ZRk70CMDrkyta44 g9+sa2txTJw3yGnVD6lQJLs6cMPLv7V1dxRAxH22WtLqF6nIWTT+5VkGfJV9xNVOWcYV tel8jjr6QyHgWAfHAcS5gWRCENYcaPlxZQb9THRFbTO2TlvIPeFLRFB7oEyqluo7mlWi zjwg42Av1GLXZX1NRr5DxFaeCAuW87wJnSjJE/Ccc7SKmwMTYyhlgelP5PN9RyYIX3qF E8mjxvqyYOTbXjKHB1/GeAhHpjZCZ5AL/YWzSl+nNczvGaEACSBEUChGqxPvi3mnasN4 TaPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yGqrc+Py; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6si98289pgg.386.2019.06.13.08.35.09; Thu, 13 Jun 2019 08:35:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yGqrc+Py; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731647AbfFMPfI (ORCPT + 25 others); Thu, 13 Jun 2019 11:35:08 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:46609 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727968AbfFMKbf (ORCPT ); Thu, 13 Jun 2019 06:31:35 -0400 Received: by mail-pl1-f194.google.com with SMTP id e5so7954403pls.13 for ; Thu, 13 Jun 2019 03:31:35 -0700 (PDT) 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=zNYSDlioe1/7qDzUymWdeZ+QFAflos+mlnY8eEGg+0o=; b=yGqrc+PyiSy4n5qr9NdwCtvk10NU0RuIEZpKtR38SSnXyuNE9KtNc4LOsjqZwwRHrh PQjFPkSB3hzxovhRjl67Bjzjq+MyaDq8caifL9XcLBUffnDo6fKiNVZJMaRJqYYrTpLD 236tIR/c1HHyhBzC+DbYQbzknd6nXkp2yR69CfUSomWNfHZq7zDwLo6CtP6Rcz9jQoyU t+UUwCGOlMlfHHdRXEbat32VLMC64YiRRvC+ES6Lwz/POGU5yfdzTRVFTEJkScAUUYU3 CLOA6wc/os0XTJLHRiURlUUYawm0WGmE6fu8bzeXwSSiF2jgcH82LXA8DmqI9CW5kKWM JwmA== 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=zNYSDlioe1/7qDzUymWdeZ+QFAflos+mlnY8eEGg+0o=; b=Mh+58yV/Ft92++lJBeTtBFmc5LtcHoCzU5QIPlq4kNmMFn3RW51zBLv/GnHPPgwbTY mIiKFCi7dd+2ObwTV1SERwwlJ+bdGP+EWsii1tsL3bkrSwXnLLddingmpc7C5wql5M2W p61cGAk7BJ0ueOp97tB9SthRnOCkHSQDANCYvEizMBc5a+O/DF1mQakpz7R4WMi3hkf+ EKlmOzr6R3SOh1zEhpddMg8cQc0l4mDANK99ODV8JCPAHDKZ3WS/hIbboVkQC/pU1ESj 36bfI5+CHXU4fvRI1zfHJ4mdVVQr+z61sguHbwPzEt3vsxrQF4R7asjFMKz5NnNcXR6n O7uQ== X-Gm-Message-State: APjAAAVgQyc10AxQivXnUj+JsfvdTl9rfwcGCryQlllO4IRn6xXTy98e gh51ItvFjOFnKWiqeFkI7SRz4g== X-Received: by 2002:a17:902:1e6:: with SMTP id b93mr43575179plb.295.1560421895353; Thu, 13 Jun 2019 03:31:35 -0700 (PDT) Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id a12sm2265078pgq.0.2019.06.13.03.31.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jun 2019 03:31:34 -0700 (PDT) From: Sumit Garg To: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: jens.wiklander@linaro.org, corbet@lwn.net, dhowells@redhat.com, jejb@linux.ibm.com, jarkko.sakkinen@linux.intel.com, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, ard.biesheuvel@linaro.org, daniel.thompson@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tee-dev@lists.linaro.org, Sumit Garg Subject: [RFC 1/7] tee: optee: allow kernel pages to register as shm Date: Thu, 13 Jun 2019 16:00:27 +0530 Message-Id: <1560421833-27414-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> References: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kernel pages are marked as normal type memory only so allow kernel pages to be registered as shared memory with OP-TEE. Signed-off-by: Sumit Garg --- drivers/tee/optee/call.c | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.7.4 Reviewed-by: Jens Wiklander diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index aa94270..bce45b1 100644 --- a/drivers/tee/optee/call.c +++ b/drivers/tee/optee/call.c @@ -553,6 +553,13 @@ static int check_mem_type(unsigned long start, size_t num_pages) struct mm_struct *mm = current->mm; int rc; + /* + * Allow kernel address to register with OP-TEE as kernel + * pages are configured as normal memory only. + */ + if (virt_addr_valid(start)) + return 0; + down_read(&mm->mmap_sem); rc = __check_mem_type(find_vma(mm, start), start + num_pages * PAGE_SIZE); From patchwork Thu Jun 13 10:30:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166695 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp908538ilk; Thu, 13 Jun 2019 08:35:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqyllYtxYsOl5BS46dYt7KBXxfcCB2C4+tRygBmmeSHo1mKCIEMsghnzvWMyw0JS8w8qEnWV X-Received: by 2002:a17:90a:20e7:: with SMTP id f94mr6096232pjg.68.1560440100306; Thu, 13 Jun 2019 08:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440100; cv=none; d=google.com; s=arc-20160816; b=gjd1D1rcABKy9bVT5zp8KFX+DLXd/13CbJZcZ5k5D1i5FNpiwutpLfsuZw0iYoOvQ/ 2GemFCcqI2wjqi4SmP8Qfa1GULGPTfhgGInPqhC3/VgZGdUXWodek4VF5nWiQJm2E5oP IlFUavjVxaPU3Ekn9QmLbI/PCY0tljZUHoOTo8KE02qO9+LSbJVvEkUD5m1ZQK28IsMM 1DXwzgczGJnqz65Gf1T7nEqvn4CpAvYAL/4eN7HnZZ1OMghVfuEOaCoY2S1kOYLzT7gG x1bRXofTRCH9fOcU6np+2B3NtTZysApVP0t5TlDdDarpSxHjPh23div2TruJWJ0g4m9e 5aJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=X1ybKF8wUkHdnaXcEVMx2e6e4CdYBWVAzo6oWbimFYQ=; b=04xF5lkC/yKNIbQmalWw0PdQqAO9TI3o8xCqnT2U+jad5YaZiJW/9QZraoed4ti8ie zqx5ajVDOsJAScZ7BYpgi9uvy2E3dVeFl5mX6VBhGMJjPhGVNkEDC063pFlb0Aq+XFaG Kq8esMfX6PATY4db/JiJxfFfLoADFnNMFz9Ps+ajYiNB9W9ZO2lZYP/2z5nQXRfRSL57 LF1BRk7f563zPadAvngsQT2ueK5A6l1/ONJbTeJzY9Y29zlojQXLqWBTwN2P9R6aY7G0 ja/9kdWhDpqTpwDmsdoh4wwrDbA2obyU30JanETtR3y675lGnNjx3/J2b+UNMShCDawR 8ncw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qQC72Jqy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si92213pgq.404.2019.06.13.08.35.00; Thu, 13 Jun 2019 08:35:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qQC72Jqy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732086AbfFMPex (ORCPT + 25 others); Thu, 13 Jun 2019 11:34:53 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33668 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728019AbfFMKbs (ORCPT ); Thu, 13 Jun 2019 06:31:48 -0400 Received: by mail-pf1-f196.google.com with SMTP id x15so11603481pfq.0 for ; Thu, 13 Jun 2019 03:31:48 -0700 (PDT) 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=X1ybKF8wUkHdnaXcEVMx2e6e4CdYBWVAzo6oWbimFYQ=; b=qQC72JqyNS5M5jXNAY8R3qU0KXWZM5lNzLTY1x45KapGIu5nY1kzXvtp8ytpYYAhNe VgEDc2Xb0TO9QjIR1scrGcXdU1EZBuzhgCjzfe7X1+jpmGG6K1x+Pf/9uqbgffhKrmNG wAPT1c1JfaM31idoL06nNamvN48hNPdql4a3HXfHAOdWsQOsfRkD3H3nKJpZB6TPX0ee lVLcpBU+49fTw+3zzRIdis+1cNwUKR2A2T/WWhA/MY121JqRxbEReGNv2toR6GuMHHgy yiSnAlAD6mp1f8mPJKrUvuiGbO6NmXN56mS8pPbZRAPe4I32m2XLpwja0iWkRglQCnZf F3Uw== 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=X1ybKF8wUkHdnaXcEVMx2e6e4CdYBWVAzo6oWbimFYQ=; b=P0jdWxYU11WFZjM+uPbEr0+VkHA0h23HGYz5gkzya74bYk1olzWbl/I01xL3t2QftM T17H8e1Yu3VWOtwt7Vr108P+P2VseirR1n36jHUp0IU9GjH2AfygY9REAVqqe4T8PvDV LUQlUu9rZ9JAooiuJeXmUmiNgO5a3EzGWsbAOx+Vsd27VYmI2OR5e8M8QOJ+sKGnMTlK /iXpamUZGJj+fi50SHvEi/kYfUzv3vv/RoyLYph18TcYXMN931S363pFweuaK4Nc2he8 08Dg631xwIbuZ3uM9a/7R/nBcr3orHBFcpcnt1kMkoYfbdSsAUAXT6FUz5ZnhipUWx93 zXUA== X-Gm-Message-State: APjAAAVK595017ZESi1z6ijGd3Y+wll1r25kwh1yd0SePnWZveaqERNk lNLtaFaNE7513gIbNTDwVmRacQ== X-Received: by 2002:a63:e24:: with SMTP id d36mr29935015pgl.80.1560421908050; Thu, 13 Jun 2019 03:31:48 -0700 (PDT) Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id a12sm2265078pgq.0.2019.06.13.03.31.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jun 2019 03:31:47 -0700 (PDT) From: Sumit Garg To: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: jens.wiklander@linaro.org, corbet@lwn.net, dhowells@redhat.com, jejb@linux.ibm.com, jarkko.sakkinen@linux.intel.com, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, ard.biesheuvel@linaro.org, daniel.thompson@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tee-dev@lists.linaro.org, Sumit Garg Subject: [RFC 2/7] tee: enable support to register kernel memory Date: Thu, 13 Jun 2019 16:00:28 +0530 Message-Id: <1560421833-27414-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> References: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enable support to register kernel memory reference with TEE. This change will allow TEE bus drivers to register memory references. Signed-off-by: Sumit Garg --- drivers/tee/tee_shm.c | 16 ++++++++++++++-- include/linux/tee_drv.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) -- 2.7.4 Reviewed-by: Jens Wiklander diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index 2da026f..5c69b89 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "tee_private.h" static void tee_shm_release(struct tee_shm *shm) @@ -224,13 +225,14 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, { struct tee_device *teedev = ctx->teedev; const u32 req_flags = TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED; + const u32 req_ker_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_flags && flags != req_ker_flags) return ERR_PTR(-ENOTSUPP); if (!tee_device_get(teedev)) @@ -264,7 +266,17 @@ 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 { + const struct kvec kiov = { + .iov_base = (void *)start, + .iov_len = PAGE_SIZE + }; + + rc = get_kernel_pages(&kiov, num_pages, 0, shm->pages); + } if (rc > 0) shm->num_pages = rc; if (rc != num_pages) { diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index 7a03f68..dedf8fa 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -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; From patchwork Thu Jun 13 10:30:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166694 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp908323ilk; Thu, 13 Jun 2019 08:34:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWi5Kyky55dL0Vmx0DohN3j7HwR2ErdBJ+0IvqFqw25s//z6BtcF0gcmeDDRy6IQ7pQRqI X-Received: by 2002:a17:902:778d:: with SMTP id o13mr37899496pll.82.1560440089940; Thu, 13 Jun 2019 08:34:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440089; cv=none; d=google.com; s=arc-20160816; b=S6y4yqoM0ODnfuzytOegsApgt2JT6VzyBWhc233274vwIr3w2Rjj52YxSjdcZJ8h61 KfPgRg3OjdhIXZvpXyAckknA8HyeVd0rtpFSDsOGwyIRem6Yh0fcR9EfdV8PY+3cO+ID /wN8ilue25gXLGPKOvZqItdOs3JPxCtpr5PP8XGiuw4CJC38ksfjVdhRMJrn6RklOM6f nVfj6w50J/YicYQfjnWJTdprufUlvDiif51zev6sV5AnroxGuzSysZfrCHnzzsSKd+xf WSw6sKGVGZibm4fo0SHQFLExlS7JEgYJq5xO8fScD9osn45/dDcMPNOYKvHI/wrPLI23 iLDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=TYugXC8ytxOCfgDh3mg7Chcw/fQ6qx25pA1xGAB2wEo=; b=ldxKGVIqZc+cBeMTXhRiDy0rx/qBbWjVUcK3xYZW6VnR3xMgi+9CZGHs6rMWMTViOa HOmiXg9/UvXM2YQxHYKjXto8rznUdyYtiWuUpwLIVXDoo47F3Joku7CAFNwcy6/xKoK6 WdzVreXYxlBRacifaegeEiRz3J5/hmmZ+/XkFjg1F/qtIuvfVLOfpkW9o6IdSMVoO069 zO5G3BDlT3hcfTRqWptQh9O07qnAWESz2KLTgx9C3lTv6ES4bYXawsAd3/uK2y9xQCLd M903xpjT9OLkpFdssIYbRziR/YG1vFSeNYD8I8DHwRt1wZ/z9Tu313BaSt7smhr7sZ9g kppQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=om1b7q3q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1si97881pgi.278.2019.06.13.08.34.49; Thu, 13 Jun 2019 08:34:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=om1b7q3q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731981AbfFMPes (ORCPT + 25 others); Thu, 13 Jun 2019 11:34:48 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:42255 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728083AbfFMKcB (ORCPT ); Thu, 13 Jun 2019 06:32:01 -0400 Received: by mail-pf1-f195.google.com with SMTP id q10so11556325pff.9 for ; Thu, 13 Jun 2019 03:32:00 -0700 (PDT) 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=TYugXC8ytxOCfgDh3mg7Chcw/fQ6qx25pA1xGAB2wEo=; b=om1b7q3qqqL3hVwwom76w942uIQ0/B4EPiCLfCuWVjwAg29AoGLw6WXFFUHqXBibE+ 0j0OKdm3jdlxA1D/O0QRQOpLhNv5Ogrd9JNks1szszwbDlTE8sSL+SuHA47qdtkMVcBK fh0ruIWuUdE46y+O1g9vrHQwJ2XRu4UtkLoRcxKKBfjvZ+D+584zH7JEa39p/I12YLsd c4SCaI0zDdmJTRvb82Hyib1W7COcIB0wpLY7Sh0Zb0Rch/NfitptGgRpcVvVcY2jHp4N Dv9pfi9mVEfWv5k4TDh02gX+UvZQ5e9qjmJ5q90DuaaSymHzayeEBweOhsV/SAvK222W fDOw== 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=TYugXC8ytxOCfgDh3mg7Chcw/fQ6qx25pA1xGAB2wEo=; b=NUoNVUbTxLFtcn5x9GXgDHaNW9G3zz3r76Qs0P57Ohkf2tnQbc9YNG10mHKirNkrWX GFLUkO8R+jqnyLS2pEqc5l3kNgB4MSTtoKaqECcvAvTPdqQuej7MT15HNgbFa5Hytvcp X9S+6WUImQFl7LctFTM6buDre+rJfUxOQE/EIXi6H7Z+JzC2qwNyJIWOBGIJLQwEEk3S Em8hfZ7rqvNWXv6ZXOEKNMoCrtlE+MJXd5eJhAyoSjsD8CtnMTqGm//EdAZPko6joHiJ bqdyv1jURXyaTQ8ODrr2aZuKknGBWztAynoqLixBeNstSr3qPqRPXrxYvWuj/KF9uKMN z8ow== X-Gm-Message-State: APjAAAV7Xp4Tn/QLbRz4ZahPzatXpoJz0WIcFeb9j5VDG0XPy/gfsjK7 k9sNYo7FxyQV+oqBezrmaZsrIA== X-Received: by 2002:a62:1c92:: with SMTP id c140mr92232910pfc.258.1560421920566; Thu, 13 Jun 2019 03:32:00 -0700 (PDT) Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id a12sm2265078pgq.0.2019.06.13.03.31.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jun 2019 03:31:59 -0700 (PDT) From: Sumit Garg To: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: jens.wiklander@linaro.org, corbet@lwn.net, dhowells@redhat.com, jejb@linux.ibm.com, jarkko.sakkinen@linux.intel.com, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, ard.biesheuvel@linaro.org, daniel.thompson@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tee-dev@lists.linaro.org, Sumit Garg Subject: [RFC 3/7] tee: add private login method for kernel clients Date: Thu, 13 Jun 2019 16:00:29 +0530 Message-Id: <1560421833-27414-4-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> References: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are use-cases where user-space shouldn't be allowed to communicate directly with a TEE device which is dedicated to provide a specific service for a kernel client. So add a private login method for kernel clients and disallow user-space to open-session using this login method. Signed-off-by: Sumit Garg --- drivers/tee/tee_core.c | 6 ++++++ include/uapi/linux/tee.h | 2 ++ 2 files changed, 8 insertions(+) -- 2.7.4 diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index 0f16d9f..4581bd1 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -334,6 +334,12 @@ static int tee_ioctl_open_session(struct tee_context *ctx, goto out; } + if (arg.clnt_login == TEE_IOCTL_LOGIN_REE_KERNEL) { + pr_err("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; diff --git a/include/uapi/linux/tee.h b/include/uapi/linux/tee.h index 4b9eb06..f33c69c 100644 --- a/include/uapi/linux/tee.h +++ b/include/uapi/linux/tee.h @@ -172,6 +172,8 @@ 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 +/* Private login method for REE kernel clients */ +#define TEE_IOCTL_LOGIN_REE_KERNEL 0x80000000 /** * struct tee_ioctl_param - parameter From patchwork Thu Jun 13 10:30:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166693 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp908214ilk; Thu, 13 Jun 2019 08:34:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4Tz5D46NdqvaUkLBoCH5S2v2WA3FXYtbpb45WBunY8OX7zEvXFp5V9L8lzKa1NU7waRv0 X-Received: by 2002:a63:374a:: with SMTP id g10mr20638470pgn.31.1560440084791; Thu, 13 Jun 2019 08:34:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440084; cv=none; d=google.com; s=arc-20160816; b=fY1oijeaYJDHi/9w1BBNo0vhVtpHqEvNuZ85gMEjbpUfya2ndgrus/xbm9mWRZ4I6/ 1k4zkkrpx34B/HbHB+NCzkGRkiS7Qus6pEjrXNIq0Az3EV9ZX8bx27R5SoEG9ACUx9Qq vjBNvvn0AMtfs0ooX7X47FEreMSFHRIBULMxFmohbX3+kvg65i/3qRA2Lzp2sVrzKCFJ nZZ+UpPPtaoRIGS88PHeIUi1c/rraSqP009YZNLMJTTFMHHgYFNuK94sxPfwayiYBVBT sQm6mAMjBoIl6QQt2XLi1Tp4FgnAugkWZfUGWOfelZN0Y2WsOP2MWHMfZ9MpiREgANc2 UOKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=eT8LPwGDFMfUyXsNtLU9GXeTPVS5UTspteAl3GI5bcc=; b=yIHxr7A+fgYozIENMQv0gZ8cDHo/mFXIsvo6pSDHgjXJYMPo7DptcYC2ncIzB1Q0rQ hA01lJI3PFr5a1pMVOioUNI+NUH2U/vSLbazEmxDqa8GpzlunnMRH4eHenqNKr7wFV30 eCwKdlkT/zzNUIwVWTKujgtp5n1eTsL0/FrwRhbRaDOSGn1+RNYcb0EG9KieRUbLLLSM vKxWm/sSPeJ/vkkjIGKOvsL+kle/AYTYlHA0V7Yo3xbjQyR00AH189KF/ylcDlSeKK8X cptI+wh5ATron6/K5cF/TnvzQI+MzsCLPCMsY5l94TDRyntKWyFKeTzNrFUSfFwtZ6fL dnOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uk1HnJFM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r3si3471115plb.14.2019.06.13.08.34.44; Thu, 13 Jun 2019 08:34:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uk1HnJFM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731542AbfFMPen (ORCPT + 25 others); Thu, 13 Jun 2019 11:34:43 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:43048 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728128AbfFMKcO (ORCPT ); Thu, 13 Jun 2019 06:32:14 -0400 Received: by mail-pf1-f196.google.com with SMTP id i189so11559625pfg.10 for ; Thu, 13 Jun 2019 03:32:13 -0700 (PDT) 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=eT8LPwGDFMfUyXsNtLU9GXeTPVS5UTspteAl3GI5bcc=; b=Uk1HnJFMQm0vEuFoU0TuFyKJICqg6OAyqKvR1FuNLoDQJ7CcH3m9qBwzlh1bDSxlN4 6NwuM2gdcK7DrCebzpHhWB0k1mUwjFku5qAHXQ8SBIUadNbd5ejy4SDpVHuBi0bj5GZJ 1IDfRwwWNw2EmhFYaTY3XwmEjmUCcJKjk4ay4ASmvAZA+ACPv03yFBWDvGlfYW87NtS3 0jWHDPSNUf3VHiSMcjYtoiZnETCNSeeHCARMd2/72+wo45oP8GgcBoaLGBQtgwueptrg 1WrHAlAHEcNdXmG0s11zTnFDms5XE9md4Rx4PVBHocxotwDPzQhO1JePK9bzbnBIx4lT BrMA== 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=eT8LPwGDFMfUyXsNtLU9GXeTPVS5UTspteAl3GI5bcc=; b=PWZ0R8U3RO81FXSzNlUdTh6Q+XR/iI+ALUMgJPT65OE0BnCjt0hPePkeSOpKxPR07j i9H3KtQOjcRGSqoMb4Beg5vTRRjDbqShbyHv9hhFK6pBL3PTYBskqwGpBy/KeSfa4CaV KQgaQTao5etjgJmfK5MAHGXvNJQeb98/Ed20C9Wh2aybTvOSx0PI4LEZeSQKDjV92SVp BSIU4ELss6XvB4S0ofzxyvGIpQC1HYzF+CEX6AGzJTcSx/bHELI0UJytrmjibF6O52PZ dRAyAnlpcHPQLTBbe9Gx6yBs+/IaZVV0GPSK9eE+NPM9tOsl5UDlVa1PcdHp650sCJEB DQVQ== X-Gm-Message-State: APjAAAXkQVWQ0iJ1BLDAmiOWWTVBg+6QlYID16Yc7YFmCjiPjN5A3c9b Qn8GpRapvh9LqTdgDct/TxRcpw== X-Received: by 2002:a62:3287:: with SMTP id y129mr35676542pfy.251.1560421933269; Thu, 13 Jun 2019 03:32:13 -0700 (PDT) Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id a12sm2265078pgq.0.2019.06.13.03.32.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jun 2019 03:32:12 -0700 (PDT) From: Sumit Garg To: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: jens.wiklander@linaro.org, corbet@lwn.net, dhowells@redhat.com, jejb@linux.ibm.com, jarkko.sakkinen@linux.intel.com, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, ard.biesheuvel@linaro.org, daniel.thompson@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tee-dev@lists.linaro.org, Sumit Garg Subject: [RFC 4/7] KEYS: trusted: Introduce TEE based Trusted Keys Date: Thu, 13 Jun 2019 16:00:30 +0530 Message-Id: <1560421833-27414-5-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> References: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for TEE based trusted keys where TEE provides the functionality to seal and unseal trusted keys using hardware unique key. Refer to Documentation/tee.txt for detailed information about TEE. Approach taken in this patch acts as an alternative to a TPM device in case platform doesn't possess one. Signed-off-by: Sumit Garg --- include/keys/tee_trusted.h | 84 ++++++++ include/keys/trusted-type.h | 1 + security/keys/Kconfig | 3 + security/keys/Makefile | 3 + security/keys/tee_trusted.c | 506 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 597 insertions(+) create mode 100644 include/keys/tee_trusted.h create mode 100644 security/keys/tee_trusted.c -- 2.7.4 diff --git a/include/keys/tee_trusted.h b/include/keys/tee_trusted.h new file mode 100644 index 0000000..e5c0042 --- /dev/null +++ b/include/keys/tee_trusted.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2019 Linaro Ltd. + * + * Author: + * Sumit Garg + */ + +#ifndef __TEE_TRUSTED_KEY_H +#define __TEE_TRUSTED_KEY_H + +#include + +#define DRIVER_NAME "tee-trusted-key" + +/* + * Get random data for symmetric key + * + * [out] memref[0] Random data + * + * Result: + * TEE_SUCCESS - Invoke command success + * TEE_ERROR_BAD_PARAMETERS - Incorrect input param + */ +#define TA_CMD_GET_RANDOM 0x0 + +/* + * Seal trusted key using hardware unique key + * + * [in] memref[0] Plain key + * [out] memref[1] Sealed key datablob + * + * Result: + * TEE_SUCCESS - Invoke command success + * TEE_ERROR_BAD_PARAMETERS - Incorrect input param + */ +#define TA_CMD_SEAL 0x1 + +/* + * Unseal trusted key using hardware unique key + * + * [in] memref[0] Sealed key datablob + * [out] memref[1] Plain key + * + * Result: + * TEE_SUCCESS - Invoke command success + * TEE_ERROR_BAD_PARAMETERS - Incorrect input param + */ +#define TA_CMD_UNSEAL 0x2 + +/** + * struct trusted_key_private - TEE Trusted key private data + * @dev: TEE based Trusted key device. + * @ctx: TEE context handler. + * @session_id: Trusted key TA session identifier. + * @shm_pool: Memory pool shared with TEE device. + */ +struct trusted_key_private { + struct device *dev; + struct tee_context *ctx; + u32 session_id; + u32 data_rate; + struct tee_shm *shm_pool; +}; + +#define TEE_KEY_DEBUG 0 + +#if TEE_KEY_DEBUG +static inline void dump_tee_payload(struct trusted_key_payload *p) +{ + pr_info("trusted_key: key_len %d\n", p->key_len); + print_hex_dump(KERN_INFO, "key ", DUMP_PREFIX_NONE, + 16, 1, p->key, p->key_len, 0); + pr_info("trusted_key: bloblen %d\n", p->blob_len); + print_hex_dump(KERN_INFO, "blob ", DUMP_PREFIX_NONE, + 16, 1, p->blob, p->blob_len, 0); +} +#else +static inline void dump_tee_payload(struct trusted_key_payload *p) +{ +} +#endif + +#endif diff --git a/include/keys/trusted-type.h b/include/keys/trusted-type.h index a94c03a..363ec83 100644 --- a/include/keys/trusted-type.h +++ b/include/keys/trusted-type.h @@ -41,5 +41,6 @@ struct trusted_key_options { }; extern struct key_type key_type_trusted; +extern struct key_type key_type_tee_trusted; #endif /* _KEYS_TRUSTED_TYPE_H */ diff --git a/security/keys/Kconfig b/security/keys/Kconfig index ee502e4..b206a20 100644 --- a/security/keys/Kconfig +++ b/security/keys/Kconfig @@ -70,6 +70,9 @@ config TRUSTED_KEYS if the boot PCRs and other criteria match. Userspace will only ever see encrypted blobs. + It also provides support for alternative TEE based Trusted keys + generation and sealing in case TPM isn't present. + If you are unsure as to whether this is required, answer N. config ENCRYPTED_KEYS diff --git a/security/keys/Makefile b/security/keys/Makefile index 9cef540..07ad3e2 100644 --- a/security/keys/Makefile +++ b/security/keys/Makefile @@ -30,3 +30,6 @@ obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += keyctl_pkey.o obj-$(CONFIG_BIG_KEYS) += big_key.o obj-$(CONFIG_TRUSTED_KEYS) += trusted.o obj-$(CONFIG_ENCRYPTED_KEYS) += encrypted-keys/ +ifdef CONFIG_TEE +obj-$(CONFIG_TRUSTED_KEYS) += tee_trusted.o +endif diff --git a/security/keys/tee_trusted.c b/security/keys/tee_trusted.c new file mode 100644 index 0000000..081e45e --- /dev/null +++ b/security/keys/tee_trusted.c @@ -0,0 +1,506 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 Linaro Ltd. + * + * Author: + * Sumit Garg + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +static struct trusted_key_private pvt_data; + +/* + * Have the TEE seal(encrypt) the symmetric key + */ +static int tee_key_seal(struct trusted_key_payload *p) +{ + int ret = 0; + struct tee_ioctl_invoke_arg inv_arg; + struct tee_param param[4]; + struct tee_shm *reg_shm_in = NULL, *reg_shm_out = NULL; + + memset(&inv_arg, 0, sizeof(inv_arg)); + memset(¶m, 0, sizeof(param)); + + reg_shm_in = tee_shm_register(pvt_data.ctx, (unsigned long)p->key, + p->key_len, TEE_SHM_DMA_BUF | + TEE_SHM_KERNEL_MAPPED); + if (IS_ERR(reg_shm_in)) { + dev_err(pvt_data.dev, "key shm register failed\n"); + return PTR_ERR(reg_shm_in); + } + + reg_shm_out = tee_shm_register(pvt_data.ctx, (unsigned long)p->blob, + sizeof(p->blob), TEE_SHM_DMA_BUF | + TEE_SHM_KERNEL_MAPPED); + if (IS_ERR(reg_shm_out)) { + dev_err(pvt_data.dev, "blob shm register failed\n"); + ret = PTR_ERR(reg_shm_out); + goto out; + } + + inv_arg.func = TA_CMD_SEAL; + inv_arg.session = pvt_data.session_id; + inv_arg.num_params = 4; + + param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; + param[0].u.memref.shm = reg_shm_in; + param[0].u.memref.size = p->key_len; + param[0].u.memref.shm_offs = 0; + param[1].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT; + param[1].u.memref.shm = reg_shm_out; + param[1].u.memref.size = sizeof(p->blob); + param[1].u.memref.shm_offs = 0; + + ret = tee_client_invoke_func(pvt_data.ctx, &inv_arg, param); + if ((ret < 0) || (inv_arg.ret != 0)) { + dev_err(pvt_data.dev, "TA_CMD_SEAL invoke err: %x\n", + inv_arg.ret); + ret = -EFAULT; + } else { + p->blob_len = param[1].u.memref.size; + } + +out: + if (reg_shm_out) + tee_shm_free(reg_shm_out); + if (reg_shm_in) + tee_shm_free(reg_shm_in); + + return ret; +} + +/* + * Have the TEE unseal(decrypt) the symmetric key + */ +static int tee_key_unseal(struct trusted_key_payload *p) +{ + int ret = 0; + struct tee_ioctl_invoke_arg inv_arg; + struct tee_param param[4]; + struct tee_shm *reg_shm_in = NULL, *reg_shm_out = NULL; + + memset(&inv_arg, 0, sizeof(inv_arg)); + memset(¶m, 0, sizeof(param)); + + reg_shm_in = tee_shm_register(pvt_data.ctx, (unsigned long)p->blob, + p->blob_len, TEE_SHM_DMA_BUF | + TEE_SHM_KERNEL_MAPPED); + if (IS_ERR(reg_shm_in)) { + dev_err(pvt_data.dev, "blob shm register failed\n"); + return PTR_ERR(reg_shm_in); + } + + reg_shm_out = tee_shm_register(pvt_data.ctx, (unsigned long)p->key, + sizeof(p->key), TEE_SHM_DMA_BUF | + TEE_SHM_KERNEL_MAPPED); + if (IS_ERR(reg_shm_out)) { + dev_err(pvt_data.dev, "key shm register failed\n"); + ret = PTR_ERR(reg_shm_out); + goto out; + } + + inv_arg.func = TA_CMD_UNSEAL; + inv_arg.session = pvt_data.session_id; + inv_arg.num_params = 4; + + param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT; + param[0].u.memref.shm = reg_shm_in; + param[0].u.memref.size = p->blob_len; + param[0].u.memref.shm_offs = 0; + param[1].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT; + param[1].u.memref.shm = reg_shm_out; + param[1].u.memref.size = sizeof(p->key); + param[1].u.memref.shm_offs = 0; + + ret = tee_client_invoke_func(pvt_data.ctx, &inv_arg, param); + if ((ret < 0) || (inv_arg.ret != 0)) { + dev_err(pvt_data.dev, "TA_CMD_UNSEAL invoke err: %x\n", + inv_arg.ret); + ret = -EFAULT; + } else { + p->key_len = param[1].u.memref.size; + } + +out: + if (reg_shm_out) + tee_shm_free(reg_shm_out); + if (reg_shm_in) + tee_shm_free(reg_shm_in); + + return ret; +} + +/* + * Have the TEE generate random symmetric key + */ +static int tee_get_random(unsigned char *key, unsigned int key_len) +{ + int ret = 0; + struct tee_ioctl_invoke_arg inv_arg; + struct tee_param param[4]; + struct tee_shm *reg_shm = NULL; + + memset(&inv_arg, 0, sizeof(inv_arg)); + memset(¶m, 0, sizeof(param)); + + reg_shm = tee_shm_register(pvt_data.ctx, (unsigned long)key, key_len, + TEE_SHM_DMA_BUF | TEE_SHM_KERNEL_MAPPED); + if (IS_ERR(reg_shm)) { + dev_err(pvt_data.dev, "random key shm register failed\n"); + return PTR_ERR(reg_shm); + } + + inv_arg.func = TA_CMD_GET_RANDOM; + inv_arg.session = pvt_data.session_id; + inv_arg.num_params = 4; + + param[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT; + param[0].u.memref.shm = reg_shm; + param[0].u.memref.size = key_len; + param[0].u.memref.shm_offs = 0; + + ret = tee_client_invoke_func(pvt_data.ctx, &inv_arg, param); + if ((ret < 0) || (inv_arg.ret != 0)) { + dev_err(pvt_data.dev, "TA_CMD_GET_RANDOM invoke err: %x\n", + inv_arg.ret); + ret = -EFAULT; + } else { + ret = param[0].u.memref.size; + } + + tee_shm_free(reg_shm); + + return ret; +} + +enum { + Opt_err, + Opt_new, Opt_load +}; + +static const match_table_t key_tokens = { + {Opt_new, "new"}, + {Opt_load, "load"}, + {Opt_err, NULL} +}; + +/* + * datablob_parse - parse the keyctl data and fill in the + * payload structure + * + * On success returns 0, otherwise -EINVAL. + */ +static int datablob_parse(char *datablob, struct trusted_key_payload *p) +{ + substring_t args[MAX_OPT_ARGS]; + long keylen; + int ret = -EINVAL; + int key_cmd; + char *c; + + /* main command */ + c = strsep(&datablob, " \t"); + if (!c) + return -EINVAL; + + key_cmd = match_token(c, key_tokens, args); + switch (key_cmd) { + case Opt_new: + /* first argument is key size */ + c = strsep(&datablob, " \t"); + if (!c) + return -EINVAL; + ret = kstrtol(c, 10, &keylen); + if (ret < 0 || keylen < MIN_KEY_SIZE || keylen > MAX_KEY_SIZE) + return -EINVAL; + p->key_len = keylen; + ret = Opt_new; + break; + case Opt_load: + /* first argument is sealed blob */ + c = strsep(&datablob, " \t"); + if (!c) + return -EINVAL; + p->blob_len = strlen(c) / 2; + if (p->blob_len > MAX_BLOB_SIZE) + return -EINVAL; + ret = hex2bin(p->blob, c, p->blob_len); + if (ret < 0) + return -EINVAL; + ret = Opt_load; + break; + case Opt_err: + return -EINVAL; + } + + return ret; +} + +static struct trusted_key_payload *trusted_payload_alloc(struct key *key) +{ + struct trusted_key_payload *p = NULL; + int ret; + + ret = key_payload_reserve(key, sizeof(*p)); + if (ret < 0) + return p; + + p = kzalloc(sizeof(*p), GFP_KERNEL); + + return p; +} + +/* + * trusted_instantiate - create a new trusted key + * + * Unseal an existing trusted blob or, for a new key, get a + * random key, then seal and create a trusted key-type key, + * adding it to the specified keyring. + * + * On success, return 0. Otherwise return errno. + */ +static int trusted_instantiate(struct key *key, + struct key_preparsed_payload *prep) +{ + struct trusted_key_payload *payload = NULL; + size_t datalen = prep->datalen; + char *datablob; + int ret = 0; + int key_cmd; + size_t key_len; + + if (datalen <= 0 || datalen > 32767 || !prep->data) + return -EINVAL; + + datablob = kmalloc(datalen + 1, GFP_KERNEL); + if (!datablob) + return -ENOMEM; + memcpy(datablob, prep->data, datalen); + datablob[datalen] = '\0'; + + payload = trusted_payload_alloc(key); + if (!payload) { + ret = -ENOMEM; + goto out; + } + + key_cmd = datablob_parse(datablob, payload); + if (key_cmd < 0) { + ret = key_cmd; + goto out; + } + + dump_tee_payload(payload); + + switch (key_cmd) { + case Opt_load: + ret = tee_key_unseal(payload); + dump_tee_payload(payload); + if (ret < 0) + dev_err(pvt_data.dev, "key_unseal failed (%d)\n", ret); + break; + case Opt_new: + key_len = payload->key_len; + ret = tee_get_random(payload->key, key_len); + if (ret != key_len) { + dev_err(pvt_data.dev, "key_create failed (%d)\n", ret); + goto out; + } + + ret = tee_key_seal(payload); + if (ret < 0) + dev_err(pvt_data.dev, "key_seal failed (%d)\n", ret); + dump_tee_payload(payload); + break; + default: + ret = -EINVAL; + goto out; + } +out: + kzfree(datablob); + if (!ret) + rcu_assign_keypointer(key, payload); + else + kzfree(payload); + return ret; +} + +static int trusted_update(struct key *key, struct key_preparsed_payload *prep) +{ + dev_info(pvt_data.dev, "trusted key update method not supported\n"); + + return -EINVAL; +} + +/* + * trusted_read - copy the sealed blob data to userspace in hex. + * On success, return to userspace the trusted key datablob size. + */ +static long trusted_read(const struct key *key, char __user *buffer, + size_t buflen) +{ + const struct trusted_key_payload *p; + char *ascii_buf; + char *bufp; + int i; + + p = dereference_key_locked(key); + if (!p) + return -EINVAL; + + if (buffer && buflen >= 2 * p->blob_len) { + ascii_buf = kmalloc_array(2, p->blob_len, GFP_KERNEL); + if (!ascii_buf) + return -ENOMEM; + + bufp = ascii_buf; + for (i = 0; i < p->blob_len; i++) + bufp = hex_byte_pack(bufp, p->blob[i]); + if (copy_to_user(buffer, ascii_buf, 2 * p->blob_len) != 0) { + kzfree(ascii_buf); + return -EFAULT; + } + kzfree(ascii_buf); + } + return 2 * p->blob_len; +} + +/* + * trusted_destroy - clear and free the key's payload + */ +static void trusted_destroy(struct key *key) +{ + kzfree(key->payload.data[0]); +} + +struct key_type key_type_tee_trusted = { + .name = "trusted", + .instantiate = trusted_instantiate, + .update = trusted_update, + .destroy = trusted_destroy, + .describe = user_describe, + .read = trusted_read, +}; +EXPORT_SYMBOL_GPL(key_type_tee_trusted); + +static int optee_ctx_match(struct tee_ioctl_version_data *ver, const void *data) +{ + if (ver->impl_id == TEE_IMPL_ID_OPTEE) + return 1; + else + return 0; +} + +static int trusted_key_probe(struct device *dev) +{ + struct tee_client_device *rng_device = to_tee_client_device(dev); + int ret = 0, err = -ENODEV; + struct tee_ioctl_open_session_arg sess_arg; + + memset(&sess_arg, 0, sizeof(sess_arg)); + + /* Open context with TEE driver */ + pvt_data.ctx = tee_client_open_context(NULL, optee_ctx_match, NULL, + NULL); + if (IS_ERR(pvt_data.ctx)) + return -ENODEV; + + /* Open session with hwrng Trusted App */ + memcpy(sess_arg.uuid, rng_device->id.uuid.b, TEE_IOCTL_UUID_LEN); + sess_arg.clnt_login = TEE_IOCTL_LOGIN_REE_KERNEL; + sess_arg.num_params = 0; + + ret = tee_client_open_session(pvt_data.ctx, &sess_arg, NULL); + if ((ret < 0) || (sess_arg.ret != 0)) { + dev_err(dev, "tee_client_open_session failed, err: %x\n", + sess_arg.ret); + err = -EINVAL; + goto out_ctx; + } + pvt_data.session_id = sess_arg.session; + + ret = register_key_type(&key_type_tee_trusted); + if (ret < 0) + goto out_sess; + + pvt_data.dev = dev; + + return 0; + +out_sess: + tee_client_close_session(pvt_data.ctx, pvt_data.session_id); +out_ctx: + tee_client_close_context(pvt_data.ctx); + + return err; +} + +static int trusted_key_remove(struct device *dev) +{ + unregister_key_type(&key_type_tee_trusted); + tee_client_close_session(pvt_data.ctx, pvt_data.session_id); + tee_client_close_context(pvt_data.ctx); + + return 0; +} + +static const struct tee_client_device_id trusted_key_id_table[] = { + {UUID_INIT(0xf04a0fe7, 0x1f5d, 0x4b9b, + 0xab, 0xf7, 0x61, 0x9b, 0x85, 0xb4, 0xce, 0x8c)}, + {} +}; + +MODULE_DEVICE_TABLE(tee, trusted_key_id_table); + +static struct tee_client_driver trusted_key_driver = { + .id_table = trusted_key_id_table, + .driver = { + .name = DRIVER_NAME, + .bus = &tee_bus_type, + .probe = trusted_key_probe, + .remove = trusted_key_remove, + }, +}; + +static int __init init_tee_trusted(void) +{ + struct tpm_chip *chip; + + /* + * Check for TPM availability as that is default source for trusted + * keys. If not present, then register driver for TEE based device + * providing support for trusted keys. + */ + chip = tpm_default_chip(); + if (chip) + return 0; + + return driver_register(&trusted_key_driver.driver); +} + +static void __exit cleanup_tee_trusted(void) +{ + driver_unregister(&trusted_key_driver.driver); +} + +late_initcall(init_tee_trusted); +module_exit(cleanup_tee_trusted); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Sumit Garg "); +MODULE_DESCRIPTION("TEE based trusted keys"); From patchwork Thu Jun 13 10:30:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166692 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp907838ilk; Thu, 13 Jun 2019 08:34:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxb0o6Dwq+BDBrLqbuB4G9hDkcMmv5Y41zVHJVEqgId+ENwdQSfBwwnbDxAjAaZqzteLu62 X-Received: by 2002:a63:c006:: with SMTP id h6mr24689609pgg.285.1560440063532; Thu, 13 Jun 2019 08:34:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440063; cv=none; d=google.com; s=arc-20160816; b=z2bTSdOFzBwE6XMnfXqXIbdEEvlJSuCNUF6QPQlosrLe2dAYvM2rDRC6Nw+RKcJhMD nGTziFIFmUvWNS8x508li9o4AFKW8NFQl+DB71jVIiskktERWvC6dPfBY82dhs3FtSmx Vdqt0gAIjWBMvgH1y4iUCQKlBXehYSiNUZQPE88pWowz80U8qsE0F1dEPLnMliKxCRcq SuzvRAcPVnGLO8qMI99UOcXwCDzXG+dNEjyCrPFwcTKtZ/eYSY3D8O3O6jZ6QTLvtj0g POtsxtbDxjX+0Shc4HOPH5GeJ26+HaEFnwevuL4lac7aQBW+yjfKADbu9bVNq++oX5+1 uMSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=zAP35FMwIaJoHRTsWTgqlS+4eqrXf3lXTLZsbBgKALU=; b=tyoxtG5mUZ7d53lceS2xvnW1VG6btF1mEtcJvhMsz9iUjbAzE0s3sHFApO0WqdFpyC 8eswcL6Wc+HznZLFtMnhEW36xCH+ogzqdYbuQCSiXcblO8TyhaZ0n86pwCPiVc2jYJcs fTu8syaxr2rMMGnxtTU8d3sRR94hmGfFSNfjjlFETOdGbgR4MojYuUmxiNahtgLqm+5V u05cfiXu/I94e7+C7Zg53hzuO3DB/fiiOUB6DbbaSUC7W98GzPol4A/4LG4Fcueofl6r OiHK1we5J9BNnBZucnSKO0DUaSCdTABXJICiY+ElnQ6H0kdnOYQ6aSOOgRqJPRkLi9aK um2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I8WZqaHu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 207si3772109pfu.258.2019.06.13.08.34.23; Thu, 13 Jun 2019 08:34:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I8WZqaHu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731414AbfFMPeW (ORCPT + 25 others); Thu, 13 Jun 2019 11:34:22 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:41697 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728197AbfFMKc0 (ORCPT ); Thu, 13 Jun 2019 06:32:26 -0400 Received: by mail-pf1-f195.google.com with SMTP id m30so11056624pff.8 for ; Thu, 13 Jun 2019 03:32:26 -0700 (PDT) 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=zAP35FMwIaJoHRTsWTgqlS+4eqrXf3lXTLZsbBgKALU=; b=I8WZqaHuq/yhoMfw5I5pMLLVxm8cNFa61hNwQ8JLEMlCB8EUyJDcawmklBfvxhPYCl 5QfsPIYKqAlH9CKbXYD8qGVKPqgYgYNL5qFGx11M2gg4jknzMJ2je5vQxiIEo2GWD5G/ RxhSDlH9Q9RQ/EG0N/XQAWCefLd9GHdFP0Ho9vndyKfvJW/F0y6GH3rSRSR/oA8ric1P KaJ5iam2I3ar+sVxc5p9E9Bfv94xReZjTfPJhJnUezS8g8jb+A8kp0qWVI4luHG7wWWh PrG1F5qZGOs5QlF8Jcng3xBuK+0z2rvPRMRUkxRXs3sbtmIRmZNB6mWw8sVkKHcVmOb8 uK1g== 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=zAP35FMwIaJoHRTsWTgqlS+4eqrXf3lXTLZsbBgKALU=; b=lNZH9B09WWvuKNAgVCyVk+Xiys5O+I7GZe0oNIkewNUWFp9STItt8d8VeN0NecczEf Dufvukn8D25B/GvQfDhCPHhZLf1z9LOXfmIqWyzvGARLaauBOfnOvFo/TTwLdOanieid x1f9FEKtLK5na4zwGIP2M5i5YACXcyqgAv7fMLR6lMFufJC3Vx4Kk8sT4+Dnpswi6OEz U2LGsF4R7R3GFJIsYBWMf6yXW0aHO9u8OSBrFUM9ITKoU4H/NLFoe+f2Vx2hBR0k5WCB XdysATJXc1IpemO9TdwZSDfb9uMliyhNW4KpTpFXScrnAhTB5xNQfwyILe34gAkHg8BL 0Jog== X-Gm-Message-State: APjAAAV2SOOWiXxqNnB7vxWSoCUH5RxbX3HjtCeo6L242LPkPcQ7Bo79 VToP4XmdQ+Zqye2z2dOntKoEKA== X-Received: by 2002:a17:90a:2525:: with SMTP id j34mr383810pje.11.1560421945985; Thu, 13 Jun 2019 03:32:25 -0700 (PDT) Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id a12sm2265078pgq.0.2019.06.13.03.32.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jun 2019 03:32:25 -0700 (PDT) From: Sumit Garg To: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: jens.wiklander@linaro.org, corbet@lwn.net, dhowells@redhat.com, jejb@linux.ibm.com, jarkko.sakkinen@linux.intel.com, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, ard.biesheuvel@linaro.org, daniel.thompson@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tee-dev@lists.linaro.org, Sumit Garg Subject: [RFC 5/7] KEYS: encrypted: Allow TEE based trusted master keys Date: Thu, 13 Jun 2019 16:00:31 +0530 Message-Id: <1560421833-27414-6-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> References: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow search for TEE based trusted keys to act as master keys in case TPM device is not present. Signed-off-by: Sumit Garg --- security/keys/encrypted-keys/masterkey_trusted.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/security/keys/encrypted-keys/masterkey_trusted.c b/security/keys/encrypted-keys/masterkey_trusted.c index c68528a..cfac27f 100644 --- a/security/keys/encrypted-keys/masterkey_trusted.c +++ b/security/keys/encrypted-keys/masterkey_trusted.c @@ -23,6 +23,9 @@ * Trusted keys are sealed to PCRs and other metadata. Although userspace * manages both trusted/encrypted key-types, like the encrypted key type * data, trusted key type data is not visible decrypted from userspace. + * + * Also, check for alternate trusted keys provided via TEE in case there + * is no TPM available. */ struct key *request_trusted_key(const char *trusted_desc, const u8 **master_key, size_t *master_keylen) @@ -31,8 +34,11 @@ struct key *request_trusted_key(const char *trusted_desc, struct key *tkey; tkey = request_key(&key_type_trusted, trusted_desc, NULL); - if (IS_ERR(tkey)) - goto error; + if (IS_ERR(tkey)) { + tkey = request_key(&key_type_tee_trusted, trusted_desc, NULL); + if (IS_ERR(tkey)) + goto error; + } down_read(&tkey->sem); tpayload = tkey->payload.data[0]; From patchwork Thu Jun 13 10:30:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166691 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp907811ilk; Thu, 13 Jun 2019 08:34:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqh+mfQVxOvPCxWOB0Hh43HQqNPRx4kIQdC/NcbmyicnUZmsIdYZYGjU0sn/KvI66UhKg8 X-Received: by 2002:a17:902:7591:: with SMTP id j17mr89076035pll.200.1560440061727; Thu, 13 Jun 2019 08:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440061; cv=none; d=google.com; s=arc-20160816; b=dz4Qiv2RulD/De6/Bjywvn2zTaXqWihTMcA6Du6c+ZvyNIj9IflsohyGbkzYZS7uv5 GhaBR+YJ1pUDV6eVO4ELX+opWSDmoWMcJai1CTJmtjBP+uyRzeN67OV0Ouor9RpGE4db pMyEeTp2zbDRvzUuCaIntK3LpmC5Cdw3Hs71DoCgN94vSAJmQXOdJ8wNuImPkPU8jzsr hj5xifGmJ682ApLAkOBeM6Gjabj0CzW6nSb5vdg5EFZBz+OUBV3whFaBiuh0rs2Aebmv +8IUUkHgfSFY+rDVBqIao8l4CBM+7q6F3aykOuVBjchrls8m+KnUAlARx/Ewph4OhFeC luOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=BG6KAi08hN8hMpB1R8APRtbarxqkieDJBwiiKnKxNvA=; b=MxSPXVz2XiE3aSs6XgF1s2XyStYKJQ78t3uZS/Fe7PeIGjcmZmzp6yit7HEuoJDRA6 6lFZMRy39vOg4y4h7YumrY8yrhzJF6M4ZGoDPPTapfmnuk6JaSB0ylTxvTS5DexCgtfU 4h0a/XQMGVaD4mrq5oxo1RAww/XQjJ8fjAUexu4xbx+JrRdfmXnj4AogxqKqXiQnCBVI vVMi+6YNooi3tPFYdok3H2f7tmAYrwdAAFsWLIOqEuASRA0+70OSK4Wa1MWxMBAuNZqv KLkMWFrWYUCMmvAOY18PdA5cg8ZPd39Wd9gUgEk+FMCdm+QTo9R1y8+SwELyJKsVhz/0 tS/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qXrt3EVT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 207si3772109pfu.258.2019.06.13.08.34.21; Thu, 13 Jun 2019 08:34:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qXrt3EVT; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732193AbfFMPeU (ORCPT + 25 others); Thu, 13 Jun 2019 11:34:20 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41721 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728217AbfFMKcj (ORCPT ); Thu, 13 Jun 2019 06:32:39 -0400 Received: by mail-pf1-f194.google.com with SMTP id m30so11056958pff.8 for ; Thu, 13 Jun 2019 03:32:39 -0700 (PDT) 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=BG6KAi08hN8hMpB1R8APRtbarxqkieDJBwiiKnKxNvA=; b=qXrt3EVTApU5PvFn4bX//ulUNLUoEPsUKJqd/tEwgQrVBEW7kK6cIqJbHvlbz0ZwZw yXkdyYL78AAok2TZ4dUIK02ownxUUArBRRhlZFyofgOaJ5Ab0Xqmfb61n4o8y6gNLDFA 9uq1ElY6ote0C9kIBMHRPLdLqbL7XZUgXPfzQaKaRLdAe00jHCagKg7cvHL/ECbtjyr6 O5B0MYJenVXtiZPFm2DIsWKMKQpoYDyi9ooepPfnJACg1HGlqLmyY9jYOmIbj1SFpKWo dR9tq4Slzc5DwWnZCRZ6ifEeYJDQNLKZ6Ip3CeXwhTQgjdCNZQuDE2Nn0S6CbrO9y+l0 tWpA== 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=BG6KAi08hN8hMpB1R8APRtbarxqkieDJBwiiKnKxNvA=; b=R7Z70t4yCM8C/Ev0Dq024ETZyt9hZSplvg1V0KXP5jJ6Ey/s1c5R1nu03Q1yXe0ots jRg7MOzaFXKcHhIRsqi847S7TjPPFbMXfWxBvQVk9EvJCvOXt6pop4DagfJgG4bKltQm ErDFpAzA51YEAfqhLM0WncNJwlwvgrH6vzAYeJWW9Z2a1dMqA0kYc6mCZiZG4YgMWIK9 LDThjizA5q8f98j+Y7J3+Ta7ahxz+4XyGRv8xqVQJ/uU3mNqe/d+CNeWEsm/Ah1eDxAp sZ8fN3HXFSVLJ3+W/bZ3Tbc2vmeQ+R96mM02Jn/zj4qbrfmKwDRfoyZoZiBYBPlaRCri +niw== X-Gm-Message-State: APjAAAUrcufRYHuSSMKKGA54gnrys37NgQ6LlT7hapBAi82HwScUOry9 SqurUlVXLUBKfoQbcbRnSOu8Aw== X-Received: by 2002:a62:ee17:: with SMTP id e23mr94599955pfi.130.1560421958641; Thu, 13 Jun 2019 03:32:38 -0700 (PDT) Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id a12sm2265078pgq.0.2019.06.13.03.32.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jun 2019 03:32:37 -0700 (PDT) From: Sumit Garg To: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: jens.wiklander@linaro.org, corbet@lwn.net, dhowells@redhat.com, jejb@linux.ibm.com, jarkko.sakkinen@linux.intel.com, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, ard.biesheuvel@linaro.org, daniel.thompson@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tee-dev@lists.linaro.org, Sumit Garg Subject: [RFC 6/7] doc: keys: Document usage of TEE based Trusted Keys Date: Thu, 13 Jun 2019 16:00:32 +0530 Message-Id: <1560421833-27414-7-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> References: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide documentation for usage of TEE based Trusted Keys via existing user-space "keyctl" utility. Also, document various use-cases. Signed-off-by: Sumit Garg --- Documentation/security/keys/tee-trusted.rst | 93 +++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Documentation/security/keys/tee-trusted.rst -- 2.7.4 diff --git a/Documentation/security/keys/tee-trusted.rst b/Documentation/security/keys/tee-trusted.rst new file mode 100644 index 0000000..ef03745 --- /dev/null +++ b/Documentation/security/keys/tee-trusted.rst @@ -0,0 +1,93 @@ +====================== +TEE based Trusted Keys +====================== + +TEE based Trusted Keys provides an alternative approach for providing Trusted +Keys in case TPM chip isn't present. + +Trusted Keys use a TEE service/device both to generate and to seal the keys. +Keys are sealed under a hardware unique key in the TEE, and only unsealed by +the TEE. + +For more information about TEE, refer to ``Documentation/tee.txt``. + +Usage:: + + keyctl add trusted name "new keylen" ring + keyctl add trusted name "load hex_blob" ring + keyctl print keyid + +"keyctl print" returns an ascii hex copy of the sealed key, which is in format +specific to TEE device implementation. The key length for new keys are always +in bytes. Trusted Keys can be 32 - 128 bytes (256 - 1024 bits). + +Examples of trusted key and its usage as 'master' key for encrypted key usage: + +More details about encrypted keys can be found here: +``Documentation/security/keys/trusted-encrypted.rst`` + +Create and save a trusted key named "kmk" of length 32 bytes:: + + $ keyctl add trusted kmk "new 32" @u + 754414669 + + $ keyctl show + Session Keyring + 827385718 --alswrv 0 65534 keyring: _uid_ses.0 + 274124851 --alswrv 0 65534 \_ keyring: _uid.0 + 754414669 --als-rv 0 0 \_ trusted: kmk + + $ keyctl print 754414669 + 15676790697861b422175596ae001c2f505cea2c6f3ebbc5fb08eeb1f343a07e + + $ keyctl pipe 754414669 > kmk.blob + +Load a trusted key from the saved blob:: + + $ keyctl add trusted kmk "load `cat kmk.blob`" @u + 491638700 + + $ keyctl print 491638700 + 15676790697861b422175596ae001c2f505cea2c6f3ebbc5fb08eeb1f343a07e + +The initial consumer of trusted keys is EVM, which at boot time needs a high +quality symmetric key for HMAC protection of file metadata. The use of a +TEE based trusted key provides security that the EVM key has not been +compromised by a user level problem and tied to particular hardware. + +Create and save an encrypted key "evm" using the above trusted key "kmk": + +option 1: omitting 'format':: + + $ keyctl add encrypted evm "new trusted:kmk 32" @u + 608915065 + +option 2: explicitly defining 'format' as 'default':: + + $ keyctl add encrypted evm "new default trusted:kmk 32" @u + 608915065 + + $ keyctl print 608915065 + default trusted:kmk 32 f380ac588a925f488d5be007cf23e4c900b8b652ab62241c8 + ed54906189b6659d139d619d4b51752a2645537b11fd44673f13154a65b3f595d5fb2131 + 2fe45529ea0407c644ea4026f2a1a75661f2c9b66 + + $ keyctl pipe 608915065 > evm.blob + +Load an encrypted key "evm" from saved blob:: + + $ keyctl add encrypted evm "load `cat evm.blob`" @u + 831684262 + + $ keyctl print 831684262 + default trusted:kmk 32 f380ac588a925f488d5be007cf23e4c900b8b652ab62241c8 + ed54906189b6659d139d619d4b51752a2645537b11fd44673f13154a65b3f595d5fb2131 + 2fe45529ea0407c644ea4026f2a1a75661f2c9b66 + +Other uses for trusted and encrypted keys, such as for disk and file encryption +are anticipated. In particular the 'ecryptfs' encrypted keys format can be used +to mount an eCryptfs filesystem. More details about the usage can be found in +the file ``Documentation/security/keys/ecryptfs.rst``. + +Another format 'enc32' can be used to support encrypted keys with payload size +of 32 bytes. From patchwork Thu Jun 13 10:30:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166690 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp907692ilk; Thu, 13 Jun 2019 08:34:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwE8THgQqe8xov4Rw80xjtjgZSZxZy7eL6wILtqGSbuArjmYom1w9wETEUrHUbuI2b98iu+ X-Received: by 2002:a63:1316:: with SMTP id i22mr32338732pgl.274.1560440055712; Thu, 13 Jun 2019 08:34:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440055; cv=none; d=google.com; s=arc-20160816; b=PioGLyqNE40DGzWb81ggVimpXdu8F1010bwZ9HOcEwHfJ162elMVPVn+7TlyI6fhKK yy2Z+7Blrqds6vlG5MumCVd3tOhtsWtRO57X4QDSWsxzJRWt/aSo4bZeClJiwkyp4VGe lp5DC0xjrTdUj8SFDsLMnUQmFuxZx+SqCcYSm4dUsgVWRj2eafDQlND3qm6ZWx/hOwkO zfM3IR6ucBU9XK+pRysoinFAcnGZ1UQDqxYeMW8wr/d+ZD5ieu2cC6rTC1fDr01qRh7Q IQmG2zlqCnyPSEkn/9WHfmxrHZrwU44v7uN/CbMqaYX+tdPcNBB0eY6CZcl96HjEGqMJ 50Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=c8B2WpV2ao/GiAyoXZe0rgTXimW81Zj9eba5b1nq+eE=; b=DjN/PNhWTtDaiJyWOd7RvfrcYACmjLh34ZDVTkkfb9Pnngu0iLv96+rSiUR3uxSX9x mHHA9Nqy5iJBF6OwGjrUOQAMX1bXeOMXl0Tpif2DX7EHdjHV3CRmGCbOYjYit2bz2/fK CYnpCu6dppIQteLmta/O5tIf74Oxs45QD76mAfiVpHyK+qZAFhYhnAWTQ1fo+05sbBiJ C54QqACepTqEg0s+WzXOsbl/HZLNvtPSRq1bGV9JCzbq4I6poU/ofXfKTjZ0VLtK8wab M/euHWQN8Hrto53cpqxQ4bS0BkLbFIxSEnj0KebFIAwbay8oQ22dJfYt29sGRVlMegdN gqkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h8V7naw5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si3515856pfd.79.2019.06.13.08.34.15; Thu, 13 Jun 2019 08:34:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h8V7naw5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732314AbfFMPeO (ORCPT + 25 others); Thu, 13 Jun 2019 11:34:14 -0400 Received: from mail-pg1-f176.google.com ([209.85.215.176]:45690 "EHLO mail-pg1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728268AbfFMKcw (ORCPT ); Thu, 13 Jun 2019 06:32:52 -0400 Received: by mail-pg1-f176.google.com with SMTP id s21so175626pga.12 for ; Thu, 13 Jun 2019 03:32:52 -0700 (PDT) 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=c8B2WpV2ao/GiAyoXZe0rgTXimW81Zj9eba5b1nq+eE=; b=h8V7naw5ZXcy9hmK/khUBCeii6w8istWHF8EhmWYofLp5tS8e7g/0p6wZ6C0USi+Dh mrRUluvbHlgWF/K0yOocTUP2YlkLwNpFUDSsXVVnXSqzMxRZWRa8AlpSQUB4RrPs6IWp Un0SbBuDDP+12ShPcNz/XCABHYeLuj6PS9IayrYHiA8AwtHPQ4tPtuphrFBF90Vs17i1 vsXkMoAETxkRSg8jeio5rfDxL0JIBqmfMMx1icRj4Xq3iUPOW52qUByywGCwTiXh8DFu 1ObjgH9WASPPsW9zF4CAFudb6rqRmc7X2kjWgK4X/RZCxjra/QjT4/pkl2l4+HA8RP9h ch5A== 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=c8B2WpV2ao/GiAyoXZe0rgTXimW81Zj9eba5b1nq+eE=; b=S8X4pITuhfvy0soxxd10euRczfXWZEORl3pFL67LCe9CQwGb5zeU5cuMSUVB0IfSO9 4XgS+X2X+J+0dXLgP4bkYEy2aI2OFtoglmS+LIEOqapKt1hLdUNJ3u2S8GJTL+BzQjma pbVr20HjXISV34FZRzBC4e/v4kNsdXLdVOic/TT9yQB+DVGHxQg0hop00B24o2F0xJuq Ej3ZKlBZ5QnzQWvoqAWdZ4Tp7gigceDB4u0YXtB6TvnyTX0D/sFzsYjUuzHeujNbO2xT EnUQewzipN4MtLUruk9qcC9Q0ccki/NUgNRbzMDCq22ZZkdmY9nuK8H7AcKiH7YGUwLw TTzg== X-Gm-Message-State: APjAAAXp1vb8BpeVX2qHiObraEnW9kCKO1S920lQAQ7RxhZXEfJeo4tU LxGLmNV29pEYh1WyX7x2CCYsbg== X-Received: by 2002:a17:90a:8c06:: with SMTP id a6mr963486pjo.45.1560421971996; Thu, 13 Jun 2019 03:32:51 -0700 (PDT) Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id a12sm2265078pgq.0.2019.06.13.03.32.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jun 2019 03:32:51 -0700 (PDT) From: Sumit Garg To: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Cc: jens.wiklander@linaro.org, corbet@lwn.net, dhowells@redhat.com, jejb@linux.ibm.com, jarkko.sakkinen@linux.intel.com, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, ard.biesheuvel@linaro.org, daniel.thompson@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, tee-dev@lists.linaro.org, Sumit Garg Subject: [RFC 7/7] MAINTAINERS: Add entry for TEE based Trusted Keys Date: Thu, 13 Jun 2019 16:00:33 +0530 Message-Id: <1560421833-27414-8-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> References: <1560421833-27414-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add MAINTAINERS entry for TEE based Trusted Keys framework. Signed-off-by: Sumit Garg --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.7.4 diff --git a/MAINTAINERS b/MAINTAINERS index 57f496c..db84fc4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8728,6 +8728,15 @@ F: include/keys/trusted-type.h F: security/keys/trusted.c F: security/keys/trusted.h +KEYS-TEE-TRUSTED +M: Sumit Garg +L: linux-integrity@vger.kernel.org +L: keyrings@vger.kernel.org +S: Supported +F: Documentation/security/keys/tee-trusted.rst +F: include/keys/tee_trusted.h +F: security/keys/tee_trusted.c + KEYS/KEYRINGS: M: David Howells L: keyrings@vger.kernel.org