Skip to contentSkip to conversation

net: imx: check buffer descriptor length

PATCH In review P J P 2 participants 3 messages Sep 21, 2016 Arm i.MX and Layerscape

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/1 net: imx: check buffer descriptor length

From: Prasad J Pandit <[email protected]>

i.MX Fast Ethernet Controller uses buffer descriptors to manage data flow to/fro receive & transmit queues. While transmitting packets, it could continue to read buffer descriptors if a buffer descriptor has length of zero. Add check to avoid it.

---
 hw/net/imx_fec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/imx_fec.c +1 -1
index e60e338..31870b0 100644
@@ -276,7 +276,7 @@ static void imx_fec_do_tx(IMXFECState *s)
         imx_fec_read_bd(&bd, addr);
         FEC_PRINTF("tx_bd %x flags %04x len %d data %08x\n",
                    addr, bd.flags, bd.length, bd.data);
-        if ((bd.flags & FEC_BD_R) == 0) {
+        if (!bd.length || (bd.flags & FEC_BD_R) == 0) {
             /* Run out of descriptors to transmit.  */
             break;
         }
Signature · 1 line
2.5.5
#1 lore raw
Quoted 19 lines · P J P

From: Prasad J Pandit <[email protected]>

i.MX Fast Ethernet Controller uses buffer descriptors to manage data flow to/fro receive & transmit queues. While transmitting packets, it could continue to read buffer descriptors if a buffer descriptor has length of zero. Add check to avoid it.

---
 hw/net/imx_fec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/imx_fec.c +0 -0
index e60e338..31870b0 100644

hw/net/imx_fec.c static void imx_fec_do_tx(IMXFECState *s) · line 282

Quoted 8 lines
hw/net/imx_fec.c +1 -1
@@ -276,7 +276,7 @@ static void imx_fec_do_tx(IMXFECState *s)
         imx_fec_read_bd(&bd, addr);
         FEC_PRINTF("tx_bd %x flags %04x len %d data %08x\n",
                    addr, bd.flags, bd.length, bd.data);
-        if ((bd.flags & FEC_BD_R) == 0) {
+        if (!bd.length || (bd.flags & FEC_BD_R) == 0) {
             /* Run out of descriptors to transmit.  */
             break;
         }

Same here---and same bug as the previous patch too:

hw/net/imx_fec.c +1 -1
index 1c415ab..50c7564 100644
@@ -429,7 +429,7 @@ static void imx_fec_do_tx(IMXFECState *s)
         frame_size += len;
         if (bd.flags & ENET_BD_L) {
             /* Last buffer in frame.  */
-            qemu_send_packet(qemu_get_queue(s->nic), frame, len);
+            qemu_send_packet(qemu_get_queue(s->nic), frame, frame_size);
             ptr = frame;
             frame_size = 0;
             s->regs[ENET_EIR] |= ENET_INT_TXF;

Paolo

author
#2 lore raw
+-- On Wed, 21 Sep 2016, Paolo Bonzini wrote --+
| > diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c
| > index e60e338..31870b0 100644
| > --- a/hw/net/imx_fec.c
| > +++ b/hw/net/imx_fec.c
| > @@ -276,7 +276,7 @@ static void imx_fec_do_tx(IMXFECState *s)
| >          imx_fec_read_bd(&bd, addr);
| >          FEC_PRINTF("tx_bd %x flags %04x len %d data %08x\n",
| >                     addr, bd.flags, bd.length, bd.data);
| > -        if ((bd.flags & FEC_BD_R) == 0) {
| > +        if (!bd.length || (bd.flags & FEC_BD_R) == 0) {
| >              /* Run out of descriptors to transmit.  */
| >              break;
| >          }
| > 
| 
| Same here---and same bug as the previous patch too:

Yep, same issue as the other patch.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F