Skip to contentSkip to conversation

net: mipsnet: check packet length against buffer

PATCH Superseded P J P 3 participants 6 messages Apr 7, 2016 – Apr 26, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/1 net: mipsnet: check packet length against buffer

From: Prasad J Pandit <[email protected]>

When receiving packets over MIPSnet network device, it uses
receive buffer of size 1514 bytes. In case the controller
accepts large(MTU) packets, it could lead to memory corruption. Add check to avoid it.

Reported by: Oleksandr Bazhaniuk <[email protected]>

---
 hw/net/mipsnet.c | 3 +++
 1 file changed, 3 insertions(+)
hw/net/mipsnet.c +3 -0
index f261011..e134b31 100644
@@ -82,6 +82,9 @@ static ssize_t mipsnet_receive(NetClientState *nc, const uint8_t *buf, size_t si
     if (!mipsnet_can_receive(nc))
         return 0;
 
+    if (size >= sizeof(s->rx_buffer)) {
+        return 0;
+    }
     s->busy = 1;
 
     /* Just accept everything. */
Signature · 1 line
2.5.5
#1 lore raw
Quoted 19 lines · P J P

From: Prasad J Pandit <[email protected]>

When receiving packets over MIPSnet network device, it uses
receive buffer of size 1514 bytes. In case the controller
accepts large(MTU) packets, it could lead to memory corruption. Add check to avoid it.

Reported by: Oleksandr Bazhaniuk <[email protected]>

---
 hw/net/mipsnet.c | 3 +++
 1 file changed, 3 insertions(+)
hw/net/mipsnet.c +0 -0
index f261011..e134b31 100644

hw/net/mipsnet.c static ssize_t mipsnet_receive(NetClientState *nc, const uint8_t *buf, size_t si · line 90

Quoted 9 lines
hw/net/mipsnet.c +3 -0
@@ -82,6 +82,9 @@ static ssize_t mipsnet_receive(NetClientState *nc, const uint8_t *buf, size_t si
     if (!mipsnet_can_receive(nc))
         return 0;
 
+    if (size >= sizeof(s->rx_buffer)) {
+        return 0;
+    }
     s->busy = 1;
 
     /* Just accept everything. */

Prompted by Peter Maydell's review of the buddy patch to stellaris_enet:
What does the physical device do when it receives such a packet?

author
#2 lore raw
+-- On Thu, 7 Apr 2016, Markus Armbruster wrote --+
| P J P <[email protected]> writes:
| 
| > --- a/hw/net/mipsnet.c
| > +++ b/hw/net/mipsnet.c
| > @@ -82,6 +82,9 @@ static ssize_t mipsnet_receive(NetClientState *nc, const uint8_t *buf, size_t si
| >      if (!mipsnet_can_receive(nc))
| >          return 0;
| >  
| > +    if (size >= sizeof(s->rx_buffer)) {
| > +        return 0;
| > +    }
| >      s->busy = 1;
| 
| Prompted by Peter Maydell's review of the buddy patch to stellaris_enet: 
| What does the physical device do when it receives such a packet?

I tried to find a device specification, but couldn't find any reference
MIPSnet.

Jason, wdyt?
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

#3 lore raw
Quoted 17 lines · P J P
+-- On Thu, 7 Apr 2016, Markus Armbruster wrote --+
| P J P <[email protected]> writes:
| 
| > --- a/hw/net/mipsnet.c
| > +++ b/hw/net/mipsnet.c
| > @@ -82,6 +82,9 @@ static ssize_t mipsnet_receive(NetClientState *nc, const uint8_t *buf, size_t si
| >      if (!mipsnet_can_receive(nc))
| >          return 0;
| >  
| > +    if (size >= sizeof(s->rx_buffer)) {
| > +        return 0;
| > +    }
| >      s->busy = 1;
| 
| Prompted by Peter Maydell's review of the buddy patch to stellaris_enet: 
| What does the physical device do when it receives such a packet?
Quoted 4 lines

I tried to find a device specification, but couldn't find any reference
MIPSnet.

Jason, wdyt?

Can't find either. Looking at kernel driver git logs, the driver was even removed since 2012 because it was not longer supported by MIPS. Consider it indeed fixes a memory corruption, I tend to apply this first for 2.6.

Quoted 4 lines

--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

author
#4 lore raw
+-- On Mon, 11 Apr 2016, Jason Wang wrote --+
| Can't find either. Looking at kernel driver git logs, the driver was even 
| removed since 2012 because it was not longer supported by MIPS. Consider it 
| indeed fixes a memory corruption, I tend to apply this first for 2.6.

Okay, thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

#5 lore raw
In reply to P J P
Quoted 19 lines · P J P

From: Prasad J Pandit <[email protected]>

When receiving packets over MIPSnet network device, it uses
receive buffer of size 1514 bytes. In case the controller
accepts large(MTU) packets, it could lead to memory corruption. Add check to avoid it.

Reported by: Oleksandr Bazhaniuk <[email protected]>

---
 hw/net/mipsnet.c | 3 +++
 1 file changed, 3 insertions(+)
hw/net/mipsnet.c +0 -0
index f261011..e134b31 100644

hw/net/mipsnet.c static ssize_t mipsnet_receive(NetClientState *nc, const uint8_t *buf, size_t si · line 90

Quoted 9 lines
hw/net/mipsnet.c +3 -0
@@ -82,6 +82,9 @@ static ssize_t mipsnet_receive(NetClientState *nc, const uint8_t *buf, size_t si
     if (!mipsnet_can_receive(nc))
         return 0;
 
+    if (size >= sizeof(s->rx_buffer)) {
+        return 0;
+    }
     s->busy = 1;
 
     /* Just accept everything. */

Apply to net-next.

Thanks