From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id dlr6CffS6mrUTxYAWB0awg (envelope-from ) for ; Wed, 04 Nov 2026 01:38:47 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=HvhXP4ZE; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 133511E09A; Wed, 04 Nov 2026 01:38:47 -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.9 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,FROM_LOCAL_NOVOWEL, HK_RANDOM_FROM,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 643A31E052 for ; Wed, 04 Nov 2026 01:38:46 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E9824BA9014 for ; Wed, 4 Nov 2026 06:38:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E9824BA9014 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=HvhXP4ZE Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by sourceware.org (Postfix) with ESMTPS id 4156C4BA23FC for ; Wed, 4 Nov 2026 06:38:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4156C4BA23FC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4156C4BA23FC Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2607:f8b0:4864:20::734 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1793774294; cv=pass; b=uT7Ci8JX6YQcSGltlfE2VarKlvdeKySIhlhJSlerEqVKWA72QgOvhGa+vjQh60XdTknDNnD0tv1ALHiwJI69F8SYSz0F97rhc7hzvA+JT0LkjsWfUd7pBdOiLg98vR4RbMnAGI7pw1SYG2BOtPo2kog2xyue1O0zpsvpD9PwHwo= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1793774294; c=relaxed/simple; bh=7MTXw1jTywQ3Jj66tXP7cdlwLWqcYofslwgqyc2pBww=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=BUs22Ax9h7+OJhutVA6yP8LFRuDd2SO0AGl/R2FGAV7cJ2MLO3Cgwfh+SBLiQ2AonTIcTEje+qui6LWtZHgC+sP+vFy/ymckjIjoXqJZC/A7sgU9oUfa+qhgeG4D1YzhJNbcV8AHkX4m0vWWy5f5PMtb6r8+ho4tY9kiY+gN8Dk= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=HvhXP4ZE DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4156C4BA23FC Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-93f079a63b8so32686985a.3 for ; Tue, 03 Nov 2026 22:38:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1793774293; cv=none; d=google.com; s=arc-20260327; b=M94KNO9upbpP6EamgDZWbIO/QWP8QesEQYy2F0ZdkjwF03fsJ0LlDv3dD+k7Qrgu5c 3DUrCvSD9+t81RgFXAA0MY9W+oC52PsK2K0mHf41hpzJns6yGl7Y2kQovSK6No+2sFRI 7CtPi1LfvuZzqz2VFnGyP72gBU+n0JgPUt+LUdXYgY2QwU7wSBDPBzmClsgBdd4aozZJ ZgK5+wW0sEKfQchcHZF3K8Lfj8frMVsdgfqiYx4DyAI3B9BnjEWRwnJgpdh/HAR+WI6M aOnwHdDfr09l6hIwEQY71UlfIHMY4YkroMsQVTSiybZiMAwROT9GyHptebzASKu7jiUD L44w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=yOOwRMWlhuONHKdY6al0XnJ0pzBtakuNNCOYuaqPxdI=; fh=HezgEiYT+PXtpEjLlUcaGujDWKlC/C7vS0Zi1A8HAMI=; b=OmMgmooMgDABwRPN4SK+zQjJ6CsSRmpSze2ZZIjTIb47w/sssKJHbyx4tE1TEdrfyG OIU2N2R9/XJt9G2XmDbRsOMZMLorU/GWQxPY0eS9mOe6zAnLNo/Lag4vsurj+pMfVpNF B2fRsjDZoUkWrqgtA97FIV1OJlJxqpiWk7S8DbvKhXDUw7IzkTimja1bFbOzBybp9gJ4 QIk/6+aAfdBs0FYW/2Usq/FPYxDJjAYxQBk/EltMcqME4gXaY9K0n2QwrZYk1sk+mgYI l2qhER1BNWdvqXtqbR6nMPOgc4fatCRk7oTH0xJX7bOZSk1LVGTL7LasROlw5A1xWOq9 D+0w==; darn=sourceware.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793774293; x=1794379093; darn=sourceware.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=yOOwRMWlhuONHKdY6al0XnJ0pzBtakuNNCOYuaqPxdI=; b=HvhXP4ZERAzwCnNNhY3/6YeDD61H2DMNVUyo6AzYqAR02HENXdO3gjBoeunk/8qwfF MpEShe3gjUiGtODmsqLbOTzh5Fs6Z0B/plaIZ87NVMn82ovgDNfQKLufz5Ai9aZm/Wdi W9puFHHMWNb37hxq7UwR6oZRrcXBGmcfIndiqAuAt2+q/jqVmNsjxPSv9L9CP/dQlzJv 1Z6FmXaTENwQm6VX5smAYyOdcNHUjRU07hMRyLh6WQDyyp3MsBEMPpsJkR8wHSjH9m34 +oDLDkiDvaug/ikC+OtNoXdX5BC8KCpC913zSfvT+MIDg+KYeokXiR8f94R5VUPNU27p w5mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793774293; x=1794379093; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=yOOwRMWlhuONHKdY6al0XnJ0pzBtakuNNCOYuaqPxdI=; b=NvJ4FO/jy+ckF5gmA6/QkbSLDXzz8w/2qd1w8efb9geEq+BXkr9kOtJH845k1N1L8Q GWQc+YTGWOi81xKkrfyan4MKyxJ+Ta9K13/DROB/KkFwFIdPhhNvV3zkUbuKmayLLiR5 ytHmqun3seynwyL4tmzdSB6KiKp+MppjgHIYK/kM3Xq5CbQvvwkjuz3JHuMwUjR1ESdq bGmG7L2QjETwzV0CZoeLOH6mB4CxooxkFHBTDqNB0zkP7Z30rwDyjz4ks6FcAi/4lfRE cdDWAUDwMocENr79PejR0Fpkq9zKQezMZYyNKKaMRaXVK305US3Pu6uQBSdswue4AYIh xJeA== X-Forwarded-Encrypted: i=1; AKwUvBxELoq/dA+/vi2KE3g2gUX2QHwnjZNwHDglGS2o2sq2d71/lmg/ayR4zTSiVc4btGTQqlzaImsAQ5KzpA==@sourceware.org X-Gm-Message-State: APuU4Z85ixAnUe7YcVVbxf28ilIpO7ny9JeHuC2RUvYJa6Cn4mwMx5lf YiXCYXOnBgoOJdijIkjuyKm0KQpTYQeudaegLJho4SBJxRB/JaQQVf+Ykadow/3+9z+tBFY//mT oXK49wofWCx0KG9s/VKDnhjZtFWAxKkc= X-Gm-Gg: AYBFou3tDzrcP2sbEzs4TX9Ilh/616JErIdbaRQgkulrRjluHWggerMRnoggJcxv+/f b/ZrypOxmC4vAuqvOXLHmNd6SmeSctqJU5LHRpXwMtsHIYrbEnSVDmGm511ZbHAuwIkrCzDI+zR Fke3k7UPnuQjctCSIARWeeCN4IpDjmilYHnRq20pwUTUrsx8QRa+c509Wu7/eQISEokdEKUCWi0 2CnOKgEAGvTHKPGAgjviIkj6Pp4BuFQvX+SYYylrD/4P+x3C213aSQtqn3rFUWE3obhdPhrM50m 3RUu9mwCp/gX2Gfiiylx2FmvrjHe9BqPrfgwl+xsfctgArxreBc5ZvJDpxXqfPvwHoRAfUYEd6W hjsL9xxaQzbeG7zBfq0dsWxIZgfgM22ZYl4hj9UumEWgu7/vACjoxGcMl7ZXpAaUFHq0uiOEKss jBk5duEuqjbi5pQ4BaG4eHJMs5bsivVs7atbw9JqqSRL9ypDUodjNfCjY= X-Received: by 2002:a05:620a:3183:b0:93f:26e7:844 with SMTP id af79cd13be357-944217942dfmr2473967685a.55.1793774293018; Tue, 03 Nov 2026 22:38:13 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Max Filippov Date: Tue, 3 Nov 2026 22:38:01 -0800 X-Gm-Features: AclHuK_Jb7EtRYtRNh_Qn7tm_mjaEvwnVTFxUyqejcrK1Y5XSp1kwC0DOkhew0o Message-ID: Subject: Re: xtensa_insnbuf_from_chars buffer overflow checking To: Alan Modra Cc: binutils@sourceware.org, gdb-patches@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Tue, Nov 3, 2026 at 3:04=E2=80=AFPM Alan Modra wrote: > On Tue, Nov 03, 2026 at 05:22:26AM -0800, Max Filippov wrote: > > On Tue, Nov 3, 2026 at 2:46=E2=80=AFAM Alan Modra wr= ote: > > > +/* Wrapper for xtensa_insnbuf_from_chars to convert frag bytes > > > + to xtensa_insnbuf. */ > > > + > > > +static bool > > > +xtensa_insnbuf_from_frag (xtensa_isa isa, xtensa_insnbuf insnbuf, > > > + const fragS *frag, size_t off) > > > +{ > > > + const unsigned char *buf =3D (const unsigned char *) frag->fr_lite= ral + off; > > > + size_t len =3D frag->fr_fix - off; > > > + gas_assert (frag->fr_fix > off); > > > + bool ret =3D xtensa_insnbuf_from_chars (isa, insnbuf, buf, len); > > > + gas_assert (ret); > > > > This assertion is triggered when assembling the attached source with > > option --text-section-literals with the following backtrace: > > Wrong testcase attached? I don't reproduce the assertion here. Um, the test case is correct, but I run it with custom xtensa configuration= , the one built from the following overlay: https://github.com/jcmvbkbc/xtensa-toolchain-build/blob/master/overlays/o= riginal/DE_233L_FPU.tar.gz with the xtensa-dynconfig generator: https://github.com/jcmvbkbc/xtensa-dynconfig/tree/original In any case, I looked at what's happening and I see that xtensa_insnbuf_from_frag() is called for a frag that contains literals and the instruction length decoding call inside the xtensa_insnbuf_from_chars() returns an error. I don't see a reason to assert that xtensa_insnbuf_from_chars() always succeeds, the callers of xtensa_insnbuf_from_frag() may need to check the return value. > > > diff --git a/include/xtensa-isa.h b/include/xtensa-isa.h > > > index 5c25f122d29..4818559ff94 100644 > > > --- a/include/xtensa-isa.h > > > +++ b/include/xtensa-isa.h > > > @@ -210,7 +210,7 @@ extern int > > > xtensa_insnbuf_to_chars (xtensa_isa isa, const xtensa_insnbuf insn, > > > unsigned char *cp, int num_chars); > > > > > > -extern void > > > +extern bool > > > > Other similar functions in this library have return type `int` and retu= rn > > 0 on success and a negative error code on failure. Could this function > > please follow this pattern too? That's because this header is included > > into the generated configuration-specific xtensa-modules.c and does > > not include itself. > > I can do that for consistency, but I can't say I like the practice of > avoiding bool. Neither do I. Is there a reason not to add `#include ` to the include/xtensa-isa.h ? > Especially for functions like xtensa_opcode_is_branch > which are used everywhere testing =3D=3D 1 or > 0 except one place in > xtensa-dis.c. (Maybe a bug?) It would be a bug if it was possible to get there with an invalid opcode, but according to the code above it that sets and checks `valid_insn` it seems impossible. --=20 Thanks. -- Max