Skip to contentSkip to conversation

mbuf: Fix illegal pointer access to mempool members

PATCH Superseded [email protected] 1 participant 2 messages Mar 30, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mbuf: Fix illegal pointer access to mempool members

From: wenwu ma <[email protected]>

Before accessing the private data of mempool in function rte_pktmbuf_priv_size() and rte_pktmbuf_data_room_size(), it is necessary to determine whether the private data exists, otherwise it will cause null pointer access.

---
 lib/librte_mbuf/rte_mbuf.h | 6 ++++++
 1 file changed, 6 insertions(+)
lib/librte_mbuf/rte_mbuf.h +6 -0
index c4c9ebfaa..9cca9a7d4 100644
@@ -811,6 +811,9 @@ rte_pktmbuf_data_room_size(struct rte_mempool *mp)
 {
 	struct rte_pktmbuf_pool_private *mbp_priv;
 
+	if (mp->private_data_size != sizeof(struct rte_pktmbuf_pool_private))
+		return 0;
+
 	mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
 	return mbp_priv->mbuf_data_room_size;
 }
@@ -832,6 +835,9 @@ rte_pktmbuf_priv_size(struct rte_mempool *mp)
 {
 	struct rte_pktmbuf_pool_private *mbp_priv;
 
+	if (mp->private_data_size != sizeof(struct rte_pktmbuf_pool_private))
+		return 0;
+
 	mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
 	return mbp_priv->mbuf_priv_size;
 }
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/1 mbuf: Fix illegal pointer access to mempool members

From: wenwu ma <[email protected]>

Before accessing the private data of mempool in function rte_pktmbuf_priv_size() and rte_pktmbuf_data_room_size(), it is necessary to determine whether the private data exists, otherwise it will cause null pointer access.

---
V2:
- Change the unequal sign in the judgment statement to less than sign

 lib/librte_mbuf/rte_mbuf.h | 6 ++++++
 1 file changed, 6 insertions(+)
lib/librte_mbuf/rte_mbuf.h +6 -0
index c4c9ebfaa..6c2559550 100644
@@ -811,6 +811,9 @@ rte_pktmbuf_data_room_size(struct rte_mempool *mp)
 {
 	struct rte_pktmbuf_pool_private *mbp_priv;
 
+	if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private))
+		return 0;
+
 	mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
 	return mbp_priv->mbuf_data_room_size;
 }
@@ -832,6 +835,9 @@ rte_pktmbuf_priv_size(struct rte_mempool *mp)
 {
 	struct rte_pktmbuf_pool_private *mbp_priv;
 
+	if (mp->private_data_size < sizeof(struct rte_pktmbuf_pool_private))
+		return 0;
+
 	mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
 	return mbp_priv->mbuf_priv_size;
 }
Signature · 1 line
2.25.1