From: "Luís Ferreira" <lsferreira@riseup.net>
To: ibuclaw@gdcproject.org, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] libiberty: prevent buffer overflow when decoding user input
Date: Thu, 23 Sep 2021 16:40:57 +0100 [thread overview]
Message-ID: <460c1e4fd71f42b4b35bcc8911e9141d68b8d973.camel@riseup.net> (raw)
In-Reply-To: <455464371.70186.1632392201366@office.mailbox.org>
[-- Attachment #1: Type: text/plain, Size: 2156 bytes --]
Hi,
Here is an example of a crafted mangle that can cause heap buffer
overflow.
```
fuzzer-results/crash-18b7f0799be49886550876b5ab6bb63e4231979b
_D2FGWG44444444444444444EQe
00000000 5f 44 32 46 47 57 47 34 34 34 34 34 34 34 34 34
|_D2FGWG444444444|
00000010 34 34 34 34 34 34 34 34 45 51 65 0a
|44444444EQe.|
0000001c
```
Here is an example of a crafted mangle that can cause stack buffer
overflow.
```
fuzzer-results/crash-79833f1c8ce510bbf138c0d5ad06a7fb11ce3bae
_D8ee2_1111Qe
00000000 5f 44 38 65 65 32 5f 31 31 31 31 51 65
|_D8ee2_1111Qe|
0000000d
```
Even though this triggers an UB by reading/writing other memory space,
I couldn't find a situation where this constantly fails, although, if
running with an address + UB sanitizer this can be easily catched and
replicated with some confidence. I didn't add this to the test suite
because of that.
On Thu, 2021-09-23 at 12:16 +0200, ibuclaw@gdcproject.org wrote:
> > On 22/09/2021 03:10 Luís Ferreira <contact@lsferreira.net> wrote:
> >
> >
> > Currently a stack/heap overflow may happen if a crafted mangle is
> > maliciously used to cause denial of service, such as intentional
> > crashes
> > by accessing a reserved memory space.
> >
>
> Hi,
>
> Thanks for this. Is there a test that could trigger this code path?
>
> Iain.
>
>
> > Signed-off-by: Luís Ferreira <contact@lsferreira.net>
> > ---
> > libiberty/d-demangle.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
> > index a2152cc65518..7ded3e2a2563 100644
> > --- a/libiberty/d-demangle.c
> > +++ b/libiberty/d-demangle.c
> > @@ -381,7 +381,7 @@ dlang_symbol_backref (string *decl, const char
> > *mangled,
> >
> > /* Must point to a simple identifier. */
> > backref = dlang_number (backref, &len);
> > - if (backref == NULL)
> > + if (backref == NULL || strlen(backref) < len)
> > return NULL;
> >
> > backref = dlang_lname (decl, backref, len);
--
Sincerely,
Luís Ferreira @ lsferreira.net
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-09-23 15:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-22 1:10 Luís Ferreira
2021-09-23 10:16 ` ibuclaw
2021-09-23 15:40 ` Luís Ferreira [this message]
2021-09-23 15:50 ` Jeff Law
2021-10-04 16:52 ` Luís Ferreira
2021-10-05 15:00 ` Jeff Law
2021-10-05 17:26 ` Luís Ferreira
2021-10-06 1:49 ` Eric Gallager
2021-10-07 18:29 ` Luís Ferreira
2021-10-08 16:52 ` Iain Buclaw
2021-10-08 17:08 ` Luís Ferreira
2021-10-08 20:11 ` Iain Buclaw
2021-10-12 12:54 ` Luís Ferreira
2021-10-12 19:40 ` Eric Gallager
2021-10-12 20:25 ` Luís Ferreira
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=460c1e4fd71f42b4b35bcc8911e9141d68b8d973.camel@riseup.net \
--to=lsferreira@riseup.net \
--cc=gcc-patches@gcc.gnu.org \
--cc=ibuclaw@gdcproject.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).