All of lore.kernel.org
 help / color / mirror / Atom feed
From: Valentin Liu <valentinliu@icloud.com>
To: u-boot@lists.u-boot-project.org
Cc: mkorpershoek@kernel.org, sjg@chromium.org, trini@konsulko.com,
	igor.opaniuk@gmail.com, alchark@flipper.net,
	quentin.schulz@cherry.de, marek.vasut+renesas@mailbox.org,
	daniel@makrotopia.org, rs@ti.com,
	Valentin Liu <valentinliu@icloud.com>
Subject: [PATCH v1 2/2] boot: android: Add AVB verification support for different bootflow.
Date: Wed, 19 Aug 2026 01:53:01 +0800	[thread overview]
Message-ID: <20260818175301.818739-2-valentinliu@icloud.com> (raw)
In-Reply-To: <20260818175301.818739-1-valentinliu@icloud.com>

The different Android versions have their own partition layout,
so the AVB verification process should be dynamic.

In the new verification process, we need to use the header version
fetched from boot partition, so we need to check the boot partition
firstly to avoid the downgrade attacking.

If we didn't check boot firstly, just use it, the attacker can
bypass the AVB verification by flashing a boot image with header
version 3 or earlier.

Signed-off-by: Valentin Liu <valentinliu@icloud.com>
---
 boot/bootmeth_android.c | 43 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/boot/bootmeth_android.c b/boot/bootmeth_android.c
index 904640d360b..55cd99f3043 100644
--- a/boot/bootmeth_android.c
+++ b/boot/bootmeth_android.c
@@ -479,11 +479,12 @@ static int avb_append_commandline(struct bootflow *bflow, char *cmdline)
 	return 0;
 }
 
-static int run_avb_verification(struct bootflow *bflow)
+static int run_avb_verification(struct bootflow *bflow, const bool boot_only)
 {
 	struct blk_desc *desc = dev_get_uclass_plat(bflow->blk);
 	struct android_priv *priv = bflow->bootmeth_priv;
-	const char * const requested_partitions[] = {"boot", "vendor_boot", NULL};
+	const char *requested_partitions[4];
+	int requested_partitions_num = 0;
 	struct AvbOps *avb_ops;
 	AvbSlotVerifyResult result;
 	AvbSlotVerifyData *out_data = NULL;
@@ -493,6 +494,28 @@ static int run_avb_verification(struct bootflow *bflow)
 	bool unlocked = false;
 	int ret;
 
+	/*
+	 * Always verify boot first.
+	 *
+	 * When boot_only is true, only verify the boot partition.
+	 * Otherwise, select additional partitions according to the
+	 * Android boot image header version.
+	 */
+	requested_partitions[requested_partitions_num++] = "boot";
+
+	if (!boot_only) {
+		if (priv->header_version >= 3)
+			requested_partitions[requested_partitions_num++] =
+				"vendor_boot";
+
+		if (priv->header_version >= 4 &&
+		    priv->init_boot_img_size > 0)
+			requested_partitions[requested_partitions_num++] =
+				"init_boot";
+	}
+
+	requested_partitions[requested_partitions_num] = NULL;
+
 	avb_ops = avb_ops_alloc(desc->devnum);
 	if (!avb_ops)
 		return log_msg_ret("avb ops", -ENOMEM);
@@ -562,9 +585,10 @@ static int run_avb_verification(struct bootflow *bflow)
 	return ret;
 }
 #else
-static int run_avb_verification(struct bootflow *bflow)
+static int run_avb_verification(struct bootflow *bflow, const bool boot_only)
 {
 	int ret;
+	(void)boot_only;
 
 	/* When AVB is unsupported, pass ORANGE state  */
 	ret = bootflow_cmdline_set_arg(bflow,
@@ -617,9 +641,13 @@ static int boot_android_normal(struct bootflow *bflow)
 	ulong iloadaddr = env_get_hex("init_boot_comp_addr_r", 0);
 	ulong vloadaddr = env_get_hex("vendor_boot_comp_addr_r", 0);
 
-	ret = run_avb_verification(bflow);
+	/*
+	 * Checking the boot partition firstly because the standard AVB
+	 * verification is rely on the header version from boot partition.
+	 */
+	ret = run_avb_verification(bflow, true);
 	if (ret < 0)
-		return log_msg_ret("avb", ret);
+		return log_msg_ret("avb boot", ret);
 
 	/* Read slot once more to decrement counter from BCB */
 	ret = android_read_slot_from_bcb(bflow, true);
@@ -631,6 +659,11 @@ static int boot_android_normal(struct bootflow *bflow)
 	if (ret < 0)
 		return log_msg_ret("read boot", ret);
 
+	/* Standard AVB verification */
+	ret = run_avb_verification(bflow, false);
+	if (ret < 0)
+		return log_msg_ret("avb", ret);
+
 	if (priv->header_version >= 4 && priv->init_boot_img_size > 0) {
 		ret = read_slotted_partition(desc, "init_boot", priv->slot,
 					     priv->init_boot_img_size,
-- 
2.53.0


  reply	other threads:[~2026-08-18 17:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 17:53 [PATCH v1 1/2] boot: android: Add Android 13+ bootflow support to bootmeth Valentin Liu
2026-08-18 17:53 ` Valentin Liu [this message]
2026-08-20 12:31   ` [PATCH v1 2/2] boot: android: Add AVB verification support for different bootflow Simon Glass
2026-08-20 12:31 ` [PATCH v1 1/2] boot: android: Add Android 13+ bootflow support to bootmeth Simon Glass
2026-08-20 15:10   ` Tom Rini
2026-08-20 16:41   ` Re:Re: " 刘垣辰

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=20260818175301.818739-2-valentinliu@icloud.com \
    --to=valentinliu@icloud.com \
    --cc=alchark@flipper.net \
    --cc=daniel@makrotopia.org \
    --cc=igor.opaniuk@gmail.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=mkorpershoek@kernel.org \
    --cc=quentin.schulz@cherry.de \
    --cc=rs@ti.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    /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.