hw/sd: sdhci: Do not transfer any data when command fails
PATCH 1/1 hw/sd: sdhci: Do not transfer any data when command fails
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.
---
hw/sd/sdhci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/sd/sdhci.c +3 -1
@@ -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); }
Signature · 1 line
2.7.4
Quoted 14 lines · Bin Meng
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.Fixes CVE-2020-17380Fixes CVE-2020-25085Reported-by Alexander Bulekov <[email protected]>Reported-by Sergej Schumilo (Ruhr-University Bochum)Reported-by Cornelius Aschermann (Ruhr-University Bochum)Reported-by Simon Wrner (Ruhr-University Bochum)Signed-off-by Bin Meng <[email protected]>
Quoted 4 lines
---
hw/sd/sdhci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 6 lines · Bin Meng
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.
Quoted 8 lines
Fixes CVE-2020-17380Fixes CVE-2020-25085Reported-by Alexander Bulekov <[email protected]>Reported-by Sergej Schumilo (Ruhr-University Bochum)Reported-by Cornelius Aschermann (Ruhr-University Bochum)Reported-by Simon Wrner (Ruhr-University Bochum)
Isn't this already fixed?
Quoted 1 line
Signed-off-by Bin Meng <[email protected]>
Alistair
Quoted 38 lines
---
hw/sd/sdhci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/sd/sdhci.c +3
-2@@ -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
Hello,
Quoted 17 lines · Alistair Francis
Quoted 6 lines · Bin Meng
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.Quoted 8 lines
Fixes CVE-2020-17380Fixes CVE-2020-25085Reported-by Alexander Bulekov <[email protected]>Reported-by Sergej Schumilo (Ruhr-University Bochum)Reported-by Cornelius Aschermann (Ruhr-University Bochum)Reported-by Simon Wrner (Ruhr-University Bochum)
Quoted 2 lines
Isn't this already fixed?
It turned out the bug was still reproducible on master. I'm actually thinking of assigning a new CVE for this, to make it possible for distros to apply this fix.
--
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0
Quoted 21 lines · Mauro Matteo Cascella
Hello,
Quoted 18 lines · Alistair Francis
Quoted 6 lines · Bin Meng
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.Quoted 8 lines
Fixes CVE-2020-17380Fixes CVE-2020-25085Reported-by Alexander Bulekov <[email protected]>Reported-by Sergej Schumilo (Ruhr-University Bochum)Reported-by Cornelius Aschermann (Ruhr-University Bochum)Reported-by Simon Wrner (Ruhr-University Bochum)Isn't this already fixed?
The previous patch was enough to catch the previous reproducer, but something changed elsewhere making the same reproducer crash QEMU again...
Quoted 3 lines
It turned out the bug was still reproducible on master. I'm actually thinking of assigning a new CVE for this, to make it possible for distros to apply this fix.
It sounds fair. Do you have an ETA for the new CVE?
Quoted 6 lines
--
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 12 lines · Mauro Matteo Cascella
Hello,
Quoted 9 lines · Alistair Francis
Quoted 5 lines · Bin Meng
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.Isn't this already fixed?
The previous patch was enough to catch the previous reproducer, but something changed elsewhere making the same reproducer crash QEMU again...
Quoted 5 lines
Quoted 3 lines
It turned out the bug was still reproducible on master. I'm actually thinking of assigning a new CVE for this, to make it possible for distros to apply this fix.
It sounds fair. Do you have an ETA for the new CVE?
This is now CVE-2021-3409.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1928146
--
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0
Quoted 5 lines · Bin Meng
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.
Quoted 7 lines
Fixes CVE-2020-17380Fixes CVE-2020-25085Reported-by Alexander Bulekov <[email protected]>Reported-by Sergej Schumilo (Ruhr-University Bochum)Reported-by Cornelius Aschermann (Ruhr-University Bochum)Reported-by Simon Wrner (Ruhr-University Bochum)
Reported-by: Muhammad Ramdhan
(don't know how to get the email from a launchpad report)
and probably:
Quoted 39 lines
Signed-off-by Bin Meng <[email protected]>---
hw/sd/sdhci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/sd/sdhci.c +3
-1@@ -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); }Signature · 1 line
2.7.4
Quoted 5 lines · Bin Meng
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.
Quoted 9 lines
Fixes CVE-2020-17380Fixes CVE-2020-25085Reported-by Alexander Bulekov <[email protected]>Reported-by Sergej Schumilo (Ruhr-University Bochum)Reported-by Cornelius Aschermann (Ruhr-University Bochum)Reported-by Simon Wrner (Ruhr-University Bochum)Signed-off-by Bin Meng <[email protected]>
I applied this along with <[email protected]> "hw/sd/sdhci: Do not modify BlockSizeRegister if transaction in progress"
I ran through the entire OSS-Fuzz corpus, and could not reproduce the crash.
Thanks
Quoted 37 lines
---
hw/sd/sdhci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/sd/sdhci.c +3
-1@@ -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); }Signature · 1 line
2.7.4
On 210211 1154, Alexander Bulekov wrote:
...
Quoted 8 lines
I applied this along with <[email protected]> "hw/sd/sdhci: Do not modify BlockSizeRegister if transaction in progress"
I ran through the entire OSS-Fuzz corpus, and could not reproduce the crash.
Tested-by Alexander Bulekov <[email protected]>
Hi Bin,
Phil explained to me that this patch should fix the problem independent of
"hw/sd/sdhci: Do not modify BlockSizeRegister if transaction in progress"
With only this patch, there are still crashes. Here are three reproducers:
Some of these are quite long, so here are pastebins for convenience:
Repro 1: https://paste.debian.net/plain/1185137
Repro 2: https://paste.debian.net/plain/1185141
Repro 3: https://paste.debian.net/plain/1185136
Just wget and pipe them into
./qemu-system-i386 -display none -machine accel=qtest -nographic \
-m 512M -nodefaults -device sdhci-pci,sd-spec-version=3 \
-drive if=sd,index=0,file=null-co://,format=raw,id=mydrive \
-device sd-card,drive=mydrive -qtest stdio
==== Repro 1 ====
cat << EOF | ./qemu-system-i386 -display none -machine accel=qtest -nographic \
-m 512M -nodefaults -device sdhci-pci,sd-spec-version=3 \
-drive if=sd,index=0,file=null-co://,format=raw,id=mydrive \
-device sd-card,drive=mydrive -qtest stdio
outl 0xcf8 0x80001010
outl 0xcfc 0xfbefff00
outl 0xcf8 0x80001001
outl 0xcfc 0x06000000
write 0xfbefff2c 0x1 0x05
write 0xfbefff0f 0x1 0x37
write 0xfbefff0a 0x1 0x01
write 0xfbefff0f 0x1 0x29
write 0xfbefff0f 0x1 0x02
write 0xfbefff0f 0x1 0x03
write 0xfbefff04 0x1 0x01
write 0xfbefff05 0x1 0x01
write 0xfbefff07 0x1 0x02
write 0xfbefff0c 0x1 0x33
write 0xfbefff0e 0x1 0x20
write 0xfbefff0f 0x1 0x00
write 0xfbefff2a 0x1 0x01
write 0xfbefff0c 0x1 0x00
write 0xfbefff03 0x1 0x00
write 0xfbefff05 0x1 0x00
write 0xfbefff2a 0x1 0x02
write 0xfbefff0c 0x1 0x32
write 0xfbefff01 0x1 0x01
write 0xfbefff02 0x1 0x01
write 0xfbefff03 0x1 0x01
EOF
==== Stack Trace 1 ====
==929953==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x615000031880 at pc 0x564cf01ceae7 bp 0x7ffe17361e10 sp 0x7ffe173615d8 READ of size 520027904 at 0x615000031880 thread T0
#0 0x564cf01ceae6 in __asan_memcpy (/home/alxndr/Development/qemu/build/qemu-system-i386+0x2a8cae6)
#1 0x564cf19111a5 in flatview_write_continue /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2781:13
#2 0x564cf1906beb in flatview_write /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2816:14
#3 0x564cf1906beb in address_space_write /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2908:18
#4 0x564cf096348c in dma_memory_rw_relaxed /home/alxndr/Development/qemu/include/sysemu/dma.h:88:12
#5 0x564cf096348c in dma_memory_rw /home/alxndr/Development/qemu/include/sysemu/dma.h:127:12
#6 0x564cf096348c in dma_memory_write /home/alxndr/Development/qemu/include/sysemu/dma.h:163:12
#7 0x564cf096348c in sdhci_sdma_transfer_multi_blocks /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:619:13
#8 0x564cf097237d in sdhci_write /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:1131:17
#9 0x564cf154333c in memory_region_write_accessor /home/alxndr/Development/qemu/build/../softmmu/memory.c:491:5==== Repro 2 ====
cat << EOF | ./qemu-system-i386 -display none -machine accel=qtest -nographic \
-m 512M -nodefaults -device sdhci-pci,sd-spec-version=3 \
-drive if=sd,index=0,file=null-co://,format=raw,id=mydrive \
-device sd-card,drive=mydrive -qtest stdio
outl 0xcf8 0x80001013
outl 0xcfc 0x91
outl 0xcf8 0x80001001
outl 0xcfc 0x06000000
write 0x9100002c 0x1 0x05
write 0x9100000f 0x1 0x37
write 0x9100000a 0x1 0x01
write 0x9100000f 0x1 0x29
write 0x9100000f 0x1 0x02
write 0x9100000f 0x1 0x03
write 0x0 0x1 0x01
write 0x8 0x1 0x01
write 0x10 0x1 0x01
write 0x18 0x1 0x01
write 0x20 0x1 0x01
write 0x28 0x1 0x01
write 0x30 0x1 0x01
write 0x38 0x1 0x01
write 0x40 0x1 0x01
write 0x48 0x1 0x01
write 0x50 0x1 0x01
write 0x58 0x1 0x01
write 0x60 0x1 0x01
write 0x68 0x1 0x01
write 0x70 0x1 0x01
write 0x91000005 0x1 0x02
write 0x91000007 0x1 0x20
write 0x78 0x1 0x01
write 0x80 0x1 0x01
write 0x88 0x1 0x01
write 0x90 0x1 0x01
write 0x98 0x1 0x01
write 0xa0 0x1 0x01
write 0xa8 0x1 0x01
write 0xb0 0x1 0x01
write 0xb8 0x1 0x01
write 0xc0 0x1 0x01
write 0x9100000e 0x1 0x21
write 0x91000028 0x1 0x10
write 0x9100000c 0x1 0x01
write 0x9100000f 0x1 0x06
write 0xc8 0x1 0x01
write 0xd0 0x1 0x01
write 0xd8 0x1 0x01
write 0xe0 0x1 0x01
write 0xe8 0x1 0x01
write 0xf0 0x1 0x01
write 0xf8 0x1 0x01
write 0x100 0x1 0x01
write 0x108 0x1 0x01
write 0x110 0x1 0x01
write 0x118 0x1 0x01
write 0x120 0x1 0x01
write 0x128 0x1 0x01
write 0x130 0x1 0x01
write 0x138 0x1 0x01
write 0x140 0x1 0x01
write 0x148 0x1 0x01
write 0x150 0x1 0x01
write 0x158 0x1 0x01
write 0x160 0x1 0x01
write 0x168 0x1 0x01
write 0x170 0x1 0x01
write 0x178 0x1 0x01
write 0x180 0x1 0x01
write 0x188 0x1 0x01
write 0x190 0x1 0x01
write 0x198 0x1 0x01
write 0x1a0 0x1 0x01
write 0x1a8 0x1 0x01
write 0x1b0 0x1 0x01
write 0x91000037 0x1 0x00
write 0x91000038 0x1 0x00
write 0x1b8 0x1 0x01
write 0x1c0 0x1 0x01
write 0x1c8 0x1 0x01
write 0x1d0 0x1 0x01
write 0x1d8 0x1 0x01
write 0x1e0 0x1 0x01
write 0x1e8 0x1 0x01
write 0x1f0 0x1 0x01
write 0x1f8 0x1 0x01
write 0x200 0x1 0x01
write 0x208 0x1 0x01
write 0x210 0x1 0x01
write 0x218 0x1 0x01
write 0x220 0x1 0x01
write 0x228 0x1 0x01
write 0x9100000d 0x1 0x00
write 0x9100000f 0x1 0x10
write 0x91000011 0x1 0x00
write 0x230 0x1 0x01
write 0x238 0x1 0x01
write 0x240 0x1 0x01
write 0x248 0x1 0x01
write 0x250 0x1 0x01
write 0x258 0x1 0x01
write 0x260 0x1 0x01
write 0x268 0x1 0x01
write 0x270 0x1 0x01
write 0x278 0x1 0x01
write 0x280 0x1 0x01
write 0x288 0x1 0x01
write 0x290 0x1 0x01
write 0x298 0x1 0x01
write 0x2a0 0x1 0x01
write 0x9100000a 0x2 0x0000
write 0x9100000c 0x6 0x010000
write 0x2a8 0x1 0x01
write 0x2b0 0x1 0x01
write 0x2b8 0x1 0x01
write 0x2c0 0x1 0x01
write 0x2c8 0x1 0x01
write 0x2d0 0x1 0x01
write 0x2d8 0x1 0x01
write 0x2e0 0x1 0x01
write 0x2e8 0x1 0x01
write 0x2f0 0x1 0x01
write 0x2f8 0x1 0x01
write 0x300 0x1 0x01
write 0x308 0x1 0x01
write 0x310 0x1 0x01
write 0x318 0x1 0x01
write 0x320 0x1 0x01
write 0x328 0x1 0x01
write 0x330 0x1 0x01
write 0x338 0x1 0x01
write 0x340 0x1 0x01
write 0x348 0x1 0x01
write 0x350 0x1 0x01
write 0x358 0x1 0x01
write 0x360 0x1 0x01
write 0x368 0x1 0x01
write 0x370 0x1 0x01
write 0x378 0x1 0x01
write 0x380 0x1 0x01
write 0x388 0x1 0x01
write 0x390 0x1 0x01
write 0x9100000f 0x1 0x00
write 0x91000011 0x1 0x00
write 0x398 0x1 0x01
write 0x3a0 0x1 0x01
write 0x3a8 0x1 0x01
write 0x3b0 0x1 0x01
write 0x3b8 0x1 0x21
write 0x3bb 0x1 0x01
write 0x3c0 0x1 0x21
write 0x9100000a 0x2 0x0000
write 0x9100000c 0x6 0x010000
write 0x9100000a 0x2 0x00
write 0x9100000c 0x6 0x01
write 0x9100000a 0x2 0x0000
write 0x9100000c 0x6 0x010000
write 0x9100000a 0x2 0x00
write 0x9100000c 0x6 0x010000
write 0x91000005 0x1 0x00
write 0x9100000c 0x1 0x00
EOF
==== Stack Trace 2 ====
==837609==ERROR: AddressSanitizer: heap-buffer-overflow on address0x615000032280 at pc 0x564afb30eb6a bp 0x7ffdda140d90 sp 0x7ffdda140558
WRITE of size 483589332 at 0x615000032280 thread T0
#0 0x564afb30eb69 in __asan_memcpy (/home/alxndr/Development/qemu/build/qemu-fuzz-i386+0x2bccb69) #1 0x564afca598bd in flatview_read_continue /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2846:13 #2 0x564afca5b09b in flatview_read /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2879:12 #3 0x564afca5b09b in address_space_read_full /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2892:18 #4 0x564afbab9e9d in dma_memory_rw_relaxed /home/alxndr/Development/qemu/include/sysemu/dma.h:88:12 #5 0x564afbab9e9d in dma_memory_rw /home/alxndr/Development/qemu/include/sysemu/dma.h:127:12 #6 0x564afbab9e9d in dma_memory_read /home/alxndr/Development/qemu/include/sysemu/dma.h:145:12 #7 0x564afbab9e9d in sdhci_do_adma /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:809:21 #8 0x564afbab2b81 in sdhci_data_transfer /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c #9 0x564afbac2966 in sdhci_resume_pending_transfer /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:964:5 #10 0x564afbac2966 in sdhci_write /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:1120:9 #11 0x564afc697c6c in memory_region_write_accessor /home/alxndr/Development/qemu/build/../softmmu/memory.c:491:5
==== Repro 3 ====
(There is an identical one for a heap overflow through read ldl_he_p. Let me know if it would be useful to provide it):
cat << EOF | ./qemu-system-i386 -display none -machine accel=qtest -nographic \
-m 512M -nodefaults -device sdhci-pci,sd-spec-version=3 \
-drive if=sd,index=0,file=null-co://,format=raw,id=mydrive \
-device sd-card,drive=mydrive -qtest stdio
outl 0xcf8 0x80001010
outl 0xcfc 0xe0000000
outl 0xcf8 0x80001004
outw 0xcfc 0x06
write 0xe0000004 0x1 0x41
write 0xe0000006 0x1 0x80
write 0xe0000028 0x1 0x10
write 0xe000002c 0x1 0x05
write 0x0 0x1 0x21
write 0x2 0x1 0x0a
write 0x8 0x1 0x01
write 0xa 0x1 0x00
write 0x10 0x1 0x01
write 0x12 0x1 0x00
write 0x18 0x1 0x21
write 0x1a 0x1 0x16
write 0x20 0x1 0x01
write 0x22 0x1 0x00
write 0x28 0x1 0x01
write 0x2a 0x1 0x00
write 0x30 0x1 0x21
write 0x32 0x1 0x16
write 0x38 0x1 0x01
write 0x3a 0x1 0x00
write 0x40 0x1 0x01
write 0x42 0x1 0x00
write 0x48 0x1 0x21
write 0x4a 0x1 0x16
write 0x50 0x1 0x01
write 0x52 0x1 0x00
write 0x58 0x1 0x01
write 0x5a 0x1 0x00
write 0x60 0x1 0x21
write 0x62 0x1 0x16
write 0x68 0x1 0x01
write 0x6a 0x1 0x00
write 0x70 0x1 0x01
write 0x72 0x1 0x00
write 0x78 0x1 0x21
write 0x80 0x1 0x21
write 0x82 0x1 0x58
write 0x88 0x1 0x01
write 0x8a 0x1 0x00
write 0x90 0x1 0x01
write 0x92 0x1 0x00
write 0x98 0x1 0x21
write 0x9a 0x1 0x16
write 0xa0 0x1 0x21
write 0xa8 0x1 0x01
write 0xaa 0x1 0x00
write 0xb0 0x1 0x01
write 0xb2 0x1 0x00
write 0xb8 0x1 0x21
write 0xba 0x1 0x18
write 0xc0 0x1 0x01
write 0xc2 0x1 0x00
write 0xc8 0x1 0x01
write 0xca 0x1 0x00
write 0xd0 0x1 0x21
write 0xd2 0x1 0x16
write 0xd8 0x1 0x01
write 0xda 0x1 0x00
write 0xe0 0x1 0x01
write 0xe2 0x1 0x00
write 0xe8 0x1 0x21
write 0xea 0x1 0x18
write 0xf0 0x1 0x01
write 0xf2 0x1 0x00
write 0xf8 0x1 0x01
write 0xfa 0x1 0x00
write 0x100 0x1 0x21
write 0x102 0x1 0x16
write 0x108 0x1 0x01
write 0x10a 0x1 0x00
write 0x110 0x1 0x01
write 0x112 0x1 0x00
write 0x118 0x1 0x21
write 0x11a 0x1 0x18
write 0x120 0x1 0x01
write 0x122 0x1 0x00
write 0x128 0x1 0x01
write 0x12a 0x1 0x00
write 0x130 0x1 0x21
write 0x132 0x1 0x16
write 0x138 0x1 0x01
write 0x13a 0x1 0x00
write 0x140 0x1 0x01
write 0x142 0x1 0x00
write 0x148 0x1 0x21
write 0x14a 0x1 0x18
write 0x150 0x1 0x01
write 0x152 0x1 0x00
write 0x158 0x1 0x01
write 0x15a 0x1 0x00
write 0x160 0x1 0x21
write 0x162 0x1 0x16
write 0xe000000c 0x1 0x01
write 0xe000000e 0x1 0x20
write 0xe000000f 0x1 0x00
write 0x168 0x1 0x21
write 0x16d 0x1 0xff
write 0x16e 0x1 0xff
write 0x16f 0x1 0x1f
write 0xe0000000 0x4 0x00
write 0xe0000004 0x4 0x03010000
write 0xe0000085 0x1 0x00
write 0xe0000086 0x6 0x00
write 0xe000008c 0x1 0x00
write 0xe0000000 0x4 0x00
write 0xe0000004 0x2 0x00
write 0xe0000038 0x1 0x00
EOF
Stack Trace 3:
=817509==ERROR: AddressSanitizer: heap-buffer-overflow on address0x615000032280 at pc 0x564afca59f2b bp 0x7ffdda140d90 sp 0x7ffdda140d88
WRITE of size 4 at 0x615000032280 thread T0
#0 0x564afca59f2a in stl_he_p /home/alxndr/Development/qemu/include/qemu/bswap.h:353:5
#1 0x564afca59f2a in stn_he_p /home/alxndr/Development/qemu/include/qemu/bswap.h:546:1
#2 0x564afca59f2a in flatview_read_continue /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2841:13 #3 0x564afca5b09b in flatview_read /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2879:12 #4 0x564afca5b09b in address_space_read_full /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2892:18 #5 0x564afbab9e9d in dma_memory_rw_relaxed /home/alxndr/Development/qemu/include/sysemu/dma.h:88:12 #6 0x564afbab9e9d in dma_memory_rw /home/alxndr/Development/qemu/include/sysemu/dma.h:127:12 #7 0x564afbab9e9d in dma_memory_read /home/alxndr/Development/qemu/include/sysemu/dma.h:145:12 #8 0x564afbab9e9d in sdhci_do_adma /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:809:21 #9 0x564afbab2b81 in sdhci_data_transfer /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c #10 0x564afbac2966 in sdhci_resume_pending_transfer /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:964:5 #11 0x564afbac2966 in sdhci_write /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:1120:9 #12 0x564afc697c6c in memory_region_write_accessor /home/alxndr/Development/qemu/build/../softmmu/memory.c:491:5
Hi Alexander,
Quoted 9 lines · Alexander Bulekov
On 210211 1154, Alexander Bulekov wrote:
...Quoted 6 lines
I applied this along with <[email protected]> "hw/sd/sdhci: Do not modify BlockSizeRegister if transaction in progress"
I ran through the entire OSS-Fuzz corpus, and could not reproduce the crash.
Quoted 6 lines
Quoted 2 lines
Tested-by Alexander Bulekov <[email protected]>Hi Bin,
Phil explained to me that this patch should fix the problem independent of
"hw/sd/sdhci: Do not modify BlockSizeRegister if transaction in progress"
Yes, that's what I expect too.
Quoted 8 lines
With only this patch, there are still crashes. Here are three reproducers:
Some of these are quite long, so here are pastebins for convenience:
Repro 1: https://paste.debian.net/plain/1185137
Repro 2: https://paste.debian.net/plain/1185141
Repro 3: https://paste.debian.net/plain/1185136
I will take a look.
Quoted 367 lines
Just wget and pipe them into
./qemu-system-i386 -display none -machine accel=qtest -nographic \(quoted diff) +0
-3-m 512M -nodefaults -device sdhci-pci,sd-spec-version=3 \ -drive if=sd,index=0,file=null-co://,format=raw,id=mydrive \ -device sd-card,drive=mydrive -qtest stdio==== Repro 1 ====
cat << EOF | ./qemu-system-i386 -display none -machine accel=qtest -nographic \(quoted diff) +0
-3-m 512M -nodefaults -device sdhci-pci,sd-spec-version=3 \ -drive if=sd,index=0,file=null-co://,format=raw,id=mydrive \ -device sd-card,drive=mydrive -qtest stdiooutl
0xcf80x80001010
outl0xcfc0xfbefff00
outl0xcf80x80001001
outl0xcfc0x06000000
write0xfbefff2c0x10x05
write0xfbefff0f0x10x37
write0xfbefff0a0x10x01
write0xfbefff0f0x10x29
write0xfbefff0f0x10x02
write0xfbefff0f0x10x03
write0xfbefff040x10x01
write0xfbefff050x10x01
write0xfbefff070x10x02
write0xfbefff0c0x10x33
write0xfbefff0e0x10x20
write0xfbefff0f0x10x00
write0xfbefff2a0x10x01
write0xfbefff0c0x10x00
write0xfbefff030x10x00
write0xfbefff050x10x00
write0xfbefff2a0x10x02
write0xfbefff0c0x10x32
write0xfbefff010x10x01
write0xfbefff020x10x01
write0xfbefff030x10x01
EOF==== Stack Trace 1 ====
==929953==ERROR: AddressSanitizer: heap-buffer-overflow on address0x615000031880at pc0x564cf01ceae7bp0x7ffe17361e10sp0x7ffe173615d8READ of size 520027904 at0x615000031880thread T0#0 0x564cf01ceae6 in __asan_memcpy (/home/alxndr/Development/qemu/build/qemu-system-i386+0x2a8cae6) #1 0x564cf19111a5 in flatview_write_continue /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2781:13 #2 0x564cf1906beb in flatview_write /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2816:14 #3 0x564cf1906beb in address_space_write /home/alxndr/Development/qemu/build/../softmmu/physmem.c:2908:18 #4 0x564cf096348c in dma_memory_rw_relaxed /home/alxndr/Development/qemu/include/sysemu/dma.h:88:12 #5 0x564cf096348c in dma_memory_rw /home/alxndr/Development/qemu/include/sysemu/dma.h:127:12 #6 0x564cf096348c in dma_memory_write /home/alxndr/Development/qemu/include/sysemu/dma.h:163:12 #7 0x564cf096348c in sdhci_sdma_transfer_multi_blocks /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:619:13 #8 0x564cf097237d in sdhci_write /home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:1131:17 #9 0x564cf154333c in memory_region_write_accessor /home/alxndr/Development/qemu/build/../softmmu/memory.c:491:5==== Repro 2 ====
cat << EOF | ./qemu-system-i386 -display none -machine accel=qtest -nographic \
(quoted diff) +0
-3-m 512M -nodefaults -device sdhci-pci,sd-spec-version=3 \ -drive if=sd,index=0,file=null-co://,format=raw,id=mydrive \ -device sd-card,drive=mydrive -qtest stdiooutl
0xcf80x80001013
outl0xcfc0x91
outl0xcf80x80001001
outl0xcfc0x06000000
write0x9100002c0x10x05
write0x9100000f0x10x37
write0x9100000a0x10x01
write0x9100000f0x10x29
write0x9100000f0x10x02
write0x9100000f0x10x03
write0x00x10x01
write0x80x10x01
write0x100x10x01
write0x180x10x01
write0x200x10x01
write0x280x10x01
write0x300x10x01
write0x380x10x01
write0x400x10x01
write0x480x10x01
write0x500x10x01
write0x580x10x01
write0x600x10x01
write0x680x10x01
write0x700x10x01
write0x910000050x10x02
write0x910000070x10x20
write0x780x10x01
write0x800x10x01
write0x880x10x01
write0x900x10x01
write0x980x10x01
write0xa00x10x01
write0xa80x10x01
write0xb00x10x01
write0xb80x10x01
write0xc00x10x01
write0x9100000e0x10x21
write0x910000280x10x10
write0x9100000c0x10x01
write0x9100000f0x10x06
write0xc80x10x01
write0xd00x10x01
write0xd80x10x01
write0xe00x10x01
write0xe80x10x01
write0xf00x10x01
write0xf80x10x01
write0x1000x10x01
write0x1080x10x01
write0x1100x10x01
write0x1180x10x01
write0x1200x10x01
write0x1280x10x01
write0x1300x10x01
write0x1380x10x01
write0x1400x10x01
write0x1480x10x01
write0x1500x10x01
write0x1580x10x01
write0x1600x10x01
write0x1680x10x01
write0x1700x10x01
write0x1780x10x01
write0x1800x10x01
write0x1880x10x01
write0x1900x10x01
write0x1980x10x01
write0x1a00x10x01
write0x1a80x10x01
write0x1b00x10x01
write0x910000370x10x00
write0x910000380x10x00
write0x1b80x10x01
write0x1c00x10x01
write0x1c80x10x01
write0x1d00x10x01
write0x1d80x10x01
write0x1e00x10x01
write0x1e80x10x01
write0x1f00x10x01
write0x1f80x10x01
write0x2000x10x01
write0x2080x10x01
write0x2100x10x01
write0x2180x10x01
write0x2200x10x01
write0x2280x10x01
write0x9100000d0x10x00
write0x9100000f0x10x10
write0x910000110x10x00
write0x2300x10x01
write0x2380x10x01
write0x2400x10x01
write0x2480x10x01
write0x2500x10x01
write0x2580x10x01
write0x2600x10x01
write0x2680x10x01
write0x2700x10x01
write0x2780x10x01
write0x2800x10x01
write0x2880x10x01
write0x2900x10x01
write0x2980x10x01
write0x2a00x10x01
write0x9100000a0x20x0000
write0x9100000c0x60x010000
write0x2a80x10x01
write0x2b00x10x01
write0x2b80x10x01
write0x2c00x10x01
write0x2c80x10x01
write0x2d00x10x01
write0x2d80x10x01
write0x2e00x10x01
write0x2e80x10x01
write0x2f00x10x01
write0x2f80x10x01
write0x3000x10x01
write0x3080x10x01
write0x3100x10x01
write0x3180x10x01
write0x3200x10x01
write0x3280x10x01
write0x3300x10x01
write0x3380x10x01
write0x3400x10x01
write0x3480x10x01
write0x3500x10x01
write0x3580x10x01
write0x3600x10x01
write0x3680x10x01
write0x3700x10x01
write0x3780x10x01
write0x3800x10x01
write0x3880x10x01
write0x3900x10x01
write0x9100000f0x10x00
write0x910000110x10x00
write0x3980x10x01
write0x3a00x10x01
write0x3a80x10x01
write0x3b00x10x01
write0x3b80x10x21
write0x3bb0x10x01
write0x3c00x10x21
write0x9100000a0x20x0000
write0x9100000c0x60x010000
write0x9100000a0x20x00
write0x9100000c0x60x01
write0x9100000a0x20x0000
write0x9100000c0x60x010000
write0x9100000a0x20x00
write0x9100000c0x60x010000
write0x910000050x10x00
write0x9100000c0x10x00
EOF==== Stack Trace 2 ====
==837609==ERROR: AddressSanitizer: heap-buffer-overflow on address0x615000032280at pc0x564afb30eb6abp0x7ffdda140d90sp0x7ffdda140558
WRITE of size 483589332 at0x615000032280thread T0
#00x564afb30eb69in__asan_memcpy(/home/alxndr/Development/qemu/build/qemu-fuzz-i386+0x2bccb69) #10x564afca598bdinflatview_read_continue/home/alxndr/Development/qemu/build/../softmmu/physmem.c:2846:13#20x564afca5b09binflatview_read/home/alxndr/Development/qemu/build/../softmmu/physmem.c:2879:12#30x564afca5b09binaddress_space_read_full/home/alxndr/Development/qemu/build/../softmmu/physmem.c:2892:18#40x564afbab9e9dindma_memory_rw_relaxed/home/alxndr/Development/qemu/include/sysemu/dma.h:88:12#50x564afbab9e9dindma_memory_rw/home/alxndr/Development/qemu/include/sysemu/dma.h:127:12#60x564afbab9e9dindma_memory_read/home/alxndr/Development/qemu/include/sysemu/dma.h:145:12#70x564afbab9e9dinsdhci_do_adma/home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:809:21#80x564afbab2b81insdhci_data_transfer/home/alxndr/Development/qemu/build/../hw/sd/sdhci.c#90x564afbac2966insdhci_resume_pending_transfer/home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:964:5#100x564afbac2966insdhci_write/home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:1120:9#110x564afc697c6cinmemory_region_write_accessor/home/alxndr/Development/qemu/build/../softmmu/memory.c:491:5==== Repro 3 ====
(There is an identical one for a heap overflow through readldl_he_p. Let me know if it would be useful to provide it):cat << EOF | ./qemu-system-i386 -display none -machine accel=qtest -nographic \
(quoted diff) +0
-3-m 512M -nodefaults -device sdhci-pci,sd-spec-version=3 \ -drive if=sd,index=0,file=null-co://,format=raw,id=mydrive \ -device sd-card,drive=mydrive -qtest stdiooutl
0xcf80x80001010
outl0xcfc0xe0000000
outl0xcf80x80001004
outw0xcfc0x06
write0xe00000040x10x41
write0xe00000060x10x80
write0xe00000280x10x10
write0xe000002c0x10x05
write0x00x10x21
write0x20x10x0a
write0x80x10x01
write0xa0x10x00
write0x100x10x01
write0x120x10x00
write0x180x10x21
write0x1a0x10x16
write0x200x10x01
write0x220x10x00
write0x280x10x01
write0x2a0x10x00
write0x300x10x21
write0x320x10x16
write0x380x10x01
write0x3a0x10x00
write0x400x10x01
write0x420x10x00
write0x480x10x21
write0x4a0x10x16
write0x500x10x01
write0x520x10x00
write0x580x10x01
write0x5a0x10x00
write0x600x10x21
write0x620x10x16
write0x680x10x01
write0x6a0x10x00
write0x700x10x01
write0x720x10x00
write0x780x10x21
write0x800x10x21
write0x820x10x58
write0x880x10x01
write0x8a0x10x00
write0x900x10x01
write0x920x10x00
write0x980x10x21
write0x9a0x10x16
write0xa00x10x21
write0xa80x10x01
write0xaa0x10x00
write0xb00x10x01
write0xb20x10x00
write0xb80x10x21
write0xba0x10x18
write0xc00x10x01
write0xc20x10x00
write0xc80x10x01
write0xca0x10x00
write0xd00x10x21
write0xd20x10x16
write0xd80x10x01
write0xda0x10x00
write0xe00x10x01
write0xe20x10x00
write0xe80x10x21
write0xea0x10x18
write0xf00x10x01
write0xf20x10x00
write0xf80x10x01
write0xfa0x10x00
write0x1000x10x21
write0x1020x10x16
write0x1080x10x01
write0x10a0x10x00
write0x1100x10x01
write0x1120x10x00
write0x1180x10x21
write0x11a0x10x18
write0x1200x10x01
write0x1220x10x00
write0x1280x10x01
write0x12a0x10x00
write0x1300x10x21
write0x1320x10x16
write0x1380x10x01
write0x13a0x10x00
write0x1400x10x01
write0x1420x10x00
write0x1480x10x21
write0x14a0x10x18
write0x1500x10x01
write0x1520x10x00
write0x1580x10x01
write0x15a0x10x00
write0x1600x10x21
write0x1620x10x16
write0xe000000c0x10x01
write0xe000000e0x10x20
write0xe000000f0x10x00
write0x1680x10x21
write0x16d0x10xff
write0x16e0x10xff
write0x16f0x10x1f
write0xe00000000x40x00
write0xe00000040x40x03010000
write0xe00000850x10x00
write0xe00000860x60x00
write0xe000008c0x10x00
write0xe00000000x40x00
write0xe00000040x20x00
write0xe00000380x10x00
EOFStack Trace 3:
=817509==ERROR: AddressSanitizer: heap-buffer-overflow on address0x615000032280at pc0x564afca59f2bbp0x7ffdda140d90sp0x7ffdda140d88
WRITE of size 4 at0x615000032280thread T0
#00x564afca59f2ainstl_he_p/home/alxndr/Development/qemu/include/qemu/bswap.h:353:5
#10x564afca59f2ainstn_he_p/home/alxndr/Development/qemu/include/qemu/bswap.h:546:1
#20x564afca59f2ainflatview_read_continue/home/alxndr/Development/qemu/build/../softmmu/physmem.c:2841:13#30x564afca5b09binflatview_read/home/alxndr/Development/qemu/build/../softmmu/physmem.c:2879:12#40x564afca5b09binaddress_space_read_full/home/alxndr/Development/qemu/build/../softmmu/physmem.c:2892:18
Quoted 8 lines
#5
0x564afbab9e9dindma_memory_rw_relaxed/home/alxndr/Development/qemu/include/sysemu/dma.h:88:12#60x564afbab9e9dindma_memory_rw/home/alxndr/Development/qemu/include/sysemu/dma.h:127:12#70x564afbab9e9dindma_memory_read/home/alxndr/Development/qemu/include/sysemu/dma.h:145:12#80x564afbab9e9dinsdhci_do_adma/home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:809:21#90x564afbab2b81insdhci_data_transfer/home/alxndr/Development/qemu/build/../hw/sd/sdhci.c#100x564afbac2966insdhci_resume_pending_transfer/home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:964:5#110x564afbac2966insdhci_write/home/alxndr/Development/qemu/build/../hw/sd/sdhci.c:1120:9#120x564afc697c6cinmemory_region_write_accessor/home/alxndr/Development/qemu/build/../softmmu/memory.c:491:5
Regards,
Bin
Quoted 26 lines · Bin Meng
Hi Alexander,
Quoted 9 lines · Alexander Bulekov
On 210211 1154, Alexander Bulekov wrote:
...Quoted 6 lines
I applied this along with <[email protected]> "hw/sd/sdhci: Do not modify BlockSizeRegister if transaction in progress"
I ran through the entire OSS-Fuzz corpus, and could not reproduce the crash.
Quoted 6 lines
Quoted 2 lines
Tested-by Alexander Bulekov <[email protected]>Hi Bin,
Phil explained to me that this patch should fix the problem independent of
"hw/sd/sdhci: Do not modify BlockSizeRegister if transaction in progress"Yes, that's what I expect too.
Quoted 4 lines
With only this patch, there are still crashes. Here are three reproducers:
Quoted 6 lines
Quoted 4 lines
Some of these are quite long, so here are pastebins for convenience:
Repro 1: https://paste.debian.net/plain/1185137
Repro 2: https://paste.debian.net/plain/1185141
Repro 3: https://paste.debian.net/plain/1185136I will take a look.
I have figured out a fix and will send out for review and testing soon.
Regards,
Bin