public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/29166] New: `demangle_const` causes infinite recursion and stack overflow
@ 2022-05-21 17:23 r3tr0spect2019 at gmail dot com
  2022-05-21 17:24 ` [Bug c++/29166] " r3tr0spect2019 at gmail dot com
  2022-05-21 17:50 ` schwab@linux-m68k.org
  0 siblings, 2 replies; 3+ messages in thread
From: r3tr0spect2019 at gmail dot com @ 2022-05-21 17:23 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=29166

            Bug ID: 29166
           Summary: `demangle_const` causes infinite recursion and stack
                    overflow
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: r3tr0spect2019 at gmail dot com
  Target Milestone: ---

Original Post: `https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105115`

The bug is similar to CVE-2021-3530, which was reported here:
`https://bugs.launchpad.net/ubuntu/+source/binutils/+bug/1925348`.

Commit: `e84412c6a3c3eed1a4eca5fe18f329bfa7efea40` at
`https://github.com/bminor/binutils-gdb`.

The simplified PoC:

$ echo _RYAbB2_ | ./binutils/cxxfilt
Segmentation fault

Root Cause Analysis:

1. In `rust_demangle_callback`, "_R" at beginning causes `rdm.version ==
0`[1][2], so `demangle_path` in the else-branch is called[3] with `rdm.sym ==
"YAbB2_"`, with `rdm.next` field initialized to 0.

2. Next char 'Y' causes `demangle_type` to be called[4] in a switch-case
branch, with `rdm.next == 1`.

3. Next char 'A' causes `demangle_type` to be called first[5] to consume char
'b', then `demangle_const` is called[6] with `rdm.next == 3`.

4. Next char 'B' is consumed[7], and "2_" is parsed as `integer_62`[8] to be
value 3, and this vlaue is assigned to `rdm.next`, then `demangle_const` is
called recursively[9]. However, currently the situation is `rdm.next == 3`
again, which is exactly same as last call to `demangle_const`, and this causes
infinite recursion.

[1] 626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1356
[2] 626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1362
[3] 626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1453
[4] 626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L759
[5] 626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L934
[6] 626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L938
[7] 626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1151
[8] 626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1153
[9] 626d0e40e55c35a4f143b70def498734e8ed3c2a/libiberty/rust-demangle.c#L1158

Possible Fix:

The infinite recursion check added in this
[commit](https://github.com/bminor/binutils-gdb/commit/f10f8617a302f45dae721eae0cd659911f03d864)
should also be applied to `demangle_const`

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/29166] `demangle_const` causes infinite recursion and stack overflow
  2022-05-21 17:23 [Bug c++/29166] New: `demangle_const` causes infinite recursion and stack overflow r3tr0spect2019 at gmail dot com
@ 2022-05-21 17:24 ` r3tr0spect2019 at gmail dot com
  2022-05-21 17:50 ` schwab@linux-m68k.org
  1 sibling, 0 replies; 3+ messages in thread
From: r3tr0spect2019 at gmail dot com @ 2022-05-21 17:24 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=29166

2019 Rong <r3tr0spect2019 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/29166] `demangle_const` causes infinite recursion and stack overflow
  2022-05-21 17:23 [Bug c++/29166] New: `demangle_const` causes infinite recursion and stack overflow r3tr0spect2019 at gmail dot com
  2022-05-21 17:24 ` [Bug c++/29166] " r3tr0spect2019 at gmail dot com
@ 2022-05-21 17:50 ` schwab@linux-m68k.org
  1 sibling, 0 replies; 3+ messages in thread
From: schwab@linux-m68k.org @ 2022-05-21 17:50 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=29166

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |MOVED

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
The demangler is owned by gcc.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-21 17:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-21 17:23 [Bug c++/29166] New: `demangle_const` causes infinite recursion and stack overflow r3tr0spect2019 at gmail dot com
2022-05-21 17:24 ` [Bug c++/29166] " r3tr0spect2019 at gmail dot com
2022-05-21 17:50 ` schwab@linux-m68k.org

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).