fdc: check for illegal dma length calculation
PATCH 1/1 fdc: check for illegal dma length calculation
The function fdctrl_start_transfer() calculates the dma data length wrongly when certain boundary conditions are fulfilled. We have noticed that the if ((fdctrl->fifo[5] - fdctrl->fifo[6]) > 1) we get a dma length that will be interpreted as negative by the next function in the chain, fdctrl_transfer_handler(). This leads to a crash.
Rather than trying to fix this obscure calculation, we just check if the harmful condition is fulfilled, and return without action if that is the case. Since this is a condition that can only be created by a malicious user we deem this solution safe.
This fix is intended to address CVE-2021-3507.
--- hw/block/fdc.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/block/fdc.c +5 -0
@@ -1532,6 +1532,11 @@ static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction)if (fdctrl->fifo[0 ] &0x80 ) tmp += fdctrl->fifo[6 ]; fdctrl->data_len *= tmp; +if (tmp <0 ) { +FLOPPY_DPRINTF ("calculated illegal data_len=%u, tmp=%i\n" , + fdctrl->data_len, tmp); +return ; + } } fdctrl->eot = fdctrl->fifo[6 ];if (fdctrl->dor &FD_DOR_DMAEN ) {
Signature · 1 line
2.31.1
Quoted 24 lines · Jon Maloy
The function
fdctrl_start_transfer()calculates the dma data length wrongly when certain boundary conditions are fulfilled. We have noticed that the if ((fdctrl->fifo[5] - fdctrl->fifo[6]) > 1) we get a dma length that will be interpreted as negative by the next function in the chain,fdctrl_transfer_handler(). This leads to a crash.Rather than trying to fix this obscure calculation, we just check if the harmful condition is fulfilled, and return without action if that is the case. Since this is a condition that can only be created by a malicious user we deem this solution safe.
This fix is intended to address CVE-2021-3507.
Signed-off-by Jon Maloy <[email protected]>--- hw/block/fdc.c | 5 +++++ 1 file changed, 5 insertions(+)hw/block/fdc.c +0
-0@@ -1532,6 +1532,11 @@ static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction)if (fdctrl->fifo[0 ] &0x80 )
hw/block/fdc.c static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction) · line 1542
Quoted 10 lines
hw/block/fdc.c +5
-0tmp += fdctrl->fifo[6 ]; fdctrl->data_len *= tmp; +if (tmp <0 ) { +FLOPPY_DPRINTF ("calculated illegal data_len=%u, tmp=%i\n" , + fdctrl->data_len, tmp); +return ; + } } fdctrl->eot = fdctrl->fifo[6 ];if (fdctrl->dor &FD_DOR_DMAEN ) {
I never received any feedback on this one.
Is there any?
///jon
Hi Jon,
Quoted 6 lines · Jon Maloy
Quoted 5 lines · Jon Maloy
The function
fdctrl_start_transfer()calculates the dma data length wrongly when certain boundary conditions are fulfilled. We have noticed that the if ((fdctrl->fifo[5] - fdctrl->fifo[6]) > 1) we get a dma length that will be interpreted as negative by the next function in the chain,fdctrl_transfer_handler(). This leads to a crash.
If a security issue is reproducible (like the ones found by fuzzers), please include the reproducer along.
Quoted 6 lines
Quoted 6 lines
Rather than trying to fix this obscure calculation, we just check if the harmful condition is fulfilled, and return without action if that is the case. Since this is a condition that can only be created by a malicious user we deem this solution safe.
This fix is intended to address CVE-2021-3507.
Ah, this is similar to:
https://lore.kernel.org/qemu-devel/[email protected]/
which already contains the reproducer...
You might want to review it ;)
Quoted 16 lines
Quoted 16 lines
Signed-off-by Jon Maloy <[email protected]>---
hw/block/fdc.c| 5 +++++1 file changed, 5 insertions(+)hw/block/fdc.c +2
-0@@ -1532,6 +1532,11 @@ static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction) if (fdctrl->fifo[0] & 0x80) tmp += fdctrl->fifo[6]; fdctrl->data_len *= tmp; + if (tmp < 0) { + FLOPPY_DPRINTF("calculated illegal data_len=%u, tmp=%i\n",
Quoted 8 lines
Quoted 6 lines
hw/block/fdc.c +3
-0+ fdctrl->data_len, tmp); + return; + } } fdctrl->eot = fdctrl->fifo[6];if (
fdctrl->dor&FD_DOR_DMAEN) {I never received any feedback on this one.
Is there any?
Probably none so far because you forgot to Cc the maintainers:
$ ./scripts/get_maintainer.pl -f hw/block/fdc.c John Snow <[email protected]> (supporter:Floppy) Kevin Wolf <[email protected]> (supporter:Block layer core) Hanna Reitz <[email protected]> (supporter:Block layer core) [email protected] (open list:Floppy) [email protected] (open list:All patches CC here)
(now Cc'ed).