qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/sd: sdhci: Do not transfer any data when command fails
@ 2021-02-09 10:54 Bin Meng
  2021-02-09 11:03 ` Philippe Mathieu-Daudé
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Bin Meng @ 2021-02-09 10:54 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Mauro Matteo Cascella, Li Qiang,
	Alexander Bulekov, Alistair Francis, Prasad J Pandit, Bandan Das
  Cc: qemu-stable, qemu-block, 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 <alxndr@bu.edu>
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 <bmeng.cn@gmail.com>
---

 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);
     }
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-02-14 15:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-09 10:54 [PATCH] hw/sd: sdhci: Do not transfer any data when command fails Bin Meng
2021-02-09 11:03 ` Philippe Mathieu-Daudé
2021-02-10 22:27 ` Alistair Francis
2021-02-11  8:52   ` Mauro Matteo Cascella
2021-02-11 19:48     ` Philippe Mathieu-Daudé
2021-02-12 13:55       ` Mauro Matteo Cascella
2021-02-11 15:49 ` Alexander Bulekov
2021-02-11 16:53 ` Alexander Bulekov
2021-02-11 21:24   ` Alexander Bulekov
2021-02-14  5:56     ` Bin Meng
2021-02-14 15:53       ` Bin Meng

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).