[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/2] optee: allow plain TMEM buffers with NULL address


  • To: "pdurrant@xxxxxxxxxx" <pdurrant@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Fri, 19 Jun 2020 22:34:01 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VAnBWq8tWHxmxrR1Lhikfu3J6pxcgll70UUIJjlkUNM=; b=TJGbMikEq95GYRQb91V6rPTatVIPels3MHmf751eDP+ATxdMG1qFsIxCYGl9BlvmBk2fyth31HrERTvPP2VXKTWIr9aJEwnpj5Gkc36/P9BUJcc3XYgUDEqVu0HIwvv7/6V7UCAEakQ4xtdI2fCZJCTZhec6xQnEQBJLVKQ3QUI/kC2nauerK5VhOhFF+kyI9sDzxsKYBo8sYP13qXdeaSbIgKakYaY/WkozNi6AWZnr4L9Sf41XkV/7pC4cafg0UjlvMN9hc25yKRaPb1j+IRcmf3bMbSi2FMHlUj7MPZKXFqFJeivK1qlp+pkW8F0Pob+3ra/OS2H6gyfb8dJpDw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Thtc1tGbhDltbnVamDKC92aY1/I3rkoDIjA87DehlksUcANdDogo2z3CY4PgBpWsaDOVV2nlNlDtyvM/enk9G3NJNEukvOjjCrr9lxz/JuAozxcw6Q85VfP0N3vO6TQE8gXrpEsvo+KwbtiVwjPTTVyBUQ0xTsWd78xqb86J+U1w9+90R/9wh62hwEmGbTdQnwhjmCx8avHhg4kGleHDl9+RdeHZCoxlaj4Fq53mCnzCSgPyRVn/lIruFA1OtdNAB2ANXojzQ7UeDw01rPsVHYuX6FzPCFryUgGmBVSDvJw+pQ46Zpjcs+MhLYJDi5Nf4w3V6Tekbm8jP9u7m+cKFw==
  • Authentication-results: amazon.com; dkim=none (message not signed) header.d=none;amazon.com; dmarc=none action=none header.from=epam.com;
  • Cc: Julien Grall <julien@xxxxxxx>, "op-tee@xxxxxxxxxxxxxxxxxxxxxxxxx" <op-tee@xxxxxxxxxxxxxxxxxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Fri, 19 Jun 2020 22:34:14 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHWRom6aQ+ko86LqESb88QJVYc4LQ==
  • Thread-topic: [PATCH v2 2/2] optee: allow plain TMEM buffers with NULL address

Trusted Applications use popular approach to determine required size
of buffer: client provides a memory reference with the NULL pointer to
a buffer. This is so called "Null memory reference". TA updates the
reference with the required size and returns it back to the
client. Then client allocates buffer of needed size and repeats the
operation.

This behavior is described in TEE Client API Specification, paragraph
3.2.5. Memory References.

OP-TEE represents this null memory reference as a TMEM parameter with
buf_ptr = 0x0. This is the only case when we should allow TMEM
buffer without the OPTEE_MSG_ATTR_NONCONTIG flag. This also the
special case for a buffer with OPTEE_MSG_ATTR_NONCONTIG flag.

This could lead to a potential issue, because IPA 0x0 is a valid
address, but OP-TEE will treat it as a special case. So, care should
be taken when construction OP-TEE enabled guest to make sure that such
guest have no memory at IPA 0x0 and none of its memory is mapped at PA
0x0.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
---

Changes from v1:
 - Added comment with TODO about possible PA/IPA 0x0 issue
 - The same is described in the commit message
 - Added check in translate_noncontig() for the NULL ptr buffer

---
 xen/arch/arm/tee/optee.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/xen/arch/arm/tee/optee.c b/xen/arch/arm/tee/optee.c
index 6963238056..70bfef7e5f 100644
--- a/xen/arch/arm/tee/optee.c
+++ b/xen/arch/arm/tee/optee.c
@@ -215,6 +215,15 @@ static bool optee_probe(void)
     return true;
 }
 
+/*
+ * TODO: There is a potential issue with guests that either have RAM
+ * at IPA of 0x0 or some of theirs memory is mapped at PA 0x0. This is
+ * because PA of 0x0 is considered as NULL pointer by OP-TEE. It will
+ * not be able to map buffer with such pointer to TA address space, or
+ * use such buffer for communication with the guest. We either need to
+ * check that guest have no such mappings or ensure that OP-TEE
+ * enabled guest will not be created with such mappings.
+ */
 static int optee_domain_init(struct domain *d)
 {
     struct arm_smccc_res resp;
@@ -725,6 +734,15 @@ static int translate_noncontig(struct optee_domain *ctx,
         uint64_t next_page_data;
     } *guest_data, *xen_data;
 
+    /*
+     * Special case: buffer with buf_ptr == 0x0 is considered as NULL
+     * pointer by OP-TEE. No translation is needed. This can lead to
+     * an issue as IPA 0x0 is a valid address for Xen. See the comment
+     * near optee_domain_init()
+     */
+    if ( !param->u.tmem.buf_ptr )
+        return 0;
+
     /* Offset of user buffer withing OPTEE_MSG_NONCONTIG_PAGE_SIZE-sized page 
*/
     offset = param->u.tmem.buf_ptr & (OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1);
 
@@ -865,9 +883,12 @@ static int translate_params(struct optee_domain *ctx,
             }
             else
             {
-                gdprintk(XENLOG_WARNING, "Guest tries to use old tmem arg\n");
-                ret = -EINVAL;
-                goto out;
+                if ( call->xen_arg->params[i].u.tmem.buf_ptr )
+                {
+                    gdprintk(XENLOG_WARNING, "Guest tries to use old tmem 
arg\n");
+                    ret = -EINVAL;
+                    goto out;
+                }
             }
             break;
         case OPTEE_MSG_ATTR_TYPE_NONE:
-- 
2.26.2



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.