net/colo.c: Fix the pointer issue reported by Coverity.
PATCH v3 1/1 net/colo.c: Fix the pointer issue 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 | 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 )) || + (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
Quoted 24 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 | 18 ++++++++++-------- net/colo.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-)net/colo.c +0
-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;
net/colo.c int parse_packet_early(Packet *pkt) · line 54
Quoted 10 lines
net/colo.c +5
-2+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)) ||
Virtio-net starts to support RSS so it means the vnet_hdr size could be greater than virtio_net_hdr now.
Or did you actually mean "<" here?
Thanks
Quoted 32 lines
net/colo.c +5
-5+ (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 47 lines
-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Tuesday, August 9, 2022 4:12 PM
To: Zhang, Chen <[email protected]>
Cc: Peter Maydell <[email protected]>; Li Zhijian <[email protected]>; qemu-dev <[email protected]>
Subject: Re: [PATCH V3]net/colo.c: Fix the pointer issue reported by Coverity.Quoted 22 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 | 18 ++++++++++-------- net/colo.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-)net/colo.c +0
-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;net/colo.c int parse_packet_early(Packet *pkt) { · line 53
Quoted 10 lines
net/colo.c +5
-2+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)) ||Virtio-net starts to support RSS so it means the
vnet_hdrsize could be greater thanvirtio_net_hdrnow.
Quoted 1 line
Or did you actually mean "<" here?
No, I just try to avoid overflow with a maliciously over-large vnet_hdr_len value as Peter's comments.
If enabled the RSS, how to get the maximum of vnet_hdr size?
Thanks
Chen
Quoted 35 lines
Thanks
Quoted 32 lines
net/colo.c +5
-5+ (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 48 lines · Chen
Quoted 48 lines
-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Tuesday, August 9, 2022 4:12 PM
To: Zhang, Chen <[email protected]>
Cc: Peter Maydell <[email protected]>; Li Zhijian <[email protected]>; qemu-dev <[email protected]>
Subject: Re: [PATCH V3]net/colo.c: Fix the pointer issue reported by Coverity.Quoted 22 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 | 18 ++++++++++-------- net/colo.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-)net/colo.c +0
-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;net/colo.c int parse_packet_early(Packet *pkt) { · line 53
Quoted 10 lines
net/colo.c +5
-2+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)) ||Virtio-net starts to support RSS so it means the
vnet_hdrsize could be greater thanvirtio_net_hdrnow.
Quoted 5 lines
Quoted 1 line
Or did you actually mean "<" here?
No, I just try to avoid overflow with a maliciously over-large
vnet_hdr_lenvalue as Peter's comments.
If enabled the RSS, how to get the maximum ofvnet_hdrsize?
With hash_report the maximum is sizeof(virtio_net_hdr_v1_hash). But it might be extended in the future.
We can probably start from it.
Thanks
Quoted 40 lines
Thanks
ChenQuoted 35 lines
Thanks
Quoted 32 lines
net/colo.c +5
-5+ (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 64 lines
-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Tuesday, August 9, 2022 4:43 PM
To: Zhang, Chen <[email protected]>
Cc: Peter Maydell <[email protected]>; Li Zhijian <[email protected]>; qemu-dev <[email protected]>
Subject: Re: [PATCH V3]net/colo.c: Fix the pointer issue reported by Coverity.Quoted 10 lines · Chen
Quoted 10 lines
-----Original Message-----
From: Jason Wang <[email protected]>
Sent: Tuesday, August 9, 2022 4:12 PM
To: Zhang, Chen <[email protected]>
Cc: Peter Maydell <[email protected]>; Li Zhijian <[email protected]>; qemu-dev <[email protected]>
Subject: Re: [PATCH V3]net/colo.c: Fix the pointer issue reported byCoverity.
Quoted 2 lines
Quoted 2 lines
On Tue, Aug 9, 2022 at 11:05 AM Zhang Chen <[email protected]>
Quoted 7 lines · wrote:
Quoted 7 lines
Quoted 7 lines
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 pointto wrong place.
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
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..4f1b4a61f6 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
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 parsedcorrectly, "
Quoted 10 lines
Quoted 9 lines
net/colo.c int parse_packet_early(Packet *pkt) · line 54
Quoted 4 lines
net/colo.c +4
-0+assert (data); + +/* Check the received vnet_hdr_len then add the offset */ + if ((pkt->vnet_hdr_len > sizeof(struct virtio_net_hdr)) ||Virtio-net starts to support RSS so it means the
vnet_hdrsize could be greater thanvirtio_net_hdrnow.Or did you actually mean "<" here?
Quoted 8 lines
Quoted 3 lines
No, I just try to avoid overflow with a maliciously over-large
vnet_hdr_lenvalue as Peter's comments.
If enabled the RSS, how to get the maximum ofvnet_hdrsize?With
hash_reportthe maximum issizeof(virtio_net_hdr_v1_hash). But it might be extended in the future.We can probably start from it.
Thanks, I will change here to " if ((pkt->vnet_hdr_len > sizeof(virtio_net_hdr_v1_hash)) ||" in next version.
Thanks
Chen
Quoted 44 lines
Thanks
Quoted 10 lines
Thanks
ChenQuoted 6 lines
Thanks
Quoted 3 lines
net/colo.c +3
-0+ (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"
Quoted 30 lines
Quoted 29 lines
Quoted 29 lines
net/colo.c +2
-5"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 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