Skip to contentSkip to conversation

ui/vnc-clipboard: fix infinite loop in inflate_buffer (CVE-2023-3255)

PATCH In review Mauro Matteo Cascella 3 participants 4 messages Jul 4, 2023 – Jul 12, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/vnc-clipboard: fix infinite loop in inflate_buffer (CVE-2023-3255)

A wrong exit condition may lead to an infinite loop when inflating a valid zlib buffer containing some extra bytes in the inflate_buffer function. The bug only occurs post-authentication. Return the buffer immediately if the end of the compressed data has been reached (Z_STREAM_END).

Fixes CVE-2023-3255
Fixes 0bf41cab ("ui/vnc: clipboard support")
---
 ui/vnc-clipboard.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
ui/vnc-clipboard.c +4 -6
index 8aeadfaa21..c759be3438 100644
@@ -50,8 +50,11 @@ static uint8_t *inflate_buffer(uint8_t *in, uint32_t in_len, uint32_t *size)
         ret = inflate(&stream, Z_FINISH);
         switch (ret) {
         case Z_OK:
-        case Z_STREAM_END:
             break;
+        case Z_STREAM_END:
+            *size = stream.total_out;
+            inflateEnd(&stream);
+            return out;
         case Z_BUF_ERROR:
             out_len <<= 1;
             if (out_len > (1 << 20)) {
@@ -66,11 +69,6 @@ static uint8_t *inflate_buffer(uint8_t *in, uint32_t in_len, uint32_t *size)
         }
     }
 
-    *size = stream.total_out;
-    inflateEnd(&stream);
-
-    return out;
-
 err_end:
     inflateEnd(&stream);
 err:
Signature · 1 line
2.41.0
Tested-by Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Mauro Matteo Cascella

A wrong exit condition may lead to an infinite loop when inflating a valid zlib buffer containing some extra bytes in the inflate_buffer function. The bug only occurs post-authentication. Return the buffer immediately if the end of the compressed data has been reached (Z_STREAM_END).

Fixes CVE-2023-3255
Fixes 0bf41cab ("ui/vnc: clipboard support")

Note: we may want to disconnect the client when there are extra bytes in the message, or print some warnings.

Quoted 40 lines
---
 ui/vnc-clipboard.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
ui/vnc-clipboard.c +4 -1
index 8aeadfaa21..c759be3438 100644
@@ -50,8 +50,11 @@ static uint8_t *inflate_buffer(uint8_t *in, uint32_t
 in_len, uint32_t *size)
         ret = inflate(&stream, Z_FINISH);
         switch (ret) {
         case Z_OK:
-        case Z_STREAM_END:
             break;
+        case Z_STREAM_END:
+            *size = stream.total_out;
+            inflateEnd(&stream);
+            return out;
         case Z_BUF_ERROR:
             out_len <<= 1;
             if (out_len > (1 << 20)) {
ui/vnc-clipboard.c +0 -5
@@ -66,11 +69,6 @@ static uint8_t *inflate_buffer(uint8_t *in, uint32_t
 in_len, uint32_t *size)
         }
     }
 
-    *size = stream.total_out;
-    inflateEnd(&stream);
-
-    return out;
-
 err_end:
     inflateEnd(&stream);

err:
--
2.41.0

Signature · 1 line
Marc-André Lureau
#2 lore raw
Quoted 17 lines · Marc-André Lureau
Quoted 11 lines · Mauro Matteo Cascella

A wrong exit condition may lead to an infinite loop when inflating a valid zlib buffer containing some extra bytes in the inflate_buffer function. The bug only occurs post-authentication. Return the buffer immediately if the end of the compressed data has been reached (Z_STREAM_END).

Fixes CVE-2023-3255
Fixes 0bf41cab ("ui/vnc: clipboard support")
Quoted 4 lines

Note: we may want to disconnect the client when there are extra bytes in the message, or print some warnings.

Sure, I guess we can call vnc_disconnect_finish or vnc_client_error for disconnecting, not sure how to properly print warnings. Feel free to add that yourself when applying the patch. Or I can try to send v2 if you prefer.

Thanks,

Quoted 42 lines
Quoted 35 lines
---
 ui/vnc-clipboard.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
ui/vnc-clipboard.c +4 -7
index 8aeadfaa21..c759be3438 100644
@@ -50,8 +50,11 @@ static uint8_t *inflate_buffer(uint8_t *in, uint32_t in_len, uint32_t *size)
         ret = inflate(&stream, Z_FINISH);
         switch (ret) {
         case Z_OK:
-        case Z_STREAM_END:
             break;
+        case Z_STREAM_END:
+            *size = stream.total_out;
+            inflateEnd(&stream);
+            return out;
         case Z_BUF_ERROR:
             out_len <<= 1;
             if (out_len > (1 << 20)) {
@@ -66,11 +69,6 @@ static uint8_t *inflate_buffer(uint8_t *in, uint32_t in_len, uint32_t *size)
         }
     }
 
-    *size = stream.total_out;
-    inflateEnd(&stream);
-
-    return out;
-
 err_end:
     inflateEnd(&stream);
 err:
--
Quoted 3 lines

2.41.0

--
Marc-André Lureau

Signature · 3 lines
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0
#3 lore raw
Quoted 22 lines · Mauro Matteo Cascella
Quoted 20 lines · Marc-André Lureau
Quoted 11 lines · Mauro Matteo Cascella

A wrong exit condition may lead to an infinite loop when inflating a valid zlib buffer containing some extra bytes in the inflate_buffer function. The bug only occurs post-authentication. Return the buffer immediately if the end of the compressed data has been reached (Z_STREAM_END).

Fixes CVE-2023-3255
Fixes 0bf41cab ("ui/vnc: clipboard support")
Quoted 6 lines
Quoted 1 line

Note: we may want to disconnect the client when there are extra bytes in the message, or print some warnings.

Sure, I guess we can call vnc_disconnect_finish or vnc_client_error for disconnecting, not sure how to properly print warnings. Feel free to add that yourself when applying the patch. Or I can try to send v2 if you prefer.

Ping, for 8.1 and -stable?

Thanks,

/mjt