All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ana Bobillo <anabobillo3@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Tom Rini <trini@konsulko.com>
Subject: [PATCH v2 7/7] test: py: efi_capsule: test truncated capsules and FMP payload headers
Date: Wed, 28 Oct 2026 05:50:24 +0000	[thread overview]
Message-ID: <a1a13d0b-d94a-4c4f-bec3-effe46e7e3ed@gmail.com> (raw)
In-Reply-To: <ab256ba2-8572-4cda-b7da-45b2c0368beb@gmail.com>

From: Ana Bobillo <anabobillo3@gmail.com>

Add capsule on disk tests for the checks that need a capsule file or a
signed capsule:

- a capsule file shorter than the capsule header;
- signed capsules whose FMP payload header has a header_size smaller
  than the header or larger than the image.

None of them may update the firmware, and each file is removed.

Signed-off-by: Ana Bobillo <anabobillo3@gmail.com>
---
Changes in v2:
- New patch: capsule on disk tests for patches 1 and 5 (Heinrich)

 arch/sandbox/dts/sandbox_capsule.dtsi         | 52 +++++++++++++++++
 .../test_capsule_firmware_raw.py              | 34 +++++++++++
 .../test_capsule_firmware_signed_raw.py       | 56 +++++++++++++++++++
 3 files changed, 142 insertions(+)

diff --git a/arch/sandbox/dts/sandbox_capsule.dtsi b/arch/sandbox/dts/sandbox_capsule.dtsi
index 34d29916b30..f7418f9794a 100644
--- a/arch/sandbox/dts/sandbox_capsule.dtsi
+++ b/arch/sandbox/dts/sandbox_capsule.dtsi
@@ -166,4 +166,56 @@
 			};
 		};
 	};
