Skip to contentSkip to conversation

net: fix buffer overflow in af_xdp_umem_create()

PATCH In review Anastasia Belova 4 participants 4 messages Jun 2, 2025 – Jul 13, 2025 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: fix buffer overflow in af_xdp_umem_create()

s->pool has n_descs elements so maximum i should be n_descs - 1. Fix the upper bound.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes cb039ef3d9 ("net: add initial support for AF_XDP network backend")
---
 net/af-xdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/af-xdp.c +1 -1
index 01c5fb914e..d022534d76 100644
@@ -323,7 +323,7 @@ static int af_xdp_umem_create(AFXDPState *s, int sock_fd, Error **errp)
 
     s->pool = g_new(uint64_t, n_descs);
     /* Fill the pool in the opposite order, because it's a LIFO queue. */
-    for (i = n_descs; i >= 0; i--) {
+    for (i = n_descs - 1; i >= 0; i--) {
         s->pool[i] = i * XSK_UMEM__DEFAULT_FRAME_SIZE;
     }
     s->n_pool = n_descs;
Signature · 1 line
2.47.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Anastasia Belova

s->pool has n_descs elements so maximum i should be n_descs - 1. Fix the upper bound.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes cb039ef3d9 ("net: add initial support for AF_XDP network backend")
---
 net/af-xdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/af-xdp.c +0 -0
index 01c5fb914e..d022534d76 100644

net/af-xdp.c static int af_xdp_umem_create(AFXDPState *s, int sock_fd, Error **errp) · line 329

Quoted 8 lines
net/af-xdp.c +1 -1
@@ -323,7 +323,7 @@ static int af_xdp_umem_create(AFXDPState *s, int sock_fd, Error **errp)
 
     s->pool = g_new(uint64_t, n_descs);
     /* Fill the pool in the opposite order, because it's a LIFO queue. */
-    for (i = n_descs; i >= 0; i--) {
+    for (i = n_descs - 1; i >= 0; i--) {
         s->pool[i] = i * XSK_UMEM__DEFAULT_FRAME_SIZE;
     }
     s->n_pool = n_descs;

As far as the fix goes:

The loop itself though doesn't do what the comment says it should be doing, but it's not related to this fix. I'll send a separate patch for that.

#2 lore raw

Ping?

Thanks,

/mjt

Quoted 33 lines · Ilya Maximets
Quoted 16 lines · Anastasia Belova

s->pool has n_descs elements so maximum i should be n_descs - 1. Fix the upper bound.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes cb039ef3d9 ("net: add initial support for AF_XDP network backend")
---
  net/af-xdp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/af-xdp.c +0 -0
index 01c5fb914e..d022534d76 100644

net/af-xdp.c static int af_xdp_umem_create(AFXDPState *s, int sock_fd, Error **errp) · line 329

Quoted 8 lines
net/af-xdp.c +1 -1
@@ -323,7 +323,7 @@ static int af_xdp_umem_create(AFXDPState *s, int sock_fd, Error **errp)
 
      s->pool = g_new(uint64_t, n_descs);
      /* Fill the pool in the opposite order, because it's a LIFO queue. */
-    for (i = n_descs; i >= 0; i--) {
+    for (i = n_descs - 1; i >= 0; i--) {
          s->pool[i] = i * XSK_UMEM__DEFAULT_FRAME_SIZE;
      }
      s->n_pool = n_descs;

As far as the fix goes:

The loop itself though doesn't do what the comment says it should be doing, but it's not related to this fix. I'll send a separate patch for that.

#3 lore raw
In reply to Anastasia Belova
Quoted 26 lines · Anastasia Belova

s->pool has n_descs elements so maximum i should be n_descs - 1. Fix the upper bound.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes cb039ef3d9 ("net: add initial support for AF_XDP network backend")
---
 net/af-xdp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/af-xdp.c +1 -2
index 01c5fb914e..d022534d76 100644
@@ -323,7 +323,7 @@ static int af_xdp_umem_create(AFXDPState *s, int sock_fd, Error **errp)
 
     s->pool = g_new(uint64_t, n_descs);
     /* Fill the pool in the opposite order, because it's a LIFO queue. */
-    for (i = n_descs; i >= 0; i--) {
+    for (i = n_descs - 1; i >= 0; i--) {
         s->pool[i] = i * XSK_UMEM__DEFAULT_FRAME_SIZE;
     }
     s->n_pool = n_descs;
--
Quoted 2 lines

2.47.0

Queued.

Thanks