From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id PuzIKyvL8moUhT0AWB0awg (envelope-from ) for ; Tue, 10 Nov 2026 02:43:39 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=P8+hRcmT; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8C0891E06A; Tue, 10 Nov 2026 02:43:39 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 6B3531E043 for ; Tue, 10 Nov 2026 02:43:37 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A96F4BA23E2 for ; Tue, 10 Nov 2026 07:43:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A96F4BA23E2 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=P8+hRcmT Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 728D94BA2E06 for ; Tue, 10 Nov 2026 07:43:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 728D94BA2E06 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 728D94BA2E06 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794296585; cv=none; b=tZE8Kf2NqA2YtQNZ6uYLl55EfenisOFWt0IG4TltnfGROmc4SnadVEraniO5XZXEH8ljE0lBskLc3436nA18fBo2t+tYOIbfgq7aEP/RuLhIloM6kNr91aykdH9/dmCe5xZPu09irYAz4jSnPKGtJMLy+NrggQ3/JWRxybaN49M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794296585; c=relaxed/simple; bh=jx/PDMQ2+ZhV8J2zULPhY/kDDeQqZ3ZaKbSkvR7hb10=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jMJpnrUxBxKFXSF64VShdwwUHauObnYYxxm6RTLlPjavybzhHogBvzOeLQs8h+tSRlCwl9nD7VzpdiUa2QkH3J2UFAPLWiV39X3FGdS7df0PNs4jAubHg1pPPtJi6NxZGdGNpozWXv2iD//tkaE5420AAoYpDS7LhUKSVoklAUY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=P8+hRcmT DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 728D94BA2E06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794296585; 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=wSiyfW7GhwU+FKNRxJ1q0L2SOHb0yzlcFTYffeTuxY0=; b=P8+hRcmTxFYZQ5MXY2R/9OclXHF3fxFKkzUVgdY7ELPtVC0dCkCRKqz2g8yxsHZHgWeyL6 jzzhBy9ik9cQhQjouS1GTYg1n0+NCAwsQaSvF935MnWUYwseIAI4p/SRJ34jw9z2sFQs61 Qruk5sWxyxRqq/BvHJd8FTp3vzoUEeI= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-130-dkuTqPEFNa2H13hAon0CCg-1; Tue, 10 Nov 2026 02:43:02 -0500 X-MC-Unique: dkuTqPEFNa2H13hAon0CCg-1 X-Mimecast-MFC-AGG-ID: dkuTqPEFNa2H13hAon0CCg_1794296582 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DDBCD1800547 for ; Tue, 10 Nov 2026 07:43:01 +0000 (UTC) Received: from kevinb-defaultstring.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2AA2D1956086; Tue, 10 Nov 2026 07:43:00 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH 1/2] gdbserver: reject malformed agent expressions in gdb_parse_agent_expr Date: Tue, 10 Nov 2026 00:07:53 -0700 Message-ID: <20261110074218.1600179-2-kevinb@redhat.com> In-Reply-To: <20261110074218.1600179-1-kevinb@redhat.com> References: <20261110074218.1600179-1-kevinb@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: bqeUgasBXCJmqjXaS6VTEtR-u0Kblm-ODiacHeHLZPM_1794296582 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org gdb_parse_agent_expr, defined in gdbserver/ax.cc, is called from four different sites within gdbserver, two from mem-break.cc and two from tracepoint.cc. Within tracepoint.cc, gdb_parse_agent_expr is called to handle the 'X' portion of a QTDP packet. The 'X' portion describes an agent expression used by tracepoints for both conditions and actions. Within mem-break.cc, it's called to handle breakpoint conditions or commands as part of a 'z' or 'Z' packet. These conditions or commands are specified in a bytecode format identical to that used for agent expressions for tracepoints. Despite the fact that they use the same format, this functionality is separate from the tracepoint facility. (Though within gdbserver, some of it is implemented using the same code.) The current implementation of gdb_parse_agent_expr has no checks about validity of the length specified in the portion of a packet that represents an agent expression. This takes the form "X,". (This is not an 'X' packet but, rather, a portion of the 'QTDP' packet for tracepoints or 'Z' packet for breakpoints.) gdb_parse_agent_expr allocates LEN bytes and asks hex2bin to convert that number of bytes, but hex2bin stops at the end of the packet, leaving the end of the buffer uninitialized. For a tracepoint condition, that buffer is later sent back to GDB in reply to qTfP/qTsP, which are used to request tracepoint data. Thus, using an overly large length can provide access to uninitialized gdbserver heap memory. The parse pointer is also advanced by 2 * LEN regardless of how much data was present, so the callers continue parsing from a pointer that can be far beyond the end of the packet; a large LEN crashes gdbserver. Similarly, a missing comma after LEN causes the parser to step past the packet's terminating NUL. Fix this by having gdb_parse_agent_expr return nullptr when the comma is missing or when LEN exceeds the amount of hex data remaining in the packet. The Z packet condition and command paths (in mem-break.cc) already handle a nullptr return. Make the tracepoint action parser discard an action whose expression could not be parsed, and make the QTDP parser skip a malformed condition, so that any remaining fields, including the trailing hyphen, are still processed. As is already the case for breakpoint conditions, this change causes the tracepoint to be defined without the condition. This fixes the bug associated with CVE-2026-121996. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34969 --- gdbserver/ax.cc | 15 ++++++++++++--- gdbserver/ax.h | 4 +++- gdbserver/tracepoint.cc | 12 ++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/gdbserver/ax.cc b/gdbserver/ax.cc index 4993bed2532..beec324f9b0 100644 --- a/gdbserver/ax.cc +++ b/gdbserver/ax.cc @@ -91,8 +91,7 @@ gdb_agent_op_name (int op) #ifndef IN_PROCESS_AGENT -/* The packet form of an agent expression consists of an 'X', number - of bytes in expression, a comma, and then the bytes. */ +/* See ax.h. */ struct agent_expr * gdb_parse_agent_expr (const char **actparm) @@ -103,7 +102,17 @@ gdb_parse_agent_expr (const char **actparm) ++act; /* skip the X */ act = unpack_varlen_hex (act, &xlen); - ++act; /* skip a comma */ + + /* The length must be followed by a comma, and must not exceed the + amount of hex data present in the packet. Otherwise HEX2BIN would + leave the tail of the buffer uninitialized, and the parse pointer + would be advanced past the end of the packet. */ + if (*act != ',') + return nullptr; + ++act; /* skip the comma */ + if (xlen > strlen (act) / 2) + return nullptr; + aexpr = XNEW (struct agent_expr); aexpr->length = xlen; aexpr->bytes = (unsigned char *) xmalloc (xlen); diff --git a/gdbserver/ax.h b/gdbserver/ax.h index 03882f4888a..7ad077f8195 100644 --- a/gdbserver/ax.h +++ b/gdbserver/ax.h @@ -48,7 +48,9 @@ struct agent_expr #ifndef IN_PROCESS_AGENT /* The packet form of an agent expression consists of an 'X', number - of bytes in expression, a comma, and then the bytes. */ + of bytes in expression, a comma, and then the bytes. Parse one at + *ACTPARM, advancing *ACTPARM past it. Return nullptr, leaving + *ACTPARM unchanged, if the expression is malformed. */ struct agent_expr *gdb_parse_agent_expr (const char **actparm); /* Release an agent expression. */ diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc index 6f657257ee8..d0f9228cad1 100644 --- a/gdbserver/tracepoint.cc +++ b/gdbserver/tracepoint.cc @@ -1877,6 +1877,11 @@ add_tracepoint_action (struct tracepoint *tpoint, const char *packet) trace_debug ("Want to evaluate expression"); xaction->expr = gdb_parse_agent_expr (&act); + if (xaction->expr == nullptr) + { + free (xaction); + action = nullptr; + } break; } default: @@ -2404,6 +2409,13 @@ cmd_qtdp (char *own_buf) else if (*packet == 'X') { tpoint->cond = gdb_parse_agent_expr (&packet); + if (tpoint->cond == nullptr) + { + /* Skip the malformed expression, so that any remaining + fields, and the trailing hyphen, are still seen. */ + trace_debug ("Malformed tracepoint condition, ignoring"); + packet += strcspn (packet, ":-"); + } } else if (*packet == '-') break; -- 2.56.0