From patchwork Wed Dec 23 10:43:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 347003 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp6088438jai; Wed, 23 Dec 2020 02:43:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6Qmt1GdasWorPTh5GOec0Lh1+Nf+pcoC0NOotqlTASlYhuSRp1/1kM3EIywqJ+B0gpNvJ X-Received: by 2002:aa7:cd71:: with SMTP id ca17mr24847753edb.25.1608720225722; Wed, 23 Dec 2020 02:43:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608720225; cv=none; d=google.com; s=arc-20160816; b=tmx/u7BsQw7I4RRMNKz+cw7/8rHeV1SKf7LDUdS8HhDlvOC+m2BgekjA7JALjN75bV qdLumu/77vMADskzJMgs+U1pkY7rCcbcRT26Imhehyf6irjuy2pJR//v0wlNP6sr87xI w3ZWeJDenIGJngVKacwxRHMVi/vci8njLXGaJAF0z6dkuyw/CDtNdyTczVpM9F6WER7B WIxNAuvo6da+NCcttUUBARViCcJBPqAkiUB0Fj1LiVBx3+e2b/LqU/pWXceppL6CYpVa rfEkthcBcx6Uzz8rPvI/n+1ueJaiudx5XYBxiLyRwRte8xRBITy8BUdtKJaKHR3zHUJx /u0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=6P5OV+BFK4G/jwt3GdR+CNMqdcg9aVkcSCuwQtdisAg=; b=rIIzXEXP2/12MgQYvatkKh9AF3GcgDwukGUqNSFPN5yromdTHestk3G2WOpSkxddnq gUnGhYHQbOsJHlQc1+rwkbj02lATUH56dXOGJfe8AK3PhaPT6Lwdk8ldsLuxe391KDSt dqA9YmKsPbScrH6VCAnlVQngWFBX2+IvkrYp2I3YAn88LvyB8/NoL6B3TOdKSGHaQa/F IGNstyrNopqdhFMRDcjTD+tizREWPaSFSrZ4ofzPjegiH85Wa+PtygOrbNLPDewYYZct zndYDQ4X4KslMY0vdZnTjVa5v9DbJfZ6G9fxLsjH1qPJ0TurOi9+k2GPdmDV1spNP9JX YcgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NuLuO13l; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id sa14si8592380ejb.54.2020.12.23.02.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 02:43:45 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NuLuO13l; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DC56482707; Wed, 23 Dec 2020 11:43:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="NuLuO13l"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 02B6A8270A; Wed, 23 Dec 2020 11:43:41 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BC1AD82705 for ; Wed, 23 Dec 2020 11:43:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x62d.google.com with SMTP id n26so22193221eju.6 for ; Wed, 23 Dec 2020 02:43:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6P5OV+BFK4G/jwt3GdR+CNMqdcg9aVkcSCuwQtdisAg=; b=NuLuO13lmi/MN4uf+Ci5nuqY5UV+BVHRF0RRFq9EEmaNmtooqyHazUNIcWnZ7IOMBb gGtGV4RvabfRU9FfVCCTul8zRvE7Y2Ze959oGwHKASh8L5+Crbz24SEIhGhpNvJarQoE na3e+/R5CBIht6AZIcFqxLKs3BvhD9jUzzhPrxOu4crLD+gZNW5E8A2e5ooIAQRWeyXY S414x4bQc/IpomdJxJf6f69MGyrVcoNQhxRKgRHG9VSPAQw1RaJx4Sp+mQg3KzR4akor 0VyoMoJAbRaNH/nbZbFDcX3UfLZuNUflV7TDWAHBYYMJMYSEalMi5d8ZwWKhUFklEvnG YB1A== 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:mime-version :content-transfer-encoding; bh=6P5OV+BFK4G/jwt3GdR+CNMqdcg9aVkcSCuwQtdisAg=; b=MMDa5nf26SAlOYFp31/iJJZQE7yqF4VG9TgJJQrphRN8YiAsrN4gfMJwEPIHe8BAxX vW4OdICsPERNLx7/+1BrrxphRzVuDgEu9A0bidrrQ41vbwz0mifYf3OWwxAM1VUTi+eh njZXzYvZnyuh7sUNDwWdh7ibbtfoarYshbBHQwzpJQDV1ts7rq+NrWOx7gN3eepwzMGo KMZVvAjfdgUk7pn2sp0+kDEUcpmvDI5ye8ENzxypbEeuQI1C0B+Z3oiAX+Ha9l3Nsc5g fUDdggJ5V7nYIYyTeQ+bG6YdiM0isHHJGiUlAzDps4mFxF+akHdofMEwDfheEEnwY2W7 gWZA== X-Gm-Message-State: AOAM531mBnsC1Q6TXop8jfOwKpAcUCQ+/gDapfTNeSw971gXrwoaRBm4 GpITuf0eAL/NGrcoOPgOAP7STg== X-Received: by 2002:a17:906:b217:: with SMTP id p23mr19160964ejz.461.1608720203344; Wed, 23 Dec 2020 02:43:23 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id v24sm31071886edw.23.2020.12.23.02.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 02:43:22 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH] efi_loader: Extra checks while opening an OPTEE session Date: Wed, 23 Dec 2020 12:43:19 +0200 Message-Id: <20201223104319.57141-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0.rc1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean When opening an OP-TEE session we need to check the internal return value of OP-TEE call arguments as well the return code of the function itself. The code was also ignoring to close the OP-TEE session in case the shared memory registration failed. Fixes: f042e47e8fb43 ("efi_loader: Implement EFI variable handling via OP-TEE") Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_variable_tee.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) -- 2.30.0.rc1 diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c index be6f3dfad469..717d0b45e7cd 100644 --- a/lib/efi_loader/efi_variable_tee.c +++ b/lib/efi_loader/efi_variable_tee.c @@ -45,10 +45,11 @@ static int get_connection(struct mm_connection *conn) memset(&arg, 0, sizeof(arg)); tee_optee_ta_uuid_to_octets(arg.uuid, &uuid); rc = tee_open_session(tee, &arg, 0, NULL); - if (!rc) { - conn->tee = tee; - conn->session = arg.session; - } + if (rc || arg.ret != TEE_SUCCESS) + return rc == 0 ? -EIO : rc; + + conn->tee = tee; + conn->session = arg.session; return rc; } @@ -88,6 +89,7 @@ static efi_status_t optee_mm_communicate(void *comm_buf, ulong dsize) if (tee_shm_register(conn.tee, comm_buf, buf_size, 0, &shm)) { log_err("Unable to register shared memory\n"); + tee_close_session(conn.tee, conn.session); return EFI_UNSUPPORTED; }