From: Jan Kiszka Date: Mon, 1 Sep 2025 05:56:22 +0000 (+0200) Subject: hw/sd/sdcard: Add validation for boot-partition-size X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=79d472a51015f9c9ab341a5f56b8c450870c006b;p=thirdparty%2Fqemu.git hw/sd/sdcard: Add validation for boot-partition-size Make sure we are not silently rounding down or even wrapping around, causing inconsistencies with the provided image. Signed-off-by: Jan Kiszka Reviewed-by: Alex Bennée [PMD: Use g_autofree, suggested by Alex] Message-ID: <1fff448da042bdf8cff7733ce67cadff4c540f1d.1756706188.git.jan.kiszka@siemens.com> Signed-off-by: Philippe Mathieu-Daudé --- diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 8b142e4796f..5603b391bf7 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2810,6 +2810,15 @@ 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) { + g_autofree char *size_str = size_to_str(sd->boot_part_size); + + error_setg(errp, "Invalid boot partition size: %s", 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)