net/colo.c: Fix the pointer issue reported by Coverity.
PATCH RESEND v4 1/1 net/colo.c: Fix the pointer issue reported by Coverity.
When enabled the virtio-net-pci, guest network packet will load the vnet_hdr. In COLO status, the primary VM's network packet maybe redirect to another VM, it need filter-redirect enable the vnet_hdr flag at the same time, COLO-proxy will correctly parse the original network packet. If have any misconfiguration here, the vnet_hdr_len is wrong for parse the packet, the data+offset will point to wrong place.
--- net/colo.c | 18 ++++++++++-------- net/colo.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-)
net/colo.c +10 -8
@@ -44,21 +44,23 @@ int parse_packet_early(Packet *pkt) {int network_length;static const uint8_t vlan[] = {0x81 ,0x00 }; -uint8_t *data = pkt->data + pkt->vnet_hdr_len; +uint8_t *data = pkt->data;uint16_t l3_proto;ssize_t l2hdr_len; -if (data ==NULL ) { -trace_colo_proxy_main_vnet_info ("This packet is not parsed correctly, " +assert (data); + +/* Check the received vnet_hdr_len then add the offset */ +if ((pkt->vnet_hdr_len >sizeof (struct virtio_net_hdr_v1_hash )) || + (pkt->size <sizeof (struct eth_header ) +sizeof (struct vlan_header ) + + pkt->vnet_hdr_len)) { +trace_colo_proxy_main_vnet_info ("This packet may be load wrong " "pkt->vnet_hdr_len" , pkt->vnet_hdr_len);return 1 ; } - l2hdr_len =eth_get_l2_hdr_length (data); + data += pkt->vnet_hdr_len; -if (pkt->size <ETH_HLEN + pkt->vnet_hdr_len) { -trace_colo_proxy_main ("pkt->size < ETH_HLEN" ); -return 1 ; - } + l2hdr_len =eth_get_l2_hdr_length (data);/* * TODO: support vlan.
net/colo.h +1 -0
@@ -18,6 +18,7 @@#include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "standard-headers/linux/virtio_net.h" #define HASHTABLE_MAX_SIZE 16384
Signature · 1 line
2.25.1
Ping.... Jason and Peter, any comments for this patch?
Thanks
Chen
Quoted 72 lines
-----Original Message-----
From: Zhang, Chen <[email protected]>
Sent: Tuesday, August 9, 2022 4:49 PM
To: Jason Wang <[email protected]>; Peter Maydell <[email protected]>; Li Zhijian <[email protected]>; qemu-dev <[email protected]>
Cc: Zhang, Chen <[email protected]>
Subject: [PATCH V4 RESEND]net/colo.c: Fix the pointer issue reported by Coverity.When enabled the virtio-net-pci, guest network packet will load the
vnet_hdr. In COLO status, the primary VM's network packet maybe redirect to another VM, it need filter-redirect enable thevnet_hdrflag at the same time, COLO- proxy will correctly parse the original network packet. If have any misconfiguration here, thevnet_hdr_lenis wrong for parse the packet, the data+offset will point to wrong place.Signed-off-by Zhang Chen <[email protected]>--- net/colo.c | 18 ++++++++++-------- net/colo.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-)net/colo.c +10
-8@@ -44,21 +44,23 @@ int parse_packet_early(Packet *pkt) {int network_length;static const uint8_t vlan[] = {0x81 ,0x00 }; -uint8_t *data = pkt->data + pkt->vnet_hdr_len; +uint8_t *data = pkt->data;uint16_t l3_proto;ssize_t l2hdr_len; -if (data ==NULL ) { -trace_colo_proxy_main_vnet_info ("This packet is not parsed correctly, " +assert (data); + +/* Check the received vnet_hdr_len then add the offset */ +if ((pkt->vnet_hdr_len >sizeof (struct virtio_net_hdr_v1_hash )) || + (pkt->size <sizeof (struct eth_header ) +sizeof (struct vlan_header ) + + pkt->vnet_hdr_len)) { +trace_colo_proxy_main_vnet_info ("This packet may be load wrong " "pkt->vnet_hdr_len" , pkt->vnet_hdr_len);return 1 ; } - l2hdr_len =eth_get_l2_hdr_length (data); + data += pkt->vnet_hdr_len; -if (pkt->size <ETH_HLEN + pkt->vnet_hdr_len) { -trace_colo_proxy_main ("pkt->size < ETH_HLEN" ); -return 1 ; - } + l2hdr_len =eth_get_l2_hdr_length (data);/* * TODO: support vlan. net/colo.h +1
-1@@ -18,6 +18,7 @@#include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "standard-headers/linux/virtio_net.h" #define HASHTABLE_MAX_SIZE 16384 --2.25.1
Quoted 41 lines · Chen
Ping.... Jason and Peter, any comments for this patch?
Thanks
ChenQuoted 35 lines
-----Original Message-----
From: Zhang, Chen <[email protected]>
Sent: Tuesday, August 9, 2022 4:49 PM
To: Jason Wang <[email protected]>; Peter Maydell <[email protected]>; Li Zhijian <[email protected]>; qemu-dev <[email protected]>
Cc: Zhang, Chen <[email protected]>
Subject: [PATCH V4 RESEND]net/colo.c: Fix the pointer issue reported by Coverity.When enabled the virtio-net-pci, guest network packet will load the
vnet_hdr. In COLO status, the primary VM's network packet maybe redirect to another VM, it need filter-redirect enable thevnet_hdrflag at the same time, COLO- proxy will correctly parse the original network packet. If have any misconfiguration here, thevnet_hdr_lenis wrong for parse the packet, the data+offset will point to wrong place.Signed-off-by Zhang Chen <[email protected]>--- net/colo.c | 18 ++++++++++-------- net/colo.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-)net/colo.c +1
-1@@ -44,21 +44,23 @@ int parse_packet_early(Packet *pkt) {int network_length;static const uint8_t vlan[] = {0x81 ,0x00 }; -uint8_t *data = pkt->data + pkt->vnet_hdr_len; +uint8_t *data = pkt->data;uint16_t l3_proto;ssize_t l2hdr_len;
Quoted 10 lines
net/colo.c int parse_packet_early(Packet *pkt) · line 58
Quoted 10 lines
net/colo.c +7
-2-if (data ==NULL ) { -trace_colo_proxy_main_vnet_info ("This packet is not parsed correctly, " +assert (data); + +/* Check the received vnet_hdr_len then add the offset */ +if ((pkt->vnet_hdr_len >sizeof (struct virtio_net_hdr_v1_hash )) || + (pkt->size <sizeof (struct eth_header ) +sizeof (struct vlan_header ) + + pkt->vnet_hdr_len)) { +trace_colo_proxy_main_vnet_info ("This packet may be load wrong " "pkt->vnet_hdr_len" , pkt->vnet_hdr_len);
Nit: I think we need to be verbose here, e.g put the pkt_size here at least.
Thanks
Quoted 28 lines
Quoted 27 lines
net/colo.c +2
-5return 1 ; } - l2hdr_len =eth_get_l2_hdr_length (data); + data += pkt->vnet_hdr_len; -if (pkt->size <ETH_HLEN + pkt->vnet_hdr_len) { -trace_colo_proxy_main ("pkt->size < ETH_HLEN" ); -return 1 ; - } + l2hdr_len =eth_get_l2_hdr_length (data);/* * TODO: support vlan. net/colo.h +1
-1@@ -18,6 +18,7 @@#include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "standard-headers/linux/virtio_net.h" #define HASHTABLE_MAX_SIZE 16384 --2.25.1
Quoted 68 lines
-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Thursday, August 18, 2022 4:04 PM
To: Zhang, Chen <[email protected]>
Cc: Peter Maydell <[email protected]>; Li Zhijian <[email protected]>; qemu-dev <[email protected]>
Subject: Re: [PATCH V4 RESEND]net/colo.c: Fix the pointer issue reported by Coverity.Quoted 17 lines · Chen
Ping.... Jason and Peter, any comments for this patch?
Thanks
ChenQuoted 11 lines
-----Original Message-----
From: Zhang, Chen <[email protected]>
Sent: Tuesday, August 9, 2022 4:49 PM
To: Jason Wang <[email protected]>; Peter Maydell <[email protected]>; Li Zhijian <[email protected]>; qemu-dev <[email protected]>
Cc: Zhang, Chen <[email protected]>
Subject: [PATCH V4 RESEND]net/colo.c: Fix the pointer issue reported by Coverity.When enabled the virtio-net-pci, guest network packet will load the
vnet_hdr.Quoted 25 lines
Quoted 25 lines
In COLO status, the primary VM's network packet maybe redirect to another VM, it need filter-redirect enable the
vnet_hdrflag at the same time, COLO- proxy will correctly parse the original network packet. If have any misconfiguration here, thevnet_hdr_lenis wrong for parse the packet, the
data+offset will point to wrong place.Signed-off-by Zhang Chen <[email protected]>--- net/colo.c | 18 ++++++++++-------- net/colo.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-)net/colo.c index 6b0ff562ad..2b5568fff4 renamed from net/colo.c +0
-0100644
net/colo.c +1
-1@@ -44,21 +44,23 @@ int parse_packet_early(Packet *pkt) {int network_length;static const uint8_t vlan[] = {0x81 ,0x00 }; -uint8_t *data = pkt->data + pkt->vnet_hdr_len; +uint8_t *data = pkt->data;uint16_t l3_proto;ssize_t l2hdr_len;Quoted 2 lines
net/colo.c int parse_packet_early(Packet *pkt) { · line 51
Quoted 2 lines
net/colo.c +0
-2-if (data ==NULL ) { - trace_colo_proxy_main_vnet_info("This packet is not parsed correctly,"
Quoted 9 lines
net/colo.c int parse_packet_early(Packet *pkt)
Quoted 9 lines
net/colo.c +7
-0+assert (data); + +/* Check the received vnet_hdr_len then add the offset */ +if ((pkt->vnet_hdr_len >sizeof (struct virtio_net_hdr_v1_hash )) || + (pkt->size <sizeof (struct eth_header ) +sizeof (struct vlan_header ) + + pkt->vnet_hdr_len)) { +trace_colo_proxy_main_vnet_info ("This packet may be load wrong " "pkt->vnet_hdr_len" , pkt->vnet_hdr_len);
Quoted 1 line
Nit: I think we need to be verbose here, e.g put the
pkt_sizehere at least.
OK, I will change here to:
/*
* The received remote packet maybe misconfiguration here,
* Please enable/disable filter module's the vnet_hdr flag at the same time. */
trace_colo_proxy_main_vnet_info("This received packet load wrong "
"pkt->vnet_hdr_len", pkt->vnet_hdr_len, pkt->size);
Thanks
Chen
Quoted 31 lines
Thanks
Quoted 28 lines
Quoted 27 lines
net/colo.c +2
-5return 1 ; } - l2hdr_len =eth_get_l2_hdr_length (data); + data += pkt->vnet_hdr_len; -if (pkt->size <ETH_HLEN + pkt->vnet_hdr_len) { -trace_colo_proxy_main ("pkt->size < ETH_HLEN" ); -return 1 ; - } + l2hdr_len =eth_get_l2_hdr_length (data);/* * TODO: support vlan. net/colo.h index 8b3e8d5a83..22fc3031f7 renamed from net/colo.h +0
-0100644
net/colo.h +1
-1@@ -18,6 +18,7 @@#include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "standard-headers/linux/virtio_net.h" #define HASHTABLE_MAX_SIZE 16384 --2.25.1