From patchwork Mon Jun 10 12:08: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: 166310 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp949300ilk; Mon, 10 Jun 2019 05:08:56 -0700 (PDT) X-Received: by 2002:a17:902:106:: with SMTP id 6mr6813329plb.64.1560168536599; Mon, 10 Jun 2019 05:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560168536; cv=none; d=google.com; s=arc-20160816; b=X51f2B8iLyGFr9drH8rZsEaYYMp468EhgQcpSD+Hd7FNW1CW3yxd1gzcqDbDbZvoYl hs+bThaTDDSXg8N4qjFQXX3GfpnjoGfV4s84o8Y8TiZc+0DvOn/Fxyu4jpRIp2WXaXox VOt+637IPY6j08vYJw9Gf/x6IwoWj22zC/x0d3ZbMlD2JamYdheFSPEpBkM+ufSQm5Yo tdKho0sNADciE1AIOF8wks/73+IY99uPcLAJVfrnvEJZq77wuTdy4rIwaL8A/gXAixH1 +EVIc9ugWF1cTDdgBwIjULjwdVyyrEay0bWY+zUAqUmHeo+MkmKJtKmOQaF8QfUx6IV2 WAtQ== 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; bh=jvasPFs4IBWgAyd3lHtflV42sV75uGuW0yjXvGnjqF8=; b=iFvWkz1B2ru3MU32bCJC/gRzl7GCZq64YPiH5T+RC7OM2VpGcimzdMiKShT51jTBRJ utSSF0Ik5Mq0JWWcfxRrf+Ld9Eh1HAeW0AT+lDC71EAGuCilxTeaDRjmaksgvLxGiWGX yno05M1YZqXDdTgt/nytVYIfOCeufx53tneQclmAyhsIQm8TqyLi6cIEYz7IZAfCUgrg Vme0lowoG3b+dPpmHM/A7qIbkjVtXd+RL2UtXAJyiprEr1CgxUKM8dUNQeLH0gfB1uC1 be+8bbsfuPiJST2hKgkE7ja5zCV1+Q1qGwyLgOhO/bOt5P6R8QF3NTQBk06P7NVkclDP oNmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rBUK0OMa; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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 b65sor11496451plb.21.2019.06.10.05.08.56 for (Google Transport Security); Mon, 10 Jun 2019 05:08:56 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@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=rBUK0OMa; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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=jvasPFs4IBWgAyd3lHtflV42sV75uGuW0yjXvGnjqF8=; b=rBUK0OMa4Xak46OP6ugnCMavFAU0M75jEb/q5OzjxrDzIyQE6JY6xEEyAyxzMgVPL4 TPFtTE/OmTyLyNh9QevxT3soMp41QOGwSlEwsEdtOBnfyFnsoOoY2tcSwXaSX93eGnDR zfreci2ZxESr1eO/nI6IdI6mOHDOu4S2eDp+m8WlZIouZiigU7DdWNSNXCOlsdSP5LMq fSgLx4qcFDsXfQ7cof1hNc8QfdPc9LlNi9uhKrMTkhO5qCATs8J65JaUK3a6t6+dGe4M pYvdU5qEOCIIUOR2KNY9UUDHJRo7brytd5Ek4Hm4LO/7hSTKWsN3mZ2KrW31DBwP3Ame HtbQ== 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=jvasPFs4IBWgAyd3lHtflV42sV75uGuW0yjXvGnjqF8=; b=MvL7JJnb9KyyDVdCelZWzlrx/e6oJsgcVsxmU+jSc28NC0yqoRW2iIEOHvxHJ/lIlm NI0TP/+4/pjEt8/dkvu1kTLJkH4Y6YAXW52S1b++tnlqX/Gdso6igFm5M/96FAL7EZ2n aGTXPnTd4pXz8eYp5HQBgg8EMgS4ZtChG9YjCN010sa9+TNzFEZcQbR7MJs8Q0lzRYSu mUNqUabapsnXII0h53BNLhu64vyDrJBGRr3VB7QrANHEW3f6S2qAsQaFv0cpGyks9jTX dmwHcn0mTSMsZhzCOJ+wdtvvl8lfcfemXYe4EPXHJ0JfuDxKuEi+Z2RUrN4xlhVRNG4n c52g== X-Gm-Message-State: APjAAAXI+MzVfniuFB1KVRNJBTuL3lKOLjSLV7nmXqew6AsEH7Ov5FXl jaXcyiHxQJrfr884otwrCKmflr1U X-Google-Smtp-Source: APXvYqzJgwXr+q/nZ+O8ek847Qw9oUoa+RO1hyof+64wjBNOhbVucs+4RbxPXa3+x415Z/TVDaI3Ag== X-Received: by 2002:a17:902:7083:: with SMTP id z3mr5692827plk.205.1560168536335; Mon, 10 Jun 2019 05:08:56 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id f7sm2452961pfd.43.2019.06.10.05.08.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jun 2019 05:08:55 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [PATCH 1/7] tee: optee: allow kernel pages to register as shm Date: Mon, 10 Jun 2019 17:38:29 +0530 Message-Id: <1560168515-32714-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560168515-32714-1-git-send-email-sumit.garg@linaro.org> References: <1560168515-32714-1-git-send-email-sumit.garg@linaro.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 diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c index 0d8605d..ab24e2a 100644 --- a/drivers/tee/optee/call.c +++ b/drivers/tee/optee/call.c @@ -567,6 +567,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 Mon Jun 10 12:08: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: 166311 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp949354ilk; Mon, 10 Jun 2019 05:08:59 -0700 (PDT) X-Received: by 2002:a17:90a:23ce:: with SMTP id g72mr21102650pje.77.1560168539018; Mon, 10 Jun 2019 05:08:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560168539; cv=none; d=google.com; s=arc-20160816; b=EOtalYkXGVr2DUvBDCVD+QExtjoumiRGdTwadZXQw6rHbmOziUIM2zTdmLQVjTD+M+ jYBt/vJDt6nJHPI3j79xtHByv9MpL+DWSZLzpQ5iIl/1DVi+2Ic1AY4wxUZT2inTW+9I UnJakWeHJERFGXM/QU/vc666YGPg9XI7YW2n6cEuMvnNXqhyxcemMIXCJ7SA/P/FmOi6 BnD+Chr/8OMKOSrLTdiocyIpfPux6lZQxmKmNFmY5xab5XCX9+6LiefKMIk83WVF5gF3 jiWKYhsGrI4dAvCW26Yq+TCfDMeZ5V9Fn8TVjiHGNe7yX3I4sOZY2PE5uov2vmLx8aTQ MGEQ== 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; bh=9XWEUuRS3wPrwIfibHck48S9qLV9JnhjzVFmaJ7/rHk=; b=XfWK+5VJcC66h+P70A8YdYHCoDbh8kU5C6B5rfI0lqNje6kJwP+74Dp3pZmt9pGrhL M4SWvD1Q3OB/ectzBC7dL/zV0xoKeUuKAvlcoyCakcvMlCLvhfOz0i2T0yyaf7vWO3nF TUg7QFJ2ygCJzDjsZ8PLFssmMZm6MS9WfKW+08rxto5zvFrWCICP1V/8aEIORFy8XKH6 sa84bzrHygkbodDTW9aLlAJwv/KXvCXW7cxHVEkTWXNGyfCK4Dz/3nKAGmLQDPtB+dex P2I/ZWEgi3QAeMW0VJ3al3N3S0DNNQe6xYfCwPTO2wNeDYIkLJucYP5q/Maofa8JDYOl fwiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IZ1hAjtg; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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 f9sor11423332plr.31.2019.06.10.05.08.58 for (Google Transport Security); Mon, 10 Jun 2019 05:08:59 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@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=IZ1hAjtg; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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=9XWEUuRS3wPrwIfibHck48S9qLV9JnhjzVFmaJ7/rHk=; b=IZ1hAjtgssPpiPAfjiphO2ulb2qgPEmXp89CXn3FdP6NzeYFbpL/M8hSZf2/rZ6BEB 52kX0nybHX0QGOcEvvDuhDcUl41XRVcsoZEI1Zw1i2RLjdYUVFYKEAJ3leaLgbjag1X1 V4ANCfn5G5HbcZkiU4jE2rgP85i6pB4vc9fYuhc8q9fwuJmN6wyVZpeAiL/p91jLF+Lq wW66qOBA0ikQ5zB3YAv57RGjAAHoTu29PuBBO+nVicFGQbI6p/uGeTgjWebU2e3dVdqM KPzO0ZvAVHEasOmwZWp5zpubPcofqH57KQ55AKlKN2AajR2RvWCBi207G87jPmiXJ6G/ udOQ== 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=9XWEUuRS3wPrwIfibHck48S9qLV9JnhjzVFmaJ7/rHk=; b=aWGPh/ROF97Mq7iA2U0HrQZlXsZR1I9vTuluZ/Y91AuMS9C2ER442Fv7O1A736mgv0 hbMRv3hy/0enG9YVJy7TUY5gbXgxEcrd4j9XKGlgfJpRniKdyAoKnQXky/ShqU4f/9QC e7JOf2cVtWZsN/U2oAI1cLogFOL2cuIHTcbEq6IlKLKTB+9X1GCuDBwEL/H3mWpK7keU zR/7SX5kTf+K8acnp0vkWlxXcZqcXTAavmIkA1RT2XpMkCb87Ph39hc5nJ4BlYaX7zqE 4UoClJ37CbhUITpS3PlSljgdAO0Z9bx6tIRVySdG6ygzWoXNg2yFcWaBA1hs5g+rRdST ppVw== X-Gm-Message-State: APjAAAXCg2avrltTsBSBVjPBks+A+rLD2i5QAEK0IsuB2sm7WzQxSu56 wl/9Ph4KoV+lobieewPm6NT2+GDBQtk2+Q== X-Google-Smtp-Source: APXvYqxSSPV2pQyrYXbpd01cMTF933Lfi2k8OWyg0IBm/6FhiW6P5b7L7R3iXqeZSEb6nSB81M3/CQ== X-Received: by 2002:a17:902:b43:: with SMTP id 61mr71871420plq.322.1560168538750; Mon, 10 Jun 2019 05:08:58 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id f7sm2452961pfd.43.2019.06.10.05.08.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jun 2019 05:08:58 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [PATCH 2/7] tee: enable support to register kernel memory Date: Mon, 10 Jun 2019 17:38:30 +0530 Message-Id: <1560168515-32714-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560168515-32714-1-git-send-email-sumit.garg@linaro.org> References: <1560168515-32714-1-git-send-email-sumit.garg@linaro.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 | 15 +++++++++++++-- include/linux/tee_drv.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index a20a043..2bb9a18 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "tee_private.h" /* extra references appended to shm object for registered shared memory */ @@ -248,13 +249,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)) @@ -288,7 +290,16 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, goto err; } - rc = get_user_pages_fast(start, num_pages, 1, shm->pages); + if (flags & TEE_SHM_USER_MAPPED) { + rc = get_user_pages_fast(start, num_pages, 1, shm->pages); + } else { + const struct kvec kiov = { + .iov_base = (void *)start, + .iov_len = PAGE_SIZE + }; + + rc = get_kernel_pages(&kiov, num_pages, 1, 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 805163e..ec2aab2 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -35,6 +35,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 Mon Jun 10 12:08: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: 166312 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp949400ilk; Mon, 10 Jun 2019 05:09:01 -0700 (PDT) X-Received: by 2002:a17:90a:30aa:: with SMTP id h39mr738826pjb.32.1560168541738; Mon, 10 Jun 2019 05:09:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560168541; cv=none; d=google.com; s=arc-20160816; b=TrKnIEmUVKipCqN9TQ1BH0L2GSCYzzRQi3K0byw7boOsMjXbh4KsnSTxNRzsTM9Ria 0nzRM5w69Wh6FLG8cTkVaWLglZ81hS/QuiQ0EmBMjtOldS4cOheNK4mWCke9arspnrgh K1O/S0QfHyX0XHKp5X7ojtju4UfXpOhXmvvvBZVV8sL8qUTlRipPHbEKCRYxOXsGA7q7 4QMtlgupdrl1WSauSowmq9iRLWiQSju+lRHvO158TW/rMIqg7J+6Z21ZnvEkDvmzMD1s P52muXdkvvpn/gJ/I0l04Q+9so5kU9T6nLaqNj2jGRWRX/lNmtFvv7fbdnz5nK9y1LA5 djRQ== 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; bh=AyoVUzrL3687ErRfsEjq7Ree76XWkq6JDxKuVSzn4fI=; b=SoP/s7+SCauxz8ZX9F5z9KcsaXC2EgaY/9gzQcjazqujwLOHFfP7IVeistzey78UjS 44RJaZOEplY54/ap13TJr0m+ANy6VcwT9Q3JnmQR5+a4gAMuRLqBibhFtKwQltJwlT+h f1MzIrWC3D85YGOqOnbh592Xqz1QSRTF2SQAL8itShkWiRctk/HcS1//YQ6OkakpFPWq 2nu/OJy8egWszBD06+vhJ+QTz6MqqQAVmWSJHYRoMlBG2WnSJ8WhFHxYnoyBRR44naZ6 KIbRQmaXcqiRCXGj6CtuUZVHQlJaaxpA3PRzi2mbitwMQBjhI3IWsLtE35f/jRcxSNZb q+lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YOf0NrRh; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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 h9sor8725731pgg.27.2019.06.10.05.09.01 for (Google Transport Security); Mon, 10 Jun 2019 05:09:01 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@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=YOf0NrRh; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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=AyoVUzrL3687ErRfsEjq7Ree76XWkq6JDxKuVSzn4fI=; b=YOf0NrRhRBKxD6fUGjur+opaTNsUeVIEUfUjXAQqDiefbFnjC0GjtEBhsBtAxbMD28 DMrwFaZnu9w9uNqZSCEXi7OdkAXC23nMYKuwrP8TwX50Ei11nRIJ//sNypyICJqbnlR/ SmxPuxE9rgEMGaGUOVbqElebTRtomra8AsdK61jj5WFQDtOQrBxX1TF07xyy9FgMc0aL qcuQfUd5t/84cmoQr9wBn9yDA9j+gBSWN4mJPytRTD5tBB/JOF/ThjzunlOM3+43hL4q SDmiV7/Aw76TlyjBtTbbfp0ZuE+/r/kOSW2YsNMeYQBcEeztlh7Qmuq23Xe5h8G+s+Le yaHw== 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=AyoVUzrL3687ErRfsEjq7Ree76XWkq6JDxKuVSzn4fI=; b=KqVlTqKgDQDaQsifP2XO9VNE6WwCc7D/RSt2UaKlXHrCtzYZFW72VDxmY+U2xII3By +hFjZU29NT1mOMpixxAexd+ubmGf/w2OYJXrCXehdO/A55XiqXGSnINN4KlsjUAbEwNX 3/mEOmZrQfOFLG4rftuz1SgbzliNJJeIGdjOSMO6aYemNMlTaB3SiEsJVHFUH1tKPjMS Zxv+qBA83osmhY5uJH6GSvRQNJ2OTF8utqMDiZqsGxWNfj3dz25Lpr6dm0h9pH8NIxUy Smw3YQQNpuOoEVo5DE1Q+dS/sweYB/DU2jN/IJjyGiMgUlCOQfo9M3Yj3weY7GxtLsqh 7lOA== X-Gm-Message-State: APjAAAWdUe7gTp+gWaDJCzW3fuEn4ls+uTEfs2SbFjfX0sf4kfP/ZXGb 61cW/mFKLmlHwwInHldxBBchTIqH X-Google-Smtp-Source: APXvYqzRPRgBuQ+zuieBDCMWjiIKcXQje4rPxCOTQwBOr90B2rcMOIvunhlzNZFpR99eoezhRop5SQ== X-Received: by 2002:a63:3148:: with SMTP id x69mr837488pgx.226.1560168541255; Mon, 10 Jun 2019 05:09:01 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id f7sm2452961pfd.43.2019.06.10.05.08.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jun 2019 05:09:00 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [PATCH 3/7] tee: add private login method for kernel clients Date: Mon, 10 Jun 2019 17:38:31 +0530 Message-Id: <1560168515-32714-4-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560168515-32714-1-git-send-email-sumit.garg@linaro.org> References: <1560168515-32714-1-git-send-email-sumit.garg@linaro.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 37716ef..a9b7ee0 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -379,6 +379,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 08fb98f5f..cdcb606 100644 --- a/include/uapi/linux/tee.h +++ b/include/uapi/linux/tee.h @@ -201,6 +201,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 Mon Jun 10 12:08: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: 166313 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp949451ilk; Mon, 10 Jun 2019 05:09:04 -0700 (PDT) X-Received: by 2002:a17:90a:3ae8:: with SMTP id b95mr20535786pjc.68.1560168544350; Mon, 10 Jun 2019 05:09:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560168544; cv=none; d=google.com; s=arc-20160816; b=c4PO4Kcd2KpgP73EihDRnLwgMDBoYsPjYurD3Hx+De+0kKYBL6gcnAxs9ZWBQTcjSU yCDJK1cGZn8M5vw+uQt75Hqdzii4EM0PVqUGQaH0t82SI0R889Zx55nRTKVnkIkYz6g5 E6ZrOEGuUR+6WyHEqdUOXNt163+jvzSSGPI4NEJ/TxiXngVyLcJmH/iWOY99xZLkRIdV NgStxKal8IMLWpYvoXxpvrX00HK4bRoSGTAaSFhoWRFO2hBHxVljmkz/3jJAgK1XNGxC g95hPjZSLdU81D9cZGaNjxpqbJ9tHTFmRcgmKh+tvcGCemEI8P5pMTO2Qu9rQJIUNX+F BdDg== 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; bh=Z8Y6doS9JUUpYqmw0XQfIa+7PVVGFChUlu/7rn/9qbI=; b=KtFxUo0hhKfkOrcJa3u1DdNj67ICI15FevOHGJQC0hnDycKsce9OGCCIO/9wGYE89+ ZvPiMHgDauG6kpFykw35rgb1LGWUSWFUNRGe/W9ANHC7YNsOwe1w7gR01619hjFuOHY/ WZ99sYUnzSjllJ1Hhn/12rHHDIjgrRhOrr/BX+E7jwJCkKewfSNnq83GZrG35IadlJ0Z KMnjGt+ONe1sK4xQiBr2fSN6MJJNKCdzDe0a7od3UQxCFk2c/XxRTPYBE0F+TOF2227w LkvxNvopbpEyO4A5alcBOCwdaPlRsL+HyfIXwpq4/y0KsL0Bgkyy55Qo9mpVtn1HSrl6 cvwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AL140DDz; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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 h1sor8693948pgc.77.2019.06.10.05.09.04 for (Google Transport Security); Mon, 10 Jun 2019 05:09:04 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@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=AL140DDz; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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=Z8Y6doS9JUUpYqmw0XQfIa+7PVVGFChUlu/7rn/9qbI=; b=AL140DDzZggDmY6z3RmdBI9euEIciWmSyfSKQrBpIBTaiK6mAmS8XsENfEj2VwZdlM 3vLZMlLp+pkhFsytMcS85pFPz57DF2vaMEVKvKQMoDRPOAyNHMgJGeH+l17bFFqMaBAA UZO+6Dt5alnAG6IpMKHwzbbv6lvE+C74x0+etk0LDUso9Ue/smqEeUMYIQnZpCz+uDkK F8QNY6n5KqVNhvr31xdaKNh4zE9IBSl8LoJrOciKjVW/t+CPqNYzReHCaMpDgNyL0lH+ iRWmBf9v60+Rf1PQAGSMsi2BwO09jAp0iK2m1XPieQ3w3/SMT+H9B4A6MWDdkUBnNuWB 5vGg== 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=Z8Y6doS9JUUpYqmw0XQfIa+7PVVGFChUlu/7rn/9qbI=; b=sOQuXvecABTA9ohyhTfSydqhLTfxprcFNnFwYhMEbp/A1dvWJ1yrUJnlHC6HytmxHA bIVL/vRX7Wmfu3xyTpzA0SHULJnIaj6jO5kLZABVhRTcc0wdSUZdj+HnXn+84pg0dt+r mKVkY1sOS9FP1TKbz0o6xWnn4HPbl78M090fc278DuQvbdJXEKhgkHpzfR9T4nsYXq7f Nx4tZy1JUjIe76f2xSrlt5E/H6PcoGiaYqjW0tLgE7Sb9hfKXhoAwy7VB5dtbjkq1f/3 zjGoFzJzpye1Joa56m1bemcvHzNeBxaDlOBGr+FlOnUJSxm54pNhtvZJ49z+LUiO0NyD PLZQ== X-Gm-Message-State: APjAAAWVRaWdzgTImy+9aERQZBPMTKqzl+JDF4mEYyUyfdbKJV5WFGPC O26gFjXiMXZ56oL4d0Qeofg48nQw X-Google-Smtp-Source: APXvYqwCMkNcuC3hEogFbWX7oZJbrh2QNkP7o45PsPSYRHGv2k19M8YpQjL/68wkMLpSWyOrc0HYag== X-Received: by 2002:a63:2349:: with SMTP id u9mr7065985pgm.410.1560168543792; Mon, 10 Jun 2019 05:09:03 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id f7sm2452961pfd.43.2019.06.10.05.09.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jun 2019 05:09:03 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [PATCH 4/7] KEYS: trusted: Introduce TEE based Trusted Keys Date: Mon, 10 Jun 2019 17:38:32 +0530 Message-Id: <1560168515-32714-5-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560168515-32714-1-git-send-email-sumit.garg@linaro.org> References: <1560168515-32714-1-git-send-email-sumit.garg@linaro.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 4ea7e55..0d3c2dc 100644 --- a/include/keys/trusted-type.h +++ b/include/keys/trusted-type.h @@ -44,5 +44,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 6462e66..7fdd4b4 100644 --- a/security/keys/Kconfig +++ b/security/keys/Kconfig @@ -69,6 +69,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 Mon Jun 10 12:08: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: 166314 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp949490ilk; Mon, 10 Jun 2019 05:09:06 -0700 (PDT) X-Received: by 2002:a17:90a:30cf:: with SMTP id h73mr21357515pjb.42.1560168546636; Mon, 10 Jun 2019 05:09:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560168546; cv=none; d=google.com; s=arc-20160816; b=PYY7NFqqwzYdObeInkju4tjwqCOc8+oOzBoONx8WyH3weTMsCYiB6PYbtF9yM9KqKf MSas2WCE4b9lzVT/92aXgCdgLs2oVYvBhnSBisOw4TT8eQnzvNlAegLQD8d5pmkJ91wS DiZzO2QFZ7KsJsQmDfRCqAcETnrpx9dbwD00tgVGZ63EgOFcmW1D0Cno8h79djSJ8Trv laMJY4t4uwBopZkKeRE5DR55+P/oWF/6oF/pjrXuYr+XkVd3Rtk4exzI7WGQ9mf8KFy5 K5+20yMv2YZ5KkXqnzzPPXnhb+4e8ohET0P4ah6kjKtll4+SDPsDo0PTkST/tfkfpck9 nExw== 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; bh=R+jHcisbx1tt/pu2xGZj1ycF1n/RmYgv7srHZQSAev4=; b=ljN5SpwRuccNMxpTZp4w7AAWPT2UIz/vcUbAt1cyhwiuez9b5zQLTwtDuuIbeqZb5N skB3RO/edcTUo5p6Y1yjOTwsYIK3StU5/mH8ERNr3BltWe+VUlc8bDpuNcmkOuRC3gl7 4LSE44w05qX8CPqf0nTMn4hF8+c7W12qcMWqE7N9vuw5EuOhGB+t6CTGjh4UZvXBDYQa Cz9WGOH3GVcsswUdbCW4DROLEu8wyfdfbSxnm4qQsnidpygZtv7Ay6HBqvfLBRk2SC7l NRJO1PVt/FPvqVnLDzI8VTNvDG7vubxvc6EyAYnM39EzbuNFXLQ/EqouzuVBAkaAfN70 7Pew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oCYS+NY5; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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 h1sor8694045pgc.77.2019.06.10.05.09.06 for (Google Transport Security); Mon, 10 Jun 2019 05:09:06 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@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=oCYS+NY5; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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=R+jHcisbx1tt/pu2xGZj1ycF1n/RmYgv7srHZQSAev4=; b=oCYS+NY5YL6PkPCcVZ715Bf8TIF/qpxha86lVwwHKZ9zKM2ZYuM/xuww7vpivroQvl 4VS3Uo67bxhpyQOWtmzv2CBwWKyvGPzV/RcJLa0MFsT6JWiebwZ3dBsVOIuJ5kMgacBD mK7OgmPcPPePr6WqncyLGsARitGh/2XxowezstNiSu2RSoQqoXXSCMo7VssbFhJprl+o Ldkp9w7DuAOtuG3rhkOAdbjVe7BE2T3WugkG8H/gG4NPpeofw8GU+hY/MoRXyDvP/DMY ceHiv8iooib4Bq9lihoZPirlL5o5MN6yr1CIjpae/9trccHvgu19CqVjfOaM9HxABEQM VfFw== 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=R+jHcisbx1tt/pu2xGZj1ycF1n/RmYgv7srHZQSAev4=; b=kPqwS09jljqx5XpeWnm7NMRU46oM2z4upTjkAQFRhPkxjBOraBC6PBEZwOmAqI0qV7 GUTeE4PA3qfqvbLXABBmX/aydOhTQGlG66iJI5mk+KlOmMabOLpKmW0Hgl3vNQ5dg+Wf HaJoMOhBRJFeYh+ZBIlX9lcw17wQYkbccBzk8rvb9x6tKsAigUFH2a39QRpwBQr9WX7A pDBWMKExX/dAsiIAc0uXqJyLyWvGg+wc0xAGa/K44d2DP9siLmcQSw2K5xJ6cgO3caoB q/t9aetFEWqVB28gRlZWMa4nkGndYeYEBgR6smbqKOac5olH7RKnjAV9cAha9pnc5wR8 yaLA== X-Gm-Message-State: APjAAAXlhnb8D+WUKrKQksT29DxWGQC4m56jlX0lFbcv5ba/zH9M6LmU x12ahFMco75vAExRhL8ASpmZCb2E X-Google-Smtp-Source: APXvYqxyArCN4nqS+GTwNqPkLkg+rCxs/r6Zpq+foFvMrMbOR7PEjUz3wq3/cMoK4eUcHUndP586Yg== X-Received: by 2002:a63:1d53:: with SMTP id d19mr15548095pgm.152.1560168546320; Mon, 10 Jun 2019 05:09:06 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id f7sm2452961pfd.43.2019.06.10.05.09.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jun 2019 05:09:05 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [PATCH 5/7] KEYS: encrypted: Allow TEE based trusted master keys Date: Mon, 10 Jun 2019 17:38:33 +0530 Message-Id: <1560168515-32714-6-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560168515-32714-1-git-send-email-sumit.garg@linaro.org> References: <1560168515-32714-1-git-send-email-sumit.garg@linaro.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 dc3d18c..cb99832 100644 --- a/security/keys/encrypted-keys/masterkey_trusted.c +++ b/security/keys/encrypted-keys/masterkey_trusted.c @@ -26,6 +26,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) @@ -34,8 +37,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 Mon Jun 10 12:08:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166315 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp949563ilk; Mon, 10 Jun 2019 05:09:09 -0700 (PDT) X-Received: by 2002:a17:90a:ac11:: with SMTP id o17mr21302338pjq.134.1560168549197; Mon, 10 Jun 2019 05:09:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560168549; cv=none; d=google.com; s=arc-20160816; b=uDoxxfG3VfN6jgjy08zfpqU/rpAky9291uYw5N7JREkShNMPr6R7MV3Fx7OL8R9rCV FyekiBLElAD+9+05YPSxTg8tc2HIzNQKtoQbOf1LXl1R5ExuiguOk9ahiywmfNTDoKK4 tHqh/ywBJ9v4VgSUKFQMzDmBy07l2cOVxVafzEQeKSsdKTpcdeF5Qn2GXVdY9uUsOV2J 1aIzMKp7mHttJEOHDnDJdl9h3Xii0p1HTEEpXH2SWbhzg7NYlsddcojq1xGdDHzAQ1HT V7mM7eJkzYl8TYB4/T/G8EA4EvWTb6du0PC8GYpQ07dFDL/Ey6z5wGWD5VqRz6CWOmAi n0MA== 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; bh=BG6KAi08hN8hMpB1R8APRtbarxqkieDJBwiiKnKxNvA=; b=ygjMwkNqSbMW9O/CLxVrBqAxVDG1tEoFBUustcPOUSnVqUJCDR0ZoZ+PB6O0SG9A8Z GmIpJBso5g7iGIswDf1PzXSMfLGqWKg7bnb11msh4epdsfHDW/sm8kLhbBjqZsQMMoNv c1rxf304lT3B+X7+mgb2wiTd3n6rKe7Z/mTKw8LKMCEXVBTnyxU5ls6f+fYPrecZQ4+X wnr9XHyYMeEKLyHP0ZI31dtBkGYFbdLSNjfsi4sgDJaNIr2vq4EVKA0VQSbCxv8gXnDW C6/zDsw5mefY0iRo43Bw1zgMi2OtB66c75sSNWA9dlx/CKM0RwdedRdEpAqWrF5pMotz bgkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kYDRbSCH; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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 s193sor9593872pfs.6.2019.06.10.05.09.08 for (Google Transport Security); Mon, 10 Jun 2019 05:09:09 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@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=kYDRbSCH; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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=BG6KAi08hN8hMpB1R8APRtbarxqkieDJBwiiKnKxNvA=; b=kYDRbSCHbSss6GpqeBvmBH8fxCn1gWNRC3Lnqv4v4Nz1xKqbXYdLmNaMwXGhbJoYvd RCryAIms2JTVgLaIAbq///1Lk3uoLGdWEL9w4M3GmMd3uH0sx/7QV3DHb2vlK0Ep3gwr 9g93Ly+isKqBsfjXQxG+aTsxUln7j1YPS6IH6WlTJLzHxC5aNXK9zMfITxhFPb82zzLt +yje/p6hdTEFShAL5GlDRFDcffqiQyd5ria0hzidX7pgNDBsIlfIacjs/1aRwkNlp/zW dDhqcHVG8w/E/aRbBob3rxHvEqiwEhMBGQEo4OQFfyYXfnU/8/z8EAYpnWF4eQo3bgXR MUag== 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=ctJcrPrMIfz1MbsilZLSrLaQnj/JWTDb57KT6cQASyvHvhtTOFZCb+sXc2LADGV0dy e1IT/dZSYFM1K0cc31QZvlXC8zjfG7X5lE8PFfknQEr95tyAVBMayn9ye8tlH0vFIBdq mtjHzrkfd9zM+RkrhdX3WFTKO4r01HjcXGRoW0hWOt3VWf6t49KqkntK5NsGELMFw3rA kaVxIGF7HU7p6eF3YfwhsQS/qNlum7naO/qzdf8eL2ULWJFE5A8vrvaW+eDhYVqkfBfE XosqcbltO+U7kLFXPeCO2u5CghlnqaNqmYC1eLtlvYBmVJXiIJY2vkeXDOBzasWxiuV5 aVwA== X-Gm-Message-State: APjAAAUWCGxmP+GHMpm/63NXXBtDRq5Pm69LhC1ep4tGM8GEuxElNeOU 0xxh44JJqZ9RKndELnfk1zFd6fxs5ti+1w== X-Google-Smtp-Source: APXvYqwF/tnH3YruVjw9+vzpV0Z2/HKFi34ElLBeSTpC2gYQ5tb7P0Bm1OTLNlWVR+mD2TZIP+AjYw== X-Received: by 2002:aa7:8013:: with SMTP id j19mr12090662pfi.212.1560168548697; Mon, 10 Jun 2019 05:09:08 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id f7sm2452961pfd.43.2019.06.10.05.09.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jun 2019 05:09:08 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [PATCH 6/7] doc: keys: Document usage of TEE based Trusted Keys Date: Mon, 10 Jun 2019 17:38:34 +0530 Message-Id: <1560168515-32714-7-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560168515-32714-1-git-send-email-sumit.garg@linaro.org> References: <1560168515-32714-1-git-send-email-sumit.garg@linaro.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 Mon Jun 10 12:08:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 166316 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp949617ilk; Mon, 10 Jun 2019 05:09:11 -0700 (PDT) X-Received: by 2002:a17:90a:2ec5:: with SMTP id h5mr20695077pjs.93.1560168551658; Mon, 10 Jun 2019 05:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560168551; cv=none; d=google.com; s=arc-20160816; b=RxDUelEMrbsvO1enGe+/HNoxXUEeT7+IAm0FhR2/x8QLR68OzW9G+4Sf/7OH0Mi8Ln i1pcY5A86Ftg7RkYBDeO2hMhxv3BU1WiRKevNLOOTZeZEmn4+nqzU4bH7fnWz54XRqHW nDx672Ax+SbcDEP6t1zXymdyJUO90nmeT6WeoIFxFWYq84R155MiSLPPiPWZMOtQUrSF iXMGMkrsoWLBgfgS0MARbB60wR0zERdABQnfgvEpg+ErDr03iLMHm33odaAyReJocKYM Guc3DVygm04NCC13ro4vU4fy4kl/kQbPTwr8Nk6umacT8c625FJq2CCtOIAwr7xEp9fM tuNg== 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; bh=tx5MQ5FkWI7Gn9BIvB/rRrUm7l5w5dusQrS17PrCD9I=; b=wQQOn5X76u9mgXA/RF8zSupfEtZX/FA8zJOPkPaVAgksHuavEsztCsrRg9rWUMAgED +iel82oUdFaTkbZ6HjHLce/2DvBZPgz8ffqZUSyWC+av1POfBPeSnkYQiI/OkZilMKKY Wr5rHm+eWLZkJ8dY99n/EZutxN8EbbAGbSy2dwBWB3TrONnH0OzPzaZUoJzutSRARpBC tjjatZOaUWw1GOAsYrP1UbJgmCwjlDICL+4WTCT6M2eUTXrruBa/fL/o3bXGyJXtxWCR NfrAQALa6M///bxg2bJRttCjZWlT65/LEfZmQixrtH485/xspFLpIzs/8bKKNe5IZQFH SnXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SB3PMlWe; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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 d37sor11516403pla.2.2019.06.10.05.09.11 for (Google Transport Security); Mon, 10 Jun 2019 05:09:11 -0700 (PDT) Received-SPF: pass (google.com: domain of sumit.garg@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=SB3PMlWe; spf=pass (google.com: domain of sumit.garg@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=sumit.garg@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=tx5MQ5FkWI7Gn9BIvB/rRrUm7l5w5dusQrS17PrCD9I=; b=SB3PMlWePFRo/GC7xe/lEweBbdfAh1riX9jTF73QDu6A6ZBWrY9rojjrQ1QUoqsZ/p gWefMXYJ9miFjwVuTFPmcJRc/TbRCQSulDAhaQ3Bek9eYMfIKAqtDHpbbt87UvgWwz2I wX94rMShIMdMcm3i9WFQwDKQf0XHVzw6husyFY8BG/cpfg3B1gTFiXhNoFpCLHgRLWG1 VLb6IM/GDDK0aNoKzlErbkbLaw6kJMQCq8bNSOcLpCsNTX8iCgRIz/M13eYBOf7/VxKr M4fRFR2h0P48ojgwEkhPXGxh8qdYyw1gW7pDNzN3uwNjAj9NQxgOhXWUGP5mWSvYN7Cj S6sQ== 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=tx5MQ5FkWI7Gn9BIvB/rRrUm7l5w5dusQrS17PrCD9I=; b=Z9CKZlel+UU1DBIJVIfTkcTDqXBwswW+3dw++q+f/vJg5qGwOGy8bZzCnboKqOnIxF JNXDSxVPqPJCEBpMOBjAUJ+bQoKvYTlxTnmyw02MTmODqZKK5RgtBlj2Mgf2ps8qHLL8 oHZ3qHUfQkFLFP967fCuUD1xO86vePLlyKgCiqE+Vq61TYdW91Nx19Lesvu/4cdjsuG7 EOsjAgk2RVGCDGznBOhMyPmM18NXB2hkgkFCaii+6C3eiMa76yl6dVRgZ44sHngy+Wd0 Xy9FaQATMI+D8ZGU8BZe3ad4a/1CMGRJcNraOgXO4d4hFbCpf6gOVFlaiYpEylmDBsv3 kNsQ== X-Gm-Message-State: APjAAAU9BhP9bpiZxf+yyNDcByWvLNNOZZCFnx4RWxPL4u/JVcdHhIh9 az1qApHs6P/cXUEOv4ov3M0NH8l+ X-Google-Smtp-Source: APXvYqw0z7wVd4A89pq7SI1Ai+359xpE7XGfuvaAkU2s01SiDyu2mW6W0WqC9WBvrSIqDf2jtk2R0Q== X-Received: by 2002:a17:902:44f:: with SMTP id 73mr12004045ple.192.1560168551248; Mon, 10 Jun 2019 05:09:11 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([117.196.234.139]) by smtp.gmail.com with ESMTPSA id f7sm2452961pfd.43.2019.06.10.05.09.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Jun 2019 05:09:10 -0700 (PDT) From: Sumit Garg To: daniel.thompson@linaro.org Cc: patches@linaro.org, Sumit Garg Subject: [PATCH 7/7] MAINTAINERS: Add entry for TEE based Trusted Keys Date: Mon, 10 Jun 2019 17:38:35 +0530 Message-Id: <1560168515-32714-8-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560168515-32714-1-git-send-email-sumit.garg@linaro.org> References: <1560168515-32714-1-git-send-email-sumit.garg@linaro.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 2c2fce7..861df92 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8588,6 +8588,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