From patchwork Tue Jan 30 18:40:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 85043 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B10643857724 for ; Tue, 30 Jan 2024 18:41:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 01209385783F for ; Tue, 30 Jan 2024 18:40:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01209385783F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 01209385783F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706640055; cv=none; b=qMWqNKQqBzzlvPE+DJLXC3KvSYU0S3tjA8g8diTd9JqIYxATJsvI6Tl69SeQLNRhEuoyjwzV+jTgkZvZ4qv7TwgR5uY8VCrhO7ps0U4vtmmJ854DR03F931/8S3SGwUp58oNVYoZFBL7/GFAwyyw2AGvYK53KMcT2nGBW88BBBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706640055; c=relaxed/simple; bh=tQXIfFip2CMERNPziCGgg7JX0enInJR6YqHlaWGC8Jg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=D8rMOTyrBABti2MGh9O2/rTNCnjEdTZZtnsYBR/3T7JDHOeK2E4qV3nTbSD7kaNmvbBM0iNBUH9/cYFZ8CkMAER/kd0DU7eW1q6cy6tWF6tWnVpj13j50FId23iCn/UQ5mA0mgEhDTU1UKgZl2S3zp2fi083uUyVyP9ktzBfV5w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706640053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iZ9zu7nXzxgLKB35hSE+0M7Zv2ymLGtwxfVqEG+okEY=; b=VdSn17jgacb6jaoGba61MSuQ4J3AOPrkh4/4moLtrMtBYKD/uP7rw84VPqshiOc8ZnI/Z8 ckcU+nFPOKMyXmiWReBVmsw26We1Fj/M3SNCOc8D7meZu3aU2WW1+9LmIpxeCC8PiwoWSE jgw+CohNcUCyLngcT4LdKv9Hi5td9NI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-1_-6LRgNM0qFbHee278dHQ-1; Tue, 30 Jan 2024 13:40:50 -0500 X-MC-Unique: 1_-6LRgNM0qFbHee278dHQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCDEB85A589; Tue, 30 Jan 2024 18:40:49 +0000 (UTC) Received: from x1carbon9g.. (dhcp129-93.brq.redhat.com [10.34.129.93]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 26E202026D66; Tue, 30 Jan 2024 18:40:49 +0000 (UTC) From: Arjun Shankar To: libc-alpha@sourceware.org Cc: Arjun Shankar , Adhemerval Zanella , Carlos O'Donell Subject: [COMMITTED 1/4] syslog: Fix heap buffer overflow in __vsyslog_internal (CVE-2023-6246) Date: Tue, 30 Jan 2024 19:40:41 +0100 Message-ID: <20240130184045.511720-1-arjun@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org __vsyslog_internal did not handle a case where printing a SYSLOG_HEADER containing a long program name failed to update the required buffer size, leading to the allocation and overflow of a too-small buffer on the heap. This commit fixes that. It also adds a new regression test that uses glibc.malloc.check. Reviewed-by: Adhemerval Zanella Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell --- misc/Makefile | 8 ++- misc/syslog.c | 50 +++++++++++++------ misc/tst-syslog-long-progname.c | 39 +++++++++++++++ .../postclean.req | 0 4 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 misc/tst-syslog-long-progname.c create mode 100644 misc/tst-syslog-long-progname.root/postclean.req diff --git a/misc/Makefile b/misc/Makefile index 42899c2b6c..c273ec6974 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -289,7 +289,10 @@ tests-special += $(objpfx)tst-error1-mem.out \ $(objpfx)tst-allocate_once-mem.out endif -tests-container := tst-syslog +tests-container := \ + tst-syslog \ + tst-syslog-long-progname \ + # tests-container CFLAGS-select.c += -fexceptions -fasynchronous-unwind-tables CFLAGS-tsearch.c += $(uses-callbacks) @@ -351,6 +354,9 @@ $(objpfx)tst-allocate_once-mem.out: $(objpfx)tst-allocate_once.out $(common-objpfx)malloc/mtrace $(objpfx)tst-allocate_once.mtrace > $@; \ $(evaluate-test) +tst-syslog-long-progname-ENV = GLIBC_TUNABLES=glibc.malloc.check=3 \ + LD_PRELOAD=libc_malloc_debug.so.0 + $(objpfx)tst-select: $(librt) $(objpfx)tst-select-time64: $(librt) $(objpfx)tst-pselect: $(librt) diff --git a/misc/syslog.c b/misc/syslog.c index 1b8cb722c5..814d224a1e 100644 --- a/misc/syslog.c +++ b/misc/syslog.c @@ -124,8 +124,9 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap, { /* Try to use a static buffer as an optimization. */ char bufs[1024]; - char *buf = NULL; - size_t bufsize = 0; + char *buf = bufs; + size_t bufsize; + int msgoff; int saved_errno = errno; @@ -177,29 +178,50 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap, #define SYSLOG_HEADER_WITHOUT_TS(__pri, __msgoff) \ "<%d>: %n", __pri, __msgoff - int l; + int l, vl; if (has_ts) l = __snprintf (bufs, sizeof bufs, SYSLOG_HEADER (pri, timestamp, &msgoff, pid)); else l = __snprintf (bufs, sizeof bufs, SYSLOG_HEADER_WITHOUT_TS (pri, &msgoff)); + + char *pos; + size_t len; + if (0 <= l && l < sizeof bufs) { - va_list apc; - va_copy (apc, ap); + /* At this point, there is still a chance that we can print the + remaining part of the log into bufs and use that. */ + pos = bufs + l; + len = sizeof (bufs) - l; + } + else + { + buf = NULL; + /* We already know that bufs is too small to use for this log message. + The next vsnprintf into bufs is used only to calculate the total + required buffer length. We will discard bufs contents and allocate + an appropriately sized buffer later instead. */ + pos = bufs; + len = sizeof (bufs); + } - /* Restore errno for %m format. */ - __set_errno (saved_errno); + { + va_list apc; + va_copy (apc, ap); - int vl = __vsnprintf_internal (bufs + l, sizeof bufs - l, fmt, apc, - mode_flags); - if (0 <= vl && vl < sizeof bufs - l) - buf = bufs; - bufsize = l + vl; + /* Restore errno for %m format. */ + __set_errno (saved_errno); - va_end (apc); - } + vl = __vsnprintf_internal (pos, len, fmt, apc, mode_flags); + + if (!(0 <= vl && vl < len)) + buf = NULL; + + bufsize = l + vl; + va_end (apc); + } if (buf == NULL) { diff --git a/misc/tst-syslog-long-progname.c b/misc/tst-syslog-long-progname.c new file mode 100644 index 0000000000..88f37a8a00 --- /dev/null +++ b/misc/tst-syslog-long-progname.c @@ -0,0 +1,39 @@ +/* Test heap buffer overflow in syslog with long __progname (CVE-2023-6246) + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +extern char * __progname; + +static int +do_test (void) +{ + char long_progname[2048]; + + memset (long_progname, 'X', sizeof (long_progname) - 1); + long_progname[sizeof (long_progname) - 1] = '\0'; + + __progname = long_progname; + + syslog (LOG_INFO, "Hello, World!"); + + return 0; +} + +#include diff --git a/misc/tst-syslog-long-progname.root/postclean.req b/misc/tst-syslog-long-progname.root/postclean.req new file mode 100644 index 0000000000..e69de29bb2 From patchwork Tue Jan 30 18:40:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 85044 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9534A385773F for ; Tue, 30 Jan 2024 18:41:24 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 7EEA93857703 for ; Tue, 30 Jan 2024 18:40:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7EEA93857703 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7EEA93857703 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706640058; cv=none; b=SZVAr+ultIBmjLyo2uFyF4VWrUzBACHWasfPf2ntsFPWfINpnaHJXAxo61xOZl94GvWEFm7EiRQLh55bc6mUEoxaoSxNZNFs1MYM/QT1xg5w6IZJufSabQQaQ0w94XOmyX+tajV3+qwqqyaRGw9Tr9Y/As5YLpO1wZkEmLp76QY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706640058; c=relaxed/simple; bh=/ZrKY59HhPk9L8hmx7SJHBFfYFxZFIgITUlJADMfm3M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DuYY5G887E2OAlthfvL2IRFk4tpIXFSkIca/fyyQDfOcLfa/uqcgxdhb2kAtnj6hy4JkEfndSgflw1VKUXI3WigHTPArn5cqqcG0kp3IvIOetvFTmPaFwTthkq3OqYC04o/iZvRsawg8NlPoYWEeDms3ZD+0F4udn83XC6LS9pw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706640056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cAhXJXrP3mqInxwrH3OOmJxmXOvVZwRmst4yDZBMxAc=; b=H7UBnHMmbtx8R97XmPgNmDSHFfMpuchnY2EOYLx4JBdSGh4X8ZdQAxj1+d4jFzVQXAeT30 ezUOW7TM2jiBHB4UzRUuytBJPxoa/nHMg8BWZ2FYLcbOD6hSlpuLkEihiOKPauN4wLNXZu xYtevFgZZOcJpqqgJqqSuOQWFqKZs2k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-335-jagyxadRPmm21xXTk5T9Lg-1; Tue, 30 Jan 2024 13:40:54 -0500 X-MC-Unique: jagyxadRPmm21xXTk5T9Lg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8330285A596 for ; Tue, 30 Jan 2024 18:40:54 +0000 (UTC) Received: from x1carbon9g.. (dhcp129-93.brq.redhat.com [10.34.129.93]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E0EFB2026D66; Tue, 30 Jan 2024 18:40:53 +0000 (UTC) From: Arjun Shankar To: libc-alpha@sourceware.org Cc: Arjun Shankar , Carlos O'Donell Subject: [COMMITTED 2/4] syslog: Fix heap buffer overflow in __vsyslog_internal (CVE-2023-6779) Date: Tue, 30 Jan 2024 19:40:42 +0100 Message-ID: <20240130184045.511720-2-arjun@redhat.com> In-Reply-To: <20240130184045.511720-1-arjun@redhat.com> References: <20240130184045.511720-1-arjun@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org __vsyslog_internal used the return value of snprintf/vsnprintf to calculate buffer sizes for memory allocation. If these functions (for any reason) failed and returned -1, the resulting buffer would be too small to hold output. This commit fixes that. All snprintf/vsnprintf calls are checked for negative return values and the function silently returns upon encountering them. Reviewed-by: Carlos O'Donell --- misc/syslog.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/misc/syslog.c b/misc/syslog.c index 814d224a1e..53440e47ad 100644 --- a/misc/syslog.c +++ b/misc/syslog.c @@ -185,11 +185,13 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap, else l = __snprintf (bufs, sizeof bufs, SYSLOG_HEADER_WITHOUT_TS (pri, &msgoff)); + if (l < 0) + goto out; char *pos; size_t len; - if (0 <= l && l < sizeof bufs) + if (l < sizeof bufs) { /* At this point, there is still a chance that we can print the remaining part of the log into bufs and use that. */ @@ -215,12 +217,15 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap, __set_errno (saved_errno); vl = __vsnprintf_internal (pos, len, fmt, apc, mode_flags); + va_end (apc); + + if (vl < 0) + goto out; - if (!(0 <= vl && vl < len)) + if (vl >= len) buf = NULL; bufsize = l + vl; - va_end (apc); } if (buf == NULL) @@ -231,25 +236,37 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap, /* Tell the cancellation handler to free this buffer. */ clarg.buf = buf; + int cl; if (has_ts) - __snprintf (buf, l + 1, - SYSLOG_HEADER (pri, timestamp, &msgoff, pid)); + cl = __snprintf (buf, l + 1, + SYSLOG_HEADER (pri, timestamp, &msgoff, pid)); else - __snprintf (buf, l + 1, - SYSLOG_HEADER_WITHOUT_TS (pri, &msgoff)); + cl = __snprintf (buf, l + 1, + SYSLOG_HEADER_WITHOUT_TS (pri, &msgoff)); + if (cl != l) + goto out; va_list apc; va_copy (apc, ap); - __vsnprintf_internal (buf + l, bufsize - l + 1, fmt, apc, - mode_flags); + cl = __vsnprintf_internal (buf + l, bufsize - l + 1, fmt, apc, + mode_flags); va_end (apc); + + if (cl != vl) + goto out; } else { + int bl; /* Nothing much to do but emit an error message. */ - bufsize = __snprintf (bufs, sizeof bufs, - "out of memory[%d]", __getpid ()); + bl = __snprintf (bufs, sizeof bufs, + "out of memory[%d]", __getpid ()); + if (bl < 0 || bl >= sizeof bufs) + goto out; + + bufsize = bl; buf = bufs; + msgoff = 0; } } From patchwork Tue Jan 30 18:40:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 85045 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EB0323857432 for ; Tue, 30 Jan 2024 18:42:10 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 049763857714 for ; Tue, 30 Jan 2024 18:40:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 049763857714 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 049763857714 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706640060; cv=none; b=AK9TwGfQGII9QduuCfkiUNXjjXrDLwpuXTgvbE3y5YB3pWHCqYLxPttxjAgQZZwrAxerH5nVtEkhdOsMKgMrrlc/brgzeFswR8NcJ1qSGRxM5VSyHoiDFuQ1YnmTa9a1/2MDge6CbXA+KoxHlH+ICWpti9bYzOuqx3bjTp01LXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706640060; c=relaxed/simple; bh=nZ+hcJjjxTmJowltMN8Z4HhiFSfk1e9FtGM6ugD//4I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=noQJ8dW1jF0ckNwvm6k6pjrlnBFtKFI91/YotoO+83xoBfZdBiq+k0bA+wxeXPOa9GOViSVTWpK4RXf/a02a87Ewjp0o1wM/Y1mPBzhMkbOxachqbuiu0hxfq2ykbFs4xRQ1VVKL5Vrt1kteTuptN2VuDlTUi38aQtCBWB3/yxw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706640058; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QpQi/WFnmc1kJ9FXxs3URkAsu9rcl5ajpSiMl0EKBp8=; b=KSFC7clqO/+VTRZ98evRMmP7bWELqOaZopayoyg9uV6hpegqhg+ATp4NmG3oUum/E0aplR cSkNfgF9QLnZj6y2JcGRrtNKh6Hcsq+8NNGGvIOj0sEv0BzgE4zWIOSiTld1dBfk/y4tMm 6dGkm0JQ87nLS0V6jjDfLmNBHpn3aGI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-481-pu7PLqksOpOK9zKOkR-IkA-1; Tue, 30 Jan 2024 13:40:56 -0500 X-MC-Unique: pu7PLqksOpOK9zKOkR-IkA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3784C1C0512C for ; Tue, 30 Jan 2024 18:40:56 +0000 (UTC) Received: from x1carbon9g.. (dhcp129-93.brq.redhat.com [10.34.129.93]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 95BF02026D66; Tue, 30 Jan 2024 18:40:55 +0000 (UTC) From: Arjun Shankar To: libc-alpha@sourceware.org Cc: Arjun Shankar , Carlos O'Donell Subject: [COMMITTED 3/4] syslog: Fix integer overflow in __vsyslog_internal (CVE-2023-6780) Date: Tue, 30 Jan 2024 19:40:43 +0100 Message-ID: <20240130184045.511720-3-arjun@redhat.com> In-Reply-To: <20240130184045.511720-1-arjun@redhat.com> References: <20240130184045.511720-1-arjun@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org __vsyslog_internal calculated a buffer size by adding two integers, but did not first check if the addition would overflow. This commit fixes that. Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell --- misc/syslog.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/misc/syslog.c b/misc/syslog.c index 53440e47ad..4af87f54fd 100644 --- a/misc/syslog.c +++ b/misc/syslog.c @@ -41,6 +41,7 @@ static char sccsid[] = "@(#)syslog.c 8.4 (Berkeley) 3/18/94"; #include #include #include +#include static int LogType = SOCK_DGRAM; /* type of socket connection */ static int LogFile = -1; /* fd for log */ @@ -219,7 +220,7 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap, vl = __vsnprintf_internal (pos, len, fmt, apc, mode_flags); va_end (apc); - if (vl < 0) + if (vl < 0 || vl >= INT_MAX - l) goto out; if (vl >= len) From patchwork Tue Jan 30 18:40:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 85046 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A83A3857038 for ; Tue, 30 Jan 2024 18:42:12 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id AD8FC385770C for ; Tue, 30 Jan 2024 18:41:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD8FC385770C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AD8FC385770C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706640062; cv=none; b=UiI4LlFXH3xhLBWpKNrxHjSYkM0UwkpaYw5QrVz1F2orfw00n9OsxxcaufqHxwoyPrmeCtVVAG+J1LtavpNtmS0a4x7nOGG7P6o1GW3I9wmwqDuQseT8fIWpkio5gVVr7aDhfbmX82ndGo6518M1KGCHLO7zcQ/LAmjhU/cLQvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706640062; c=relaxed/simple; bh=0GNt57OGKjFbNADoZWxbpn1WGKkBLoKwLoitpxxseX0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sg7tYDeWN2GBBy9fPRkjWDrKQksV9W+V0jiSuYyPUEiymdQpZ4Z3ynkZcpnahBggpTqXxR9XuFzSUUXXaBCASy2jqop4ssWkqf7SrfXbdTTuaTkQI7LYdaVyMI3+sr6EXmqSldx/0QVrTMNOUhffSMAWrmhLbUygI6RMBckt9K0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706640060; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BTaG4FFYfxAW4YjSCnlAyn5AarqcrJDLpakOPRLStvI=; b=DdFMrcAFoMwSP/XWPYC661YwpUH+pkZKromo8btnIjZNTDMaGLEcPmRaCpsyYyRi03yg4Q FMmS267SeaFrHpygxBqXIOs61GtA22roIdih1kiNvIHGijjUia0bHMkut4ubxeseZXWwLR LJVyM9ddKqH6Hiyhgo55Js8GBlDSXwU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-tFeT8FjENTaDTKKim8oc-g-1; Tue, 30 Jan 2024 13:40:58 -0500 X-MC-Unique: tFeT8FjENTaDTKKim8oc-g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7AF4A1C0512C for ; Tue, 30 Jan 2024 18:40:58 +0000 (UTC) Received: from x1carbon9g.. (dhcp129-93.brq.redhat.com [10.34.129.93]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 054E42026D66; Tue, 30 Jan 2024 18:40:57 +0000 (UTC) From: Arjun Shankar To: libc-alpha@sourceware.org Cc: Arjun Shankar Subject: [COMMITTED 4/4] Document CVE-2023-6246, CVE-2023-6779, and CVE-2023-6780 Date: Tue, 30 Jan 2024 19:40:44 +0100 Message-ID: <20240130184045.511720-4-arjun@redhat.com> In-Reply-To: <20240130184045.511720-1-arjun@redhat.com> References: <20240130184045.511720-1-arjun@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_LOTSOFHASH, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org This commit adds "advisories" entries for the above three CVEs. --- advisories/GLIBC-SA-2024-0001 | 15 +++++++++++++++ advisories/GLIBC-SA-2024-0002 | 15 +++++++++++++++ advisories/GLIBC-SA-2024-0003 | 13 +++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 advisories/GLIBC-SA-2024-0001 create mode 100644 advisories/GLIBC-SA-2024-0002 create mode 100644 advisories/GLIBC-SA-2024-0003 diff --git a/advisories/GLIBC-SA-2024-0001 b/advisories/GLIBC-SA-2024-0001 new file mode 100644 index 0000000000..28931c75ae --- /dev/null +++ b/advisories/GLIBC-SA-2024-0001 @@ -0,0 +1,15 @@ +syslog: Heap buffer overflow in __vsyslog_internal + +__vsyslog_internal did not handle a case where printing a SYSLOG_HEADER +containing a long program name failed to update the required buffer +size, leading to the allocation and overflow of a too-small buffer on +the heap. + +CVE-Id: CVE-2023-6246 +Public-Date: 2024-01-30 +Vulnerable-Commit: 52a5be0df411ef3ff45c10c7c308cb92993d15b1 (2.37) +Fix-Commit: 6bd0e4efcc78f3c0115e5ea9739a1642807450da (2.39) +Fix-Commit: 23514c72b780f3da097ecf33a793b7ba9c2070d2 (2.38-42) +Fix-Commit: 97a4292aa4a2642e251472b878d0ec4c46a0e59a (2.37-57) +Vulnerable-Commit: b0e7888d1fa2dbd2d9e1645ec8c796abf78880b9 (2.36-16) +Fix-Commit: d1a83b6767f68b3cb5b4b4ea2617254acd040c82 (2.36-126) diff --git a/advisories/GLIBC-SA-2024-0002 b/advisories/GLIBC-SA-2024-0002 new file mode 100644 index 0000000000..940bfcf2fc --- /dev/null +++ b/advisories/GLIBC-SA-2024-0002 @@ -0,0 +1,15 @@ +syslog: Heap buffer overflow in __vsyslog_internal + +__vsyslog_internal used the return value of snprintf/vsnprintf to +calculate buffer sizes for memory allocation. If these functions (for +any reason) failed and returned -1, the resulting buffer would be too +small to hold output. + +CVE-Id: CVE-2023-6779 +Public-Date: 2024-01-30 +Vulnerable-Commit: 52a5be0df411ef3ff45c10c7c308cb92993d15b1 (2.37) +Fix-Commit: 7e5a0c286da33159d47d0122007aac016f3e02cd (2.39) +Fix-Commit: d0338312aace5bbfef85e03055e1212dd0e49578 (2.38-43) +Fix-Commit: 67062eccd9a65d7fda9976a56aeaaf6c25a80214 (2.37-58) +Vulnerable-Commit: b0e7888d1fa2dbd2d9e1645ec8c796abf78880b9 (2.36-16) +Fix-Commit: 2bc9d7c002bdac38b5c2a3f11b78e309d7765b83 (2.36-127) diff --git a/advisories/GLIBC-SA-2024-0003 b/advisories/GLIBC-SA-2024-0003 new file mode 100644 index 0000000000..b43a5150ab --- /dev/null +++ b/advisories/GLIBC-SA-2024-0003 @@ -0,0 +1,13 @@ +syslog: Integer overflow in __vsyslog_internal + +__vsyslog_internal calculated a buffer size by adding two integers, but +did not first check if the addition would overflow. + +CVE-Id: CVE-2023-6780 +Public-Date: 2024-01-30 +Vulnerable-Commit: 52a5be0df411ef3ff45c10c7c308cb92993d15b1 (2.37) +Fix-Commit: ddf542da94caf97ff43cc2875c88749880b7259b (2.39) +Fix-Commit: d37c2b20a4787463d192b32041c3406c2bd91de0 (2.38-44) +Fix-Commit: 2b58cba076e912961ceaa5fa58588e4b10f791c0 (2.37-59) +Vulnerable-Commit: b0e7888d1fa2dbd2d9e1645ec8c796abf78880b9 (2.36-16) +Fix-Commit: b9b7d6a27aa0632f334352fa400771115b3c69b7 (2.36-128)