[PATCH v2 2/8] hw/sd/sdcard: Add validation for boot-partition-size

Jan Kiszka posted 8 patches 3 weeks, 6 days ago
Maintainers: "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Bin Meng <bmeng.cn@gmail.com>
There is a newer version of this series
[PATCH v2 2/8] hw/sd/sdcard: Add validation for boot-partition-size
Posted by Jan Kiszka 3 weeks, 6 days ago
From: Jan Kiszka <jan.kiszka@siemens.com>

Make sure we are not silently rounding down or even wrapping around,
causing inconsistencies with the provided image.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/sd/sd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 16aee210b4..834392b0a8 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -2818,6 +2818,16 @@ static void sd_realize(DeviceState *dev, Error **errp)
         }
         blk_set_dev_ops(sd->blk, &sd_block_ops, sd);
     }
+    if (sd->boot_part_size % (128 * KiB) ||
+        sd->boot_part_size > 255 * 128 * KiB) {
+        char *size_str = size_to_str(sd->boot_part_size);
+
+        error_setg(errp, "Invalid boot partition size: %s", size_str);
+        g_free(size_str);
+        error_append_hint(errp,
+                          "The boot partition size must be multiples of 128K"
+                          "and not larger than 32640K.\n");
+    }
 }
 
 static void emmc_realize(DeviceState *dev, Error **errp)
-- 
2.43.0
Re: [PATCH v2 2/8] hw/sd/sdcard: Add validation for boot-partition-size
Posted by Alex Bennée 3 weeks, 5 days ago
Jan Kiszka <jan.kiszka@siemens.com> writes:

> From: Jan Kiszka <jan.kiszka@siemens.com>
>
> Make sure we are not silently rounding down or even wrapping around,
> causing inconsistencies with the provided image.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  hw/sd/sd.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
> index 16aee210b4..834392b0a8 100644
> --- a/hw/sd/sd.c
> +++ b/hw/sd/sd.c
> @@ -2818,6 +2818,16 @@ static void sd_realize(DeviceState *dev, Error **errp)
>          }
>          blk_set_dev_ops(sd->blk, &sd_block_ops, sd);
>      }
> +    if (sd->boot_part_size % (128 * KiB) ||
> +        sd->boot_part_size > 255 * 128 * KiB) {
> +        char *size_str = size_to_str(sd->boot_part_size);
> +

This could be:

  g_autofree char *size_str = size_to_str(sd->boot_part_size);

> +        error_setg(errp, "Invalid boot partition size: %s", size_str);
> +        g_free(size_str);

which drops this.

> +        error_append_hint(errp,
> +                          "The boot partition size must be multiples of 128K"
> +                          "and not larger than 32640K.\n");
> +    }
>  }
>  
>  static void emmc_realize(DeviceState *dev, Error **errp)

Otherwise:

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>


-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro