net: check that seg is valid before dereference
PATCH 1/1 net: check that seg is valid before dereference
If the overall pkt_len and segment lengths are out of agreement, it is possible for the seg to be NULL after the loop. Add assert to check this condition in debug builds.
--- lib/librte_net/rte_ip.h | 1 + 1 file changed, 1 insertion(+)
lib/librte_net/rte_ip.h +1 -0
@@ -225,6 +225,7 @@ rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len,break ; off -= seglen; } +RTE_ASSERT (seg !=NULL ); seglen -= off; buf = rte_pktmbuf_mtod_offset(seg, const char *, off);if (seglen >= len) {
Signature · 1 line
2.26.2
Quoted 23 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Chas Williams
Sent: Monday, September 28, 2020 11:32 PM
To: [email protected]
Cc: [email protected]; Chas Williams <[email protected]>
Subject: [dpdk-dev] [PATCH] net: check that seg is valid before dereferenceIf the overall
pkt_lenand segment lengths are out of agreement, it is possible for the seg to be NULL after the loop. Add assert to check this condition in debug builds.Fixes c442fed81bb9 ("net: add function to calculate checksum in mbuf")Signed-off-by Chas Williams <[email protected]>--- lib/librte_net/rte_ip.h | 1 + 1 file changed, 1 insertion(+)lib/librte_net/rte_ip.h index renamed from lib/librte_net/rte_ip.h +0
-0
fcd1eb342..6b3e4cdda100644
lib/librte_net/rte_ip.h rte_raw_cksum_mbuf(const struct rte_mbuf *m, · line 229
Quoted 5 lines
lib/librte_net/rte_ip.h +1
-0@@ -225,6 +225,7 @@ rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len, break; off -= seglen; } +RTE_ASSERT (seg !=NULL );
Is it better to return an error code?
Quoted 5 lines
lib/librte_net/rte_ip.h +0
-0seglen -= off; buf = rte_pktmbuf_mtod_offset(seg, const char *, off);if (seglen >= len) {
--
2.26.2
Quoted 18 lines · wangyunjian
Quoted 18 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Chas Williams
Sent: Monday, September 28, 2020 11:32 PM
To: [email protected]
Cc: [email protected]; Chas Williams <[email protected]>
Subject: [dpdk-dev] [PATCH] net: check that seg is valid before dereferenceIf the overall
pkt_lenand segment lengths are out of agreement, it is possible for the seg to be NULL after the loop. Add assert to check this condition in debug builds.Fixes c442fed81bb9 ("net: add function to calculate checksum in mbuf")Signed-off-by Chas Williams <[email protected]>--- lib/librte_net/rte_ip.h | 1 + 1 file changed, 1 insertion(+)
Quoted 12 lines
lib/librte_net/rte_ip.h rte_raw_cksum_mbuf(const struct rte_mbuf *m, · line 229
Quoted 10 lines
lib/librte_net/rte_ip.h index renamed from lib/librte_net/rte_ip.h +0
-0
fcd1eb342..6b3e4cdda100644lib/librte_net/rte_ip.h +1
-0@@ -225,6 +225,7 @@ rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len, break; off -= seglen; } +RTE_ASSERT (seg !=NULL );Is it better to return an error code?
Maybe. However, to get into this state your mbuf chain is already badly broken. Personally, I would prefer an immediate failure in the application so I can track
down the source of this error.
No one is checking the return code now, so returning one wouldn't really help unless I also fix the callers. Lastly, would everyone be happy with an extra branch in the virtio RX path?
Quoted 7 lines
Quoted 6 lines
lib/librte_net/rte_ip.h +0
-0seglen -= off; buf = rte_pktmbuf_mtod_offset(seg, const char *, off);if (seglen >= len) {--
2.26.2
PATCH v2 1/2 net: check that seg is valid before dereference
In reply to Chas WilliamsIf the overall pkt_len and segment lengths are out of agreement, it is possible for the seg to be NULL after the loop. Add assert to check this condition in debug builds. Otherwise, return failure.
--- lib/librte_net/rte_ip.h | 3 +++ 1 file changed, 3 insertions(+)
lib/librte_net/rte_ip.h +3 -0
@@ -225,6 +225,9 @@ rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len,break ; off -= seglen; } +RTE_ASSERT (seg !=NULL ); +if (seg ==NULL ) +return -1 ; seglen -= off; buf = rte_pktmbuf_mtod_offset(seg, const char *, off);if (seglen >= len) {
Signature · 1 line
2.26.2
PATCH v2 2/2 net/virtio: check return from rte_raw_cksum_mbuf
rte_raw_cksum_mbuf can fail, so we should check to see if it has. If so, return with an error.
--- drivers/net/virtio/virtio_rxtx.c | 5 +++-- drivers/net/virtio/virtio_rxtx_packed_avx.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/net/virtio/virtio_rxtx.c +3 -2
@@ -910,9 +910,10 @@ virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr)*/ uint16_t csum =0 , off; -rte_raw_cksum_mbuf (m, hdr->csum_start, +if (rte_raw_cksum_mbuf (m, hdr->csum_start,rte_pktmbuf_pkt_len (m) - hdr->csum_start, - &csum); + &csum) <0 ) +return -EINVAL ;if (likely (csum !=0xffff )) csum = ~csum; off = hdr->csum_offset + hdr->csum_start;
drivers/net/virtio/virtio_rxtx_packed_avx.c +3 -2
@@ -328,9 +328,10 @@ virtio_vec_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr)*/ uint16_t csum =0 , off; -rte_raw_cksum_mbuf (m, hdr->csum_start, +if (rte_raw_cksum_mbuf (m, hdr->csum_start,rte_pktmbuf_pkt_len (m) - hdr->csum_start, - &csum); + &csum) <0 ) +return -1 ;if (likely (csum !=0xffff )) csum = ~csum; off = hdr->csum_offset + hdr->csum_start;
Signature · 1 line
2.26.2
Re: [dpdk-dev] [PATCH v2 2/2] net/virtio: check return from rte_raw_cksum_mbuf
Quoted 4 lines
rte_raw_cksum_mbufcan fail, so we should check to see if it has. If so, return with an error.Fixes 96cb6711939e ("net/virtio: support Rx checksum offload")
It is an old bug, so it should be backported, right?
Cc: [email protected]
Quoted 5 lines
Signed-off-by Chas Williams <[email protected]>---
drivers/net/virtio/virtio_rxtx.c | 5 +++-- drivers/net/virtio/virtio_rxtx_packed_avx.c | 5 +++--
Please use --cc-cmd devtools/get-maintainer.sh
so the maintainers are aware.
Re: [dpdk-dev] [PATCH v2 2/2] net/virtio: check return from rte_raw_cksum_mbuf
In reply to Chas WilliamsQuoted 11 lines · Chas Williams
rte_raw_cksum_mbufcan fail, so we should check to see if it has. If so, return with an error.Fixes 96cb6711939e ("net/virtio: support Rx checksum offload")Signed-off-by Chas Williams <[email protected]>--- drivers/net/virtio/virtio_rxtx.c | 5 +++-- drivers/net/virtio/virtio_rxtx_packed_avx.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
Thanks,
Maxime
Re: [dpdk-dev] [PATCH v2 2/2] net/virtio: check return from rte_raw_cksum_mbuf
09/10/2020 09:14, Maxime Coquelin:
Quoted 10 lines · Chas Williams
Quoted 6 lines
rte_raw_cksum_mbufcan fail, so we should check to see if it has. If so, return with an error.Fixes 96cb6711939e ("net/virtio: support Rx checksum offload")Signed-off-by Chas Williams <[email protected]>Reviewed-by Maxime Coquelin <[email protected]>
Series applied, thanks