From patchwork Tue Jun 6 09:40:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 689689 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp2537948wru; Tue, 6 Jun 2023 02:43:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ61AiGUe8/dtDsiv0yD0vlDCH+x8W1bpL3Iob/EobG5ThkLxuwP/6A3BrDucvt3WhvkQNba X-Received: by 2002:a05:6a00:198f:b0:656:5182:5e61 with SMTP id d15-20020a056a00198f00b0065651825e61mr2126410pfl.2.1686044584687; Tue, 06 Jun 2023 02:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686044584; cv=none; d=google.com; s=arc-20160816; b=v5yO5uLPZcMn7JW1Dz2Jiy97E+Y2zYojTCgBheKH4SgcyLx+a+RmVmY0Q052buhHGe jABjwxeVSrNcp4g3UX5HaeHxg0JpujnPzj/c4IGZAvcYZVYwdeoNyYaf8QC4xCEWhdEO DZGkM82pFZcjX7jjpUXj81RkG4Fguzq83sFIZLsxMbLtS4XAsFDOX6v9Icf55gXiE+PU +9PV2g4yt0DqXcYKvOj4ksEaDivpbcP0leNYzcfaKd8raNQzKoRxPzu9/S/Ieg1cQaJW U2ebYoL2nUShh1xvq+7Dq0H47NdpN/meCt17xOL3YHyvmwQ5ML8pmj33BLRuOD0tnhrk PSHg== 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=OSoc++DJVlCLrZ9Q5UqP+rleG8W/ZCbrDfazF/772omrmIr+BU7tGADPfQMfk9voaK mJhrE/WchcjI3esZnlhshXy2aZpLffb8N49qVG0mRWIMiHJA62RsWUFfLRDcj7+yYZwR VIa9YZqUCXhBKlFwlV0nQ3bL9NBw6KkhjvomaNiyLi3Azlewd7vWGjG69KWVpiNsfhxX J96smt01Wm3f/YmmTDtPfzwUcoKvSCaRECK0hcSt0veabJb4Vl2puWJHIpon0YtCehVf 1wPkqgoo/bTAJV0yhpvXLo2O9aPhH872SrrxvMTASBviUXdb5ZBGL09JU6uqvToQbyIa fXmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b5x4S4EZ; 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 b13-20020aa78ecd000000b0064d33e22709si6924718pfr.66.2023.06.06.02.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 02:43:04 -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=b5x4S4EZ; 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 039EC85F13; Tue, 6 Jun 2023 11:42:01 +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="b5x4S4EZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E921385EDD; Tue, 6 Jun 2023 11:41:52 +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-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (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 B7D6685EDD for ; Tue, 6 Jun 2023 11:41:48 +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-pf1-x433.google.com with SMTP id d2e1a72fcca58-64d24136685so4261763b3a.1 for ; Tue, 06 Jun 2023 02:41:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686044507; x=1688636507; 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=b5x4S4EZke+0M+1oA6mvTDOsnEjAbKEREhAVYCpPOIH1SqlH6REfCHdzI+BlEH5DnY trhv3SM9cm5x/m+67ikWbLx0YFgXw81/ZNRdVbJIYmZADgl0ox4eqfObn35pCL67W3B9 RRIOFWshc0AQZkv97QZ7EZTMuSlpuDnyRgwuXicVBTFoUWpm1HvlStd9nOEmGrA1Ymtv 34gCJhixq2guE6FeSs5GuUSnZ7g8RKbG6Q/dGM9UhQwXRsvHpL4xpG2ABWRi63r0WtsE diKFa4W4/v/gxSdmFIitGraZpdg1GMVoEfwdGUWCv3728+GY4AEeYCf6NZfd2umrikuP t8og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686044507; x=1688636507; 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=DMZ+tI1qDVG3uDlzwR+6ryDECRL/EsI65SNgfBVxtcj+8b8kzVkJX1vmqyQ57b+rDh vQMh+EJHT7/E9C7gBq+P7LfV0qR/C04bzkKCzH+yuSyFiIRvC3ajtfNm00yBSxHjxcHX gopAuBLNQE5hA6MLlEhnnDHll+CakMxKZKuIoZtsmS6VyMB7cpU30VYmFEQDo5DYzlxi vVsKHJNILmh9YZ3M/DUEBAS7APLHAIbHXWq9g8PAWk9QXLVAfS5TStBSupy9DH7ZzOTo D93nczUuk5/99KoJwW6zvPDjeEVd0+f3JR+M65Ux6Y3nlR3yQsDFmo49P/AuAZngGD9t KrOw== X-Gm-Message-State: AC+VfDy7iFMU8Y5z1/APGSOgzYyLx7GH/H47CX+mAXx+wuJXw+3bN0mM FolIG02GpMDh5/RLEI5VsITFXvgBtj3rOb69+fE= X-Received: by 2002:a05:6a00:2794:b0:655:a7b4:2c8f with SMTP id bd20-20020a056a00279400b00655a7b42c8fmr2260128pfb.11.1686044506789; Tue, 06 Jun 2023 02:41:46 -0700 (PDT) Received: from ubuntu-SVE15129CJS.. ([240d:1a:cf7:5800:d3c2:bf07:d08b:b72d]) by smtp.gmail.com with ESMTPSA id u25-20020aa78399000000b00627ed4e23e0sm6542809pfm.101.2023.06.06.02.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 02:41:46 -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 v8 05/10] efi_loader: check lowest supported version Date: Tue, 6 Jun 2023 18:40:29 +0900 Message-Id: <20230606094035.28990-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230606094035.28990-1-masahisa.kojima@linaro.org> References: <20230606094035.28990-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; }