Skip to contentSkip to conversation

hw/dma/pl080: Handle bogus swidth and dwidth in transfers

PATCH In review Peter Maydell 2 participants 3 messages Mar 6

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/dma/pl080: Handle bogus swidth and dwidth in transfers

The PL080 TRM states that the DWidth and SWidth fields of the channel control registers can only validly specify widths up to 32 bits (i.e. values from 0 to 2) and all other values are reserved.

Currently we don't check this, so if the guest specifies an invalid value we will transfer more data into our local 'buff[]' array than it can hold.

Check the widths; since the TRM doesn't clearly specify any behaviour for what to do on invalid values, we choose to log them and then ignore the channel for transfers.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3203

---
 hw/dma/pl080.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
hw/dma/pl080.c +15 -0
index 3f8acb03de..6262c3f3df 100644
@@ -164,6 +164,21 @@ again:
                destination widths are different.  */
             swidth = 1 << ((ch->ctrl >> 18) & 7);
             dwidth = 1 << ((ch->ctrl >> 21) & 7);
+
+            /* Only widths of 1, 2 or 4 are valid */
+            if (swidth > 4) {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "pl080: channel %d: invalid SWidth %d\n",
+                              c, extract32(ch->ctrl, 18, 3));
+                continue;
+            }
+            if (dwidth > 4) {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "pl080: channel %d: invalid DWidth %d\n",
+                              c, extract32(ch->ctrl, 21, 3));
+                continue;
+            }
+
             for (n = 0; n < dwidth; n+= swidth) {
                 address_space_read(&s->downstream_as, ch->src,
                                    MEMTXATTRS_UNSPECIFIED, buff + n, swidth);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 47 lines · Peter Maydell

The PL080 TRM states that the DWidth and SWidth fields of the channel control registers can only validly specify widths up to 32 bits (i.e. values from 0 to 2) and all other values are reserved.

Currently we don't check this, so if the guest specifies an invalid value we will transfer more data into our local 'buff[]' array than it can hold.

Check the widths; since the TRM doesn't clearly specify any behaviour for what to do on invalid values, we choose to log them and then ignore the channel for transfers.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3203

---
 hw/dma/pl080.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
hw/dma/pl080.c +15 -0
index 3f8acb03de..6262c3f3df 100644
@@ -164,6 +164,21 @@ again:
                destination widths are different.  */
             swidth = 1 << ((ch->ctrl >> 18) & 7);
             dwidth = 1 << ((ch->ctrl >> 21) & 7);
+
+            /* Only widths of 1, 2 or 4 are valid */
+            if (swidth > 4) {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "pl080: channel %d: invalid SWidth %d\n",
+                              c, extract32(ch->ctrl, 18, 3));
+                continue;
+            }
+            if (dwidth > 4) {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "pl080: channel %d: invalid DWidth %d\n",
+                              c, extract32(ch->ctrl, 21, 3));
+                continue;
+            }
+
             for (n = 0; n < dwidth; n+= swidth) {
                 address_space_read(&s->downstream_as, ch->src,
                                    MEMTXATTRS_UNSPECIFIED, buff + n, swidth);
Signature · 1 line
2.43.0

Thanks for picking this up, Peter.

#2 lore raw
Quoted 14 lines · Jim MacArthur
Quoted 12 lines · Peter Maydell

The PL080 TRM states that the DWidth and SWidth fields of the channel control registers can only validly specify widths up to 32 bits (i.e. values from 0 to 2) and all other values are reserved.

Currently we don't check this, so if the guest specifies an invalid value we will transfer more data into our local 'buff[]' array than it can hold.

Check the widths; since the TRM doesn't clearly specify any behaviour for what to do on invalid values, we choose to log them and then ignore the channel for transfers.

Quoted 8 lines
Quoted 3 lines

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3203

Thanks for picking this up, Peter.

Thanks.

NB that you need to keep qemu-devel on the cc list as the automated tooling like patchew and patchwork that tracks signoffs only listens to that list. (The rule of thumb is "don't send anything to a sub-list without ccing qemu-devel").

-- PMM