From patchwork Wed Feb 22 10:40:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 655686 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp621426wrb; Wed, 22 Feb 2023 02:40:04 -0800 (PST) X-Google-Smtp-Source: AK7set/GNtOA7zfzLxWuzw5PSn18aSNrIr1svt4YSRi1dXzRgJvF1JOv7dPfeXBmkb2mI+pOSke/ X-Received: by 2002:a05:6870:eca0:b0:16d:c848:30e2 with SMTP id eo32-20020a056870eca000b0016dc84830e2mr8706974oab.44.1677062404486; Wed, 22 Feb 2023 02:40:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677062404; cv=none; d=google.com; s=arc-20160816; b=bejI1YdOpsXRQPnwi6vcH8qFl+UmffHmAkYaPpwqgfImmHmDNOC/W8KkfK0idVAEv7 GeVI0UqffNpgt+gqgqo7vUjfqS7FNDgcpmmfaqmnVMESeW5+vyVWmrbYlyjAAkPQ0T/e iTmdeZt7D+ETqzC/c8xDR+C2JHSl5t7VjpkUfJ4VgJwnxIxhYK6kihaw5oWB9K0HRvBX 0naKQZ5+b7sTXdpNae0UV3qkuhhCSxM/crgzqHkMsFjoU/lnB6t4ZHBwxvo442bhHwWK aWoecTttJHf5ED11wZfi5sYjxTk6x1KjQ3I+hly5c+BKSG8Dg6d1/l1GkGnpF86Zgz+O ehIA== 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=DW/AvdWSNwqm0QbWNS2q10yo2kQQ7nMsbIT7S5po7hY=; b=WEQwAwlQT4CJIYU2eCFtgv6ShUwEYcOvpXQpcWVFf4JRa2ELprLM+LiRNt1K6LiH26 1T16lidwoYIkgKc+puSKDhv+xtR8T3evp/qFq4kSCBhrBiwUDb2UIcCoNSWK2oSfX3UB Fxr+ucNz4VKLuAaYQ+A5unaLeMfoYbcRZaXkRdhTJMcEICHusVcjN08J0GtNUjRIdOIM sCT0Ikw4+8B0ViF4Bds4UgHVCWia4ZbNihWyTDn/UsiobqRREFk7UkVwiXQFStho776E i75eyGzYN3+BgQrWWnXBzVNpfjxDdwtnuD8eer8DG3qHfipznK4MNHtpETdfc26HP6+V gJ2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FOfb6KMn; 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 yf2-20020a05687c000200b0015bae89ef4csi19947226oab.252.2023.02.22.02.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 02:40:04 -0800 (PST) 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=FOfb6KMn; 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 0013785A9C; Wed, 22 Feb 2023 11:39:40 +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="FOfb6KMn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 67CEA85A86; Wed, 22 Feb 2023 11:39:23 +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-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (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 3308785A8F for ; Wed, 22 Feb 2023 11:39:16 +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-pj1-x1033.google.com with SMTP id q31-20020a17090a17a200b0023750b69614so98474pja.5 for ; Wed, 22 Feb 2023 02:39:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=DW/AvdWSNwqm0QbWNS2q10yo2kQQ7nMsbIT7S5po7hY=; b=FOfb6KMn7ray6z4FfJfRcWt89hPmMUegq9cHkpfCtXNJlEzgnSMhUoU+/hktk2MlQO PNbDg0b4h+4VPlTP2wZH7ObLtRHdwkn62nmAyiMdMONHHX84RjZB6WT3MOCD+aC+F+Gt mYLtoZH8v7PAnRapC5+Ox+RG+XzlC05B96xbB2VASh4Ft2zFi0my0pnHU+f700ewOT4l X5Isogh1URtQYBe+e9pYZBeIYphHsnQIpaY7rDW1nimDkquDuJ6JEeh07d8aMxBwMFXR j6IJHB0Dqg5hdjp2IRPjybHJktd9bdmEK12vTZJNx4xPR3d8FdoghqBFE66lmDnscGeM Q/TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=DW/AvdWSNwqm0QbWNS2q10yo2kQQ7nMsbIT7S5po7hY=; b=240XNvgSjPbXnGtChMP8kWLvyM3d6iQMFGUdzdA9M+Pz5X/zkZgI4DeiKjQMhkMKbO /WiC5tOUW8jsCmaUv5n4g3EBV+ks2tDHyqJqBtq6eKm5aZ/addgQm/rcrl0fImgOg5w+ xqILKytKL4SE0myyxqFwnHRD5wXuX/tTAraJVKiVwxLjPLEge1TdtixpTjzuAsshgNut Y92mhr86LNDgjbM1SK5Z1t8Pv/pYZLG2o7svw28E1jN3OGMHa4k6yRv4J52xMQ9m4BVW cMK0BcwG/EdkKXUfx9eWO14sMvx2Fz7ajNxscIUrp5J0btfdAWf63ptb+Tq6BJGZ4Wt2 PoYg== X-Gm-Message-State: AO0yUKV5QhV+w3KekkfJI6pfrdbsKIADyPcj6mFbXCkIZZBkd8xwrYrM 7Nwjx/OGW2iszhz81SG2SrCcn5E8s7YInOxGJdI= X-Received: by 2002:a17:903:28c6:b0:19a:a43c:41b7 with SMTP id kv6-20020a17090328c600b0019aa43c41b7mr7029927plb.21.1677062352787; Wed, 22 Feb 2023 02:39:12 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id ja17-20020a170902efd100b0019acd3151d0sm6201029plb.114.2023.02.22.02.39.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 02:39:12 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Takahiro Akashi , Masahisa Kojima Subject: [PATCH RFC 3/3] efi_loader: check lowest supported version in capsule update Date: Wed, 22 Feb 2023 19:40:36 +0900 Message-Id: <20230222104036.14262-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230222104036.14262-1-masahisa.kojima@linaro.org> References: <20230222104036.14262-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 --- lib/efi_loader/efi_firmware.c | 43 ++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 1d63804717..8bbbb3f081 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,22 @@ 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) { + state->last_attempt_status = + LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION; + ret = EFI_INVALID_PARAMETER; + } + } + return ret; }