From patchwork Tue Feb 9 10:54:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12077753 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 8B9C2C433DB for ; Tue, 9 Feb 2021 10:56:14 +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 B715764E56 for ; Tue, 9 Feb 2021 10:56:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B715764E56 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Qgm-0002uC-JQ for qemu-devel@archiver.kernel.org; Tue, 09 Feb 2021 05:56:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9Qff-0002OE-Ot; Tue, 09 Feb 2021 05:55:03 -0500 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]:41472) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l9Qfd-0005d1-Ok; Tue, 09 Feb 2021 05:55:03 -0500 Received: by mail-ej1-x62a.google.com with SMTP id f14so30508673ejc.8; Tue, 09 Feb 2021 02:55:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=P/ly+8lO7GHDefJgMR7mC5hr1z+tDL7329TuCx7q6EE=; b=jcNmfHxX2U7zu50WgfXytx24hiHHL8gt+NZ98YlkEXm6/fDV5yYOjQ0mdlpCjxY6BD gW6Ae8wdcXaDcatkXioWEhq1ndV/id0WTYE8C99d1FCH0Mq3O23/z49Qn5EqXGvV8HGA cRnPv//lCKSrlQ7a/Hkpx9jNzpaC8rg3F0M5EJRXk574UOmb29a7dtZ77ObViIitcsBR 5B8autBQbzF1O8yUVLHWv2Dnz0iOqWW7cWoJmyoalnQibig/0/DO218YstcW3Wp/R3Dx s6AtfEThRVfSGek5RHX/9GKU5yrZK3VvVr6MBjRyEbzy4oeR2B4byOx5m9SsFvKG6BmJ OPCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=P/ly+8lO7GHDefJgMR7mC5hr1z+tDL7329TuCx7q6EE=; b=HmQk3nNaKydGMXMfZFgQJmAMLxOE9ikdbMRw9KzI/d3mNEFELKfFgCF1JAyYsFS6SH LqNO9raTSVMk3RnmP/acR4U+K+SMsrLhFMit5SDuImmwnv7zEI/MJQ93ZULWjyp/3f7A o0yLJh4XYS02rfiGj8S7lqniwyRfESDs6wbVpWSR1voiqCw4GuyfQewr6ddUxPZ0gWTL JOKwDm4vwIPoXavlQNKUOSzo7ZxcsQP7ApZGhfcznYxN0W5fWNDU9m5IEcv5R7AvZRlb IJy0vj0a+OGDbs6uETAdtSae6TSGbrJLDcSEStqnQ/ijfxuWYM3oT24z8MD+dbm70AkJ jXsw== X-Gm-Message-State: AOAM530U+oiZykRmUE4dYXDic05zqXaNiOJ9Gix+ghjixBr8tMZIClN1 BceQGoK5quiKnKVzWzUnq9g= X-Google-Smtp-Source: ABdhPJwiShmPeR5oCdOQQjIyzGm990KVXDUHtmC0fNLmOLj5IV/GosCzlTwrLDbBR7Z4LkCivlLG6A== X-Received: by 2002:a17:906:ad9:: with SMTP id z25mr21929680ejf.513.1612868099455; Tue, 09 Feb 2021 02:54:59 -0800 (PST) Received: from pek-vx-bsp2.wrs.com (ec2-44-242-66-180.us-west-2.compute.amazonaws.com. [44.242.66.180]) by smtp.gmail.com with ESMTPSA id g4sm11498872edv.59.2021.02.09.02.54.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Feb 2021 02:54:59 -0800 (PST) From: Bin Meng To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Mauro Matteo Cascella , Li Qiang , Alexander Bulekov , Alistair Francis , Prasad J Pandit , Bandan Das Subject: [PATCH] hw/sd: sdhci: Do not transfer any data when command fails Date: Tue, 9 Feb 2021 18:54:45 +0800 Message-Id: <1612868085-72809-1-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.7.4 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=bmeng.cn@gmail.com; helo=mail-ej1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: qemu-stable@nongnu.org, qemu-block@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" At the end of sdhci_send_command(), it starts a data transfer if the command register indicates a data is associated. However the data transfer should only be initiated when the command execution has succeeded. Cc: qemu-stable@nongnu.org Fixes: CVE-2020-17380 Fixes: CVE-2020-25085 Reported-by: Alexander Bulekov Reported-by: Sergej Schumilo (Ruhr-University Bochum) Reported-by: Cornelius Aschermann (Ruhr-University Bochum) Reported-by: Simon Wrner (Ruhr-University Bochum) Buglink: https://bugs.launchpad.net/qemu/+bug/1892960 Signed-off-by: Bin Meng Tested-by: Philippe Mathieu-Daudé Acked-by: Alistair Francis Reported-by: Muhammad Ramdhan Tested-by: Alexander Bulekov --- hw/sd/sdhci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index 8ffa539..0450110 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -326,6 +326,7 @@ static void sdhci_send_command(SDHCIState *s) SDRequest request; uint8_t response[16]; int rlen; + bool cmd_failure = false; s->errintsts = 0; s->acmd12errsts = 0; @@ -349,6 +350,7 @@ static void sdhci_send_command(SDHCIState *s) trace_sdhci_response16(s->rspreg[3], s->rspreg[2], s->rspreg[1], s->rspreg[0]); } else { + cmd_failure = true; trace_sdhci_error("timeout waiting for command response"); if (s->errintstsen & SDHC_EISEN_CMDTIMEOUT) { s->errintsts |= SDHC_EIS_CMDTIMEOUT; @@ -369,7 +371,7 @@ static void sdhci_send_command(SDHCIState *s) sdhci_update_irq(s); - if (s->blksize && (s->cmdreg & SDHC_CMD_DATA_PRESENT)) { + if (!cmd_failure && s->blksize && (s->cmdreg & SDHC_CMD_DATA_PRESENT)) { s->data_count = 0; sdhci_data_transfer(s); }