[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/2] tests/acceptance/boot_linux: Truncate SD card image to p
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH 1/2] tests/acceptance/boot_linux: Truncate SD card image to power of 2 |
Date: |
Tue, 7 Jul 2020 18:10:45 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
On 7/7/20 5:53 PM, Alistair Francis wrote:
> n Tue, Jul 7, 2020 at 6:21 AM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>>
>> 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)
>
> Why truncate the image, can't we expand it instead?
pow2ceil() round UP to the next power of 2. I think this
Python truncate() is a simple wrapper around the ftruncate()
syscall. IOW we only "expand the image". Note, these are
test images copied in tmpdir and discarded after the tests
ran. I'll improve the description.
>
> Alistair
>
>> +
>> 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
>>
>>
>
- [PATCH 0/2] hw/sd/sdcard: Fix CVE-2020-13253 (Do not allow invalid SD card sizes), Philippe Mathieu-Daudé, 2020/07/07
- [PATCH 1/2] tests/acceptance/boot_linux: Truncate SD card image to power of 2, Philippe Mathieu-Daudé, 2020/07/07
- [PATCH 2/2] hw/sd/sdcard: Do not allow invalid SD card sizes, Philippe Mathieu-Daudé, 2020/07/07
- Re: [PATCH 2/2] hw/sd/sdcard: Do not allow invalid SD card sizes, Alistair Francis, 2020/07/07
- Re: [PATCH 2/2] hw/sd/sdcard: Do not allow invalid SD card sizes, Peter Maydell, 2020/07/07
- Re: [PATCH 2/2] hw/sd/sdcard: Do not allow invalid SD card sizes, Philippe Mathieu-Daudé, 2020/07/07
- Re: [PATCH 2/2] hw/sd/sdcard: Do not allow invalid SD card sizes, Niek Linnenbank, 2020/07/07
- Re: [PATCH 2/2] hw/sd/sdcard: Do not allow invalid SD card sizes, Philippe Mathieu-Daudé, 2020/07/09
- Re: [PATCH 2/2] hw/sd/sdcard: Do not allow invalid SD card sizes, Peter Maydell, 2020/07/09
- Re: [PATCH 2/2] hw/sd/sdcard: Do not allow invalid SD card sizes, Philippe Mathieu-Daudé, 2020/07/09
- Re: [PATCH 2/2] hw/sd/sdcard: Do not allow invalid SD card sizes, Alistair Francis, 2020/07/09