CVE-2023-34966: mdssvc: harden sl_unpack_loop()
authorRalph Boehme <slow@samba.org>
Fri, 26 May 2023 11:06:19 +0000 (13:06 +0200)
committerJule Anger <janger@samba.org>
Fri, 14 Jul 2023 13:12:20 +0000 (15:12 +0200)
A malicious client could send a packet where subcount is zero, leading to a busy
loop because

    count -= subcount
=>  count -= 0
=>  while (count > 0)

loops forever.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15340

Signed-off-by: Ralph Boehme <slow@samba.org>
source3/rpc_server/mdssvc/marshalling.c

index 9ba6ef571f2466f299d2992bc44e15754242b542..d794ba158389d451201e885d243f9ad765004bbf 100644 (file)
@@ -1119,7 +1119,7 @@ static ssize_t sl_unpack_loop(DALLOC_CTX *query,
                        sl_nil_t nil = 0;
 
                        subcount = tag.count;
-                       if (subcount > count) {
+                       if (subcount < 1 || subcount > count) {
                                return -1;
                        }
                        for (i = 0; i < subcount; i++) {
@@ -1147,7 +1147,7 @@ static ssize_t sl_unpack_loop(DALLOC_CTX *query,
 
                case SQ_TYPE_INT64:
                        subcount = sl_unpack_ints(query, buf, offset, bufsize, encoding);
-                       if (subcount == -1 || subcount > count) {
+                       if (subcount 1 || subcount > count) {
                                return -1;
                        }
                        offset += tag.size;
@@ -1156,7 +1156,7 @@ static ssize_t sl_unpack_loop(DALLOC_CTX *query,
 
                case SQ_TYPE_UUID:
                        subcount = sl_unpack_uuid(query, buf, offset, bufsize, encoding);
-                       if (subcount == -1 || subcount > count) {
+                       if (subcount 1 || subcount > count) {
                                return -1;
                        }
                        offset += tag.size;
@@ -1165,7 +1165,7 @@ static ssize_t sl_unpack_loop(DALLOC_CTX *query,
 
                case SQ_TYPE_FLOAT:
                        subcount = sl_unpack_floats(query, buf, offset, bufsize, encoding);
-                       if (subcount == -1 || subcount > count) {
+                       if (subcount 1 || subcount > count) {
                                return -1;
                        }
                        offset += tag.size;
@@ -1174,7 +1174,7 @@ static ssize_t sl_unpack_loop(DALLOC_CTX *query,
 
                case SQ_TYPE_DATE:
                        subcount = sl_unpack_date(query, buf, offset, bufsize, encoding);
-                       if (subcount == -1 || subcount > count) {
+                       if (subcount 1 || subcount > count) {
                                return -1;
                        }
                        offset += tag.size;