From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: stack overflow in debug_write_type
Date: Tue, 9 May 2023 17:18:58 +0930 [thread overview]
Message-ID: <ZFn66p7K1lW/yNEL@squeak.grove.modra.org> (raw)
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
next reply other threads:[~2023-05-09 7:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-09 7:48 Alan Modra [this message]
2023-05-10 13:41 Alan Modra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZFn66p7K1lW/yNEL@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).