From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 55A7F3857835 for ; Tue, 9 May 2023 07:49:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55A7F3857835 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-52cbd7e73d2so3131790a12.3 for ; Tue, 09 May 2023 00:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683618542; x=1686210542; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=UVeOATDbJ3UhAhNMzsUpd4zPGFEzgep/E4CawNRRmq8=; b=cq+XOnD7xak0eAW+NY/tkfZQX3Z/af7wPJ8SFkHLqOs8LPeKqN/+SslROu/bEeRvPV moaLY12cl98vtXTaXNKL2qtl5/oF2spWp2TQSG4SzArKfZm7Eo0XmtAEYJmw+Ta47QA7 eyqkOHlP5vA3zyFdlBs2+lk/heqfExWNHQSVEDtjK9TZzIJpWF7L9Q9qAijPwq7Pmdos dEE1X9O+KFPfBj/aMYf8K/1Z+PdapcMJWrSYWxMypTYCMSZ25qFAvSihfeXoLiT2OFS4 LaC1QMagJLuDVkZTWKFAylAcA8pqFWV/qnr+UaCCQkAwgbVY9jQ0ptDSxGaCsLAXxo4N ZlPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683618542; x=1686210542; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UVeOATDbJ3UhAhNMzsUpd4zPGFEzgep/E4CawNRRmq8=; b=MIYtD7dWosdDxNBro9F4QdpDyspHFcLLUvFhLC6DNj2FnbpA99022G1nZWESJTOnaw E6sSTKGFB6FVfPgbn3eP4bK8TSMBTy07Y5IR26GDyjbfWPuF3aTl+PGYe9D4iXnuXgmo 3tfvACT5+g2JMZhcBImXm8ZrYgE+LJeBl4x9V3btMJXUjana3UjwIglTlVvHGSYUMxlR EzKj9SxnAuOCC4LZHZ7qTacoZT+cIHxHYm0SsytqppI4kk0RhhmGD1tC+L1Vaebd6vRb 6qtNDSy9OxumjRWDdpbHHJ7duhfFE/FVSStk8S8W8p6RRTz48R+xPYKWM6D6wBG1V3Ol OljQ== X-Gm-Message-State: AC+VfDxNJf9yEHly5xisEakNgp8qaM7D7s/ijtUWxubWUuFN5RKPiT3/ 24Wo3VPJ9Yhsm9zUeoOn6UgHdb+SMCQ= X-Google-Smtp-Source: ACHHUZ4ZLa3exJC69qSihIA9fX0O9m/wcwho/MWIzZAin6nKgSunLrqQwl3hkcZajH+oTZIIbgnQDA== X-Received: by 2002:a17:903:2308:b0:19c:fc41:2dfd with SMTP id d8-20020a170903230800b0019cfc412dfdmr15719049plh.29.1683618542596; Tue, 09 May 2023 00:49:02 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:d355:ce8c:3fd4:7c01]) by smtp.gmail.com with ESMTPSA id jb17-20020a170903259100b001a27e5ee634sm850925plb.33.2023.05.09.00.49.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 00:49:01 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 2A6101142C09; Tue, 9 May 2023 17:18:58 +0930 (ACST) Date: Tue, 9 May 2023 17:18:58 +0930 From: Alan Modra To: binutils@sourceware.org Subject: stack overflow in debug_write_type Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3034.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Another fuzzer attack. This one was a "set" with elements using an indirect type pointing back at the set. The existing recursion check only prevented simple recursion. * debug.c (struct debug_type_s): Add mark. (debug_write_type): Set mark and check before recursing into indirect types. diff --git a/binutils/debug.c b/binutils/debug.c index 53b45879e00..5cc77f74906 100644 --- a/binutils/debug.c +++ b/binutils/debug.c @@ -105,6 +105,8 @@ struct debug_type_s enum debug_type_kind kind; /* Size of type (0 if not known). */ unsigned int size; + /* Used by debug_write to stop DEBUG_KIND_INDIRECT infinite recursion. */ + unsigned int mark; /* Type which is a pointer to this type. */ debug_type pointer; /* Tagged union with additional information about the type. */ @@ -2422,6 +2424,9 @@ debug_write_type (struct debug_handle *info, if (type == DEBUG_TYPE_NULL) return (*fns->empty_type) (fhandle); + /* Mark the type so that we don't define a type in terms of itself. */ + type->mark = info->mark; + /* If we have a name for this type, just output it. We only output typedef names after they have been defined. We output type tags whenever we are not actually defining them. */ @@ -2485,7 +2490,7 @@ debug_write_type (struct debug_handle *info, return false; case DEBUG_KIND_INDIRECT: /* Prevent infinite recursion. */ - if (*type->u.kindirect->slot == type) + if ((*type->u.kindirect->slot)->mark == info->mark) return (*fns->empty_type) (fhandle); return debug_write_type (info, fns, fhandle, *type->u.kindirect->slot, name); -- Alan Modra Australia Development Lab, IBM