+
+	capsule12 {
+		filename = "Test116";
+		efi-capsule {
+			image-index = <0x1>;
+			image-guid = SANDBOX_UBOOT_IMAGE_GUID;
+			private-key = CAPSULE_PRIV_KEY;
+			public-key-cert = CAPSULE_PUB_KEY;
+			monotonic-count = <0x1>;
+
+			/* FMP payload header, header_size 0: smaller than the header */
+			payload-header {
+				type = "text";
+				text = "MSS1";
+			};
+
+			payload-header-rest {
+				type = "fill";
+				size = <12>;
+			};
+
+			text {
+				text = "u-boot:New";
+			};
+		};
+	};
+
+	capsule13 {
+		filename = "Test117";
+		efi-capsule {
+			image-index = <0x1>;
+			image-guid = SANDBOX_UBOOT_IMAGE_GUID;
+			private-key = CAPSULE_PRIV_KEY;
+			public-key-cert = CAPSULE_PUB_KEY;
+			monotonic-count = <0x1>;
+
+			/* FMP payload header, header_size 64: larger than the image */
+			payload-header {
+				type = "text";
+				text = "MSS1\x40";
+			};
+
+			payload-header-rest {
+				type = "fill";
+				size = <11>;
+			};
+
+			text {
+				text = "u-boot:New";
+			};
+		};
+	};
 };
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py
index b8cb483b380..a79a975c67e 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py
@@ -7,6 +7,7 @@ This test verifies capsule-on-disk firmware update for raw images
 """
 
 import pytest
+from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
 from capsule_common import (
     capsule_setup,
     init_content,
@@ -238,3 +239,36 @@ class TestEfiCapsuleFirmwareRaw:
             check_file_removed(ubman, disk_img, capsule_files)
 
             verify_content(ubman, '100000', 'u-boot:Old')
+
+    def test_efi_capsule_fw6(
+            self, u_boot_config, ubman, efi_capsule_data):
+        """ Test Case 6
+        Update U-Boot on SPI Flash with a capsule file shorter than
+        the capsule header
+        No update should happen
+        0x100000-0x150000: U-Boot binary (but dummy)
+        """
+        disk_img = efi_capsule_data
+        capsule_files = ['Test01']
+        with ubman.log.section('Test Case 6-a, before reboot'):
+            capsule_setup(ubman, disk_img, '0x0000000000000004')
+            init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+            # place only the first 16 bytes of the capsule file
+            ubman.run_command_list([
+                f'fatload host 0:1 4000000 {CAPSULE_DATA_DIR}/Test01',
+                f'fatwrite host 0:1 4000000 {CAPSULE_INSTALL_DIR}/Test01 10'])
+
+        capsule_early = u_boot_config.buildconfig.get(
+            'config_efi_capsule_on_disk_early')
+
+        # reboot
+        ubman.restart_uboot(expect_reset = capsule_early)
+
+        with ubman.log.section('Test Case 6-b, after reboot'):
+            if not capsule_early:
+                exec_manual_update(ubman, disk_img, capsule_files)
+
+            # deleted anyway
+            check_file_removed(ubman, disk_img, capsule_files)
+
+            verify_content(ubman, '100000', 'u-boot:Old')
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py
index a500c499bb9..6e4cca9bfe6 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py
@@ -190,3 +190,59 @@ class TestEfiCapsuleFirmwareSignedRaw():
             check_file_removed(ubman, disk_img, capsule_files)
 
             verify_content(ubman, '100000', 'u-boot:Old')
+
+    def test_efi_capsule_auth6(
+            self, u_boot_config, ubman, efi_capsule_data):
+        """Test Case 6 - Update U-Boot on SPI Flash, raw image format
+        0x100000-0x150000: U-Boot binary (but dummy)
+
+        If the capsule is properly signed but the header_size of the
+        FMP payload header in its image is smaller than the header,
+        the firmware should not be updated.
+        """
+        disk_img = efi_capsule_data
+        capsule_files = ['Test116']
+        with ubman.log.section('Test Case 6-a, before reboot'):
+            capsule_setup(ubman, disk_img, '0x0000000000000004')
+            init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+            place_capsule_file(ubman, capsule_files)
+
+        do_reboot_dtb_specified(u_boot_config, ubman, 'test_sig.dtb')
+
+        capsule_early = u_boot_config.buildconfig.get(
+            'config_efi_capsule_on_disk_early')
+        with ubman.log.section('Test Case 6-b, after reboot'):
+            if not capsule_early:
+                exec_manual_update(ubman, disk_img, capsule_files)
+
+            check_file_removed(ubman, disk_img, capsule_files)
+
+            verify_content(ubman, '100000', 'u-boot:Old')
+
+    def test_efi_capsule_auth7(
+            self, u_boot_config, ubman, efi_capsule_data):
+        """Test Case 7 - Update U-Boot on SPI Flash, raw image format
+        0x100000-0x150000: U-Boot binary (but dummy)
+
+        If the capsule is properly signed but the header_size of the
+        FMP payload header in its image is larger than the image,
+        the firmware should not be updated.
+        """
+        disk_img = efi_capsule_data
+        capsule_files = ['Test117']
+        with ubman.log.section('Test Case 7-a, before reboot'):
+            capsule_setup(ubman, disk_img, '0x0000000000000004')
+            init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+            place_capsule_file(ubman, capsule_files)
+
+        do_reboot_dtb_specified(u_boot_config, ubman, 'test_sig.dtb')
+
+        capsule_early = u_boot_config.buildconfig.get(
+            'config_efi_capsule_on_disk_early')
+        with ubman.log.section('Test Case 7-b, after reboot'):
+            if not capsule_early:
+                exec_manual_update(ubman, disk_img, capsule_files)
+
+            check_file_removed(ubman, disk_img, capsule_files)
+
+            verify_content(ubman, '100000', 'u-boot:Old')

      parent reply	other threads:[~2026-10-28  5:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28  5:49 [PATCH v2 0/7] efi_loader: capsule: check sizes against the capsule Ana Bobillo
2026-10-28  5:49 ` [PATCH v2 1/7] efi_loader: capsule: check the size of a capsule file Ana Bobillo
2026-10-28  5:49 ` [PATCH v2 2/7] efi_loader: capsule: check the capsule header size Ana Bobillo
2026-10-28  5:50 ` [PATCH v2 3/7] efi_loader: capsule: check the FMP capsule against its size Ana Bobillo
2026-10-28  5:50 ` [PATCH v2 4/7] efi_loader: capsule: check the certificate length of an image Ana Bobillo
2026-10-28  5:50 ` [PATCH v2 5/7] efi_loader: firmware: check the FMP payload header size Ana Bobillo
2026-10-28  5:50 ` [PATCH v2 6/7] test: lib: add tests for the capsule size checks Ana Bobillo
2026-10-28  5:50 ` Ana Bobillo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a1a13d0b-d94a-4c4f-bec3-effe46e7e3ed@gmail.com \
    --to=anabobillo3@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.