From patchwork Wed Jun 7 05:41:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 690170 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp139867wru; Tue, 6 Jun 2023 22:43:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4J0TmdoBe0dbX7bMSNscGZCpa2rqKdNlFLOBBQMfUgDILEeJUrAQCgIDyzS/kdMakAa+mC X-Received: by 2002:aca:1c11:0:b0:39a:531b:db6c with SMTP id c17-20020aca1c11000000b0039a531bdb6cmr4305167oic.47.1686116629900; Tue, 06 Jun 2023 22:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686116629; cv=none; d=google.com; s=arc-20160816; b=xsKDrKnQU30xJmGfqNxN1ZGzXhVXEXBk+0V1XzJHdmiIOscm/Q7v4G6l2Ra0+9vFyO 9+l5HPSK6/gpSgUU0elvkCecjWO3HFV1aGzV8MeCZIbmfopZtRIepsLhaG4lyNUFgu+M afBHFE88l4ngkcPSdrFFiZnWQGwlGDk99Hek27yQ1SMRGKdC98p9FRKyhBtYNDEur0Hl t7lkGA7rvbA0ZTd2gYdHrvOPyyRIxdFJiVlI7Ge6fOLOrcAP/xNng4nlg/lO3k6nRvGw PAz9O4wv/h/yJYmoPm4WEANGztUI0QtzFJTMql1NmySbFVBzhb4vWGHwAdb53Z9Yd2t8 DZPw== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kAiYNifcUFjH2u10kgcQy2iwEfX1E4cUKuU88IaJLNg=; b=xSZcly4p7jUt0ynuBZkoAqgvA0OsRfJDv420nAzJ/HTk6L/9/l4VAJkQ5uGJZMekM3 MLqt2eihR6Xb+qIZ7s7dF/eUuADAA7bsF4krqGGbxizyCQn/8lWy8EaZKClrFm0UnB2L QN9HsYHbtjVJpTzMvYttrDrTAwdH8RF5pCALfE4o+NVTPiWOKRfT3wyqDjToj+ZC+HhL 0dGuDftb4s2wbjbwTViDk7Le2OreYLHHJJgjfdCmKaGRyE8+wOO4hrABzQ4OPVPfyrcM 1Zkr3HVwcN2caZrF13PeieRJebkGrwReyaiU7jcEPX+NLf2D8GQMqM+Ryn9VmLmAqffz OriQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EhhqBtJ8; 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 w12-20020a17090aea0c00b002568322e3d0si616602pjy.34.2023.06.06.22.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 22:43: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=EhhqBtJ8; 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 732D585FF6; Wed, 7 Jun 2023 07:42:58 +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="EhhqBtJ8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6482385FD3; Wed, 7 Jun 2023 07:42:56 +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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) (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 269EA85FD3 for ; Wed, 7 Jun 2023 07:42:53 +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=masahisa.kojima@linaro.org Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-39a9b16b37bso3509032b6e.1 for ; Tue, 06 Jun 2023 22:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686116571; x=1688708571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kAiYNifcUFjH2u10kgcQy2iwEfX1E4cUKuU88IaJLNg=; b=EhhqBtJ8BiEBFENn/8Dvj9+5s19AU2hFzIsaMgeUFzYu1mauGEFQYCCJyPT3WIPmXL Ths7DexVT/h2+FdhSaevWWGmd1TXt4W/m/+Owxk1zakPDXhJn8DQW2ryq3qm6TofgDV6 Ni5F0f1cIysLhlKfAcnNRsNqJtcPakEWZOaobeAfWjpbKfRIvrtYx6KRcaBu5jsTPAag kiNgChzeYsHEFbU9MO3SXDxUUuW5KHwy6/lHf5J6vwwMbMRkP+AowEAcxcaa+RY1OHoc 5f2N4TiBZnUFJokKICEk2llMv0mryTjCYTbKWXpcsZkyFZVeKUg22pkAot6U6ZpM+u8m wCXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686116571; x=1688708571; h=content-transfer-encoding:mime-version: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=kAiYNifcUFjH2u10kgcQy2iwEfX1E4cUKuU88IaJLNg=; b=HSS54L4Xr9fvPVHNjm2ERsWIN0tkva6JyzNexqmA1Up/kgme0SHZpo3yCaKE9pssFk 46KgKVz73IR6XE1BGyvoy2mwAOLinL43P8JWl0j/I6LuUnyUTuIs5FZj31Vk+ZLbeAE9 PrumckDYJ4ceHC/qMm3IWyjZw7X3CZLg6reCOiu6h/VCMNm9QJPkTpVeiPtYsOgWbQog A6RmF4n01t+pgRoKeyCkQt2FHv6enmssNF7IzBORinE3dcu36NOkm6ZJuxfk/TzO/CeF DegKL0VZJ4teWslhmDv8tY/W+5O9LHc9MLG1NwhBwhEtZf5YThovfOIbxaVk04nuzdh8 AF1g== X-Gm-Message-State: AC+VfDyfPQoaxOPYm5UaOyogIhmgahNHIcVVhalgFy++51CKMh7BqErh BMuARSGS+GohpzC44coFZbBWMr62JhwPHqqApTA= X-Received: by 2002:a05:6808:17:b0:39c:6a9b:2eeb with SMTP id u23-20020a056808001700b0039c6a9b2eebmr281571oic.46.1686116570864; Tue, 06 Jun 2023 22:42:50 -0700 (PDT) Received: from ubuntu-SVE15129CJS.. ([240d:1a:cf7:5800:d3c2:bf07:d08b:b72d]) by smtp.gmail.com with ESMTPSA id fh2-20020a17090b034200b0024df2b712a7sm469033pjb.52.2023.06.06.22.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 22:42:50 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , malte.schmidt-oss@weidmueller.com, Masahisa Kojima Subject: [PATCH v9 05/10] efi_loader: check lowest supported version Date: Wed, 7 Jun 2023 14:41:55 +0900 Message-Id: <20230607054201.42702-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230607054201.42702-1-masahisa.kojima@linaro.org> References: <20230607054201.42702-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean The FMP Payload Header which EDK II capsule generation scripts insert has a firmware version. This commit reads the lowest supported version stored in the device tree, then check if the firmware version in FMP payload header of the ongoing capsule is equal or greater than the lowest supported version. If the firmware version is lower than lowest supported version, capsule update will not be performed. Signed-off-by: Masahisa Kojima --- No update since v7 Changes in v7: - return immediately if efi_firmware_capsule_authenticate() fails Changes in v6: - get aligned to the latest implementation Changes in v5: - newly implement the device tree based versioning Changes in v4: - use log_err() instead of printf() Changes in v2: - add error message when the firmware version is lower than lowest supported version lib/efi_loader/efi_firmware.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index ae631f49f7..b557738370 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -419,7 +419,8 @@ static void efi_firmware_get_fw_version(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 */ @@ -429,11 +430,27 @@ efi_status_t efi_firmware_verify_image(const void **p_image, u8 image_index, struct fmp_state *state) { + u32 lsv; efi_status_t ret; + efi_guid_t *image_type_id; ret = efi_firmware_capsule_authenticate(p_image, p_image_size); + if (ret != EFI_SUCCESS) + return ret; + efi_firmware_get_fw_version(p_image, p_image_size, state); + image_type_id = efi_firmware_get_image_type_id(image_index); + if (!image_type_id) + return EFI_INVALID_PARAMETER; + + efi_firmware_get_lsv_from_dtb(image_index, image_type_id, &lsv); + if (state->fw_version < lsv) { + log_err("Firmware version %u too low. Expecting >= %u. Aborting update\n", + state->fw_version, lsv); + return EFI_INVALID_PARAMETER; + } + return ret; }