From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 1yWRB4VcA2sGPy0AWB0awg (envelope-from ) for ; Sun, 22 Nov 2026 16:20:05 -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=CtAh8Djq; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DCAC51E023; Sun, 22 Nov 2026 16:20:04 -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 [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 DB9151E023 for ; Sun, 22 Nov 2026 16:20:02 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 78CD94292CEE for ; Sun, 22 Nov 2026 21:20:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78CD94292CEE 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=CtAh8Djq 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 5E66943CC23C for ; Sun, 22 Nov 2026 21:19:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E66943CC23C 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 5E66943CC23C 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=1795382375; cv=none; b=R1d7ii2NOfI830OqbcLs7XqpTAVxclFkxOEcDr0ksxLTq2NBeWgZY8PVvvcDtRyRKLg1T/lfocGR5WpOFOI2/WqIQZHRsNOlVtCfd18e65ZiAscVsmYxypYrxxhZj/Bpuy0/NP2K/hz+w2Plh68xChMCG7ScbONzFS5gZisNPDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795382375; c=relaxed/simple; bh=UPecsOHpP4GxUgBfa8YyRlbEsY/C7uywa+pI5XYK0ec=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Zwoz/pWvVvf6su0YUX7znOftvuppYTEUaMZ2+PFvNlidbUcWmAgNh/JNPMrS3tyZ74sZ2RcGmou3iMNMgSsUpipeHiA7XEPFmN1P80U7z2/9Ggehb6PVPA6wtzU18OQ8bJqDGgXk8MQPo/xPNiFF0heYetRAhIrLCAY9m57V/BA= 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=CtAh8Djq DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E66943CC23C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795382375; 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: in-reply-to:in-reply-to:references:references; bh=UcoKMj0rYQbdr1h+RNTOnPqbIoq4OzyFHPHIv9r3cZo=; b=CtAh8DjqDVxJBprnybtkmdwzeDir+fnJmMAqaxOxiEIP2XQDUMG7s6zqV72/EQ1TBr136m 6dPz38g9fXOjmcxbJlTU4ZNpE6Kdzi6+iprbYv6zuSs3Ljp1LGh96gp4dKISl/YHwkXEoK pStsv5QrGqM4C3frORbZkQbMuvlCT20= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-296-hlVbWIDJMZC173jQ7g7mjQ-1; Sun, 22 Nov 2026 21:19:10 +0000 X-MC-Unique: hlVbWIDJMZC173jQ7g7mjQ-1 X-Mimecast-MFC-AGG-ID: hlVbWIDJMZC173jQ7g7mjQ_1795382349 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4a647e776b4so1886327f8f.1 for ; Sun, 22 Nov 2026 13:19:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795382349; x=1795987149; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=UcoKMj0rYQbdr1h+RNTOnPqbIoq4OzyFHPHIv9r3cZo=; b=TtVdR6zyKsgtXhlquHoIZipVyyBx89qlPJaA8jdx72akC5O892sHZzJNLDhQIAbUj6 79kG9gY7nsNGIuy+qlbYxB9JeW4mI4dfZ769ABfO46jiy1J5fNH6vGsDz14Cba4OSOOk g1fa0HpGnogRBlA8XRF7ZEtZUEjtd6TBKolr7zi+F191olD2hZH2rNy8zbVbVyEmKKwV oZvqPnmUgwYK8nddM18nBLdiGBG906nIf4LKsv7v+EuPBOgcXuzBZn+sQNnoMCnsEJDc 6ZMBKvEcwjiqEsud3HJcdpbqruOqXQHS48IzGkkyg0nnDT9zLNYOTsCBOM2i01rr7jlp MyLw== X-Forwarded-Encrypted: i=1; AL+hErEICYmUxhYtLhruIoU84hgsM96dZcH/KZXn6mmxytW/4nDgRERvGDJV4vymc8Oof9gi1wZZf6OgqLKGeQ==@sourceware.org X-Gm-Message-State: APuU4Z8DNvc42z3PFp5aqjwjy/YHgZrAYYAyKmVe4E0c/551/ZNxQa/0 N++6THcCpB+9Ujz6sY5N57LPOycO4FNmqt6mk7+BwXZbuWLtH83FS8Otr7MSLywW5WbfpkhU2B3 rmfVuSfF1+gcEHtpLPxuTRR/z5njLyEzv2Q3WBW64Sg4DgSh2d6QPfLc0TPnelAI= X-Gm-Gg: AZFdTZd+2NGF6V7Cph7dgC6cZPDjsY1SRMbLtcYLm2i81OE8oalmzN+FATvJz+JyvVw H+RGYWHAz04MBILa+OEi/Gdu+VSiXMgvV+4hVzq39Cm5c3MGcyF9St/Y3rnYSXpzVXYx4uUhzqU 8Bi+tWO4M86h7SZxL2fjOfb2GZw0AZ7X3cpd9tEBTvIdX1ZFLD+mh9QmFna9RqaPRT9H6LbBhFG i2V98ZZHGhrkkQ9hcFBY0k8sEMtmx4exyqSH39KjGl7zNLgsTecZd38PT5ee3EydycWTxE/qWRz 6SMgE49TCHqUVnqJAiTynKLpXHS0STLQgswslnwyTO8dsXiuKw1iLguyYmfU17rzoNsS9MAb4v7 YokoBAHgWoBTS9yH/TkjRl6pmelR0lRf8HfbLZuQvdAg4TQ== X-Received: by 2002:a5d:64eb:0:b0:4ae:e824:1fa8 with SMTP id ffacd0b85a97d-4aee8241fc9mr8862103f8f.9.1795382349159; Sun, 22 Nov 2026 13:19:09 -0800 (PST) X-Received: by 2002:a5d:64eb:0:b0:4ae:e824:1fa8 with SMTP id ffacd0b85a97d-4aee8241fc9mr8862079f8f.9.1795382348671; Sun, 22 Nov 2026 13:19:08 -0800 (PST) Received: from localhost ([83.216.138.189]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6baa3c4dsm15286117f8f.46.2026.11.22.13.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2026 13:19:08 -0800 (PST) From: Andrew Burgess To: Kevin Buettner , gdb-patches@sourceware.org Cc: Kevin Buettner Subject: Re: [PATCH v2 1/1] gdbserver: reject malformed agent expressions in gdb_parse_agent_expr In-Reply-To: <20261120084131.659727-3-kevinb@redhat.com> References: <20261120084131.659727-2-kevinb@redhat.com> <20261120084131.659727-3-kevinb@redhat.com> Date: Sun, 22 Nov 2026 21:19:05 +0000 Message-ID: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: n0XJsfIyX0J5eFL2eVnZpZ4EjSWHJKbb-zfuMxAzdac_1795382349 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 Kevin Buettner writes: > 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 agent expressions > 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' packet. These conditions or commands are > specified in a bytecode format identical to that used for agent > expressions for tracepoints. > > The current implementation of gdb_parse_agent_expr contains 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 'Z0' 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, a potential > security concern. > > The parse pointer is also advanced by 2 * LEN bytes regardless of how > much data was present, so callers continue parsing from a pointer that > can be far beyond the end of the packet; a large LEN crashes gdbserver. > > Fix this by having gdb_parse_agent_expr return nullptr (representing > an error condition) when the specified length exceeds the amount of > hex data actually present. This code also wasn't checking for the > mandated comma character in the packet syntax. I added a check and > error return for that too. > > The remainder of this patch to gdbserver consists of propagating the > error back to various points in the code where write_enn may be > called. This causes the error to be sent as the reply to GDB. > > For Z0 packet support, I removed two warning messages. One concerned > a malformed condition and the other was about a malformed action > (command). A malformed condition was discarded, making the breakpoint > unconditional; similarly, a malformed action was simply dropped. The > warning message (which might not even be seen by the user) stated > these facts. gdbserver now returns an error response for these cases. > > The test case uses GDB's little-used "maintenance packet" command to > send bad packets to gdbserver. This has been done not only for the > tracepoint related packets, but for the Z0 (set breakpoint) packet as > well. Z0 used to silently drop malformed packets and set a breakpoint > without the (presumably intended, but malformed) condition or action. > It no longer does this. Malformed conditions and actions within a > Z0 packet now cause an error to be returned. > > While working on this patch, I spotted numerous other problems in > nearby code (e.g. memory leaks and lack of packet syntax checking). > I left these alone. gdbserver desperately needs attention to fix > myriad problems. > > This fixes the bug associated with CVE-2026-121996. > > Regression tested on x86_64 Fedora 44. The new test case was tested > on RISC-V Fedora 42, for which neither Z0 packets nor tracepoint > packets are implemented. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34969 Hi Kevin, Thanks for working on this. I agree that the gdbserver code is in need of some serious updates, but you cannot be expected to fix everything in one go. I think this fix is basically sound. I do have a couple of minor nits (see inline below), but I think once these are resolved: Approved-By: Andrew Burgess > +# Send out Z0 / z0 (breakpoint) packets for this test. Use "main" for the > +# address at which to place the breakpoint. > +proc test_Z0 {exp testname} { > + with_test_prefix $testname { > + prepare_server > + set addr [format %x [get_hexadecimal_valueof "&main" 0]] Is the 'format' really needed here? Doesn't get_hexadecimal_valueof return a value in hex format? > + > +# Check whether gdbserver supports the Z0 packet; return 1 if so, otherwise > +# return 0 and show that tests involving Z0 packets are unsupported. Throughout this file: TCL supports true/false, so you don't need to use 1/0. > diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc > index 6f657257ee8..4cd1722869b 100644 > --- a/gdbserver/tracepoint.cc > +++ b/gdbserver/tracepoint.cc > @@ -1802,7 +1802,7 @@ find_next_tracepoint_by_number (struct tracepoint *prev_tp, int num) > > /* Append another action to perform when the tracepoint triggers. */ > > -static void > +static bool > add_tracepoint_action (struct tracepoint *tpoint, const char *packet) The header comment for this function should be updated to reflect the change in return type. Thanks, Andrew