From patchwork Mon Jul 13 18:32:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 277938 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B3C1C433E2 for ; Mon, 13 Jul 2020 18:33:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1EB142075D for ; Mon, 13 Jul 2020 18:33:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oGNSLeFY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1EB142075D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jv3GY-0003fz-6D for qemu-devel@archiver.kernel.org; Mon, 13 Jul 2020 14:33:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jv3FS-0001wx-0K; Mon, 13 Jul 2020 14:32:18 -0400 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]:39949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jv3FQ-0004FX-74; Mon, 13 Jul 2020 14:32:17 -0400 Received: by mail-ed1-x543.google.com with SMTP id b15so14574637edy.7; Mon, 13 Jul 2020 11:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uyp96aoYkkNgfFwZ8UhO6hrlMhJXRb1SNh8r9bSD384=; b=oGNSLeFYoy0wqXyj6T1ho54TK4QAUEASzjT1eBk64HZhgkvf3HYMfQS1A+bmxVdFb2 26ttJPWIu5pN2JQMju3b9Iagm44CSd45huqXmLTckZy3eALson1eYmaa8Ndh5KbXk3W4 O58cPCVO+Af6O7FPsTVXzX4G5OTzCECZ9VsGzKlFywmFoQu44yGgFnLLa41prkduULTx 4hLcUnp+uUQMRdHSiatQX/8BFwzfCIG7+umYDVchpiqF7N+/H5JNqEc6LD0nFYXdKy0e 9Q0lMYToSxRJDufkXY/eoajbSVZwTGNjrd4zgitf+3GSRxQtYbg/s4GwHz/F7d+NoKr+ rX2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=uyp96aoYkkNgfFwZ8UhO6hrlMhJXRb1SNh8r9bSD384=; b=g2KAE6pLVmqnUGBGmdsYPQ1rhfRiI44Qopthujt7Tnwb9UdRL8ZSsasweYuHopLm59 f2jFT7bYlNIqrMCFz7WmfD1NYk06M6obYlf3bv+D3QFgvZKBwTrKZjQ6+G1Yp6q7TODJ amuylfK4ZWw6QTf9oYHRFHPeM0DgqUNvCtQP8mzFLpR+55kgN8gGNFqFCnQEdoIoWJsL QQnB9JU2Hlu2bkRSxANPDH/wvoVbTtJQ0fLR6RewbSa70Ic0c9euCcuPM9/KNU4fBqtH levJbk6530ipIzzXbwrfc7a6ZD+qvoTN3i/EAlRRAeMeWdkzsNbyolq7kcO+6pUBdz6w pD2A== X-Gm-Message-State: AOAM5335FRltlL14qDAvmJhMyGJK8im2Ge4J2iJZVXJEyK0vUkd58M7V FpuB36WIeV9pA8cS3A/HL5ZbyZxXqF8= X-Google-Smtp-Source: ABdhPJxkG8aBXH5nMHTp8bVR/0bi+rXLij8SDEfXvTpkanubvbT5pHQtYuVRgqe77E20/ZfyyV4Suw== X-Received: by 2002:aa7:c54e:: with SMTP id s14mr715323edr.81.1594665134253; Mon, 13 Jul 2020 11:32:14 -0700 (PDT) Received: from x1w.redhat.com (138.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.138]) by smtp.gmail.com with ESMTPSA id ce12sm4353148edb.4.2020.07.13.11.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 11:32:13 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 2/9] docs/orangepi: Add instructions for resizing SD image to power of two Date: Mon, 13 Jul 2020 20:32:02 +0200 Message-Id: <20200713183209.26308-3-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200713183209.26308-1-f4bug@amsat.org> References: <20200713183209.26308-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::543; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Prasad J Pandit , qemu-block@nongnu.org, Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Alexander Bulekov , Niek Linnenbank , Cleber Rosa , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Niek Linnenbank SD cards need to have a size of a power of two. Update the Orange Pi machine documentation to include instructions for resizing downloaded images using the qemu-img command. Signed-off-by: Niek Linnenbank Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20200712183708.15450-1-nieklinnenbank@gmail.com> Signed-off-by: Philippe Mathieu-Daudé --- docs/system/arm/orangepi.rst | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/system/arm/orangepi.rst b/docs/system/arm/orangepi.rst index c41adad488..6f23907fb6 100644 --- a/docs/system/arm/orangepi.rst +++ b/docs/system/arm/orangepi.rst @@ -127,6 +127,16 @@ can be downloaded from: Alternatively, you can also choose to build you own image with buildroot using the orangepi_pc_defconfig. Also see https://buildroot.org for more information. +When using an image as an SD card, it must be resized to a power of two. This can be +done with the qemu-img command. It is recommended to only increase the image size +instead of shrinking it to a power of two, to avoid loss of data. For example, +to prepare a downloaded Armbian image, first extract it and then increase +its size to one gigabyte as follows: + +.. code-block:: bash + + $ qemu-img resize Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img 1G + You can choose to attach the selected image either as an SD card or as USB mass storage. For example, to boot using the Orange Pi PC Debian image on SD card, simply add the -sd argument and provide the proper root= kernel parameter: @@ -213,12 +223,12 @@ Next, unzip the NetBSD image and write the U-Boot binary including SPL using: $ dd if=/path/to/u-boot-sunxi-with-spl.bin of=armv7.img bs=1024 seek=8 conv=notrunc Finally, before starting the machine the SD image must be extended such -that the NetBSD kernel will not conclude the NetBSD partition is larger than -the emulated SD card: +that the size of the SD image is a power of two and that the NetBSD kernel +will not conclude the NetBSD partition is larger than the emulated SD card: .. code-block:: bash - $ dd if=/dev/zero bs=1M count=64 >> armv7.img + $ qemu-img resize armv7.img 2G Start the machine using the following command: From patchwork Mon Jul 13 18:32:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 277936 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54709C433E0 for ; Mon, 13 Jul 2020 18:35:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22976206F0 for ; Mon, 13 Jul 2020 18:35:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WUE4NAkm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22976206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jv3IG-0007OH-Bm for qemu-devel@archiver.kernel.org; Mon, 13 Jul 2020 14:35:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jv3FU-00023Z-SE; Mon, 13 Jul 2020 14:32:20 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]:40918) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jv3FT-0004Gb-0Y; Mon, 13 Jul 2020 14:32:20 -0400 Received: by mail-ej1-x62e.google.com with SMTP id o18so18423579eje.7; Mon, 13 Jul 2020 11:32:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nhs5ynfW5eDBEuVG49jlv4iF3aFNW3dwv+4Ev+duU34=; b=WUE4NAkmAlOifZiMBxX5My0GMHicjoD8ZRZ8sqc+PRKD/069odhAiCx+ay2wA/ft+J rA2OgepZapgR9blqpIwT3UP2M0AbEJzkpKvFgtzvUI1dIh5DwrS3ewvKFGlA/5UciIpv 5OA+CQqEp05Y2tF7B2HttpzdtwZB4ecxv0QRoiGubkLiRuWWXOOOm+vsph6Y1uOMizez 0MJrcoBBOcQ/+48NXuQzt4Mm482f1OuJ2SNjZtcyPfS0ZWyd4cYa/BYZaNAQsX9wJtlR 1TmDyZgESg4pc3rwoS8sbcCi9IZOX5ci8w68/G+AXMgomkhVcbO73rExLWpPJso3+ZYj IOxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=nhs5ynfW5eDBEuVG49jlv4iF3aFNW3dwv+4Ev+duU34=; b=oA+mfF+dS2s9ZpoPGIMNO8MFfKemopi6u174j/iuV3bpwTuN2JVesn05rAgQcNnITs WHJxEjnmneWlhL+l2RSijfN+pXkCaumX/f8mte06ljHy5LvcTjDFc+Y5H7d0HEv90rMY CzfxtKnoaO9NXY5TfwV8zO+Qf0ocpeYbAUvadpTK9X5FfKiLEmp2pWVPL5V5MA04Cks9 AtM7ZklhIDmxd2/21B+iEFfs7FtOOeZaw1JEFVUquMjZA/i/MRJ130XiikKjZZioypXg KkYECFhlhFTlVNKtq1du5lTzt6qe4sa/TlnqSL6niVgiVex5U4jVquPU192VtOhxErFn EZ0w== X-Gm-Message-State: AOAM533lXU1wL/VVc4/6oHkGNE74WQJBhNqZ34eUv1w0MYs/gLLzD4IL kJBrwpWMAx/on1IBoD/I6Y98AxTl3Xs= X-Google-Smtp-Source: ABdhPJxydMgwoAoprxteI6j0mm8uut16kwy5azGZOq1xng4INmyxdQxNqE4GT2cJ/lbgxmpc+RpbmQ== X-Received: by 2002:a17:906:c56:: with SMTP id t22mr1090312ejf.50.1594665137027; Mon, 13 Jul 2020 11:32:17 -0700 (PDT) Received: from x1w.redhat.com (138.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.138]) by smtp.gmail.com with ESMTPSA id ce12sm4353148edb.4.2020.07.13.11.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 11:32:16 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 4/9] tests/acceptance/boot_linux: Expand SD card image to power of 2 Date: Mon, 13 Jul 2020 20:32:04 +0200 Message-Id: <20200713183209.26308-5-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200713183209.26308-1-f4bug@amsat.org> References: <20200713183209.26308-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-x62e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Prasad J Pandit , qemu-block@nongnu.org, Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Alexander Bulekov , Niek Linnenbank , Cleber Rosa , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In few commits 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_expand() methods and resize the images (expanding) of the tests using SD cards. Signed-off-by: Philippe Mathieu-Daudé --- Since v1: Addressed review comments - truncate -> expand reword (Alistair Francis) - expand after uncompress (Niek Linnenbank) --- tests/acceptance/boot_linux_console.py | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py index b7e8858c2d..8f2a6aa8a4 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() + +# expand file size to next power of 2 +def image_pow2ceil_expand(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 ' @@ -636,6 +648,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_expand(rootfs_path) self.vm.set_console() kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + @@ -673,7 +686,7 @@ def test_arm_orangepi_bionic(self): :avocado: tags=device:sd """ - # This test download a 196MB compressed image and expand it to 932MB... + # This test download a 196MB compressed image and expand it to 1GB image_url = ('https://dl.armbian.com/orangepipc/archive/' 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.7z') image_hash = '196a8ffb72b0123d92cea4a070894813d305c71e' @@ -681,6 +694,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_expand(image_path) self.vm.set_console() self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw', @@ -714,7 +728,7 @@ def test_arm_orangepi_uboot_netbsd9(self): :avocado: tags=machine:orangepi-pc :avocado: tags=device:sd """ - # This test download a 304MB compressed image and expand it to 1.3GB... + # This test download a 304MB compressed image and expand it to 2GB deb_url = ('http://snapshot.debian.org/archive/debian/' '20200108T145233Z/pool/main/u/u-boot/' 'u-boot-sunxi_2020.01%2Bdfsg-1_armhf.deb') @@ -731,8 +745,9 @@ 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_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path archive.gzip_uncompress(image_path_gz, image_path) + image_pow2ceil_expand(image_path) + image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc with open(uboot_path, 'rb') as f_in: @@ -740,12 +755,6 @@ def test_arm_orangepi_uboot_netbsd9(self): f_out.seek(8 * 1024) shutil.copyfileobj(f_in, f_out) - # Extend image, to avoid that NetBSD thinks the partition - # inside the image is larger than device size itself - f_out.seek(0, 2) - f_out.seek(64 * 1024 * 1024, 1) - f_out.write(bytearray([0x00])) - self.vm.set_console() self.vm.add_args('-nic', 'user', '-drive', image_drive_args, From patchwork Mon Jul 13 18:32:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 277934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15D97C433E3 for ; Mon, 13 Jul 2020 18:35:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C4590206F0 for ; Mon, 13 Jul 2020 18:35:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xejc1Pr7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4590206F0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jv3IV-0007eu-W6 for qemu-devel@archiver.kernel.org; Mon, 13 Jul 2020 14:35:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jv3FW-00027p-Mj; Mon, 13 Jul 2020 14:32:22 -0400 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]:40261) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jv3FU-0004HB-Fe; Mon, 13 Jul 2020 14:32:22 -0400 Received: by mail-ej1-x644.google.com with SMTP id o18so18423687eje.7; Mon, 13 Jul 2020 11:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SN1q0PMCO1/b3G/yTwrOsu/XAVNUpaToYvO1YyH52/o=; b=Xejc1Pr7KYGOXiEWoif+Zso7A5D77D4/ExAVGk/jqOVZLeV2GpdLynJZm6yiObHN3f pqRCwJuZhrXleP2cIV6GxR9y1zYWYD9zoafaZd6/ejWLZZm+XbuN3KuP/UOnqWvPIyHL aAcdjKDM2rZQmdhzSxEZ+J63K/+giTaPZc+V8NY3Vb3X4+MgIq1Lvh3vl48xBfgcC1EG 7jWICq8f61zeQ9BW0nm27rb1eELx2ZGIox3SwoHLINtO/naiLIU1bdRlFWzcandkxjCy FJOAkEWV57KUdg3YUW4XWeHgLBKG3J6/5raPhQq9tR62xmCy+AeCua0wumZLMho/Jq6+ fI9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=SN1q0PMCO1/b3G/yTwrOsu/XAVNUpaToYvO1YyH52/o=; b=Mc02/CZcHyDbxGYQESA+KT0m8kA+jBkh7bWQ9cv2hfc9EQ+7Tb94qVZ6X9ZrdcdgZE EQG3dQ73JXXCnVYckT1VQ7wzzR51qigW2+Im5bb8CGhZ8p8XoIKhNfbRRGfyhZ0/whUe GfzWwiFTdxNJshHS3WFIulDrUPPDkqIxn53E6QoD/9BOtL+QGmN7kuyKHbdFWnPyi2lp T47XYd2jqXFrm50Q81xOo9JhPMiSI97Pwnl/rufOQm6gLwWwCY8x7KwjC2wQY+z5ix2h 7WkAD/BludPy/nvWiZ6nryZVKQIjNPdEl6/15MBJNWb82emfiyOwzCUO7SGYBwPAE+WA lRqw== X-Gm-Message-State: AOAM533PWeR0CEhuFMqoPyAgZMppzuIBBSotyskLKTVPw36+EVlgzTxt tNFWQiVaSLbUg68MI0EqR4b8ZC2qWK8= X-Google-Smtp-Source: ABdhPJxE6OxkdisEP4bvRpUfZ85Uto0+Rvw9utbKVHtqJtVJCKMPmwjBbgusrC3TFD2InzFEpAy5zA== X-Received: by 2002:a17:906:191a:: with SMTP id a26mr1006282eje.315.1594665138603; Mon, 13 Jul 2020 11:32:18 -0700 (PDT) Received: from x1w.redhat.com (138.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.138]) by smtp.gmail.com with ESMTPSA id ce12sm4353148edb.4.2020.07.13.11.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 11:32:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 5/9] hw/sd/sdcard: Restrict Class 6 commands to SCSD cards Date: Mon, 13 Jul 2020 20:32:05 +0200 Message-Id: <20200713183209.26308-6-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200713183209.26308-1-f4bug@amsat.org> References: <20200713183209.26308-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::644; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-x644.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Prasad J Pandit , qemu-block@nongnu.org, Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Alexander Bulekov , Niek Linnenbank , Alistair Francis , Cleber Rosa , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Only SCSD cards support Class 6 (Block Oriented Write Protection) commands. "SD Specifications Part 1 Physical Layer Simplified Spec. v3.01" 4.3.14 Command Functional Difference in Card Capacity Types * Write Protected Group SDHC and SDXC do not support write-protected groups. Issuing CMD28, CMD29 and CMD30 generates the ILLEGAL_COMMAND error. Reviewed-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Message-Id: <20200630133912.9428-7-f4bug@amsat.org> --- hw/sd/sd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 5137168d66..1cc16bfd31 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -920,6 +920,11 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->multi_blk_cnt = 0; } + if (sd_cmd_class[req.cmd] == 6 && FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { + /* Only Standard Capacity cards support class 6 commands */ + return sd_illegal; + } + switch (req.cmd) { /* Basic commands (Class 0 and Class 1) */ case 0: /* CMD0: GO_IDLE_STATE */ From patchwork Mon Jul 13 18:32:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 277935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F0D3C433E5 for ; Mon, 13 Jul 2020 18:37:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 08F262076D for ; Mon, 13 Jul 2020 18:37:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rOYJFU2R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08F262076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jv3KG-0002Y9-9m for qemu-devel@archiver.kernel.org; Mon, 13 Jul 2020 14:37:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jv3FX-0002As-TM; Mon, 13 Jul 2020 14:32:23 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:39006) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jv3FW-0004Hm-8U; Mon, 13 Jul 2020 14:32:23 -0400 Received: by mail-ej1-x62d.google.com with SMTP id w6so18425359ejq.6; Mon, 13 Jul 2020 11:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NesnoNVp8mV726mwx9/wPWtnd6LQdD+PlLDlGLZ9HWI=; b=rOYJFU2RGFhHMsYarEeYkwV6i2BnjZ4R/9zefMmzON2/jxgmkY9mvXdG3okNQOsxx7 Ow64FiMyWiOqn7YkM6jdMWJrkrUHeIet8gepIlQ1lU4RljejuDwpvqUdQFrcR0Bz9aYq TS0aggWkXDP7HzCLUar9B9WXSmnWICmcDnzNTbfFJY2emOXDW6zQGt6jz7HhQBCEtMuC ULj+It4Lc7Gxm2sXi8YCzUjq7cTH4afUgmdPRkZdlFvdxRBHcava6omoqzxZpmS8xIjM t9ZfQBuDQ+QmO79e3bn5vLsB2bpP7gG0m0LgTMhEkF8hTyFpGJERNbjvsP4hhsZ3s6Gk w0zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=NesnoNVp8mV726mwx9/wPWtnd6LQdD+PlLDlGLZ9HWI=; b=p+qDCT5GKLnynl7WRvR8IGBTLQV0EYDmwR76a7gatbVZc//g3+hr6OScivn7xkWiKA 1Wb79EXGkBEZ/ImZwFBsRwnFs28EJTiNThwEMeda+i1HKHxJWXH3tLMPh/3a+Am5a3DZ 5p/9jkBXxgffiKBYmudAGdU6GBGR5tg4E4fcx91Er89ZeGz/aRHVF0AjU5h62gTwh/SZ Tb/4bJb7KEb/DpUV7aKKatXgBi9PCzalYqafdP39cFEDLY3Y+xjOuNfpE7KoP0j2iW/s KfNmXLsAm4m5b+HTn4zYrrBbrtg63k9Cdun4kcv4xky/t38TNCFf3vMhymxWCoH5N/1B 10vA== X-Gm-Message-State: AOAM531WBqdyCtIn5KZDxymXLat3Q11o82w5wxucyKM56rg2DwuIwo28 4ygDcXV/954/nMr7hVNLPg6QEw7KRMI= X-Google-Smtp-Source: ABdhPJwTWTfC0FfKrws8ySY0SAa3FrmHcfKJgKroe1DsIXEwZ1f/NoSNqIBoESPRq4osKsWPNMycOQ== X-Received: by 2002:a17:907:1114:: with SMTP id qu20mr1024365ejb.41.1594665140185; Mon, 13 Jul 2020 11:32:20 -0700 (PDT) Received: from x1w.redhat.com (138.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.138]) by smtp.gmail.com with ESMTPSA id ce12sm4353148edb.4.2020.07.13.11.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 11:32:19 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 6/9] hw/sd/sdcard: Simplify realize() a bit Date: Mon, 13 Jul 2020 20:32:06 +0200 Message-Id: <20200713183209.26308-7-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200713183209.26308-1-f4bug@amsat.org> References: <20200713183209.26308-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-x62d.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Prasad J Pandit , qemu-block@nongnu.org, Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Alexander Bulekov , Niek Linnenbank , Alistair Francis , Cleber Rosa , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We don't need to check if sd->blk is set twice. Reviewed-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis Message-Id: <20200630133912.9428-18-f4bug@amsat.org> --- hw/sd/sd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 1cc16bfd31..edd60a09c0 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -2105,12 +2105,12 @@ static void sd_realize(DeviceState *dev, Error **errp) return; } - if (sd->blk && blk_is_read_only(sd->blk)) { - error_setg(errp, "Cannot use read-only drive as SD card"); - return; - } - if (sd->blk) { + if (blk_is_read_only(sd->blk)) { + error_setg(errp, "Cannot use read-only drive as SD card"); + return; + } + ret = blk_set_perm(sd->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE, BLK_PERM_ALL, errp); if (ret < 0) { From patchwork Mon Jul 13 18:32:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 277937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 329A0C433E3 for ; Mon, 13 Jul 2020 18:34:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F2DFD2075D for ; Mon, 13 Jul 2020 18:34:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RrTzR7+0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2DFD2075D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:51612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jv3Hb-0005dA-6w for qemu-devel@archiver.kernel.org; Mon, 13 Jul 2020 14:34:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jv3FZ-0002Fx-GA; Mon, 13 Jul 2020 14:32:25 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]:41885) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jv3FX-0004IV-P0; Mon, 13 Jul 2020 14:32:25 -0400 Received: by mail-ej1-x629.google.com with SMTP id dp18so18410911ejc.8; Mon, 13 Jul 2020 11:32:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A45CZTNPoBUm1W95oEJT02xG5DfWi0IK+venM/Qt9bs=; b=RrTzR7+0l7YaevPSpaniWmb86Wlj4IrrZlKRLeAhQ6KZAG3sski4737esWwL5su6Pp Ce3l1UH/qBNR+ynPijOSaUcCEK+Lk0GI/gPp1slF2LjS79HcHNnWwPDBBJqZuH94tYt4 CikzDbl0L1RZJ2prXPK06kqm5YjCHy8oFoJqBUgGLGgIEY0JXumZeY+vxssK4u3/SjUF XRGYnPAmgqjuaLt9Qa9mUmnqX2yjDv6iNRYN1ueAjde0GFW+Az5Ykxalo0DN8Rh8kWwQ gZ9xflMSO6vAArf4ulsQ1qf4P6/opS1i2PuXT/0ALg3pL3L0HbZ6gDbnD0ipiLHA/wI0 3IVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=A45CZTNPoBUm1W95oEJT02xG5DfWi0IK+venM/Qt9bs=; b=giWewntv2U9q831HP0bffGFOs42DWtygnoIrXe4EV+kdKPgV/JSGi8I3hg5HK/9U3H ci5V51O3vOppTG0piKWYczgu1uC80biYu40sR5SaR9SbE3LPXHssWq3Us7yOO3RYRaWM f7ijlL9Qg00ZNg/cT+ZiQ27x5zQqUWdEh2LgdRd8JMX4TLypos8ZEVte5b9aNh7fbZuV pSyRdTO8zThgj/f3P5A0BJoykIqObRBrgMzBGYfZmgpedZ3chIZjfz0o2M6Sx26yZaoO YuTK/ZYMe6nQAY4LLWYtO69QwXNtqgAxieSO8/nc1mFetsKxjNZeBARZjRX55LCfUAkN CzLA== X-Gm-Message-State: AOAM5326NujSmeDX1UBDuJX4oYj6phAw2X1pwjGk0KGT1yBCspFHVLBI ke2A0ZyUb38jwbrMHfAEUaZtTmJ0iqA= X-Google-Smtp-Source: ABdhPJz0Qw8SlxeFe9OpDRbyHyGFrAh21kTo5G35ARfVjmG9nKS4QXR+N8grcx7i+gAD69uapIJ+iQ== X-Received: by 2002:a17:907:20d1:: with SMTP id qq17mr1032942ejb.214.1594665141592; Mon, 13 Jul 2020 11:32:21 -0700 (PDT) Received: from x1w.redhat.com (138.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.138]) by smtp.gmail.com with ESMTPSA id ce12sm4353148edb.4.2020.07.13.11.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 11:32:21 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 7/9] hw/sd/sdcard: Do not allow invalid SD card sizes Date: Mon, 13 Jul 2020 20:32:07 +0200 Message-Id: <20200713183209.26308-8-f4bug@amsat.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200713183209.26308-1-f4bug@amsat.org> References: <20200713183209.26308-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-x629.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Prasad J Pandit , qemu-block@nongnu.org, Alistair Francis , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Alexander Bulekov , Niek Linnenbank , Cleber Rosa , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" QEMU allows to create SD card with unrealistic sizes. This could work, but some guests (at least Linux) consider sizes that are not a power of 2 as a firmware bug and fix the card size to the next power of 2. While the possibility to use small SD card images has been seen as a feature, it became a bug with CVE-2020-13253, where the guest is able to do OOB read/write accesses past the image size end. In a pair of commits we will fix CVE-2020-13253 as: Read command is rejected if BLOCK_LEN_ERROR or ADDRESS_ERROR occurred and no data transfer is performed. Write command is rejected if BLOCK_LEN_ERROR or ADDRESS_ERROR occurred and no data transfer is performed. WP_VIOLATION errors are not modified: the error bit is set, we stay in receive-data state, wait for a stop command. All further data transfer is ignored. See the check on sd->card_status at the beginning of sd_read_data() and sd_write_data(). While this is the correct behavior, in case QEMU create smaller SD cards, guests still try to access past the image size end, and QEMU considers this is an invalid address, thus "all further data transfer is ignored". This is wrong and make the guest looping until eventually timeouts. Fix by not allowing invalid SD card sizes (suggesting the expected size as a hint): $ qemu-system-arm -M orangepi-pc -drive file=rootfs.ext2,if=sd,format=raw qemu-system-arm: Invalid SD card size: 60 MiB SD card size has to be a power of 2, e.g. 64 MiB. You can resize disk images with 'qemu-img resize ' (note that this will lose data if you make the image smaller than it currently is). Signed-off-by: Philippe Mathieu-Daudé --- Since v1: Addressed Alistair & Peter comments (error_append_hint message) --- hw/sd/sd.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index edd60a09c0..5ab945dade 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -32,6 +32,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" +#include "qemu/cutils.h" #include "hw/irq.h" #include "hw/registerfields.h" #include "sysemu/block-backend.h" @@ -2106,11 +2107,35 @@ static void sd_realize(DeviceState *dev, Error **errp) } if (sd->blk) { + int64_t blk_size; + if (blk_is_read_only(sd->blk)) { error_setg(errp, "Cannot use read-only drive as SD card"); return; } + 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; + + 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 '\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; + } + ret = blk_set_perm(sd->blk, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE, BLK_PERM_ALL, errp); if (ret < 0) {