[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 9/9] hw/sd: Allow card size not power of 2 again
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 9/9] hw/sd: Allow card size not power of 2 again |
Date: |
Wed, 23 Jun 2021 20:00:21 +0200 |
In commit a9bcedd15a5 ("hw/sd/sdcard: Do not allow invalid SD card
sizes") we tried to protect us from CVE-2020-13253 by only allowing
card with power-of-2 sizes. However doing so we disrupted valid user
cases. As a compromise, allow any card size, but warn only power of 2
sizes are supported, still suggesting the user how to increase a
card with 'qemu-img resize'.
Cc: Tom Yan <tom.ty89@gmail.com>
Cc: Warner Losh <imp@bsdimp.com>
Buglink: https://bugs.launchpad.net/qemu/+bug/1910586
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/sd/sd.c | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 9c8dd11bad1..cab4aab1475 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -2131,23 +2131,16 @@ static void sd_realize(DeviceState *dev, Error **errp)
blk_size = blk_getlength(sd->blk);
if (blk_size > 0 && !is_power_of_2(blk_size)) {
int64_t blk_size_aligned = pow2ceil(blk_size);
- char *blk_size_str;
+ g_autofree char *blk_size_s = size_to_str(blk_size);
+ g_autofree char *blk_size_aligned_s =
size_to_str(blk_size_aligned);
- blk_size_str = size_to_str(blk_size);
- error_setg(errp, "Invalid SD card size: %s", blk_size_str);
- g_free(blk_size_str);
-
- blk_size_str = size_to_str(blk_size_aligned);
- error_append_hint(errp,
- "SD card size has to be a power of 2, e.g. %s.\n"
- "You can resize disk images with"
- " 'qemu-img resize <imagefile> <new-size>'\n"
- "(note that this will lose data if you make the"
- " image smaller than it currently is).\n",
- blk_size_str);
- g_free(blk_size_str);
-
- return;
+ warn_report("SD card size is not a power of 2 (%s). It might work"
+ " but is not supported by QEMU. If possible, resize"
+ " your disk image to %s with:",
+ blk_size_s, blk_size_aligned_s);
+ warn_report(" 'qemu-img resize <imagefile> <new-size>'");
+ warn_report("(note that this will lose data if you make the"
+ " image smaller than it currently is).");
}
ret = blk_set_perm(sd->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE,
--
2.31.1
- [RFC PATCH 0/9] hw/sd: Allow card size not power of 2 again, Philippe Mathieu-Daudé, 2021/06/23
- [PATCH 1/9] hw/sd: When card is in wrong state, log which state it is, Philippe Mathieu-Daudé, 2021/06/23
- [PATCH 2/9] hw/sd: Extract address_in_range() helper, log invalid accesses, Philippe Mathieu-Daudé, 2021/06/23
- [PATCH 3/9] tests/acceptance: Tag NetBSD tests as 'os:netbsd', Philippe Mathieu-Daudé, 2021/06/23
- [PATCH 4/9] tests/acceptance: Extract image_expand() helper, Philippe Mathieu-Daudé, 2021/06/23
- [PATCH 5/9] tests/acceptance: Use image_expand() in test_arm_orangepi_uboot_netbsd9, Philippe Mathieu-Daudé, 2021/06/23
- [RFC PATCH 6/9] tests/acceptance: Use image_expand() in test_arm_orangepi_bionic_20_08, Philippe Mathieu-Daudé, 2021/06/23
- [RFC PATCH 7/9] tests/acceptance: Do not expand SD card image in test_arm_orangepi_sd, Philippe Mathieu-Daudé, 2021/06/23
- [PATCH 8/9] tests/acceptance: Remove now unused pow2ceil(), Philippe Mathieu-Daudé, 2021/06/23
- [RFC PATCH 9/9] hw/sd: Allow card size not power of 2 again,
Philippe Mathieu-Daudé <=
- Re: [RFC PATCH 0/9] hw/sd: Allow card size not power of 2 again, Alexander Bulekov, 2021/06/23