summaryrefslogtreecommitdiff
path: root/boot/android_ab.c
diff options
context:
space:
mode:
authorJoshua Watt <[email protected]>2024-08-28 08:37:57 -0600
committerMattijs Korpershoek <[email protected]>2024-09-05 08:55:04 +0200
commitcc2f60c13f6aaf1bd277cf10c8b375c2e4a695b7 (patch)
tree03909474db52042b7745961c51bb3743fd439bd6 /boot/android_ab.c
parent1312faac5f52d27cfb45dfe1a5a93a2944ca5c21 (diff)
android_ab: Fixes: Fix backup offset calculation
The backup offset is in bytes, but was incorrectly be interpreted as blocks, leading to it being written to the wrong location. Fix the calculation, clarify that ANDROID_AB_BACKUP_OFFSET is in bytes and must be a multiple of the block size, and add a runtime check to validate the offset. Signed-off-by: Joshua Watt <[email protected]> Reviewed-by: Mattijs Korpershoek <[email protected]> Fixes: 3430f24bc69d ("android_ab: Try backup booloader_message") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mattijs Korpershoek <[email protected]>
Diffstat (limited to 'boot/android_ab.c')
-rw-r--r--boot/android_ab.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/boot/android_ab.c b/boot/android_ab.c
index 143f373aae9..1196a189ed5 100644
--- a/boot/android_ab.c
+++ b/boot/android_ab.c
@@ -139,8 +139,13 @@ static int ab_control_store(struct blk_desc *dev_desc,
{
ulong abc_offset, abc_blocks, ret;
- abc_offset = offset +
- offsetof(struct bootloader_message_ab, slot_suffix) /
+ if (offset % part_info->blksz) {
+ log_err("ANDROID: offset not block aligned\n");
+ return -EINVAL;
+ }
+
+ abc_offset = (offset +
+ offsetof(struct bootloader_message_ab, slot_suffix)) /
part_info->blksz;
abc_blocks = DIV_ROUND_UP(sizeof(struct bootloader_control),
part_info->blksz);