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

Fix dmht for glibc caused by wrong tcache offset and definition #16247

Merged
merged 6 commits into from
Mar 26, 2020
Merged

Fix dmht for glibc caused by wrong tcache offset and definition #16247

merged 6 commits into from
Mar 26, 2020

Conversation

x0urc3
Copy link
Contributor

@x0urc3 x0urc3 commented Mar 18, 2020

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository
  • I made sure to follow the project's coding style
  • I've added tests that prove my fix is effective or that my feature works (if possible)
  • I've updated the documentation and the radare2 book with the relevant information (if needed)

Detailed description

Related to PR #16239, dmht does not show freed tcache chunk due to wrong tcache size and definition.
...

Test plan

  • Result has been compared with gdb-gef
  • Pass added test

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 18, 2020

Hmmm. both dmht and test are working on my machine

@XVilka
Copy link
Contributor

XVilka commented Mar 18, 2020

@x0urc3 different version of glibc?

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 18, 2020

@x0urc3 different version of glibc?

Might explain it. How could I find the glibc version in Travis?

@XVilka
Copy link
Contributor

XVilka commented Mar 18, 2020

It's 2.23 in Travis (Ubuntu Xenial) it seems: https://repology.org/project/glibc/versions

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 18, 2020

One more thing is the expected output does not follow the sequence of command

r2 -escr.utf8=0 -escr.color=0 -escr.interactive=0 -N -Q -d -c "dcu main;dmht~Tcache;20dso;dmht~Tcache" ../bins/elf/simple_malloc_x86_64 2>/dev/null
p=3
Tcache main arena @ 0x7f6d1e4b2b80
Tcache main arena @ 0x7f6d1e4b2b80

-p=3 should come after the first dmht~Tcache

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 18, 2020

It's 2.23 in Travis (Ubuntu Xenial) it seems: https://repology.org/project/glibc/versions

This caused issue because dbg.glibc.tcache should only be enabled for glibc >2.26

@radare
Copy link
Collaborator

radare commented Mar 18, 2020

can you fix this?

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 19, 2020

can you fix this?

Yes. I will create another PR for glibc version detection to set dbg.glibc.tcache

@radare
Copy link
Collaborator

radare commented Mar 19, 2020

resolve the conflicts

@radare
Copy link
Collaborator

radare commented Mar 20, 2020

still conflicting

1 similar comment
@radare
Copy link
Collaborator

radare commented Mar 20, 2020

still conflicting

@radare
Copy link
Collaborator

radare commented Mar 20, 2020

Screenshot 2020-03-20 at 12 12 09

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 20, 2020

Forgot to rebase

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 20, 2020

Failed one of the added test. I'm recreating a ubuntu xenial image to test locally

@radare
Copy link
Collaborator

radare commented Mar 20, 2020

Screenshot 2020-03-20 at 13 30 43

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 20, 2020

  • Could not reproduce using docker debian/xenial:latest image.
  • Tested by running the command in r2 and r2r.js
  • Any suggestion?

@radare
Copy link
Collaborator

radare commented Mar 21, 2020 via email

@XVilka
Copy link
Contributor

XVilka commented Mar 21, 2020

Xenial is the default Travis configuration, and we do not specify the distro in YAML, so should be it.

@XVilka
Copy link
Contributor

XVilka commented Mar 21, 2020

Ideally, it should be tested with a sequence of om and wx commands, for different glibc versions. Relying on the runtime for testing is wrong.

@radare
Copy link
Collaborator

radare commented Mar 22, 2020

ping

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 22, 2020

I'm creating a test as suggested by @XVilka. May take some time

@radare
Copy link
Collaborator

radare commented Mar 23, 2020

keep us updated

@radare
Copy link
Collaborator

radare commented Mar 24, 2020

red

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 24, 2020

Ideally, it should be tested with a sequence of om and wx commands, for different glibc versions. Relying on the runtime for testing is wrong.

glibc struct for heap management requires around 3kB. Should I just add the memory dump to radare2-testbins rather than using wx?

@XVilka
Copy link
Contributor

XVilka commented Mar 24, 2020 via email

@XVilka
Copy link
Contributor

XVilka commented Mar 25, 2020

@x0urc3 can you add tests with dumps with and without tcache? And for the binary - it's probably better to include the glibc version in the name.

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 25, 2020

@x0urc3 can you add tests with dumps with and without tcache? And for the binary - it's probably better to include the glibc version in the name.

@XVilka
Copy link
Contributor

XVilka commented Mar 25, 2020

@x0urc3 merged, please update.

@x0urc3 x0urc3 changed the title Fix dmht caused by wrong tcache offset and definition Fix dmht for glibc caused by wrong tcache offset and definition Mar 25, 2020
@XVilka
Copy link
Contributor

XVilka commented Mar 26, 2020

Well done - one missing thing left:

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 26, 2020

Well done - one missing thing left:

  • Do not just replace the old value - use the new only for the newer glibc

I don't understand what you mean here. Which value?

Can we do this in a different PR?

@XVilka
Copy link
Contributor

XVilka commented Mar 26, 2020

@x0urc3 the value of SETI ("dbg.glibc.fc_offset", 0x00280, "First chunk offset from brk_start");

Determine the GLIBC version from runtime, maybe https://benohead.com/blog/2015/01/28/linux-check-glibc-version/ can be helpful
Add test for the older glibc version too

Can we do this in a different PR?

Yes, just please add a #ifdef for the GLIBC version meanwhile for the dbg.glibc.fc_offset, so it will not suddenly break for the users with older glibc versions installed.

@x0urc3
Copy link
Contributor Author

x0urc3 commented Mar 26, 2020

  • dbg.glibc.fc_offset does not depend on glibc version but host bit. The #ifdef to handle host bit (32/64) difference have already been in the code. This PR just reuse those
  • There are few places where hardcoded dbg.glibc.fc_offset is still used and requires fixing

@XVilka XVilka merged commit 80f59a7 into radareorg:master Mar 26, 2020
@x0urc3 x0urc3 deleted the fix-dmht branch March 26, 2020 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
heap Parsing memory heap structures
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants