mbuf: fix boundary check at dynamic field registration
authorXiaolong Ye <xiaolong.ye@intel.com>
Sat, 13 Jun 2020 15:49:17 +0000 (23:49 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 25 Jun 2020 21:03:18 +0000 (23:03 +0200)
We should make sure off + size < sizeof(struct rte_mbuf) to avoid
possible out-of-bounds access of free_space array, there is no issue
currently due to the low bits of free_flags (which is adjacent to
free_space) are always set to 0. But we shouldn't rely on it since it's
fragile and layout of struct mbuf_dyn_shm may be changed in the future.
This patch adds boundary check explicitly to avoid potential risk of
out-of-bounds access.

Fixes: 4958ca3a443a ("mbuf: support dynamic fields and flags")
Cc: stable@dpdk.org
Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
lib/librte_mbuf/rte_mbuf_dyn.c

index 953e3ec..13d6da6 100644 (file)
@@ -69,7 +69,8 @@ process_score(void)
 
        for (off = 0; off < sizeof(struct rte_mbuf); off++) {
                /* get the size of the free zone */
-               for (size = 0; shm->free_space[off + size]; size++)
+               for (size = 0; (off + size) < sizeof(struct rte_mbuf) &&
+                            shm->free_space[off + size]; size++)
                        ;
                if (size == 0)
                        continue;