CVE-2023-39976 (published 2023-08-08T06:15Z)

log_blackbox.c in libqb before 2.0.8 allows a buffer overflow via long log messages because the header size is not considered.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-120
cwe_name: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
description: The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.
extended_description: A buffer overflow condition exists when a product attempts to put more data in a buffer than it can hold, or when it attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the product copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
         

Fix information:
repo_url: https://github.com/ClusterLabs/libqb
commit_details: repo_url: https://github.com/ClusterLabs/libqb
author: Chrissie Caulfield
author_date: 2023-07-20 07:19:01+01:00
msg: log: fix potential overflow with long log messages (#490)

qb_vsnprintf_serialize was called with 'max_size' as the
limiting number for the length of the formatted log
message. But the buffer also needs to contain the
log header (given by 'actual_size'), so we now pass
't->max_line_length' as the maximum length of the
formatted log message to limit space to the actual 
bytes left

Also added error checks to the blackbox calls at
the end of the test, as these now provide a proper
test that the BB is functioning. Before they were
masking failures.
repository: repo_url: https://github.com/ClusterLabs/libqb
repo_name: ClusterLabs/libqb
description: libqb is a library providing high performance logging, tracing, ipc, and poll.
repo_language: C
owner: ClusterLabs
file_changes: filename: log_blackbox.c
change_type: ModificationType.MODIFY
diff: @@ -110,8 +110,8 @@ _blackbox_vlogger(int32_t target,
 	chunk += sizeof(uint32_t);
 
 	/* log message */
-	msg_len = qb_vsnprintf_serialize(chunk, max_size, cs->format, ap);
-	if (msg_len >= max_size) {
+	msg_len = qb_vsnprintf_serialize(chunk, t->max_line_length, cs->format, ap);
+	if (msg_len >= t->max_line_length) {
 	    chunk = msg_len_pt + sizeof(uint32_t); /* Reset */
 
 	    /* Leave this at QB_LOG_MAX_LEN so as not to overflow the blackbox */

programming_language: C
filename: check_log.c
change_type: ModificationType.MODIFY
diff: @@ -832,8 +832,10 @@ START_TEST(test_log_long_msg)
 		qb_log(LOG_INFO, "Message %d %d - %s", lpc, lpc%600, buffer);
 	}
 
-        qb_log_blackbox_write_to_file("blackbox.dump");
-        qb_log_blackbox_print_from_file("blackbox.dump");
+        rc = qb_log_blackbox_write_to_file("blackbox.dump");
+	ck_assert_int_gt(rc, 0);
+        rc = qb_log_blackbox_print_from_file("blackbox.dump");
+	ck_assert_int_le(rc, 0);
 	unlink("blackbox.dump");
 	qb_log_fini();
 }

programming_language: C