From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
qemu-block@nongnu.org,
"Alistair Francis" <alistair@alistair23.me>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
"Niek Linnenbank" <nieklinnenbank@gmail.com>,
"Cleber Rosa" <crosa@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH 1/2] tests/acceptance/boot_linux: Truncate SD card image to power of 2
Date: Tue, 7 Jul 2020 15:21:15 +0200 [thread overview]
Message-ID: <20200707132116.26207-2-f4bug@amsat.org> (raw)
In-Reply-To: <20200707132116.26207-1-f4bug@amsat.org>
In the next commit we won't allow SD card images with invalid
size (not aligned to a power of 2). Prepare the tests: add the
pow2ceil() and image_pow2ceil_truncate() methods and truncate
the images of the tests using SD cards.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
tests/acceptance/boot_linux_console.py | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index 3d02519660..f4d4e3635f 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -28,6 +28,18 @@
except CmdNotFoundError:
P7ZIP_AVAILABLE = False
+# round up to next power of 2
+def pow2ceil(x):
+ return 1 if x == 0 else 2**(x - 1).bit_length()
+
+# truncate file size to next power of 2
+def image_pow2ceil_truncate(path):
+ size = os.path.getsize(path)
+ size_aligned = pow2ceil(size)
+ if size != size_aligned:
+ with open(path, 'ab+') as fd:
+ fd.truncate(size_aligned)
+
class LinuxKernelTest(Test):
KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
@@ -635,6 +647,7 @@ def test_arm_orangepi_sd(self):
rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
archive.lzma_uncompress(rootfs_path_xz, rootfs_path)
+ image_pow2ceil_truncate(rootfs_path)
self.vm.set_console()
kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
@@ -679,6 +692,7 @@ def test_arm_orangepi_bionic(self):
image_name = 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img'
image_path = os.path.join(self.workdir, image_name)
process.run("7z e -o%s %s" % (self.workdir, image_path_7z))
+ image_pow2ceil_truncate(image_path)
self.vm.set_console()
self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw',
@@ -728,6 +742,7 @@ def test_arm_orangepi_uboot_netbsd9(self):
image_hash = '2babb29d36d8360adcb39c09e31060945259917a'
image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
image_path = os.path.join(self.workdir, 'armv7.img')
+ image_pow2ceil_truncate(image_path)
image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path
archive.gzip_uncompress(image_path_gz, image_path)
--
2.21.3
next prev parent reply other threads:[~2020-07-07 13:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-07 13:21 [PATCH 0/2] hw/sd/sdcard: Fix CVE-2020-13253 (Do not allow invalid SD card sizes) Philippe Mathieu-Daudé
2020-07-07 13:21 ` Philippe Mathieu-Daudé [this message]
2020-07-07 15:53 ` [PATCH 1/2] tests/acceptance/boot_linux: Truncate SD card image to power of 2 Alistair Francis
2020-07-07 16:10 ` Philippe Mathieu-Daudé
2020-07-12 18:43 ` Niek Linnenbank
2020-07-07 13:21 ` [PATCH 2/2] hw/sd/sdcard: Do not allow invalid SD card sizes Philippe Mathieu-Daudé
2020-07-07 15:55 ` Alistair Francis
2020-07-07 16:06 ` Peter Maydell
2020-07-07 16:11 ` Philippe Mathieu-Daudé
2020-07-07 20:29 ` Niek Linnenbank
2020-07-09 13:56 ` Philippe Mathieu-Daudé
2020-07-09 14:15 ` Peter Maydell
2020-07-09 14:35 ` Philippe Mathieu-Daudé
2020-07-09 16:17 ` Alistair Francis
2020-07-10 9:54 ` Peter Maydell
2020-07-09 17:56 ` Niek Linnenbank
2020-07-10 9:58 ` Kevin Wolf
2020-07-10 9:59 ` Peter Maydell
2020-07-10 12:07 ` Kevin Wolf
2020-07-10 12:30 ` Peter Maydell
2020-07-09 17:53 ` Niek Linnenbank
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=20200707132116.26207-2-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=alistair@alistair23.me \
--cc=crosa@redhat.com \
--cc=nieklinnenbank@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=wainersm@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).