From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wKKvH3V4BmvC6zoAWB0awg (envelope-from ) for ; Wed, 25 Nov 2026 00:56: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=YShn1Dsg; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6472E1E09B; Wed, 25 Nov 2026 00:56:05 -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 [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 627161E09B for ; Wed, 25 Nov 2026 00:56:04 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80004468102D for ; Wed, 25 Nov 2026 05:56:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80004468102D 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=YShn1Dsg 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 AF15E4705E07 for ; Wed, 25 Nov 2026 05:55:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF15E4705E07 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 AF15E4705E07 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=1795586134; cv=none; b=HdPhhgjMPwXabZXSlS+mWIiwiC1urwWrGJ//oFu+fM9MYP3v+L4z5AKgCuu4xi5nEcX5d+AQzOjjEjY7I8cJjgW4fJ7c1uQ75fr2e+jvBVOlokTOeOes2C6Pw/oIKIuN7CsnWZD6Gg5DsaeaUnGgyYSGqlnFolGoiqQ7XDLsa7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795586134; c=relaxed/simple; bh=Dup46y4VW/w1nxz+va9SVef1uPtbthRJIg14QdYWu9A=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=uJ5aKNFzgH8aNjtUhi+71dNwxx2umF5GFKQ17+wHk2TTkFN/iwlF29t3lM4pLN2CHlSQE1sh61mDq7VKlLxKMAPBAqc5EYyh84VrVpLEAErEIA66qgtwaBWDetad8ZoH0RyULwqDJ2e/ly7oWTtENFopgR/vIkBx208XJGPo3iE= 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=YShn1Dsg DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AF15E4705E07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795586134; 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=0OmOWrl725NbT1cm4lehwKBmxv7U6Qwkq6o0Ed/+KzM=; b=YShn1DsgcOFN4mDMzrUVE+15ny0I+uWztHO3g8gClmgsfXt4urUXONOJcdCBQqk1G2aSUu k0Yv5qE8Qwgn835NtNBSMP5ewKWIsuswEgBtJYu0nMFp+fFWTf2EgZN9c5FDhUpup+krge 4xTvJyLE4SklYBcOifydH/koM+4IR8o= 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-225-xQ3Il2oCM9KapNH2ONIwhw-1; Wed, 25 Nov 2026 05:55:32 +0000 X-MC-Unique: xQ3Il2oCM9KapNH2ONIwhw-1 X-Mimecast-MFC-AGG-ID: xQ3Il2oCM9KapNH2ONIwhw_1795586131 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 351E419560B4 for ; Wed, 25 Nov 2026 05:55:31 +0000 (UTC) Received: from [100.90.172.125] (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 ESMTPS id EE3EE195B3CB; Wed, 25 Nov 2026 05:55:29 +0000 (UTC) Message-ID: <93333453-b4d8-40e2-a20f-adabf34d9690@redhat.com> Date: Tue, 24 Nov 2026 22:55:27 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/5] gdbserver: merge look_up_one_symbol and relocate_instruction packet handling To: Andrew Burgess , gdb-patches@sourceware.org References: <18919cf28001b47de5aa101126ad7a17a69a469a.1795186852.git.aburgess@redhat.com> From: Kevin Buettner In-Reply-To: <18919cf28001b47de5aa101126ad7a17a69a469a.1795186852.git.aburgess@redhat.com> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ovhgL_B8EyPTRvaoH3pBE_mwiTD3X5qTUnKBGTn5pIQ_1795586131 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: > Both the look_up_one_symbol and relocate_instruction functions contain a > loop which handles a limited number of packets received from GDB. This > commit merges these loops in order to reduce code duplication. A > follow-up commit fixes a buffer overflow bug in this code. The bug was > present at both locations, merging the code means only one site needs > fixing. The new merged code is added in a new function > handle_limited_packets_while_waiting. > > There is a potentially user-visible change in this commit though. > Previously look_up_one_symbol handled m, x, and v packets only, while > relocate_instruction handled m, M, x, and X packets. By merging the > code both functions now handle the superset of these packets, m, M, x, > X, and v. Both functions contained a comment saying something along the > lines of "we should really handle all packets here, but for now these > will do", I assume the current lists are based on what GDB happens to > send. Supporting more packets in each case should not have any negative > consequences. If it turns out that there are problems caused by > accepting this wider set of packets then we can add a packet filter > argument to handle_limited_packets_while_waiting, but I'd prefer to only > do this once we know there's a need for it. > > As part of the commit, the result of sending the reply to a 'v' packet > is now error checked; previously, the look_up_one_symbol loop ignored a > failure to send this reply. > > Additionally, while thinking about the 'v' packet handling, I wondered > what would happen if we received a vCont or vKill while we were within > look_up_one_symbol or relocate_instruction, and I suspect the outcome > would not be good. If the inferior disappeared then these functions > might end up trying to operate on freed process state. The 'v' packet > handling was added in commit: > > commit 28170b88cc8b40fdea2b065dafe6e1872a47ee4e > Date: Sat Mar 12 14:03:26 2016 +0100 > > gdbserver: Handle 'v' packet while processing qSymbol. > > The commit message talks about needing vFile support. So, while making > this merge I have made the 'v' packet handling stricter. We now drop > out of the handle_limited_packets_while_waiting loop for vCont, vAttach, > vRun, or vKill. All other 'v' packets (including vFile) are handled as > before. > > To the best of my knowledge, existing GDB does not send any packets > other than m, M, x, X, or v during these two exchanges. If it did, the > old code would have rejected the packet as a malformed response, and the > resulting symbol lookup or instruction relocation failure would most > likely have shown up as a failing test somewhere. There should > therefore be no visible changes after this commit. I ran the entire series through an AI patch review. After reading through a very dense version of what has now been rewritten to be more comprehensible, it appeared to me that you were aware of these concerns. Nonetheless, you may wish to read what Claude thought of this patch: I have one point, and I'd class it as a nit: four 'v' packets now get no reply when they arrive during a qSymbol or qRelocInsn exchange. As I read handle_limited_packets_while_waiting, anything other than m, M, x, X, or a 'v' packet ends the loop and is handed back to the caller, which expects it to be the qSymbol or qRelocInsn answer. With this patch, vCont;, vAttach;, vRun;, and vKill; also end the loop instead of being carried out. I agree with the reason you give: carrying out any of them in the middle of the exchange could resume, kill, or replace the inferior, and leave the caller working on stale or freed state. Removing that risk fits well in this series. The side effect I noticed is that neither caller recognises these packets when they come back. Both print "Malformed response ..." and give up, and nothing ever replies to the packet itself. In the qSymbol case the main loop then sends "OK", so a client that sent vCont would get "OK" instead of a stop reply, and the two sides end up out of step. When I compared this with master, I found: - qSymbol path: this is new with the patch. On master these packets were carried out and answered (unsafely, as you point out). - qRelocInsn path: this was already the case. On master that loop ended on every 'v' packet and dropped it in the same way. - More generally, any unexpected packet (a 'g', say) was already handled like this in both loops. The patch just puts these four packets into that existing group. I don't think this needs to hold up the series. Your commit message covers it: these packets now end the loop, existing GDB sends nothing but m, M, x, X, or v during these exchanges, and you'd rather add filtering "once we know there's a need for it". GDB can't send vCont in the middle of the exchange anyway, because it is busy servicing the exchange. What's left is a protocol mix-up with a client that has already broken the protocol, not a memory-safety bug, so leaving it seems a reasonable choice to me. If you do want to tidy it up, one option would be to reply with an error rather than ending the loop: if (startswith (cs.own_buf, "vCont;") || startswith (cs.own_buf, "vAttach;") || startswith (cs.own_buf, "vRun;") || startswith (cs.own_buf, "vKill;")) write_enn (cs.own_buf); else handle_v_requests (cs.own_buf, len, &new_len); The putpkt at the bottom of the loop would send the E01 straight back as the reply to the refused packet, and the loop would go on waiting for the real qSymbol or qRelocInsn answer. The client gets a clear refusal, and clients already have to cope with E01 from these packets. The comment above the check would then say "refuse with an error" rather than "don't service". I'd be equally happy to see this as a follow-up. Otherwise I like this patch. Merging the two copied loops into one function means the later fixes only need one site, the reply to 'v' packets is now checked for send errors, and the vFile support added in 2016 is kept. I'm fine with your approach of waiting until there's a demonstrated need for a fix. Obviously, if you want to post a follow-up that's okay too. Approved-By: Kevin Buettner