-
-
Notifications
You must be signed in to change notification settings - Fork 710
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
heap chunks
does not work with (all) x86 executables
#689
Comments
Confirmed: with this ugly patch diff --git a/gef.py b/gef.py
index f0aef0f..7134a13 100644
--- a/gef.py
+++ b/gef.py
@@ -799,14 +799,20 @@ class GlibcChunk:
def __init__(self, addr, from_base=False):
self.ptrsize = current_arch.ptrsize
if from_base:
- self.chunk_base_address = addr
- self.address = addr + 2 * self.ptrsize
+ if get_libc_version() >= (2, 26) and is_x86_32(): # post-tcache on x86-32
+ self.chunk_base_address = addr + 8
+ self.address = addr + 8 + 2 * self.ptrsize
+ else:
+ self.chunk_base_address = addr
+ self.address = addr + 2 * self.ptrsize
+
else:
self.chunk_base_address = int(addr - 2 * self.ptrsize)
self.address = addr It works everywhere... I'd rather avoid this kind of ultra-specific cases so I'll look into a better solution, if you find any, please update. |
I think you're right and the reason for this is glibc's Before version 2.26 every supported linux architecture calculated it as follows: /* The corresponding word size. */
#define SIZE_SZ (sizeof (INTERNAL_SIZE_T))
/* MALLOC_ALIGNMENT is the minimum alignment for malloc'ed chunks. It
must be a power of two at least 2 * SIZE_SZ, even on machines for
which smaller alignments would suffice. It may be defined as larger
than this though. Note however that code and data structures are
optimized for the case of 8-byte alignment. */
#ifndef MALLOC_ALIGNMENT
# define MALLOC_ALIGNMENT (2 * SIZE_SZ < __alignof__ (long double) \
? __alignof__ (long double) : 2 * SIZE_SZ)
#endif (From: https://elixir.bootlin.com/glibc/glibc-2.25/source/malloc/malloc-internal.h#L67) But since version 2.26 this snippet was moved to #define MALLOC_ALIGNMENT 16 (From: https://elixir.bootlin.com/glibc/glibc-2.26/source/sysdeps/i386/malloc-alignment.h#L22) So unless this memory alignment constant is later written to some header somewhere in memory the only way to correctly handle this IMO is to do the check in your "ugly patch". So because the EDIT: EDIT: |
Fair point, I'll apply the patch and a comment to this issue since you did a good job investigating the root cause. Cheers, |
otherwise i would have PR coming up that mimics Glibc's behavior to keep it in sync easier (and it's even commented ;) ) |
dev
branch?gdb -nx
the closed ones) - and the PR?
Step 1: Describe your environment
Step 2: Describe your problem
This issue was identified in issue #646. It seems like the
heap chunks
command does not work with x86 executables (or at least not with all of them). The issue is that the first chunks address is miscalculated.Steps to reproduce / Minimalist test case
Observed Results
No heap chunks in output (but also no error message)
Expected results
I expected heap chunks :)
This is the same source compiled for 64-bit with some nice heap chunks:
The Problem
self.address
is not calculated the correct way here (L803):gef/gef.py
Lines 799 to 810 in 48a9fd7
With this testcase the real heap chunk address is not at this address but at
this address + 8
. I'm not sure as to why this is - maybe because of some memory alignment or just simply the formula is not correct for x86 but only x86_64 and we need to make this calculation aware of the current architecture and adjust it accordingly.The text was updated successfully, but these errors were encountered: