Skip to contentSkip to conversation

net: vmxnet: use g_new for pkt initialisation

PATCH Applied P J P 3 participants 3 messages Aug 16, 2016 – Aug 18, 2016

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH v2 1/1 net: vmxnet: use g_new for pkt initialisation

From: Li Qiang <[email protected]>

When network transport abstraction layer initialises pkt, the maximum fragmentation count is not checked. This could lead to an integer overflow causing a NULL pointer dereference. Replace g_malloc() with g_new() to catch the multiplication overflow.

---
 hw/net/net_tx_pkt.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Update as per review:
-> https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg02544.html

hw/net/net_tx_pkt.c +2 -3
index 53dfaa2..20b2549 100644
@@ -65,10 +65,9 @@ void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev,
 
     p->pci_dev = pci_dev;
 
-    p->vec = g_malloc((sizeof *p->vec) *
-        (max_frags + NET_TX_PKT_PL_START_FRAG));
+    p->vec = g_new(struct iovec, max_frags + NET_TX_PKT_PL_START_FRAG);
 
-    p->raw = g_malloc((sizeof *p->raw) * max_frags);
+    p->raw = g_new(struct iovec, max_frags);
 
     p->max_payload_frags = max_frags;
     p->max_raw_frags = max_frags;
Signature · 1 line
2.5.5
Acked-by on v2 1/1
#1 lore raw
Quoted 38 lines · P J P

From: Li Qiang <[email protected]>

When network transport abstraction layer initialises pkt, the maximum fragmentation count is not checked. This could lead to an integer overflow causing a NULL pointer dereference. Replace g_malloc() with g_new() to catch the multiplication overflow.

---
hw/net/net_tx_pkt.c | 5 ++---

1 file changed, 2 insertions(+), 3 deletions(-)

Update as per review:
-> https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg02544.html

hw/net/net_tx_pkt.c +2 -3
index 53dfaa2..20b2549 100644
@@ -65,10 +65,9 @@ void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev,
 
    p->pci_dev = pci_dev;
 
-    p->vec = g_malloc((sizeof *p->vec) *
-        (max_frags + NET_TX_PKT_PL_START_FRAG));
+    p->vec = g_new(struct iovec, max_frags + NET_TX_PKT_PL_START_FRAG);
 
-    p->raw = g_malloc((sizeof *p->raw) * max_frags);
+    p->raw = g_new(struct iovec, max_frags);
 
    p->max_payload_frags = max_frags;
    p->max_raw_frags = max_frags;
Signature · 1 line
2.5.5
Applied
#2 lore raw
Quoted 32 lines · Dmitry Fleytman
Quoted 30 lines · P J P

From: Li Qiang <[email protected]>

When network transport abstraction layer initialises pkt, the maximum fragmentation count is not checked. This could lead to an integer overflow causing a NULL pointer dereference. Replace g_malloc() with g_new() to catch the multiplication overflow.

---
hw/net/net_tx_pkt.c | 5 ++---

1 file changed, 2 insertions(+), 3 deletions(-)

Update as per review:
-> https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg02544.html

hw/net/net_tx_pkt.c +1 -2
index 53dfaa2..20b2549 100644
@@ -65,10 +65,9 @@ void net_tx_pkt_init(struct NetTxPkt **pkt, PCIDevice *pci_dev,
 
     p->pci_dev = pci_dev;
 
-    p->vec = g_malloc((sizeof *p->vec) *
-        (max_frags + NET_TX_PKT_PL_START_FRAG));
+    p->vec = g_new(struct iovec, max_frags + NET_TX_PKT_PL_START_FRAG);
 
Quoted 8 lines
Quoted 8 lines
hw/net/net_tx_pkt.c +1 -1
-    p->raw = g_malloc((sizeof *p->raw) * max_frags);
+    p->raw = g_new(struct iovec, max_frags);
 
     p->max_payload_frags = max_frags;
     p->max_raw_frags = max_frags;
Signature · 1 line
2.5.5

Applied, thanks.