From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id E09iKJHOA2u8ci4AWB0awg (envelope-from ) for ; Mon, 23 Nov 2026 00:26:41 -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=GcuXsqco; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9473B1E167; Mon, 23 Nov 2026 00:26:41 -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.1 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_SBL_CSS 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 974B11E09B for ; Mon, 23 Nov 2026 00:26:40 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C99504315063 for ; Mon, 23 Nov 2026 05:26:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C99504315063 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=GcuXsqco Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id E8B924417BF2 for ; Mon, 23 Nov 2026 05:26:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8B924417BF2 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 E8B924417BF2 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795411574; cv=none; b=dN8tK1KGIduI5CnCJnhbuCpWN2kvWRuKrCVD2O5xeIeUwS/B0vB9tBIgA+p+e4+LBAV4nV+e4QXKBEMQKib7li5L1faU9rUmvNDyWZCD9M4u6ShhsgtFCkZa5fziM2u2ovOAECf+sksxGCFU1PKwc/p/cCqCySHo6Mp790Nz5cE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795411574; c=relaxed/simple; bh=mYIIfcbRQSwkvLOsm1O/MjRmfdKZHz4wlAujhcV7QYw=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=XGj+ZQ2nd7CR8z0OkLxX580P7orCtyKa+edPCei9PiAJyC4q4cR9aA68lc1L8xwnJNWPbfKZYGXfQvEdcZJOb/mnUBzpmki4SZpJvM9pzYdoRaF97d2HJVIB8PS7LujphBLgn0zhEFC3eo5BnCyBf6n0Cdab2ffH52Yl/CjbLIg= 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=GcuXsqco DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8B924417BF2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795411573; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AUkjE2BIzjI9y6DNa7PxBb9wIwRvwxUHCruqwHaGRqY=; b=GcuXsqcoIHbGQ0n49wOHDm4a8PrxnIbPcWWtMcjnzX/Kd27/wA3bt1zypzSfJyvR2UEDpX WQc3NL99dXjn8V2WTxjEGaK3dPA5JXG1nJm16pqioSaQUN0rZUJ3uaCiSLlS1w1vCPc8e2 La/5qJN9qe/WE7oz3kgXC0IguKIU5js= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-191-PntEk9yVMieDQBmNwCu6BQ-1; Mon, 23 Nov 2026 05:26:09 +0000 X-MC-Unique: PntEk9yVMieDQBmNwCu6BQ-1 X-Mimecast-MFC-AGG-ID: PntEk9yVMieDQBmNwCu6BQ_1795411568 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A3DE01955F44 for ; Mon, 23 Nov 2026 05:26:08 +0000 (UTC) Received: from [100.90.172.125] (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C1B14588; Mon, 23 Nov 2026 05:26:07 +0000 (UTC) Message-ID: <8bf598ac-9352-4556-9eb8-ca012cdff357@redhat.com> Date: Sun, 22 Nov 2026 22:26:03 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/5] gdbserver: avoid buffer overflow from 'm' and 'x' packets To: Andrew Burgess , gdb-patches@sourceware.org References: <742c0f2f772ecb9365d3411aef9acad9f7e2ef6d.1795186852.git.aburgess@redhat.com> From: Kevin Buettner In-Reply-To: <742c0f2f772ecb9365d3411aef9acad9f7e2ef6d.1795186852.git.aburgess@redhat.com> X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zzHZTuAQLP7mb3fg8Z-kHx_GBYkyiZSVktDmca7vg8M_1795411568 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 On 11/20/26 8:12 AM, Andrew Burgess wrote: > In the process_serial_event function (gdbserver/server.cc), the 'm' > and 'x' packets, which both read inferior memory, take a length from > the incoming packet and read that much data into a fixed-size buffer. > This read can overflow the buffer. > > Cap the length to avoid this overflow. For 'm', the length is capped > at half the buffer size, as the result of the read is passed through > bin2hex, which encodes each byte as two hex characters, doubling the > space required for the result. > > For 'x' the raw binary data is returned, so the full buffer size is > available. The binary data reply places a 'b' at the front; however, > the outbound result buffer is actually sized to 'PBUFSIZ + 1'. The > '+1' in this case allows for the 'b', as a binary data packet does not > need a trailing '\0' character. > > I've added a new test gdb.server/mx-packet-overflow.exp which tests a > number of different read request sizes with the 'm' and 'x' packets. I ran the entire series through my AI review workflow. For this first commit, it found a nit in the documentation: 3. [minor, 1/5 doc] gdb.texinfo limits text is inaccurate. SUBSTANTIALLY CONFIRMED. The added paragraphs (gdb.texinfo:43929-43935 and :44322-44328) say "maximum supported packet size, which is currently 131104 bytes". gdbserver advertises PacketSize=%x with PBUFSIZ-1 = 131103 (server.cc:2764), so the quoted number does not match what the stub reports; the text also states a gdbserver-specific limit in the generic protocol section without saying whose limit it is, and attributes future change to GDB releases. The numeric mismatch is objective; the wording judgements (b)/(c) are editorial. You can fix that if you want. I'm not that concerned about an off-by-one inaccuracy. (I'm still working through the rest.) Approved-By: Kevin Buettner