about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2024-04-25 15:00:45 +0200
committerFlorian Weimer <fweimer@redhat.com>2024-04-25 15:40:34 +0200
commitf75c298e747b2b8b41b1c2f551c011a52c41bfd1 (patch)
tree8c88bc152e49778e0b6b77513891117be84b66ab
parentae014a15b40f4b35bdcee35c95684e684223ba25 (diff)
downloadglibc-f75c298e747b2b8b41b1c2f551c011a52c41bfd1.tar.gz
glibc-f75c298e747b2b8b41b1c2f551c011a52c41bfd1.tar.xz
glibc-f75c298e747b2b8b41b1c2f551c011a52c41bfd1.zip
CVE-2024-33599: nscd: Stack-based buffer overflow in netgroup cache (bug 31677)
Using alloca matches what other caches do.  The request length is
bounded by MAXKEYLEN.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit 87801a8fd06db1d654eea3e4f7626ff476a9bdaa)
-rw-r--r--nscd/netgroupcache.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/nscd/netgroupcache.c b/nscd/netgroupcache.c
index 439dd4ba38..ef76a7e590 100644
--- a/nscd/netgroupcache.c
+++ b/nscd/netgroupcache.c
@@ -502,12 +502,13 @@ addinnetgrX (struct database_dyn *db, int fd, request_header *req,
       = (struct indataset *) mempool_alloc (db,
 					    sizeof (*dataset) + req->key_len,
 					    1);
-  struct indataset dataset_mem;
   bool cacheable = true;
   if (__glibc_unlikely (dataset == NULL))
     {
       cacheable = false;
-      dataset = &dataset_mem;
+      /* The alloca is safe because nscd_run_worker verfies that
+	 key_len is not larger than MAXKEYLEN.  */
+      dataset = alloca (sizeof (*dataset) + req->key_len);
     }
 
   datahead_init_pos (&dataset->head, sizeof (*dataset) + req->key_len,