From patchwork Mon Mar 20 05:54:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 665178 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp958126wrv; Sun, 19 Mar 2023 22:55:48 -0700 (PDT) X-Google-Smtp-Source: AK7set9nR+0YvJ237VVYehLkt4lOvlGnvCy6NbQSpR9c6hTclYWndcvGjryy4zKuYLsHIoLf0q2J X-Received: by 2002:a05:622a:110c:b0:3bd:1bbc:8d8e with SMTP id e12-20020a05622a110c00b003bd1bbc8d8emr26149238qty.0.1679291748092; Sun, 19 Mar 2023 22:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679291748; cv=none; d=google.com; s=arc-20160816; b=g0cFAx52yS0kBf7MG99d/WWWtopKM2lYerYSDHWl3lb1jeqi0fUzqbi1/UVHRGf1Vb UjDS9JXueG53eLogN++jmi5xcNUSas65JlV1IP4xh0Me2ssnNqQNKpitCrw+HSJKwDuP o/1YwS85bq8XsrDLfGD1kWhnMIX6sYzJaKu3K9HsazUFveyxaMiQkxUYWBvOcobVDxc2 Jo+3YzVmzlRfFIabKiSxCQyicTBZIFWqXDLf+h2JAf78uvNVdkuOOAADma+BSdYk7dd8 P8OlFQ5ZLQQKMh9Uk+HcGXsgGGbbeH2a8uU6cIvws49zoT5Ayf7yAGFD7i8HgDHQpE+V rPyA== 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=36xDDela0eAJXRcqva0QdwKAeoM57B0OShAZWqdtv04=; b=GedXG7OkYHh3zBZ1mp8AH/oCM9oPB9nZCvI1QYyWHgKsVvoE6TNQY02eoKziXnIT3D AH8O+w58C0z1p4y+HKVtUdyp8Uh3AJedg2A4tGaWgoq38wih3d/dab33xU795MXfRSWv k0MEg8uBCZaDR547oKLwf9g1RL65FqkooU/v0Bm1XwojQB0FaGPA1zhyJuGWDByb5y0Y yiqrX+Jw8NDsFwplHh4qx10xahOlTqOijRXZ9rMlNw/NO6LsMs4uuMF1rWOEkwaYEybf 59o10PY9IK14MIAfMKrld64NVuS+dQvmhFHbIVFxpkAsUIv3QfX3r/K+4BuHwto7MAq1 hp2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RKO6+gOn; 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 g20-20020ac87f54000000b003d511c18987si5205817qtk.513.2023.03.19.22.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 22:55:48 -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=RKO6+gOn; 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 0283885BAC; Mon, 20 Mar 2023 06:55:22 +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="RKO6+gOn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8EA2D85B34; Mon, 20 Mar 2023 06:55:11 +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-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (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 A72D685AA2 for ; Mon, 20 Mar 2023 06:55: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-pl1-x633.google.com with SMTP id bc12so10719274plb.0 for ; Sun, 19 Mar 2023 22:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679291702; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=36xDDela0eAJXRcqva0QdwKAeoM57B0OShAZWqdtv04=; b=RKO6+gOnPO3X+0OnqJ/t7/9B3jiyDVzl+YSUrhk27J2nQAd06ADjDgRuKFuyfsyUIb IQ+ilCEhQ2TmGmd9Rv1i/HxKljuv6hLTz5kLKPLQF5NONcsgQcPSNlzVzAd/Rrt9OUCL jvAorIy3A5obiA0l2MXdmEgKF0ZhXc1iebHueA7y5PQ11P7P+uoBW7F3zEuGzL2FPANT Czj3RmQp31ZVwmY0DYV80EScUpfxxBkWn1G6Twrws9whflVyI0mPZ3hoSOVUYo2SaT1H a5XawxBsBBePyoWdaCUOOW25edfcM4omKMsAKf+pFBvdKiERUgSn5km5Bdi8DNAo64Zh 8T7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679291702; 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=36xDDela0eAJXRcqva0QdwKAeoM57B0OShAZWqdtv04=; b=WPalMwKO6wxqqSleJdnoMMJSpNKn1GQ8lhtGr1bI4WrA9d3jrSh1yKLUpt3n31fvEc UpQSejXl56eCz9LX1VjCnfVbfGbwFs4bxCS+64OH+SsmPFyzudsmmZ0UOcSaMczifFN/ JbD3qrcHWMRHz8lmgLEsXxIlGez3jyS1+L60wQI3KYdmafCnT7fzbzz0fvJH7omMWUB/ U5nF2toJSMunuoGqWuT9lztwMRukGjn4Iv7pdXGMgcsME5wb7CsuL2rovyKmL8bLnh8e NXlI3pVt0Yqw91m9wfliNjm/L8Ns8SO/zmGZvulB9RfyQOHw/b+Q2ETgu1ZXmULp0DKS rXUA== X-Gm-Message-State: AO0yUKVdT9DjAHWqoB52J/3nDniXmZMMTRyHXR1Mz9xfKqK+WxSdBY1A xNyb9ote/cTGBfQokZRA2MAlrVrTZGCkLrZbP+4= X-Received: by 2002:a17:903:2109:b0:19e:5cc3:8289 with SMTP id o9-20020a170903210900b0019e5cc38289mr12081483ple.34.1679291701747; Sun, 19 Mar 2023 22:55:01 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id h6-20020a170902eec600b0019cb131b89csm4826718plb.254.2023.03.19.22.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 22:55:01 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v3 3/4] efi_loader: check lowest supported version in capsule update Date: Mon, 20 Mar 2023 14:54:46 +0900 Message-Id: <20230320055448.12439-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230320055448.12439-1-masahisa.kojima@linaro.org> References: <20230320055448.12439-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.8 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 --- No changes since v2 Changes in v2: - add error message when the firmware version is lower than lowest supported version lib/efi_loader/efi_firmware.c | 50 ++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 289456ecbb..8d6e32006d 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -391,6 +391,39 @@ 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; + efi_guid_t *image_type_id; + struct fmp_state var_state = { 0 }; + + image_type_id = efi_firmware_get_image_type_id(image_index); + if (!image_type_id) + return 0; + + efi_create_indexed_name(varname, sizeof(varname), "FmpState", + image_index); + size = sizeof(var_state); + ret = efi_get_variable_int(varname, image_type_id, 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 @@ -398,7 +431,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 */ @@ -409,10 +443,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; }