net/colo.c: Fix the pointer issuse reported by Coverity.
PATCH 1/1 net/colo.c: Fix the pointer issuse reported by Coverity.
When enable 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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
net/colo.c +10 -6
@@ -44,21 +44,25 @@ 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, " -"pkt->vnet_hdr_len" , pkt->vnet_hdr_len); +trace_colo_proxy_main ("COLO-proxy got NULL data packet " );return 1 ; } - l2hdr_len =eth_get_l2_hdr_length (data); -if (pkt->size <ETH_HLEN + pkt->vnet_hdr_len) { -trace_colo_proxy_main ("pkt->size < ETH_HLEN" ); +/* Check the received vnet_hdr_len then add the offset */ +if (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 ; } + data += pkt->vnet_hdr_len; + + l2hdr_len =eth_get_l2_hdr_length (data);/* * TODO: support vlan.
Signature · 1 line
2.25.1
Quoted 19 lines · Zhang Chen
When enable 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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)net/colo.c +0
-0
net/colo.c int parse_packet_early(Packet *pkt) · line 51
Quoted 9 lines
net/colo.c +1
-1@@ -44,21 +44,25 @@ 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 ) {
I wonder under which case we can see data == NULL?
AFAIK, data is either dup via packet_new() or assigned to a pointer to the buf in packet_new_nocopy().
Thanks
Quoted 25 lines
net/colo.c +9
-6-trace_colo_proxy_main_vnet_info ("This packet is not parsed correctly, " -"pkt->vnet_hdr_len" , pkt->vnet_hdr_len); +trace_colo_proxy_main ("COLO-proxy got NULL data packet " );return 1 ; } - l2hdr_len =eth_get_l2_hdr_length (data); -if (pkt->size <ETH_HLEN + pkt->vnet_hdr_len) { -trace_colo_proxy_main ("pkt->size < ETH_HLEN" ); +/* Check the received vnet_hdr_len then add the offset */ +if (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 ; } + data += pkt->vnet_hdr_len; + + l2hdr_len =eth_get_l2_hdr_length (data);/* * TODO: support vlan. -- 2.25.1
Quoted 36 lines
-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Friday, August 5, 2022 11:46 AM
To: Zhang, Chen <[email protected]>
Cc: Peter Maydell <[email protected]>; Li Zhijian <[email protected]>; qemu-dev <[email protected]>
Subject: Re: [PATCH]net/colo.c: Fix the pointer issuse reported by Coverity.Quoted 25 lines · Zhang Chen
When enable 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 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)net/colo.c +1
-1@@ -44,21 +44,25 @@ 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 6 lines
net/colo.c int parse_packet_early(Packet *pkt) · line 51
Quoted 1 line
net/colo.c +0
-0if (data ==NULL ) {I wonder under which case we can see data == NULL?
AFAIK, data is either dup via
packet_new()or assigned to a pointer to the buf inpacket_new_nocopy().
Yes, you are right. I just checked it for hint of bugs. Do you think no need to do it?
Thanks
Chen
Quoted 30 lines
Thanks
net/colo.c int parse_packet_early(Packet *pkt) { · line 51
Quoted 1 line
net/colo.c +0
-1- trace_colo_proxy_main_vnet_info("This packet is not parsed correctly,"
Quoted 25 lines
net/colo.c +10
-5- "pkt->vnet_hdr_len", pkt->vnet_hdr_len); +trace_colo_proxy_main ("COLO-proxy got NULL data packet " );return 1 ; } - l2hdr_len =eth_get_l2_hdr_length (data); -if (pkt->size <ETH_HLEN + pkt->vnet_hdr_len) { -trace_colo_proxy_main ("pkt->size < ETH_HLEN" ); +/* Check the received vnet_hdr_len then add the offset */ +if (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 ; } + data += pkt->vnet_hdr_len; + + l2hdr_len =eth_get_l2_hdr_length (data);/* * TODO: support vlan. -- 2.25.1
Quoted 7 lines · Chen
Quoted 7 lines
-----Original Message-----
From: Jason Wang <[email protected]>
I wonder under which case we can see data == NULL?
Quoted 5 lines
Quoted 2 lines
AFAIK, data is either dup via
packet_new()or assigned to a pointer to the buf inpacket_new_nocopy().Yes, you are right. I just checked it for hint of bugs. Do you think no need to do it?
If you think it is a "should never happen unless QEMU is buggy" case, then
assert(data).
thanks
-- PMM
Quoted 19 lines
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, August 5, 2022 4:53 PM
To: Zhang, Chen <[email protected]>
Cc: Jason Wang <[email protected]>; Li Zhijian <[email protected]>; qemu-dev <[email protected]>
Subject: Re: [PATCH]net/colo.c: Fix the pointer issuse reported by Coverity.Quoted 5 lines · Chen
Quoted 5 lines
-----Original Message-----
From: Jason Wang <[email protected]> I wonder under which casewe
Quoted 2 lines
Quoted 2 lines
can see data == NULL?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
AFAIK, data is either dup via
packet_new()or assigned to a pointer to the buf inpacket_new_nocopy().Yes, you are right. I just checked it for hint of bugs. Do you think no need to do it?
If you think it is a "should never happen unless QEMU is buggy" case, then assert(data).
OK, I will change it to assert() in V2.
Thanks
Chen
Quoted 3 lines
thanks
-- PMM