Bug 31631 - [gdb/python] inferior.read_memory: internal-error: virtual memory exhausted
Summary: [gdb/python] inferior.read_memory: internal-error: virtual memory exhausted
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: unknown
: P2 normal
Target Milestone: 15.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 31630 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-04-10 18:33 UTC by N1nEmAn
Modified: 2024-04-16 13:56 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
poc (82 bytes, text/x-python)
2024-04-11 02:51 UTC, N1nEmAn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description N1nEmAn 2024-04-10 18:33:41 UTC
for the details, read this report
thanks
https://github.com/N1nEmAn/wp/
Comment 1 Tom de Vries 2024-04-10 20:04:17 UTC
So, we do:
...
import gdb
gdb.selected_inferior().read_memory(0, 18446744073709551615)
...
and get a virtual memory exhausted error.
Comment 2 N1nEmAn 2024-04-11 00:05:28 UTC
i love u man. I am a college student, and this is the first binary vulnerability in my life that has been recognized.


-------- Original Message --------
2024/4/11 上午4:04,vries at gcc dot gnu.org <sourceware-bugzilla@sourceware.org>,来信:

>  https://sourceware.org/bugzilla/show_bug.cgi?id=31631
>  
>  Tom de Vries <vries at gcc dot gnu.org> changed:
>  
>             What    |Removed                     |Added
>  ----------------------------------------------------------------------------
>                   CC|                            |vries at gcc dot gnu.org
>  
>  --- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
>  So, we do:
>  ...
>  import gdb
>  gdb.selected_inferior().read_memory(0, 18446744073709551615)
>  ...
>  and get a virtual memory exhausted error.
>  
>  --
>  You are receiving this mail because:
>  You reported the bug.
>  You are on the CC list for the bug.
Comment 3 N1nEmAn 2024-04-11 01:48:24 UTC
(In reply to Tom de Vries from comment #1)
> So, we do:
> ...
> import gdb
> gdb.selected_inferior().read_memory(0, 18446744073709551615)
> ...
> and get a virtual memory exhausted error.

i think we can fix the python code of gdb, and add a check for the number if valid.
Comment 4 N1nEmAn 2024-04-11 02:51:41 UTC
Created attachment 15459 [details]
poc
Comment 5 Tom de Vries 2024-04-11 10:53:39 UTC
Looks like a python-specific dup of PR17611.

https://sourceware.org/pipermail/gdb-patches/2024-April/208019.html
Comment 6 Tom de Vries 2024-04-11 11:33:39 UTC
> just run gdb and source the poc can make the memory corrupt/exhausted

I'm not sure where you see memory corruption.

I'm updating $subject to make the failure mode more clear.
Comment 7 N1nEmAn 2024-04-11 12:04:29 UTC
(In reply to Tom de Vries from comment #6)
> > just run gdb and source the poc can make the memory corrupt/exhausted
> 
> I'm not sure where you see memory corruption.
> 
> I'm updating $subject to make the failure mode more clear.

you are right. sorry for my unclear descreption.
Comment 8 Tom de Vries 2024-04-11 12:05:49 UTC
(In reply to N1nEmAn from comment #7)
> (In reply to Tom de Vries from comment #6)
> > > just run gdb and source the poc can make the memory corrupt/exhausted
> > 
> > I'm not sure where you see memory corruption.
> > 
> > I'm updating $subject to make the failure mode more clear.
> 
> you are right. sorry for my unclear descreption.

No problem, thanks for reporting this PR.
Comment 9 N1nEmAn 2024-04-11 12:16:54 UTC
(In reply to Tom de Vries from comment #8)
> (In reply to N1nEmAn from comment #7)
> > (In reply to Tom de Vries from comment #6)
> > > > just run gdb and source the poc can make the memory corrupt/exhausted
> > > 
> > > I'm not sure where you see memory corruption.
> > > 
> > > I'm updating $subject to make the failure mode more clear.
> > 
> > you are right. sorry for my unclear descreption.
> 
> No problem, thanks for reporting this PR.

Thank you for your recognition. We look forward to your team's resolution of this issue.
Additionally, I have a question. Can we apply for a CVE for this vulnerability through MITRE? Or is there another process? I didn't see Sourceware on the CNA list, but I only saw Glibc.
Comment 10 Tom de Vries 2024-04-11 12:21:29 UTC
(In reply to N1nEmAn from comment #9)
> (In reply to Tom de Vries from comment #8)
> > (In reply to N1nEmAn from comment #7)
> > > (In reply to Tom de Vries from comment #6)
> > > > > just run gdb and source the poc can make the memory corrupt/exhausted
> > > > 
> > > > I'm not sure where you see memory corruption.
> > > > 
> > > > I'm updating $subject to make the failure mode more clear.
> > > 
> > > you are right. sorry for my unclear descreption.
> > 
> > No problem, thanks for reporting this PR.
> 
> Thank you for your recognition. We look forward to your team's resolution of
> this issue.
> Additionally, I have a question. Can we apply for a CVE for this
> vulnerability through MITRE? Or is there another process? I didn't see
> Sourceware on the CNA list, but I only saw Glibc.

AFAIU, there's no vulnerability here, just a usability issue.
Comment 11 N1nEmAn 2024-04-11 12:26:53 UTC
(In reply to Tom de Vries from comment #10)
> (In reply to N1nEmAn from comment #9)
> > (In reply to Tom de Vries from comment #8)
> > > (In reply to N1nEmAn from comment #7)
> > > > (In reply to Tom de Vries from comment #6)
> > > > > > just run gdb and source the poc can make the memory corrupt/exhausted
> > > > > 
> > > > > I'm not sure where you see memory corruption.
> > > > > 
> > > > > I'm updating $subject to make the failure mode more clear.
> > > > 
> > > > you are right. sorry for my unclear descreption.
> > > 
> > > No problem, thanks for reporting this PR.
> > 
> > Thank you for your recognition. We look forward to your team's resolution of
> > this issue.
> > Additionally, I have a question. Can we apply for a CVE for this
> > vulnerability through MITRE? Or is there another process? I didn't see
> > Sourceware on the CNA list, but I only saw Glibc.
> 
> AFAIU, there's no vulnerability here, just a usability issue.

However, I believe that if it is present in pwndbg or any other code that could exist in gdbinit, it could potentially lead to a local denial-of-service attack.
Comment 12 Tom de Vries 2024-04-11 13:38:43 UTC
*** Bug 31630 has been marked as a duplicate of this bug. ***
Comment 13 Tom Tromey 2024-04-11 16:00:30 UTC
For the record, I think this is not a vulnerability
according to the soon-to-be-landed security policy.

See https://sourceware.org/pipermail/gdb-patches/2024-April/207917.html

So, don't file a CVE.

To my mind it's not even really a gdb bug, more like
"don't do that".
Comment 14 N1nEmAn 2024-04-12 02:02:17 UTC
(In reply to Tom Tromey from comment #13)
> For the record, I think this is not a vulnerability
> according to the soon-to-be-landed security policy.
> 
> See https://sourceware.org/pipermail/gdb-patches/2024-April/207917.html
> 
> So, don't file a CVE.
> 
> To my mind it's not even really a gdb bug, more like
> "don't do that".

ok fine. i see. thanks
Comment 15 Sourceware Commits 2024-04-16 13:53:35 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=06e967dbc9b75a4a3c1b15b54360cf1abbf9c2bd

commit 06e967dbc9b75a4a3c1b15b54360cf1abbf9c2bd
Author: Tom de Vries <tdevries@suse.de>
Date:   Tue Apr 16 15:53:47 2024 +0200

    [gdb/python] Throw MemoryError in inferior.read_memory if malloc fails
    
    PR python/31631 reports a gdb internal error when doing:
    ...
    (gdb) python gdb.selected_inferior().read_memory (0, 0xffffffffffffffff)
    utils.c:709: internal-error: virtual memory exhausted.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    ...
    
    Fix this by throwing a python MemoryError, such that we have instead:
    ...
    (gdb) python gdb.selected_inferior().read_memory (0, 0xffffffffffffffff)
    Python Exception <class 'MemoryError'>:
    Error occurred in Python.
    (gdb)
    ...
    
    Likewise for DAP.
    
    Tested on x86_64-linux.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31631
Comment 16 Tom de Vries 2024-04-16 13:56:43 UTC
Fixed.