Skip to contentSkip to conversation

Fixed integer overflow in e1000e

PATCH Applied [email protected] 4 participants 6 messages Mar 4, 2020 – Mar 17, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Fixed integer overflow in e1000e

From: Andrew Melnychenko <[email protected]>

Fixed setting max_queue_num if there are no peers in NICConf. qemu_new_nic() creates NICState with 1 NetClientState(index 0) without peers, set max_queue_num to 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.

---
 hw/net/e1000e.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/e1000e.c +1 -1
index a91dbdca3c..f2cc1552c5 100644
@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr)
     s->nic = qemu_new_nic(&net_e1000e_info, &s->conf,
         object_get_typename(OBJECT(s)), dev->id, s);
 
-    s->core.max_queue_num = s->conf.peers.queues - 1;
+    s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues - 1 : 0;
 
     trace_e1000e_mac_set_permanent(MAC_ARG(macaddr));
     memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac));
Signature · 1 line
2.24.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · On 3/4/20 3:20 PM, [email protected] wrote:

From: Andrew Melnychenko <[email protected]>

Fixed setting max_queue_num if there are no peers in NICConf. qemu_new_nic() creates NICState with 1 NetClientState(index 0) without peers, set max_queue_num to 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.

Hoping the maintainer taking this can reformat the commit description a bit nicer... (moving the tags down), then for the code part:

Quoted 20 lines
---
  hw/net/e1000e.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/e1000e.c +1 -1
index a91dbdca3c..f2cc1552c5 100644
@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr)
      s->nic = qemu_new_nic(&net_e1000e_info, &s->conf,
          object_get_typename(OBJECT(s)), dev->id, s);
 
-    s->core.max_queue_num = s->conf.peers.queues - 1;
+    s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues - 1 : 0;
 
      trace_e1000e_mac_set_permanent(MAC_ARG(macaddr));
      memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac));
#2 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 5 lines · On 3/4/20 3:20 PM, [email protected] wrote:

From: Andrew Melnychenko <[email protected]>

Fixed setting max_queue_num if there are no peers in NICConf. qemu_new_nic() creates NICState with 1 NetClientState(index 0) without peers, set max_queue_num to 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.

Hoping the maintainer taking this can reformat the commit description a bit nicer... (moving the tags down), then for the code part:

Yes, I tweak the log.

Thanks

Quoted 24 lines
Quoted 20 lines

---
  hw/net/e1000e.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/e1000e.c +1 -0
index a91dbdca3c..f2cc1552c5 100644
@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice 
 *pci_dev, uint8_t *macaddr)
       s->nic = qemu_new_nic(&net_e1000e_info, &s->conf,
           object_get_typename(OBJECT(s)), dev->id, s);
   -    s->core.max_queue_num = s->conf.peers.queues - 1;
+    s->core.max_queue_num = s->conf.peers.queues ? 
 s->conf.peers.queues - 1 : 0;
         trace_e1000e_mac_set_permanent(MAC_ARG(macaddr));

      memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac));

Reviewed-by on v2 1/1
#3 lore raw
In reply to [email protected]
Quoted 9 lines · On 4 Mar 2020, at 16:20, [email protected] wrote:

From: Andrew Melnychenko <[email protected]>

Fixed setting max_queue_num if there are no peers in NICConf. qemu_new_nic() creates NICState with 1 NetClientState(index 0) without peers, set max_queue_num to 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.

Quoted 20 lines

---
hw/net/e1000e.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/e1000e.c +1 -1
index a91dbdca3c..f2cc1552c5 100644
@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr)
    s->nic = qemu_new_nic(&net_e1000e_info, &s->conf,
        object_get_typename(OBJECT(s)), dev->id, s);
 
-    s->core.max_queue_num = s->conf.peers.queues - 1;
+    s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues - 1 : 0;
 
    trace_e1000e_mac_set_permanent(MAC_ARG(macaddr));
    memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac));
Signature · 1 line
2.24.1
Reviewed-by on v2 1/1
#4 lore raw
In reply to [email protected]
Quoted 11 lines · On 4 Mar 2020, at 16:20, [email protected] wrote:

From: Andrew Melnychenko <[email protected]>

Fixed setting max_queue_num if there are no peers in NICConf. qemu_new_nic() creates NICState with 1 NetClientState(index 0) without peers, set max_queue_num to 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.

Quoted 20 lines

---
hw/net/e1000e.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/e1000e.c +1 -1
index a91dbdca3c..f2cc1552c5 100644
@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr)
    s->nic = qemu_new_nic(&net_e1000e_info, &s->conf,
        object_get_typename(OBJECT(s)), dev->id, s);
 
-    s->core.max_queue_num = s->conf.peers.queues - 1;
+    s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues - 1 : 0;
 
    trace_e1000e_mac_set_permanent(MAC_ARG(macaddr));
    memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac));
Signature · 1 line
2.24.1
Applied
#5 lore raw
Quoted 11 lines · Dmitry Fleytman
Quoted 10 lines · On 4 Mar 2020, at 16:20, [email protected] wrote:

From: Andrew Melnychenko <[email protected]>

Fixed setting max_queue_num if there are no peers in NICConf. qemu_new_nic() creates NICState with 1 NetClientState(index 0) without peers, set max_queue_num to 0 - It prevents undefined behavior and possible crashes, especially during pcie hotplug.

Applied.

Thanks

Quoted 21 lines
Quoted 21 lines

---
hw/net/e1000e.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/e1000e.c +1 -1
index a91dbdca3c..f2cc1552c5 100644
@@ -328,7 +328,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr)
     s->nic = qemu_new_nic(&net_e1000e_info, &s->conf,
         object_get_typename(OBJECT(s)), dev->id, s);
 
-    s->core.max_queue_num = s->conf.peers.queues - 1;
+    s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues - 1 : 0;
 
     trace_e1000e_mac_set_permanent(MAC_ARG(macaddr));
     memcpy(s->core.permanent_mac, macaddr, sizeof(s->core.permanent_mac));
Signature · 1 line
2.24.1