From patchwork Tue Jul 21 22:50:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 246941 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp15398ilg; Tue, 21 Jul 2020 15:50:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcQSUxmPa067PVMN83J/kAYQbMGNZk/6NDF9neu6+75XdpbTgG2piRszmdpkaq62mfRnWy X-Received: by 2002:aa7:d70f:: with SMTP id t15mr27117896edq.237.1595371849074; Tue, 21 Jul 2020 15:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595371849; cv=none; d=google.com; s=arc-20160816; b=AF0cfZWsSxmKwJ95/NyXEXRLA5zt+66MAm3JI1eIwoemziZg6hcbod7bsWE/zWGBRe T3xjhQRG3dvAYlT+fuGCKciAXGgUgOkoyneMFG3hBaYCUMorF2eO4knBihcM01aBnlj6 OZbpUQYHHCyaD8nQkZu3ue/XTSkOJFfQBfp9aYiZXbNesQgHt399Ty18PCmPBcYIUWZp ktsnyZk/dYvucFm67iyBXFs7Ek7D93zXGhuNxUYfsYQ1qTx7D5FIwFu9QcKJrYJr78/1 uIiTdgT54Tzjx4NY6PyP68zEh2h8oig0Yd9HLVtqpPAflatH4BahjM07YyEAcB+r00q7 uezQ== 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=faw4DYNsiGj5A+JhHkF7jsZgGLlnNRkHFIuTM/LbgXQ=; b=PZKBXjSLXAw1aMTIOq11qbW/r0EmNXAAGDDqNxwjm5u4u4pjscFV1dZgIVFUdodyDl Z1saWpHBNXh6PsWcBAJmwXPUv50vDNg6ClkD+D5VhWSKnyjpjRo15YRauCmQRTbhmbmF zUoyLE8nVWJkIMhlHowyzh00ihI+XCIB0lKlRyvrvi2h5nnnISNn9OiGT6QbqXIMHxc1 sEpMofNvH6Y9KJPmLxMtWK+X654M8XsNuPL2sm3F/R41Dgr7r+F91ocSuJhCA9LyrI3J c98jZn02OxvHCofWpb/hCe3tSElmqR8zsPu7r/yMBD52zkzfZ6itXo0wWUKEDX/tAqFl QqXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZaY9KsPV; 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 u10si12698619ejh.592.2020.07.21.15.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 15:50:49 -0700 (PDT) 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=ZaY9KsPV; 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 F1CCA819F0; Wed, 22 Jul 2020 00:50:45 +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="ZaY9KsPV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 37C8581B7D; Wed, 22 Jul 2020 00:50:44 +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-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) (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 522A9819EA for ; Wed, 22 Jul 2020 00:50:41 +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-wr1-x442.google.com with SMTP id z15so73094wrl.8 for ; Tue, 21 Jul 2020 15:50:41 -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=faw4DYNsiGj5A+JhHkF7jsZgGLlnNRkHFIuTM/LbgXQ=; b=ZaY9KsPVKZUyAzUV20VfPA2MWDz2gIddlrQkyk1RJe0poS9LCJyUYnwjv8iy1X22yg isGmE6Bdbp42fVFTzE7Au5aIILCFQoaP329k5Xw6QON5Lg4fyHIxBvIXtmY5Xw72Efor MEqtf29pC+cZ4bW9llhIs8lrh5HNgjVu/CTw/pKdJV9hPrGobcjTQQfyBmR79wjNRZYW 1OlgabcR1nBKWCF7TRskrZDULQlkwkEzkU8/JM9AJ/10XiqwLOFHta6Ph2Ikaa7lbo3h DysqyLfs7Fb8NfaEihB8BCm+csGxo92jKB/aYUGU2invVkg4Zd/7Tl4pZgROqZ0OMq79 5PwQ== 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=faw4DYNsiGj5A+JhHkF7jsZgGLlnNRkHFIuTM/LbgXQ=; b=kDyXIgbZusJ7ZVp71NtEO9zmY4T6N4mPA+sbF43XIzEQVONVj3lQe7+hQIUkCnrG5j a/WxB2Txw0Z1x8CLmnfeG7Jenoru2ZLyR6eOZgWLz3YoLb6I6yqQYpEveJ52f6El6KMz o0vo4nV6d3yOPmmkZEod8JP7ozKOKhbq/UTwsqfd5Qu3Mf5dHFHquhBYgPDAY/H/0w4T r7Mx3ytqnsFTPeyfCcNNVHxxCope2j00DDNOKeRMElajmckdLMEWIM8uXfWWJY5UYc3I qv2S6/IhdeQnZ9oNI7CIHAIeucUUzY2P+cPgSnfH7pEZNDkL66BpAxQxE5vm7VGhaXBF Al2Q== X-Gm-Message-State: AOAM531CL+ISPxq54sKAVqg9vA2uqXx/IGM0/C3+u6qidhh9sEqMEvKZ auYhbC4Q8Rb+ndaJ9IVJ3/skZtfb9Js= X-Received: by 2002:a5d:4e8c:: with SMTP id e12mr5506570wru.19.1595371840550; Tue, 21 Jul 2020 15:50:40 -0700 (PDT) Received: from apalos.home ([2a02:587:460d:e29f:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id i6sm38883000wrp.92.2020.07.21.15.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 15:50:40 -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: Trim output buffer size correctly for tee variables Date: Wed, 22 Jul 2020 01:50:37 +0300 Message-Id: <20200721225037.450919-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 The current code does not trim the output buffer correctly. In fact it doesn't trim the buffer at all, since it calculates a wrong value for it, which isn't even applied. So let's remove the unused temporary size variable and trim the buffer correctly. Since we are editing efi_get_next_variable_name_int(), fix an indentation error along the way. Fixes: f042e47e8fb43 ("efi_loader: Implement EFI variable handling via OP-TEE") Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_variable_tee.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 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..0e5b4479d936 100644 --- a/lib/efi_loader/efi_variable_tee.c +++ b/lib/efi_loader/efi_variable_tee.c @@ -410,7 +410,6 @@ efi_status_t efi_get_next_variable_name_int(efi_uintn_t *variable_name_size, efi_uintn_t payload_size; efi_uintn_t out_name_size; efi_uintn_t in_name_size; - efi_uintn_t tmp_dsize; u8 *comm_buf = NULL; efi_status_t ret; @@ -433,13 +432,8 @@ efi_status_t efi_get_next_variable_name_int(efi_uintn_t *variable_name_size, } /* Trim output buffer size */ - tmp_dsize = *variable_name_size; - if (in_name_size + tmp_dsize > - max_payload_size - MM_VARIABLE_GET_NEXT_HEADER_SIZE) { - tmp_dsize = max_payload_size - - MM_VARIABLE_GET_NEXT_HEADER_SIZE - - in_name_size; - } + if (out_name_size > max_payload_size - MM_VARIABLE_GET_NEXT_HEADER_SIZE) + out_name_size = max_payload_size - MM_VARIABLE_GET_NEXT_HEADER_SIZE; payload_size = MM_VARIABLE_GET_NEXT_HEADER_SIZE + out_name_size; comm_buf = setup_mm_hdr((void **)&var_getnext, payload_size, @@ -465,8 +459,7 @@ efi_status_t efi_get_next_variable_name_int(efi_uintn_t *variable_name_size, goto out; guidcpy(guid, &var_getnext->guid); - memcpy(variable_name, (u8 *)var_getnext->name, - var_getnext->name_size); + memcpy(variable_name, (u8 *)var_getnext->name, var_getnext->name_size); out: free(comm_buf);