From patchwork Wed Mar 1 09:15:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 657798 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp3386760wrb; Wed, 1 Mar 2023 01:17:10 -0800 (PST) X-Google-Smtp-Source: AK7set8KwPn53ZhUVybTsZceNQ+k1A9OZ+ktnMsjYyb2Lxit5ndUksa+ghx32blpUKabs67MUzA0 X-Received: by 2002:a9d:4e5:0:b0:68d:c122:5a51 with SMTP id 92-20020a9d04e5000000b0068dc1225a51mr3085492otm.14.1677662229963; Wed, 01 Mar 2023 01:17:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677662229; cv=none; d=google.com; s=arc-20160816; b=Z3k/QReFyKVdkTciA7/+ZGQEpSSBnEiwbj5kXIR4EghmMw1sZD/67JOb9EPfPjywlt Fha/P8aSEAe4LR/DgHN43Z2E2nic7YX9/chw/3U1RxzV1RyjAcleGZDnNgPa9uPDuqTJ Zwct0H5UTuq5nMbjVdgQgz+xhZKuzm/9i21QOIDRNqralQZoCGFBKu4gfOdAuvkdYC33 9CNi+DQByyQ9w3y51d9b0i7zJFfRAnDvnL7FqK/avV9YuRGB9LOIThsSx6gpaGQdWwvN moMYHZKDvArwIRJqp1gzpv8OblBCABei+KeDSMoGumwL7pAxM62sydODUbif7oLPjFH9 Xf/w== 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:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=s8+XMNzwQS4X33rmGS+Gr1gY1iTVDbpkTqXPcNm3xdI=; b=QAYYaJ8QEP1oF7MpSPhC+clUO3Nz9HxkrRfbvivPNYh0C8U3lOyEWeKCsz+B8ErLdi WCXkzJgaTaL4ZcDJ4VHmKB75+Oe8pCZEmolpYZ+1ZbT0ywO8IwW0nDRWHtVkROShy/Dt laZQOQ8YPbQFVqZT/a7dxOUQHiS8nqHqfPccF+czkPDRbNMni295BN49yOFgQPu5IPEQ WgCtH+eoAOvM0Pl+vnldMilwVatZaSLZ9RniurnI/P4oZVC40zSiDr/51vpNob6C5XQO CPyhp+vmPbcgS+7iSzdo1MhxgZ0d3eu6fB1BFKytibIw0iTBM2VPqq38jlf5ZdIjILm2 ffjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="wrp8xs/4"; 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 w10-20020a9d638a000000b00690daa32382si4861393otk.181.2023.03.01.01.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 01:17:09 -0800 (PST) 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="wrp8xs/4"; 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 6DF7B85C31; Wed, 1 Mar 2023 10:16:32 +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="wrp8xs/4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8EBEA85C04; Wed, 1 Mar 2023 10:16:24 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) (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 B17B885911 for ; Wed, 1 Mar 2023 10:16:03 +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=masahisa.kojima@linaro.org Received: by mail-pg1-x531.google.com with SMTP id 16so7293316pge.11 for ; Wed, 01 Mar 2023 01:16:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1677662160; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=s8+XMNzwQS4X33rmGS+Gr1gY1iTVDbpkTqXPcNm3xdI=; b=wrp8xs/4tRietHp5HKXbA0r6ZSKkTbQTzdF5BTcyDU1u+RRDNwuI4hRSZU/+6UAGm9 8QMcftc0PLCyJeChwNlalpqRUHKdpOZgVOokG68f+qKkK9+v0q7MTjWVBpG2jTfpwdAg q19Tazl+D3wurMgQH+UBoUrO8ysEUDUdlQ63cZzllz+vBrFNEEC3/WKxSGrRLVzqfqYK GLLc6kaTv+fHQK+mgTWxSJftlov/0phuzA+E+3N0cuuHXGoXKFIi5O1jnrYzAno/xKdq 80Y0leOIEcnBrcFZ+BC3kk5x5LUiipgtsWTL4oZfgFa5YWWk8AI9LRbkKXdKinpW0NoH VYbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677662160; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=s8+XMNzwQS4X33rmGS+Gr1gY1iTVDbpkTqXPcNm3xdI=; b=PNZIhwRbf+EtXQ2nyPD8RgaYsZSAmUYxJCZOZtxtb40nTDIg6VGz0WTB+MiGPb55Gf umVBA2K4hdE5DgI8+Hl4WzcYl5orEARn6IhAyh9jc++Pqn1nnrSExkQneQswo9tn5OVY ySleiBmjNkxfHgwzlK9/XIgQYk4RgLVgNi/agwjFQtd6f+g9xJrkwt74ofWtEc68sXCz hlUFiCZXrMmruzuEMZv3yu3Gx7MQsaSf+R5a+LLWhLCadEcPk5+jy1ITS0aKLfs2agWz /aLwRINTKmEUTC8eZ2X1OpSLnoNXO8WBJwrCEIRvPLVjzi5s2SrRO6kFsk0lHmE97yMy Ak+w== X-Gm-Message-State: AO0yUKUtlEU/qzlrG92XlkPTlgllex3DPcHm6tde+77KlQCccxWXI8iO 1GOfJgguDxtQZOUE8pSeTODj23rrJnabfOnp X-Received: by 2002:aa7:9e8d:0:b0:5da:cbe6:a613 with SMTP id p13-20020aa79e8d000000b005dacbe6a613mr5784260pfq.22.1677662160124; Wed, 01 Mar 2023 01:16:00 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id 13-20020aa7910d000000b005a8173829d5sm7466637pfh.66.2023.03.01.01.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 01:15:59 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v2 3/4] efi_loader: check lowest supported version in capsule update Date: Wed, 1 Mar 2023 18:15:21 +0900 Message-Id: <20230301091523.18384-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230301091523.18384-1-masahisa.kojima@linaro.org> References: <20230301091523.18384-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean The FMP Payload Header which EDK2 capsule generation scripts insert contains lowest supported version. This commit reads the lowest supported version stored in the "FmpStateXXXX" EFI non-volatile variable, then check if the firmware version of ongoing capsule is equal or greater than the lowest supported version. Signed-off-by: Masahisa Kojima --- Changes in v2: - add error message when the firmware version is lower than lowest supported version lib/efi_loader/efi_firmware.c | 45 ++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index ead20fa914..fc6babfc34 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -368,6 +368,34 @@ void efi_firmware_parse_payload_header(const void **p_image, *p_image_size = image_size; } +/** + * efi_firmware_get_lowest_supported_version - get the lowest supported version + * @image_index: image_index + * + * Get the lowest supported version from FmpStateXXXX variable. + * + * Return: lowest supported version, return 0 if reading FmpStateXXXX + * variable failed + */ +static +u32 efi_firmware_get_lowest_supported_version(u8 image_index) +{ + u16 varname[13]; /* u"FmpStateXXXX" */ + efi_status_t ret; + efi_uintn_t size; + struct fmp_state var_state = { 0 }; + + efi_create_indexed_name(varname, sizeof(varname), "FmpState", + image_index); + size = sizeof(var_state); + ret = efi_get_variable_int(varname, &efi_guid_fmp_state, NULL, &size, + &var_state, NULL); + if (ret != EFI_SUCCESS) + return 0; + + return var_state.lowest_supported_version; +} + /** * efi_firmware_verify_image - verify image * @p_image: Pointer to new image @@ -375,7 +403,8 @@ void efi_firmware_parse_payload_header(const void **p_image, * @image_index Image index * @state Pointer to fmp state * - * Verify the capsule file + * Verify the capsule authentication and check if the fw_version + * is equal or greater than the lowest supported version. * * Return: status code */ @@ -386,10 +415,24 @@ efi_status_t efi_firmware_verify_image(const void **p_image, struct fmp_state *state) { efi_status_t ret; + u32 lowest_supported_version; ret = efi_firmware_capsule_authenticate(p_image, p_image_size, state); efi_firmware_parse_payload_header(p_image, p_image_size, state); + /* check lowest_supported_version if capsule authentication passes */ + if (ret == EFI_SUCCESS) { + lowest_supported_version = + efi_firmware_get_lowest_supported_version(image_index); + if (lowest_supported_version > state->fw_version) { + printf("fw_version(%u) is too low(expected >%u). Aborting update\n", + state->fw_version, lowest_supported_version); + state->last_attempt_status = + LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION; + ret = EFI_INVALID_PARAMETER; + } + } + return ret; }