|
| 1 | +From dc633990f3750e09fd70583c9c976c9562b475ec Mon Sep 17 00:00:00 2001 |
| 2 | +From: Mike Gorse <mgorse@suse.com> |
| 3 | +Date: Mon, 2 Feb 2026 10:46:00 -0600 |
| 4 | +Subject: [PATCH] websocket: Fix out-of-bounds read in process_frame |
| 5 | + |
| 6 | +If the maximum incoming payload size is unset, then a malicious frame could |
| 7 | +cause an overflow when calculating the needed amount of data, leading to an |
| 8 | +out-of-bounds read later. |
| 9 | + |
| 10 | +This is CVE-2026-0716. |
| 11 | + |
| 12 | +Closes #476 |
| 13 | + |
| 14 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 15 | +Upstream-reference: https://gitlab.gnome.org/GNOME/libsoup/-/merge_requests/494.patch |
| 16 | +--- |
| 17 | + libsoup/websocket/soup-websocket-connection.c | 6 +++ |
| 18 | + tests/websocket-test.c | 44 +++++++++++++++++++ |
| 19 | + 2 files changed, 50 insertions(+) |
| 20 | + |
| 21 | +diff --git a/libsoup/websocket/soup-websocket-connection.c b/libsoup/websocket/soup-websocket-connection.c |
| 22 | +index ef54ab6..5d14006 100644 |
| 23 | +--- a/libsoup/websocket/soup-websocket-connection.c |
| 24 | ++++ b/libsoup/websocket/soup-websocket-connection.c |
| 25 | +@@ -1096,6 +1096,12 @@ process_frame (SoupWebsocketConnection *self) |
| 26 | + payload += 4; |
| 27 | + at += 4; |
| 28 | + |
| 29 | ++ /* at has a maximum value of 10 + 4 = 14 */ |
| 30 | ++ if (payload_len > G_MAXSIZE - 14) { |
| 31 | ++ bad_data_error_and_close (self); |
| 32 | ++ return FALSE; |
| 33 | ++ } |
| 34 | ++ |
| 35 | + if (len < at + payload_len) |
| 36 | + return FALSE; /* need more data */ |
| 37 | + |
| 38 | +diff --git a/tests/websocket-test.c b/tests/websocket-test.c |
| 39 | +index a7fc7e9..bd866d4 100644 |
| 40 | +--- a/tests/websocket-test.c |
| 41 | ++++ b/tests/websocket-test.c |
| 42 | +@@ -2170,6 +2170,41 @@ test_connection_error (void) |
| 43 | + soup_test_session_abort_unref (session); |
| 44 | + } |
| 45 | + |
| 46 | ++static void |
| 47 | ++test_cve_2026_0716 (Test *test, |
| 48 | ++ gconstpointer unused) |
| 49 | ++{ |
| 50 | ++ GError *error = NULL; |
| 51 | ++ GIOStream *io; |
| 52 | ++ gsize written; |
| 53 | ++ const char *frame; |
| 54 | ++ gboolean close_event = FALSE; |
| 55 | ++ |
| 56 | ++ g_signal_handlers_disconnect_by_func (test->server, on_error_not_reached, NULL); |
| 57 | ++ g_signal_connect (test->server, "error", G_CALLBACK (on_error_copy), &error); |
| 58 | ++ g_signal_connect (test->client, "closed", G_CALLBACK (on_close_set_flag), &close_event); |
| 59 | ++ |
| 60 | ++ io = soup_websocket_connection_get_io_stream (test->client); |
| 61 | ++ |
| 62 | ++ soup_websocket_connection_set_max_incoming_payload_size (test->server, 0); |
| 63 | ++ |
| 64 | ++ // Malicious masked frame header (10-byte header + 4-byte mask) */ |
| 65 | ++ frame = "\x82\xff\xff\xff\xff\xff\xff\xff\xff\xf6\xaa\xbb\xcc\xdd"; |
| 66 | ++ if (!g_output_stream_write_all (g_io_stream_get_output_stream (io), |
| 67 | ++ frame, 14, &written, NULL, NULL)) |
| 68 | ++ g_assert_cmpstr ("This code", ==, "should not be reached"); |
| 69 | ++ g_assert_cmpuint (written, ==, 14); |
| 70 | ++ |
| 71 | ++ WAIT_UNTIL (error != NULL); |
| 72 | ++ g_assert_error (error, SOUP_WEBSOCKET_ERROR, SOUP_WEBSOCKET_CLOSE_BAD_DATA); |
| 73 | ++ g_clear_error (&error); |
| 74 | ++ |
| 75 | ++ WAIT_UNTIL (soup_websocket_connection_get_state (test->client) == SOUP_WEBSOCKET_STATE_CLOSED); |
| 76 | ++ g_assert_true (close_event); |
| 77 | ++ |
| 78 | ++ g_assert_cmpuint (soup_websocket_connection_get_close_code (test->client), ==, SOUP_WEBSOCKET_CLOSE_BAD_DATA); |
| 79 | ++} |
| 80 | ++ |
| 81 | + int |
| 82 | + main (int argc, |
| 83 | + char *argv[]) |
| 84 | +@@ -2441,6 +2476,15 @@ main (int argc, |
| 85 | + |
| 86 | + g_test_add_func ("/websocket/soup/connection-error", test_connection_error); |
| 87 | + |
| 88 | ++ g_test_add ("/websocket/direct/cve-2026-0716", Test, NULL, |
| 89 | ++ setup_direct_connection, |
| 90 | ++ test_cve_2026_0716, |
| 91 | ++ teardown_direct_connection); |
| 92 | ++ g_test_add ("/websocket/soup/cve-2026-0716", Test, NULL, |
| 93 | ++ setup_soup_connection, |
| 94 | ++ test_cve_2026_0716, |
| 95 | ++ teardown_soup_connection); |
| 96 | ++ |
| 97 | + ret = g_test_run (); |
| 98 | + |
| 99 | + test_cleanup (); |
| 100 | +-- |
| 101 | +2.45.4 |
| 102 | + |
0 commit comments