From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CRg9L0LL8moUhT0AWB0awg (envelope-from ) for ; Tue, 10 Nov 2026 02:44:02 -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=iXHr48Gl; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BC2411E06A; Tue, 10 Nov 2026 02:44:02 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 1039A1E043 for ; Tue, 10 Nov 2026 02:44:01 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C416D4BA2E21 for ; Tue, 10 Nov 2026 07:43:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C416D4BA2E21 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=iXHr48Gl 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 70DC54BA2E28 for ; Tue, 10 Nov 2026 07:43:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70DC54BA2E28 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 70DC54BA2E28 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=1794296592; cv=none; b=KxFHqsfk80Fj5XZsEX6dCEn1pp6VeHquqtGONcm3JTt5WG0bnb9VibGOtqf3vbiZXIk4laEGtt4t+nBcsoNeEWwPCQxyNx1coKveIiZ3brcTI54RVHVCIjRJtYGO7d2t4BjR39LLWaKEdBWeX2APWcx7kYL5eqf+FkotBavUwlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794296592; c=relaxed/simple; bh=Lx+o071rAuspT4mhqPIhKCwcz+jWcgnEE9UW80m1ics=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KtQLYyAaNEsVCBJWROlqkbDBd4dn8pF4sd+Ptwa6hUpaOAo8P7ob+vzukLMXs9HBUMRBB7UwHLNx6udqmv9TrhY3ZYvd4vvCa5dYixwNxORKOw/igZ3Yx/l4i6wVa+LnJnFrl2AFBbHTXkSAusyH923/Bo+1geOjIsZg9fQOg34= 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=iXHr48Gl DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70DC54BA2E28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794296592; 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=9ieOv6SRioAvO5Y70TN0RqNElqkD0KP1eAzg6X8ZW6c=; b=iXHr48GlvNqCcHTnYxVubbD1ZC6zQrpFByHl6W0qLfYpIwyvZNIn8xff3kFI0DsRSU2WK9 W+haouqbFaqobT5JvqXkYH8/unlEdrHjh8iftPbTsyLpN+IbRjJa5uwOWmeOa0vgYvOocu BBExP5tpsigigaWRqU+8XzK/j0px8Jc= Received: from mx-prod-mc-06.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-228-yLaEZfeJPGasD6sXofAxnw-1; Tue, 10 Nov 2026 02:43:06 -0500 X-MC-Unique: yLaEZfeJPGasD6sXofAxnw-1 X-Mimecast-MFC-AGG-ID: yLaEZfeJPGasD6sXofAxnw_1794296585 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4DFF7180054E for ; Tue, 10 Nov 2026 07:43:05 +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 70F401956086; Tue, 10 Nov 2026 07:43:04 +0000 (UTC) From: Kevin Buettner To: gdb-patches@sourceware.org Cc: Kevin Buettner Subject: [PATCH 2/2] gdb/testsuite: test malformed agent expressions sent to gdbserver Date: Tue, 10 Nov 2026 00:07:54 -0700 Message-ID: <20261110074218.1600179-3-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: B7g4ipjYhFH7OLR3cZNrL1sdz7Ciowgpgw5diVG4nds_1794296585 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 Add gdb.server/agent-expr-length.exp, which uses "maintenance packet" to send gdbserver agent expressions whose declared length exceeds the hex data present in the packet, or which lack the comma after the length. They are sent as breakpoint conditions and commands (Z0) and as tracepoint conditions and actions (QTDP). The test checks that gdbserver survives each one and, by reading the tracepoint definitions back with qTfP/qTsP, that the malformed parts are dropped instead of being stored with an uninitialized tail, while the well-formed conditions and actions alongside them are kept. Against a gdbserver without the previous commit's fix, the test shows the heap disclosure (a tracepoint condition read back with 63 bytes of heap contents beyond the single byte sent), and gdbserver crashes on the expressions with a huge declared length. This is a test for CVE-2026-121996. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34969 Assisted-by: LLM --- .../gdb.server/agent-expr-length.exp | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 gdb/testsuite/gdb.server/agent-expr-length.exp diff --git a/gdb/testsuite/gdb.server/agent-expr-length.exp b/gdb/testsuite/gdb.server/agent-expr-length.exp new file mode 100644 index 00000000000..f9c85fa5190 --- /dev/null +++ b/gdb/testsuite/gdb.server/agent-expr-length.exp @@ -0,0 +1,188 @@ +# Copyright 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test that gdbserver rejects agent expressions ("X,") whose +# declared length exceeds the hex data present in the packet, or which +# lack the comma after the length (CVE-2026-121996). Such expressions +# used to leave the tail of the expression's buffer uninitialized, +# which was then sent back to GDB as part of a tracepoint condition, +# and to advance gdbserver's packet parser past the end of the packet, +# crashing gdbserver. +# +# GDB never sends such an expression itself, so the packets are sent +# with "maintenance packet". Each case uses a fresh gdbserver, so +# that a crash in one does not hide the results of the others. + +load_lib gdbserver-support.exp + +require allow_gdbserver_tests + +standard_testfile normal.c + +if {[build_executable "failed to prepare" $testfile $srcfile]} { + return +} + +# Malformed expressions to try: one declaring 0x40 bytes but carrying +# only one, one whose declared length would move the parse pointer far +# beyond the end of the packet buffer, and one without the comma. +set bad_exprs {"X40,ab" "X10000000,ab" "X40"} + +# Start GDB and a new gdbserver, and connect them. Return true on +# success. + +proc start_gdbserver {} { + clean_restart $::testfile + + # Make sure we're disconnected, in case we're testing with an + # extended-remote board, therefore already connected. + gdb_test "disconnect" ".*" + + if {[gdbserver_run ""] != 0} { + fail "connect to gdbserver" + return false + } + return true +} + +# Send PACKET to gdbserver and return its reply, or the empty string +# if no reply was seen. TEST is the test name. + +proc send_packet { packet test } { + set reply "" + gdb_test_multiple "maintenance packet $packet" $test { + -re -wrap "received: \"(\[^\r\n\]*)\"" { + set reply $expect_out(1,string) + pass $gdb_test_name + } + } + return $reply +} + +# Send PACKET to gdbserver, expecting an "OK" reply. + +proc send_packet_ok { packet test } { + gdb_test "maintenance packet $packet" "received: \"OK\"" $test +} + +# Return true if gdbserver supports tracepoints. + +proc supports_tracepoints {} { + if {![start_gdbserver]} { + return false + } + return [expr {[send_packet "qTStatus" "query trace status"] != ""}] +} + +# Insert a breakpoint at main whose condition or commands (according to +# KIND) are the malformed expression EXPR. The expression must be +# rejected without disturbing gdbserver; the breakpoint itself is still +# inserted. + +proc test_breakpoint { kind expr } { + if {![start_gdbserver]} { + return + } + + set addr [format %x [get_hexadecimal_valueof "&main" 0]] + if {$kind == "condition"} { + set option $expr + } else { + set option "cmds:0,$expr" + } + + send_packet_ok "Z0,$addr,1;$option" "insert breakpoint" + send_packet_ok "z0,$addr,1" "remove breakpoint" +} + +# Send the tracepoint definition PACKETS to gdbserver, then read the +# definitions back, and check that they match EXPECTED. The +# malformed parts must not appear, in particular not with the heap +# contents an uninitialized buffer would contain. + +proc test_tracepoints { packets expected } { + if {![start_gdbserver]} { + return + } + + send_packet_ok "QTinit" "clear tracepoints" + set i 0 + foreach packet $packets { + incr i + send_packet_ok $packet "define tracepoint piece $i" + } + + set pieces {} + set reply [send_packet "qTfP" "read first tracepoint piece"] + set i 0 + while {$reply != "" && $reply != "l" && $i < 20} { + lappend pieces $reply + incr i + set reply [send_packet "qTsP" "read subsequent tracepoint piece $i"] + } + + gdb_assert {$pieces eq $expected} "tracepoint definitions" +} + +foreach_with_prefix kind {"condition" "commands"} { + foreach_with_prefix expr $bad_exprs { + test_breakpoint $kind $expr + } +} + +if {![supports_tracepoints]} { + unsupported "gdbserver does not support tracepoints" + return +} + +# Malformed tracepoint conditions are dropped. + +foreach_with_prefix expr $bad_exprs { + with_test_prefix "condition" { + test_tracepoints \ + [list \ + "QTDP:1:1000:E:1:1:X1,ab" \ + "QTDP:2:2000:E:1:1:$expr"] \ + [list \ + "T1:1000:E:1:1:X1,ab" \ + "T2:2000:E:1:1"] + } +} + +# The parser must find its way past a malformed condition to any +# following field, here a good condition. + +foreach_with_prefix expr $bad_exprs { + with_test_prefix "condition, then good condition" { + test_tracepoints \ + [list "QTDP:1:1000:E:1:1:$expr:X1,cd"] \ + [list "T1:1000:E:1:1:X1,cd"] + } +} + +# Malformed tracepoint actions are dropped, leaving the good ones. + +foreach_with_prefix expr $bad_exprs { + with_test_prefix "action" { + test_tracepoints \ + [list \ + "QTDP:1:1000:E:1:1-" \ + "QTDP:-1:1000:X1,ab-" \ + "QTDP:-1:1000:$expr"] \ + [list \ + "T1:1000:E:1:1" \ + "A1:1000:X1,ab"] + } +} -- 2.56.0