Skip to contentSkip to conversation

sd: sdhci: check data length during dma_memory_read

PATCH Applied P J P 2 participants 3 messages Jan 30, 2017 – Feb 3, 2017

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/1 sd: sdhci: check data length during dma_memory_read

From: Prasad J Pandit <[email protected]>

While doing multi block SDMA transfer in routine 'sdhci_sdma_transfer_multi_blocks', the 's->fifo_buffer' starting index 'begin' and data length 's->data_count' could end up to be same. This could lead to an OOB access issue. Correct transfer data length to avoid it.

---
 hw/sd/sdhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sdhci.c +1 -1
index 01fbf22..5bd5ab6 100644
@@ -536,7 +536,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
                 boundary_count -= block_size - begin;
             }
             dma_memory_read(&address_space_memory, s->sdmasysad,
-                            &s->fifo_buffer[begin], s->data_count);
+                            &s->fifo_buffer[begin], s->data_count - begin);
             s->sdmasysad += s->data_count - begin;
             if (s->data_count == block_size) {
                 for (n = 0; n < block_size; n++) {
Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · P J P

From: Prasad J Pandit <[email protected]>

While doing multi block SDMA transfer in routine 'sdhci_sdma_transfer_multi_blocks', the 's->fifo_buffer' starting index 'begin' and data length 's->data_count' could end up to be same. This could lead to an OOB access issue. Correct transfer data length to avoid it.

---
 hw/sd/sdhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sdhci.c +0 -0
index 01fbf22..5bd5ab6 100644

hw/sd/sdhci.c static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s) · line 542

Quoted 8 lines
hw/sd/sdhci.c +1 -1
@@ -536,7 +536,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
                 boundary_count -= block_size - begin;
             }
             dma_memory_read(&address_space_memory, s->sdmasysad,
-                            &s->fifo_buffer[begin], s->data_count);
+                            &s->fifo_buffer[begin], s->data_count - begin);
             s->sdmasysad += s->data_count - begin;
             if (s->data_count == block_size) {
                 for (n = 0; n < block_size; n++) {

thanks
-- PMM

#2 lore raw
Quoted 15 lines · Peter Maydell
Quoted 14 lines · P J P

From: Prasad J Pandit <[email protected]>

While doing multi block SDMA transfer in routine 'sdhci_sdma_transfer_multi_blocks', the 's->fifo_buffer' starting index 'begin' and data length 's->data_count' could end up to be same. This could lead to an OOB access issue. Correct transfer data length to avoid it.

---
 hw/sd/sdhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

hw/sd/sdhci.c static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s) · line 542

Quoted 13 lines
hw/sd/sdhci.c +1 -1
index 01fbf22..5bd5ab6 100644
@@ -536,7 +536,7 @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
                 boundary_count -= block_size - begin;
             }
             dma_memory_read(&address_space_memory, s->sdmasysad,
-                            &s->fifo_buffer[begin], s->data_count);
+                            &s->fifo_buffer[begin], s->data_count - begin);
             s->sdmasysad += s->data_count - begin;
             if (s->data_count == block_size) {
                 for (n = 0; n < block_size; n++) {

Applied to target-arm.next, thanks.

-- PMM