From patchwork Wed Jul 22 07:32:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 246977 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp301462ilg; Wed, 22 Jul 2020 00:32:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJye9+fyZYv2bPVWoDDnFzv9usX8itvp+zdGHiJreQ96VaWE8td6MvanNkElw4M51hj8okui X-Received: by 2002:a17:906:71d4:: with SMTP id i20mr30688911ejk.533.1595403153569; Wed, 22 Jul 2020 00:32:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595403153; cv=none; d=google.com; s=arc-20160816; b=QSxWHRTd0skSU0N3iE/keqUAuMPHkchuiHXI/S5FgzJaIHh5UP16gRDM67qFUXncIl vtQQ+QLJ7LR9MMQ66GMF9Lcgs7W+uU7OxsKCo7VsA3bFtGwDiffro0ANfJSoLbH1b0C2 pHEwBNuKnuE5fcCnZnlMPsS4iflEXvcszckN0DNL+H8VG9DtkRomw+8SXkbLc+J981eY rZuz6BjW2zgWW/FAr7vQ2ZKPNfQfLq9uS41X3Hwh2Cg3Q4euHD7BgGpERZJhcjXzgFuR SlRXuFI9Fjr6GvoNPciywZ/2ZaOKrmGaqvWUWDRKgihTaHSP6WyOy76q7mUk1PZbNmnD q6UQ== 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=l0Lft94CAXySv+ozKoh32PLIorcl0zpDcXGUrQBVDmY=; b=TnmGXIfAtBfA3Osb8PV8E1ovgs5PlBio9z00CwP4EI+8tbe8jPiENGmv+bbx9P1O/H QGIxveyH4ftSJU7Fhkx/2puF/Z3CQVVQorSZoeUEsveOauVkjz+w4wNAfW/LbNykO3Mk YQbihuHmq0Wl7vU8e/n2UF4vK8kteylA5OrNZc/pTYxCLZhAjus4skYHpsoZ6chN9S39 O1cMkjo5hDqtiuz7rxfubpZ6OSAFX167j1vMUlAjdTM8KapmMhn74ktQeLDO80jELJUk oiMlj4mhsNpWgujpqDbWyFsdLSEyH/budWu/Im4WVXJvtQa4eaivjdrhBwUoVTnLQkH9 5j8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="H8aPoZH/"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id w5si14641562edx.179.2020.07.22.00.32.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 00:32:33 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="H8aPoZH/"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 C9B0A81991; Wed, 22 Jul 2020 09:32:31 +0200 (CEST) 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="H8aPoZH/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A16A819EA; Wed, 22 Jul 2020 09:32:30 +0200 (CEST) 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,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (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 4547381765 for ; Wed, 22 Jul 2020 09:32:27 +0200 (CEST) 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-wm1-x344.google.com with SMTP id f139so980003wmf.5 for ; Wed, 22 Jul 2020 00:32:27 -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:mime-version :content-transfer-encoding; bh=l0Lft94CAXySv+ozKoh32PLIorcl0zpDcXGUrQBVDmY=; b=H8aPoZH/CK4omEEdYMP4IKkCNJhGwu6MhkzyMQFccA53d9YlygZxHtAWR28wOidDdv FyLEoCWHp1JZSDhW3zJlynEOKd+9yxRmP+gDf/FiYsCiaEFhCGSjQ/DsmVwXu4kYSv/O AWaPurr4m0oqelNt73ZEVvmNY2wF9djWm6J893rqBqRXj6Bri1Xofj9srcFV9iYCZkyC ydBR7ptimq6h3vylWy/h3KaEt9HEWbZbTT8PxcOTltiEuhaSqEQiL9K+DIwP/FR8m8kF aCURzj7ltJwaqp6rU7zMGafrYmMgqSVBwoY9Gp00GLYQA6y7vIPlv40E9Stfs+stmIRK fd4Q== 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=l0Lft94CAXySv+ozKoh32PLIorcl0zpDcXGUrQBVDmY=; b=qVzd7WKHKV42ld4UzDehMEqk2Mdye7CMp3Phu5ve/ZLz6+7lz7TIR6VAiH1wxF9vCt ej0kUmnUnLOrRcgTwF1isOHymzKO2mEgZzWKf8A4xmVTcueAID/hjJzBa3fVs+YwBE1+ ck+YuiLFX5pnbK5KokZo2F6Y3p8djjuERwMynNwhFdi/InE0Oc2oDxmT9sNiwjmLRxqw 5ZEUTBEMEK/zVZlIEQLcPzJNOCI70eDs7cvAr/B0WYXROPCNgNtRH6Ta6EmnbsATbfsY w4h0tEQIUk+iXxyPyN6kIXHPEeu1QcVKpnHWhvpz2E3evdM4wmdWoIPdeV6SMrjKhWIO JJUA== X-Gm-Message-State: AOAM530oJ19mo5ek6tmdWNDX9KzFcz/M1NPaZ3OcnsXA6cI54X0jKkhR VNMzmqmmXliqVjukd0s4xinxW0UsiAE= X-Received: by 2002:a1c:4b08:: with SMTP id y8mr7263526wma.89.1595403146392; Wed, 22 Jul 2020 00:32:26 -0700 (PDT) Received: from apalos.home ([2a02:587:460d:e29f:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id o30sm18160240wra.67.2020.07.22.00.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 00:32:25 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de, xypron.glpk@gmx.de Cc: agraf@csgraf.de, Ilias Apalodimas Subject: [PATCH] efi_loader: Check for the native OP-TEE result on mm_communicate calls Date: Wed, 22 Jul 2020 10:32:22 +0300 Message-Id: <20200722073222.510135-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.28.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 Currently we only check for the return value of tee_invoke_func(). Although OP-TEE and StMM will correctly set param[1].u.value.a and we'll eventually return an error, the correct thing to do is check for the OP_TEE return code as well. So let's check for that and move tee_shm_free() and tee_close_session() before exiting with an error to make sure we always clear the registered memory. Fixes: f042e47e8fb43 ("efi_loader: Implement EFI variable handling via OP-TEE") Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_variable_tee.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.28.0.rc1 Reviewed-by: Heinrich Schuchardt diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c index c0423489388a..346f4c786f28 100644 --- a/lib/efi_loader/efi_variable_tee.c +++ b/lib/efi_loader/efi_variable_tee.c @@ -100,10 +100,10 @@ static efi_status_t optee_mm_communicate(void *comm_buf, ulong dsize) param[1].attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT; rc = tee_invoke_func(conn.tee, &arg, 2, param); - if (rc) - return EFI_INVALID_PARAMETER; tee_shm_free(shm); tee_close_session(conn.tee, conn.session); + if (rc || arg.ret != TEE_SUCCESS) + return EFI_INVALID_PARAMETER; switch (param[1].u.value.a) { case ARM_SMC_MM_RET_SUCCESS: