patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] mbuf: fix out-of-bounds access
@ 2020-06-10 15:08 Xiaolong Ye
  2020-06-11  0:48 ` [dpdk-stable] [PATCH v2] " Xiaolong Ye
  2020-06-11 15:12 ` [dpdk-stable] [PATCH v3] mbuf: fix out-of-bounds access at dyn field register Xiaolong Ye
  0 siblings, 2 replies; 4+ messages in thread
From: Xiaolong Ye @ 2020-06-10 15:08 UTC (permalink / raw)
  To: Olivier Matz, Konstantin Ananyev, Thomas Monjalon
  Cc: dev, Xiaolong Ye, stable

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>
---
 lib/librte_mbuf/rte_mbuf_dyn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c
index d6931f847..8af89dde4 100644
--- a/lib/librte_mbuf/rte_mbuf_dyn.c
+++ b/lib/librte_mbuf/rte_mbuf_dyn.c
@@ -71,7 +71,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; shm->free_space[off + size] &&
+			     (off + size) < sizeof(struct rte_mbuf); size++)
 			;
 		if (size == 0)
 			continue;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [dpdk-stable] [PATCH v2] mbuf: fix out-of-bounds access
  2020-06-10 15:08 [dpdk-stable] [PATCH] mbuf: fix out-of-bounds access Xiaolong Ye
@ 2020-06-11  0:48 ` Xiaolong Ye
  2020-06-11 15:03   ` Olivier Matz
  2020-06-11 15:12 ` [dpdk-stable] [PATCH v3] mbuf: fix out-of-bounds access at dyn field register Xiaolong Ye
  1 sibling, 1 reply; 4+ messages in thread
From: Xiaolong Ye @ 2020-06-11  0:48 UTC (permalink / raw)
  To: Olivier Matz, Thomas Monjalon, Konstantin Ananyev
  Cc: dev, Xiaolong Ye, stable

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>
---

V2: put the check before accessing free_space

 lib/librte_mbuf/rte_mbuf_dyn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c
index d6931f847..9d6388cff 100644
--- a/lib/librte_mbuf/rte_mbuf_dyn.c
+++ b/lib/librte_mbuf/rte_mbuf_dyn.c
@@ -71,7 +71,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;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-stable] [PATCH v2] mbuf: fix out-of-bounds access
  2020-06-11  0:48 ` [dpdk-stable] [PATCH v2] " Xiaolong Ye
@ 2020-06-11 15:03   ` Olivier Matz
  0 siblings, 0 replies; 4+ messages in thread
From: Olivier Matz @ 2020-06-11 15:03 UTC (permalink / raw)
  To: Xiaolong Ye; +Cc: Thomas Monjalon, Konstantin Ananyev, dev, stable

On Thu, Jun 11, 2020 at 08:48:01AM +0800, Xiaolong Ye wrote:
> 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>

I suggest to change the title in:
mbuf: fix out-of-bounds access at dyn field register

Thomas, as Xiaolong pointed-out, it fixes a bug in the code but there is
no impact. I let you decide if it should be tagged as a fix or not, and
if it should be backported. I'll tend to say yes.

Acked-by: Olivier Matz <olivier.matz@6wind.com>

> ---
> 
> V2: put the check before accessing free_space
> 
>  lib/librte_mbuf/rte_mbuf_dyn.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c
> index d6931f847..9d6388cff 100644
> --- a/lib/librte_mbuf/rte_mbuf_dyn.c
> +++ b/lib/librte_mbuf/rte_mbuf_dyn.c
> @@ -71,7 +71,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;
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [dpdk-stable] [PATCH v3] mbuf: fix out-of-bounds access at dyn field register
  2020-06-10 15:08 [dpdk-stable] [PATCH] mbuf: fix out-of-bounds access Xiaolong Ye
  2020-06-11  0:48 ` [dpdk-stable] [PATCH v2] " Xiaolong Ye
@ 2020-06-11 15:12 ` Xiaolong Ye
  1 sibling, 0 replies; 4+ messages in thread
From: Xiaolong Ye @ 2020-06-11 15:12 UTC (permalink / raw)
  To: Olivier Matz, Thomas Monjalon, Konstantin Ananyev
  Cc: dev, Xiaolong Ye, stable

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>
---

V3: update subject as Olivier suggested

 lib/librte_mbuf/rte_mbuf_dyn.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_mbuf/rte_mbuf_dyn.c b/lib/librte_mbuf/rte_mbuf_dyn.c
index d6931f847..9d6388cff 100644
--- a/lib/librte_mbuf/rte_mbuf_dyn.c
+++ b/lib/librte_mbuf/rte_mbuf_dyn.c
@@ -71,7 +71,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;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-11 15:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-10 15:08 [dpdk-stable] [PATCH] mbuf: fix out-of-bounds access Xiaolong Ye
2020-06-11  0:48 ` [dpdk-stable] [PATCH v2] " Xiaolong Ye
2020-06-11 15:03   ` Olivier Matz
2020-06-11 15:12 ` [dpdk-stable] [PATCH v3] mbuf: fix out-of-bounds access at dyn field register Xiaolong Ye

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).