Skip to contentSkip to conversation

hw/net/can: sja1000 fix buff2frame_bas and buff2frame_pel when dlc is out of std CAN 8 bytes

PATCH Applied Pavel Pisa 3 participants 3 messages Jul 29, 2021 – Aug 2, 2021

lore
Share & tools
lore

Pavel Pisa

author
#0 lore raw

PATCH v2 1/1 hw/net/can: sja1000 fix buff2frame_bas and buff2frame_pel when dlc is out of std CAN 8 bytes

Problem reported by openEuler fuzz-sig group.

The buff2frame_bas function (hw\net\can\can_sja1000.c) infoleak(qemu5.x~qemu6.x) or stack-overflow(qemu 4.x).

---
 hw/net/can/can_sja1000.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/net/can/can_sja1000.c +8 -0
index 42d2f99dfb..34eea684ce 100644
@@ -275,6 +275,10 @@ static void buff2frame_pel(const uint8_t *buff, qemu_can_frame *frame)
     }
     frame->can_dlc = buff[0] & 0x0f;
 
+    if (frame->can_dlc > 8) {
+        frame->can_dlc = 8;
+    }
+
     if (buff[0] & 0x80) { /* Extended */
         frame->can_id |= QEMU_CAN_EFF_FLAG;
         frame->can_id |= buff[1] << 21; /* ID.28~ID.21 */
@@ -311,6 +315,10 @@ static void buff2frame_bas(const uint8_t *buff, qemu_can_frame *frame)
     }
     frame->can_dlc = buff[1] & 0x0f;
 
+    if (frame->can_dlc > 8) {
+        frame->can_dlc = 8;
+    }
+
     for (i = 0; i < frame->can_dlc; i++) {
         frame->data[i] = buff[2 + i];
     }
Signature · 1 line
2.20.1
Reviewed-by on v2 1/1
#1 lore raw

"hw/net/can: sja1000 fix buff2frame* when dlc is out of std CAN 8 bytes"

Quoted 4 lines · Pavel Pisa

Problem reported by openEuler fuzz-sig group.

The buff2frame_bas function (hw\net\can\can_sja1000.c) infoleak(qemu5.x~qemu6.x) or stack-overflow(qemu 4.x).

Quoted 2 lines
Quoted 31 lines
---
 hw/net/can/can_sja1000.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/net/can/can_sja1000.c +8 -0
index 42d2f99dfb..34eea684ce 100644
@@ -275,6 +275,10 @@ static void buff2frame_pel(const uint8_t *buff, qemu_can_frame *frame)
     }
     frame->can_dlc = buff[0] & 0x0f;
 
+    if (frame->can_dlc > 8) {
+        frame->can_dlc = 8;
+    }
+
     if (buff[0] & 0x80) { /* Extended */
         frame->can_id |= QEMU_CAN_EFF_FLAG;
         frame->can_id |= buff[1] << 21; /* ID.28~ID.21 */
@@ -311,6 +315,10 @@ static void buff2frame_bas(const uint8_t *buff, qemu_can_frame *frame)
     }
     frame->can_dlc = buff[1] & 0x0f;
 
+    if (frame->can_dlc > 8) {
+        frame->can_dlc = 8;
+    }
+
     for (i = 0; i < frame->can_dlc; i++) {
         frame->data[i] = buff[2 + i];
     }
Applied
#2 lore raw
Quoted 5 lines · Philippe Mathieu-Daudé

"hw/net/can: sja1000 fix buff2frame* when dlc is out of std CAN 8 bytes"

Quoted 2 lines · Pavel Pisa

Problem reported by openEuler fuzz-sig group.

Quoted 7 lines
Quoted 2 lines

The buff2frame_bas function (hw\net\can\can_sja1000.c) infoleak(qemu5.x~qemu6.x) or stack-overflow(qemu 4.x).

Quoted 2 lines

Applied.

Thanks

Quoted 32 lines
Quoted 32 lines
---
  hw/net/can/can_sja1000.c | 8 ++++++++
  1 file changed, 8 insertions(+)
hw/net/can/can_sja1000.c +8 -0
index 42d2f99dfb..34eea684ce 100644
@@ -275,6 +275,10 @@ static void buff2frame_pel(const uint8_t *buff, qemu_can_frame *frame)
      }
      frame->can_dlc = buff[0] & 0x0f;
 
+    if (frame->can_dlc > 8) {
+        frame->can_dlc = 8;
+    }
+
      if (buff[0] & 0x80) { /* Extended */
          frame->can_id |= QEMU_CAN_EFF_FLAG;
          frame->can_id |= buff[1] << 21; /* ID.28~ID.21 */
@@ -311,6 +315,10 @@ static void buff2frame_bas(const uint8_t *buff, qemu_can_frame *frame)
      }
      frame->can_dlc = buff[1] & 0x0f;
 
+    if (frame->can_dlc > 8) {
+        frame->can_dlc = 8;
+    }
+
      for (i = 0; i < frame->can_dlc; i++) {
          frame->data[i] = buff[2 + i];
      }