From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4HvrGCijBWvDrzIAWB0awg (envelope-from ) for ; Tue, 24 Nov 2026 09:46:00 -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=dOYRnAl6; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4E72A1E09B; Tue, 24 Nov 2026 09:46:00 -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 34C941E09B for ; Tue, 24 Nov 2026 09:45:59 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 541C146B7922 for ; Tue, 24 Nov 2026 14:45:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 541C146B7922 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=dOYRnAl6 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 D0D7F4702D1C for ; Tue, 24 Nov 2026 14:45:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D0D7F4702D1C 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 D0D7F4702D1C 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=1795531531; cv=none; b=LsMlOLuGXAmXGyx66i0DNXsfR4QA4BENC4SzVeMzMk0WdzcMhY2Nw9Lfy6kKRUWOg2bvZnASjvoAt+5FJPaHXhva+0DuJYGSpenO3uV14TkTpD5nOa3rNJN4FHbx1nPLgSELySoDOCN0SQP5Amdl780tzGBdQRoW60AHGthDODk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795531531; c=relaxed/simple; bh=bGBPo3swcDkt2BDGA3EGknoin5+jVUtEWCOq64Hd6x0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nuyT+U8Ozyn0RMZHvej5+GLZl28IK/03VCuzb+RdaVI+33i2JsuIqRpA0gjFcRVdogIx7yXJNVgy6fZjuGFiHFmerkkaUWZQJFieNKQBpGl1CgwQhTN4nl4xnz74iGNMeOdRxhj2CiyxFL0kbMRvcCCMb7k1j5OY4ght221BSek= 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=dOYRnAl6 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0D7F4702D1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795531531; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LVq7jPtl6EmnAWp1QQBOjXrRkxTS1qgurrGQ+A1HmEg=; b=dOYRnAl6UmqPmbIrIDKuvCO+3Fp10m0z4LEntsvLkwTQbE8Hbn4qjxdEpCeq7A3SFE5ZjZ hc8vaQ34A7i2EbHJGiTZ4U+rL9wFUc1mhFkuP+x0poFv8+eBxGEmZFxBwFoVumQwNsWJv7 BRH6IgZBiIetQrES7YaP8fdoQfr6Dwc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-378-0pSv5DTPNvGVCBZPKIwK8w-1; Tue, 24 Nov 2026 14:45:27 +0000 X-MC-Unique: 0pSv5DTPNvGVCBZPKIwK8w-1 X-Mimecast-MFC-AGG-ID: 0pSv5DTPNvGVCBZPKIwK8w_1795531525 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4a16dc2323cso15590245e9.3 for ; Tue, 24 Nov 2026 06:45:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795531525; x=1796136325; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=LVq7jPtl6EmnAWp1QQBOjXrRkxTS1qgurrGQ+A1HmEg=; b=JjS1zpQUFlbd66Oxmy+ggsfvntWeCPDKGmMtE9Lama1d3m/98ErujBVIEHLX8Gaect zXJrX0jy4cYAkx+RjzLeU0t59K3Ha0Kwk5vPMgEzWy/kOEzbGVDh5noOcudMc9pP/ff1 YHF79pyUVGDfOn9+k9wHxooWlxummTdaZl5PaCnm0t6cJ35dKGoVs/GdYhvfT8NDRlhm 5gSZC0Wg/lWrDGdgsF24TKUDCIgs5FUHrp1J+ZaJipVcpGxB7NOjGsFLhP2sS0NXSweE gT6wfatclD50iPoNj7vtj4Ie40RjuK7LDmrQrXPoowlnYdI8LsGbraWvviYplFoQW3af 3CrA== X-Forwarded-Encrypted: i=1; AL+hErFKwV8f6mW+zoGsH7NPw3OqTyoJka+qhHWJblFxecay5Vn18sPjTaQyS6E4yLNAkV79XejsXVmUshe/Hw==@sourceware.org X-Gm-Message-State: APuU4Z/nNGDD6KLALAJInBtaGDqzm77sEtbSuqtbXrwrhZ8QNNlpdEhr dv4nkVDMttKIIgC6Vra3ZJK/lzmF0qrtCRpmCAv/sY+xM7vkd190825Q56ziEK+jVN4cFQ3CA3k TK3Zv4A89XGPfSU8Fq+SM1EvYxuoHUABBPAFvvkxcCX5A3d2n5MK1JU1t1rqEIb0bsM9KH8Y= X-Gm-Gg: AZFdTZeuUjBnM8LbMvEIZALtFgX2VyaqsTPgyWlwnpsJeQt/0CGTZ6Ovx4iHjHGMClS 21mo5q3byRo6PM4lRFW5FyU2ytz8jzFhSR7kaL3ovc2JiiLwvaBsFx3rg+Y2/S1tH1JGbHKN77q bYTTrlegMx+upFnXz0gMK68am8kzZSjQAkW8i8Y3y1gwJcGla4wqKe6sj4SiejLDEJNmszQnANj t2N3GyKscIfll5eCog5r3+vN4dFuHWR7aDPVcvPwGOS+SfD7uxD2tjuNHKuvQrnUvwxfjRKn6ZA KRdiBWbcOs/jVAls4dkTLDwWya5Vd7L/wlTF8bZKwCtv7sWcelJoBrBQdaXb5zZ06olP33u34fM g2bUOa6lpzjh3V9G1RVcNHHFpugQEykQ= X-Received: by 2002:a05:600c:83ca:b0:4a1:9661:14b5 with SMTP id 5b1f17b1804b1-4bb888176eamr304727235e9.29.1795531524671; Tue, 24 Nov 2026 06:45:24 -0800 (PST) X-Received: by 2002:a05:600c:83ca:b0:4a1:9661:14b5 with SMTP id 5b1f17b1804b1-4bb888176eamr304726305e9.29.1795531523836; Tue, 24 Nov 2026 06:45:23 -0800 (PST) Received: from localhost ([83.216.138.189]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab69bf680fsm32527996f8f.14.2026.11.24.06.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 06:45:23 -0800 (PST) From: Andrew Burgess To: Keith Seitz , gdb-patches@sourceware.org Subject: Re: [PATCH 2/5] [gdb/remote] Fix stack overflow in parse_tracepoint_definition In-Reply-To: References: Date: Tue, 24 Nov 2026 14:45:21 +0000 Message-ID: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: B8fnWTJFS2mV-E6ih3oEBXat5s5numa8-vjzAWrAVmc_1795531525 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 Thanks for working on this. I have a couple of really minor thoughts, see inline below. Keith Seitz writes: > gdb/34971 demonstrates how a malicious remote stub may cause > a stack overflow with a malformed tracepoint definition. > > Similar to parse_tsv_definition issues with missing colons in > the packet reply and how that can cause hex2bin to copy more > bytes than allocated, fix this in the same way: more stringent > checking for proper packet layout. > > This fixes the missing-colon occurrences in > parse_tracepoint_definition. While touching that parser, also > require the enable flag to be 'E' or 'D' rather than treating any > other character as disabled, and add unit tests for both. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34971 > --- > gdb/tracepoint.c | 38 ++++++------ > gdb/unittests/tracepoint-selftests.c | 88 ++++++++++++++++++++++++++++ > 2 files changed, 108 insertions(+), 18 deletions(-) > > diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c > index 7a5af33b42e..7a3339617ef 100644 > --- a/gdb/tracepoint.c > +++ b/gdb/tracepoint.c > @@ -3428,34 +3428,40 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp) > const char *p; > char piece; > ULONGEST num, addr, step, pass, orig_size, xlen, start; > - int enabled, end; > + int enabled; > enum bptype type; > const char *srctype; > - char *buf; > struct uploaded_tp *utp = NULL; > > + auto require = [&] (const char *q, char sep = ':') Can you add the " -> const char *" at the end of this line to make the return type explicit please. > + { > + return trace_definition_require_char (q, sep, "tracepoint", line); > + }; > + > p = line; > /* Both tracepoint and action definitions start with the same number > and address sequence. */ > piece = *p++; > p = unpack_varlen_hex (p, &num); > - p++; /* skip a colon */ > + p = require (p); > p = unpack_varlen_hex (p, &addr); > - p++; /* skip a colon */ > + p = require (p); > if (piece == 'T') > { > gdb::unique_xmalloc_ptr cond; > > + if (*p != 'E' && *p != 'D') > + bad_trace_definition ("tracepoint", line); > enabled = (*p++ == 'E'); > - p++; /* skip a colon */ > + p = require (p); > p = unpack_varlen_hex (p, &step); > - p++; /* skip a colon */ > + p = require (p); > p = unpack_varlen_hex (p, &pass); > type = bp_tracepoint; > /* Thumb through optional fields. */ > while (*p == ':') > { > - p++; /* skip a colon */ > + p = require (p); Could avoid the 'require' here: /* Skip the colon the while loop checks for. */ p++; there are places below where you left 'p++' when someone else already checks the character for us. But also, a redundant check isn't the end of the world, so if you'd rather keep this, then that's fine with me. > if (*p == 'F') > { > type = bp_fast_tracepoint; Inside the F, S, and X handling there are some p++; lines. These are fine as these are skipping over the F, S, and X characters which have just been checked. However, in the X case there is also this line: p++; /* skip a comma */ which I think can become: p = require (p, ','); maybe a test for this case could be added? > @@ -3501,24 +3507,20 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp) > /* Parse a chunk of source form definition. */ > utp = get_uploaded_tp (num, addr, utpp); > srctype = p; > - p = strchr (p, ':'); > - p++; /* skip a colon */ > + p = require (strchr (p, ':')); > p = unpack_varlen_hex (p, &start); > - p++; /* skip a colon */ > + p = require (p); > p = unpack_varlen_hex (p, &xlen); > - p++; /* skip a colon */ > - > - buf = (char *) alloca (strlen (line)); > + p = require (p); > > - end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2); > - buf[end] = '\0'; > + std::string decoded = hex2str (p); Maybe I'm looking in the wrong place, but I couldn't find the specification for this 'Z' case anywhere, so I'm guessing a little bit about what the fields mean. Still, we parse XLEN from the packet, then process the remaining bytes as a string. XLEN isn't used anywhere else. I'm assuming that XLEN is supposed to be the number of bytes in the string? The old code didn't check that these things matched, but maybe, as you're improving the code anyway, we could/should add something like: if (decoded.size () != xlen) bad_trace_definition ("tracepoint", line); What do you think? Thanks, Andrew