From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id FfjEHmhpAGuLiCQAWB0awg (envelope-from ) for ; Fri, 20 Nov 2026 10:38:16 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=Moz70rCq; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6D3AA1E023; Fri, 20 Nov 2026 10:38:16 -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 AB97D1E023 for ; Fri, 20 Nov 2026 10:38:15 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C032A4308B12 for ; Fri, 20 Nov 2026 15:38:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C032A4308B12 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=Moz70rCq Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 727EF4307F1B for ; Fri, 20 Nov 2026 15:37:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 727EF4307F1B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 727EF4307F1B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795189072; cv=none; b=jM5VImG9Qd/lflu9z7f9x1Xe/K6YSDFs3vtFplUGZWBb1aPhBy6wlfUMQMTNN2VFzVPefgqi5fzb5SvIqNWJTfmhDemVmf8JycQSeUKkYBoW6aZLeHgSf7qxLwHvwZhfb5+Yfqb02ZK90l1l1PtwbXutvDrXfRbBU36ezdynXCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795189072; c=relaxed/simple; bh=fEKLBNjFFRe7R5w2e9mcU0YQS7x0Zu09wm4+k2K2C7U=; h=DKIM-Signature:Date:Message-Id:From:To:Subject; b=S/z3r3Q/+p75Nnf5NYW0Stvsi3atdXbL4EwBV6mef1jqRzURzldQKZAPqQ+FFXurlN46UEov2HtglYcFJD3X8ATLlGMRtoGmB430GMePde4AZsr59P8tqhrWLS1rxA5sBrRwM/qCRcXqHvt6i9L7CpgQRqe9kPpVv7OxqLqIcn0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=Moz70rCq DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 727EF4307F1B Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xUQgR-0005O9-DK; Fri, 20 Nov 2026 10:37:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=+CqQ2rYpmpvLOh5ut2Snl3F84/G0thiiSIhapDOWjDk=; b=Moz70rCqNWVu mCJFSMXoJ5xaEyV0onHo4XXLD4JPFOCmLd6SRlKfHPsHVPq3rWEY9lKydl6hGiCSYDqGDafbyWtZ1 aPur+JxDEmDvgAuxfpCuv6zLWxwKdMRcqmh+vMkcex4bIdN41Nk2q6RgC2eiDsDTClotVE2swNVAE Qdqma+s1oXzTDI7TqZTD+2vuhG+AWF2UtZYYyCcfE4vui0xJ2rBCAKIlVXO5xsD5QxJeqRa7ASRUt MclC5ghhafVUX2rUg99pcR8xX4q/A3Ais+k2iqKhaytjANjctuVBIBkyfcOQa6gj6Rbe4KmVQHsCn zwTCZB2xyL9JYDR+vBE9tQ==; Date: Fri, 20 Nov 2026 17:37:49 +0200 Message-Id: <8633svjyya.fsf@gnu.org> From: Eli Zaretskii To: Andrew Burgess Cc: gdb-patches@sourceware.org In-Reply-To: <742c0f2f772ecb9365d3411aef9acad9f7e2ef6d.1795186852.git.aburgess@redhat.com> (message from Andrew Burgess on Fri, 20 Nov 2026 15:12:46 +0000) Subject: Re: [PATCH 1/5] gdbserver: avoid buffer overflow from 'm' and 'x' packets References: <742c0f2f772ecb9365d3411aef9acad9f7e2ef6d.1795186852.git.aburgess@redhat.com> 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 > From: Andrew Burgess > Cc: Andrew Burgess > Date: Fri, 20 Nov 2026 15:12:46 +0000 > > 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. > --- > gdb/doc/gdb.texinfo | 16 ++ > gdb/testsuite/gdb.server/mx-packet-overflow.c | 63 ++++++ > .../gdb.server/mx-packet-overflow.exp | 179 ++++++++++++++++++ > gdbserver/server.cc | 15 ++ > 4 files changed, 273 insertions(+) > create mode 100644 gdb/testsuite/gdb.server/mx-packet-overflow.c > create mode 100644 gdb/testsuite/gdb.server/mx-packet-overflow.exp Thanks, the gdb.texinfo part is okay. Reviewed-By: Eli Zaretskii