Skip to contentSkip to conversation

vhost/vhost_crypto: do not use possibly NULL Pointers

PATCH New Thierry Herbelot 3 participants 4 messages May 24, 2021 – Jun 17, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost/vhost_crypto: do not use possibly NULL Pointers

Use vc_req only after it was checked not to be NULL.

Fixes 2d962bb736521 ("vhost/crypto: fix possible TOCTOU attack")
Cc Maxime Coquelin <[email protected]>
Cc Chenbo Xia <[email protected]>
---
 lib/vhost/vhost_crypto.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/vhost/vhost_crypto.c +4 -2
index 6689c52df239..5113a552bd2e 100644
@@ -1337,13 +1337,15 @@ vhost_crypto_finalize_one_request(struct rte_crypto_op *op,
 	struct rte_mbuf *m_src = op->sym->m_src;
 	struct rte_mbuf *m_dst = op->sym->m_dst;
 	struct vhost_crypto_data_req *vc_req = rte_mbuf_to_priv(m_src);
-	struct vhost_virtqueue *vq = vc_req->vq;
-	uint16_t used_idx = vc_req->desc_idx, desc_idx;
+	struct vhost_virtqueue *vq;
+	uint16_t used_idx;
 
 	if (unlikely(!vc_req)) {
 		VC_LOG_ERR("Failed to retrieve vc_req");
 		return NULL;
 	}
+	vq = vc_req->vq;
+	used_idx = vc_req->desc_idx, desc_idx;
 
 	if (old_vq && (vq != old_vq))
 		return vq;
Signature · 1 line
2.29.2
#1 lore raw

PATCH v2 1/1 vhost/vhost_crypto: do not use possibly NULL Pointers

Use vc_req only after it was checked not to be NULL.

Fixes 2d962bb736521 ("vhost/crypto: fix possible TOCTOU attack")
Cc Maxime Coquelin <[email protected]>
Cc Chenbo Xia <[email protected]>

--
V2: fix copy/paste typo

---
 lib/vhost/vhost_crypto.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/vhost/vhost_crypto.c +4 -2
index 6689c52df239..926b5c0bd94a 100644
@@ -1337,13 +1337,15 @@ vhost_crypto_finalize_one_request(struct rte_crypto_op *op,
 	struct rte_mbuf *m_src = op->sym->m_src;
 	struct rte_mbuf *m_dst = op->sym->m_dst;
 	struct vhost_crypto_data_req *vc_req = rte_mbuf_to_priv(m_src);
-	struct vhost_virtqueue *vq = vc_req->vq;
-	uint16_t used_idx = vc_req->desc_idx, desc_idx;
+	struct vhost_virtqueue *vq;
+	uint16_t used_idx, desc_idx;
 
 	if (unlikely(!vc_req)) {
 		VC_LOG_ERR("Failed to retrieve vc_req");
 		return NULL;
 	}
+	vq = vc_req->vq;
+	used_idx = vc_req->desc_idx;
 
 	if (old_vq && (vq != old_vq))
 		return vq;
Signature · 1 line
2.29.2
Reviewed-by on v2 1/1
#2 lore raw

Hi Thierry,

Quoted 27 lines · Thierry Herbelot

Use vc_req only after it was checked not to be NULL.

Fixes 2d962bb736521 ("vhost/crypto: fix possible TOCTOU attack")
Cc Maxime Coquelin <[email protected]>
Cc Chenbo Xia <[email protected]>

--
V2: fix copy/paste typo

---
 lib/vhost/vhost_crypto.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/vhost/vhost_crypto.c +2 -2
index 6689c52df239..926b5c0bd94a 100644
@@ -1337,13 +1337,15 @@ vhost_crypto_finalize_one_request(struct rte_crypto_op *op,
 	struct rte_mbuf *m_src = op->sym->m_src;
 	struct rte_mbuf *m_dst = op->sym->m_dst;
 	struct vhost_crypto_data_req *vc_req = rte_mbuf_to_priv(m_src);
-	struct vhost_virtqueue *vq = vc_req->vq;
-	uint16_t used_idx = vc_req->desc_idx, desc_idx;
+	struct vhost_virtqueue *vq;
+	uint16_t used_idx, desc_idx;

lib/vhost/vhost_crypto.c vhost_crypto_finalize_one_request(struct rte_crypto_op *op, · line 1351

Quoted 10 lines
lib/vhost/vhost_crypto.c +2 -0
 
 	if (unlikely(!vc_req)) {
 		VC_LOG_ERR("Failed to retrieve vc_req");
 		return NULL;
 	}
+	vq = vc_req->vq;
+	used_idx = vc_req->desc_idx;
 
 	if (old_vq && (vq != old_vq))
 		return vq;

Thanks,
Maxime

#3 lore raw
In reply to Thierry Herbelot
Quoted 7 lines · Thierry Herbelot

Use vc_req only after it was checked not to be NULL.

Fixes 2d962bb736521 ("vhost/crypto: fix possible TOCTOU attack")
Cc Maxime Coquelin <[email protected]>
Cc Chenbo Xia <[email protected]>
Quoted 7 lines

--
V2: fix copy/paste typo

---
 lib/vhost/vhost_crypto.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Applied to dpdk-next-virtio/main.

Thanks,
Maxime