Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDB command call doesn't trigger any gdb.Event #826

Closed
4 tasks done
rednhot opened this issue Feb 15, 2022 · 7 comments
Closed
4 tasks done

GDB command call doesn't trigger any gdb.Event #826

rednhot opened this issue Feb 15, 2022 · 7 comments

Comments

@rednhot
Copy link

rednhot commented Feb 15, 2022

  • Did you use the latest version of GEF from dev branch?
  • Is your bug specific to GEF (not GDB)? - Try to reproduce it running gdb -nx
  • Did you read the documentation first?
  • Did you check issues (including
    the closed ones) - and the PR?

Step 1: Describe your environment

  • Operating System / Distribution: Gentoo Hardened 5.16.5-gentoo-x86_64
  • Architecture: x86_64
  • GEF version (including the Python library version) run version in GEF.
gef➤  version
GEF: rev:2b7f31515a3638718b133e0d3b096aedeef5518c (Git - clean)
SHA256(/var/tmp/test/gef/gef.py): 767fcae12cac4cc6dbd3a0b2f51ad6b66f40ed72be199f256ed6c85aed44a70f
GDB: 11.2
GDB-Python: 3.9

Step 2: Describe your problem

heap bins doesn't show the real state of the heap when using gdb commands like call free and call malloc. After using them,
heap bins shows wrong information.

For example. when I execute call (void*) malloc(0x10) it returns the chunk which was just in fastbin. Nevertheless, when I use heap bins after that, the chunk still show up in the output, even though the count has decreased.
That's how it looks like

Steps to reproduce

  1. Call malloc(0x10) from the binary.
  2. Call free(<chunk_from_step1>) from the binary.
  3. Use call (void*) malloc(0x10) from inside of gdb.
  4. Use heap bins and see, that tcachebins are not empty.

Minimalist test case

test.c

#include <stdlib.h>

int main(void)
{
    char *p;

    p = malloc(0x10);
    free(p);
} // it's the 9th line

gdbcommands.txt

!cc -g -o test test.c
gef config context.enable False
file ./test
b 9
run
heap bins
call (void*)malloc(0x10)
heap bins

Command line

gdb -x gdbcommands.txt

Expected results

fastbin should be emptied like in the case where we malloc-ed the same chunk from inside the binary.

@rednhot rednhot added the triage label Feb 15, 2022
@hugsy
Copy link
Owner

hugsy commented Feb 15, 2022

It looks like a UI problem. What if you clear the caches after the 2nd malloc call but before the 2nd heap bins?

@rednhot
Copy link
Author

rednhot commented Feb 15, 2022

It looks like a UI problem. What if you clear the caches after the 2nd malloc call but before the 2nd heap bins?

How can I do it, could you guide me please?

@hugsy
Copy link
Owner

hugsy commented Feb 15, 2022

gef➤ reset-cache
would be the simplest way

@rednhot
Copy link
Author

rednhot commented Feb 15, 2022

gef➤ reset-cache would be the simplest way

Well, that worked, thanks! Nevertheless, help reset-cache says that this command exists for debugging and testing, so it shouldn't be used under normal conditions, like in my case. Or am i wrong?

@hugsy
Copy link
Owner

hugsy commented Feb 15, 2022

I wasn't saying there isn't a bug, just trying to identify it. Yeah, normal usage should not require the use of reset-cache as we (normally) should handle the cases where the cache must be flushed partially or in full.
Normally GEF detects changes of registers or memory through the GDB event hook but it seems direct function call (using call) triggers any of those event so it's hard for us to detect the change.
I'll keep this ticket open to see if we can find an acceptable solution to this.

@hugsy hugsy changed the title heap bins breaks when using gdb's call command GDB command call doesn't trigger any gdb.Event Feb 15, 2022
@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. You can reopen it by adding a comment to this issue.

@stale stale bot added the stale label Apr 17, 2022
@stale
Copy link

stale bot commented May 17, 2022

This issue has been automatically closed because it has not had recent activity. If you are the owner of this issue, you can either re-open it and provide a more complete description; or create a new issue. Thank you for your contributions.

@stale stale bot closed this as completed May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants