net/virtio: fix Rx checksum calculation
PATCH 1/1 net/virtio: fix Rx checksum calculation
From: Olivier Matz <[email protected]>
If hdr->csum_start is larger than packet length, the len argument passed to rte_raw_cksum_mbuf() overflows and causes a segmentation fault.
Ignore checksum computation in this case.
CVE-2024-11614
--- lib/vhost/virtio_net.c | 3 +++ 1 file changed, 3 insertions(+)
lib/vhost/virtio_net.c +3 -0
@@ -2823,6 +2823,9 @@ vhost_dequeue_offload(struct virtio_net *dev, struct virtio_net_hdr *hdr,*/ uint16_t csum =0 , off; +if (hdr->csum_start >=rte_pktmbuf_pkt_len (m)) +return ; +if (rte_raw_cksum_mbuf (m, hdr->csum_start,rte_pktmbuf_pkt_len (m) - hdr->csum_start, &csum) <0 )return ;
Signature · 1 line
2.47.0
Quoted 32 lines
-----Original Message-----
From: Maxime Coquelin [mailto:[email protected]]
Sent: Tuesday, December 17, 2024 11:33 PM
To: [email protected]
Cc: Olivier Matz <[email protected]>; Maxime Gouin <[email protected]>; Maxime Coquelin <[email protected]>
Subject: [PATCH] net/virtio: fix Rx checksum calculationFrom: Olivier Matz <[email protected]>
If
hdr->csum_startis larger than packet length, the len argument passed torte_raw_cksum_mbuf()overflows and causes a segmentation fault.Ignore checksum computation in this case.
CVE-2024-11614
Fixes ca7036b4af3a ("vhost: fix offload flags in Rx path")Signed-off-by Maxime Gouin <[email protected]>Signed-off-by Olivier Matz <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>--- lib/vhost/virtio_net.c | 3 +++ 1 file changed, 3 insertions(+)lib/vhost/virtio_net.c +0
-0
lib/vhost/virtio_net.c vhost_dequeue_offload(struct virtio_net *dev, · line 2829
Quoted 7 lines
lib/vhost/virtio_net.c +3
-0@@ -2823,6 +2823,9 @@ vhost_dequeue_offload(struct virtio_net *dev,struct virtio_net_hdr *hdr, */ uint16_t csum =0 , off; +if (hdr->csum_start >=rte_pktmbuf_pkt_len (m)) +return ; +
The hdr->csum_start does two successive reads from user space to read a variable length data structure. The result overflow if the data structure changes between the two reads.
We can prevent double fetch issue by using the temporary variable csum_start.
Thanks,
Yunjian
Quoted 6 lines
lib/vhost/virtio_net.c +0
-0if (rte_raw_cksum_mbuf(m, hdr->csum_start, rte_pktmbuf_pkt_len(m) - hdr->csum_start, &csum) <0)
return;
--
2.47.0
Hi,
Quoted 44 lines · Wangyunjian(wangyunjian,TongTu)
Quoted 32 lines
-----Original Message-----
From: Maxime Coquelin [mailto:[email protected]]
Sent: Tuesday, December 17, 2024 11:33 PM
To: [email protected]
Cc: Olivier Matz <[email protected]>; Maxime Gouin <[email protected]>; Maxime Coquelin <[email protected]>
Subject: [PATCH] net/virtio: fix Rx checksum calculationFrom: Olivier Matz <[email protected]>
If
hdr->csum_startis larger than packet length, the len argument passed torte_raw_cksum_mbuf()overflows and causes a segmentation fault.Ignore checksum computation in this case.
CVE-2024-11614
Fixes ca7036b4af3a ("vhost: fix offload flags in Rx path")Signed-off-by Maxime Gouin <[email protected]>Signed-off-by Olivier Matz <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>--- lib/vhost/virtio_net.c | 3 +++ 1 file changed, 3 insertions(+)lib/vhost/virtio_net.c +0
-0lib/vhost/virtio_net.c vhost_dequeue_offload(struct virtio_net *dev, · line 2829
Quoted 7 lines
lib/vhost/virtio_net.c +3
-0@@ -2823,6 +2823,9 @@ vhost_dequeue_offload(struct virtio_net *dev,struct virtio_net_hdr *hdr, */ uint16_t csum =0 , off; +if (hdr->csum_start >=rte_pktmbuf_pkt_len (m)) +return ; +The
hdr->csum_startdoes two successive reads from user space to read a variable length data structure. The result overflow if the data structure changes between the two reads.
Quoted 1 line
We can prevent double fetch issue by using the temporary variable
csum_start.
Right, that's a good catch! The exploitation od this issue seem difficult though.
We may systematically copy the full header, as we only do it for ones not contiguous in host VA space.
What do you think? Are you willing to contribute a fix?
Thanks,
Maxime
Quoted 11 lines
Thanks,
YunjianQuoted 6 lines
lib/vhost/virtio_net.c +0
-0if (rte_raw_cksum_mbuf(m, hdr->csum_start, rte_pktmbuf_pkt_len(m) - hdr->csum_start, &csum) <0)
return;
--
2.47.0
Hi,
Quoted 48 lines · Maxime Coquelin
Hi,
Quoted 45 lines · Wangyunjian(wangyunjian,TongTu)
Quoted 32 lines
-----Original Message-----
From: Maxime Coquelin [mailto:[email protected]]
Sent: Tuesday, December 17, 2024 11:33 PM
To: [email protected]
Cc: Olivier Matz <[email protected]>; Maxime Gouin <[email protected]>; Maxime Coquelin <[email protected]>
Subject: [PATCH] net/virtio: fix Rx checksum calculationFrom: Olivier Matz <[email protected]>
If
hdr->csum_startis larger than packet length, the len argument passed torte_raw_cksum_mbuf()overflows and causes a segmentation fault.Ignore checksum computation in this case.
CVE-2024-11614
Fixes ca7036b4af3a ("vhost: fix offload flags in Rx path")Signed-off-by Maxime Gouin <[email protected]>Signed-off-by Olivier Matz <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>--- lib/vhost/virtio_net.c | 3 +++ 1 file changed, 3 insertions(+)lib/vhost/virtio_net.c +0
-0lib/vhost/virtio_net.c vhost_dequeue_offload(struct virtio_net *dev, · line 2829
Quoted 7 lines
lib/vhost/virtio_net.c +3
-0@@ -2823,6 +2823,9 @@ vhost_dequeue_offload(struct virtio_net *dev,struct virtio_net_hdr *hdr, */ uint16_t csum =0 , off; +if (hdr->csum_start >=rte_pktmbuf_pkt_len (m)) +return ; +The
hdr->csum_startdoes two successive reads from user space to read a variable length data structure. The result overflow if the data structure changes between the two reads.We can prevent double fetch issue by using the temporary variable
csum_start.
This is an interesting remark, thanks!
However, in practical, I'd say that the hdr->csum_start is fetched in a register only once if using optimized compilation, because the compiler has no reason to think that hdr->csum_start can be modified.
Olivier
Quoted 23 lines
Right, that's a good catch! The exploitation od this issue seem difficult though.
We may systematically copy the full header, as we only do it for ones not contiguous in host VA space.
What do you think? Are you willing to contribute a fix?
Thanks,
MaximeQuoted 11 lines
Thanks,
YunjianQuoted 6 lines
lib/vhost/virtio_net.c +0
-0if (rte_raw_cksum_mbuf(m, hdr->csum_start, rte_pktmbuf_pkt_len(m) - hdr->csum_start, &csum) <0)
return;
--
2.47.0
Quoted 52 lines · On Wed, 18 Dec 2024 10:20:47 +0100 Olivier Matz <[email protected]> wrote:
Hi,
Quoted 48 lines · Maxime Coquelin
Hi,
Quoted 45 lines · Wangyunjian(wangyunjian,TongTu)
Quoted 32 lines
-----Original Message-----
From: Maxime Coquelin [mailto:[email protected]]
Sent: Tuesday, December 17, 2024 11:33 PM
To: [email protected]
Cc: Olivier Matz <[email protected]>; Maxime Gouin <[email protected]>; Maxime Coquelin <[email protected]>
Subject: [PATCH] net/virtio: fix Rx checksum calculationFrom: Olivier Matz <[email protected]>
If
hdr->csum_startis larger than packet length, the len argument passed torte_raw_cksum_mbuf()overflows and causes a segmentation fault.Ignore checksum computation in this case.
CVE-2024-11614
Fixes ca7036b4af3a ("vhost: fix offload flags in Rx path")Signed-off-by Maxime Gouin <[email protected]>Signed-off-by Olivier Matz <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>--- lib/vhost/virtio_net.c | 3 +++ 1 file changed, 3 insertions(+)lib/vhost/virtio_net.c +0
-0lib/vhost/virtio_net.c vhost_dequeue_offload(struct virtio_net *dev, · line 2829
Quoted 7 lines
lib/vhost/virtio_net.c +3
-0@@ -2823,6 +2823,9 @@ vhost_dequeue_offload(struct virtio_net *dev,struct virtio_net_hdr *hdr, */ uint16_t csum =0 , off; +if (hdr->csum_start >=rte_pktmbuf_pkt_len (m)) +return ; +The
hdr->csum_startdoes two successive reads from user space to read a variable length data structure. The result overflow if the data structure changes between the two reads.We can prevent double fetch issue by using the temporary variable
csum_start.
Quoted 7 lines
This is an interesting remark, thanks!
However, in practical, I'd say that the
hdr->csum_startis fetched in a register only once if using optimized compilation, because the compiler has no reason to think thathdr->csum_startcan be modified.Olivier
True, but security never depend on optimization.
Needs a fetch and compiler barrier to be truly safe against compilers.
Quoted 47 lines · Maxime Coquelin
Hi,
Quoted 44 lines · Wangyunjian(wangyunjian,TongTu)
Quoted 32 lines
-----Original Message-----
From: Maxime Coquelin [mailto:[email protected]]
Sent: Tuesday, December 17, 2024 11:33 PM
To: [email protected]
Cc: Olivier Matz <[email protected]>; Maxime Gouin <[email protected]>; Maxime Coquelin <[email protected]>
Subject: [PATCH] net/virtio: fix Rx checksum calculationFrom: Olivier Matz <[email protected]>
If
hdr->csum_startis larger than packet length, the len argument passed torte_raw_cksum_mbuf()overflows and causes a segmentation fault.Ignore checksum computation in this case.
CVE-2024-11614
Fixes ca7036b4af3a ("vhost: fix offload flags in Rx path")Signed-off-by Maxime Gouin <[email protected]>Signed-off-by Olivier Matz <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>---
lib/vhost/virtio_net.c| 3 +++1 file changed, 3 insertions(+)lib/vhost/virtio_net.c +0
-0lib/vhost/virtio_net.c vhost_dequeue_offload(struct virtio_net *dev, · line 2829
Quoted 7 lines
lib/vhost/virtio_net.c +3
-0@@ -2823,6 +2823,9 @@ vhost_dequeue_offload(struct virtio_net *dev,struct virtio_net_hdr *hdr, */ uint16_t csum = 0, off; + if (hdr->csum_start >= rte_pktmbuf_pkt_len(m)) + return; +The
hdr->csum_startdoes two successive reads from user space to read a variable length data structure. The result overflow if the data structure changes between the two reads.
You don't know if the resulting object code will perform one, two or more loads from memory.
If you want to be sure it's exactly one load, you need to go through a volatile pointer. This seems like a use case for RTE_READ_ONCE() (which doesn't exist).
An alternative is to do a relaxed atomic load, which is really what you ask for.
Quoted 2 lines
Quoted 1 line
We can prevent double fetch issue by using the temporary variable
csum_start.
I don't think that makes a difference. The compiler is still free to generate object code which load from the same location multiple times.
Quoted 6 lines
Right, that's a good catch! The exploitation od this issue seem difficult though.
We may systematically copy the full header, as we only do it for ones not contiguous in host VA space.
I think you would need to go through a volatile pointer here as well, to make sure the copy actually occur. At least if the target is stack-allocated object.
Quoted 16 lines
What do you think? Are you willing to contribute a fix?
Thanks,
MaximeQuoted 11 lines
Thanks,
YunjianQuoted 6 lines
lib/vhost/virtio_net.c +0
-0if (rte_raw_cksum_mbuf(m, hdr->csum_start,
rte_pktmbuf_pkt_len(m)-hdr->csum_start, &csum) <
0)
return;Signature · 1 line
2.47.0