From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Subject: Patch: check for over- and under-flow in decode_locdesc
Date: Thu, 18 Nov 2010 21:24:00 -0000 [thread overview]
Message-ID: <m362vucol0.fsf@fleche.redhat.com> (raw)
I am going to check this in sometime soon, barring complaints.
This is a new version of a patch we've been carrying in Fedora for quite
some time. It changes decode_locdesc to check for under- and
over-flow. This is the topic of CVE-2006-4146.
This version of the patch issues a complaint where earlier versions
called internal_error. I also cleaned up the comment formatting.
Writing a test case for this is a pain, but I tried it by hand (by
modifying state using a second gdb) to make sure it does the right
thing.
Built and regtested on x86-64 (compile farm).
Tom
2010-11-18 Will Drewry <wad@google.com>
Tavis Ormandy <taviso@google.com>
Jan Kratochvil <jan.kratochvil@redhat.com>
* dwarf2read.c (decode_locdesc): Enforce location description stack
boundaries.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 33ebea8..30e1baa 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -13279,8 +13279,7 @@ read_signatured_type (struct objfile *objfile,
callers will only want a very basic result and this can become a
complaint.
- Note that stack[0] is unused except as a default error return.
- Note that stack overflow is not yet handled. */
+ Note that stack[0] is unused except as a default error return. */
static CORE_ADDR
decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
@@ -13297,6 +13296,7 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
i = 0;
stacki = 0;
stack[stacki] = 0;
+ stack[++stacki] = 0;
while (i < size)
{
@@ -13478,6 +13478,22 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
dwarf_stack_op_name (op, 1));
return (stack[stacki]);
}
+
+ /* Enforce maximum stack depth of SIZE-1 to avoid writing
+ outside of the allocated space. Also enforce minimum>0. */
+ if (stacki >= sizeof (stack) / sizeof (*stack) - 1)
+ {
+ complaint (&symfile_complaints,
+ _("location description stack overflow"));
+ return 0;
+ }
+
+ if (stacki <= 0)
+ {
+ complaint (&symfile_complaints,
+ _("location description stack underflow"));
+ return 0;
+ }
}
return (stack[stacki]);
}
next reply other threads:[~2010-11-18 21:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-18 21:24 Tom Tromey [this message]
2010-11-19 6:25 ` Jan Kratochvil
2010-11-19 16:32 ` Tom Tromey
2010-11-19 16:37 ` Jan Kratochvil
2010-11-19 16:34 ` Tom Tromey
2010-11-20 1:53 ` Jan Kratochvil
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=m362vucol0.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=gdb-patches@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