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

[Bug] $_stack() calculate error #928

Closed
1 of 9 tasks
jylsec opened this issue Jan 24, 2023 · 3 comments
Closed
1 of 9 tasks

[Bug] $_stack() calculate error #928

jylsec opened this issue Jan 24, 2023 · 3 comments

Comments

@jylsec
Copy link

jylsec commented Jan 24, 2023

GEF+GDB version

GEF: (Standalone)
Blob Hash(/home/jylsec/.gef-2b72f5d0d9f0f218a91cd1ca5148e45923b950d5.py): 8dc57b700e3c1c85822449033a01c94dfae9e4a6
SHA256(/home/jylsec/.gef-2b72f5d0d9f0f218a91cd1ca5148e45923b950d5.py): 63d3e10d38a367c3e4d37de8e0701bcdff2a4e7c9a0a4ec5d83ccb8b2fe6188d
GDB: 12.1
GDB-Python: 3.10

Operating System

Ubuntu22.04

Describe the issue you encountered

context shows

$rax   : 0x007fffffffe810  →  "1234567890\n"
$rbx   : 0x0               
$rcx   : 0x005555555592ab  →  0x0000000000000000
$rdx   : 0xfbad2288        
$rsp   : 0x007fffffffe7b0  →  0x007ffff7ffd040  →  0x007ffff7ffe2e0  →  0x00555555554000  →   jg 0x555555554047
$rbp   : 0x007fffffffe7e0  →  0x007fffffffe840  →  0x0000000000000001
$rsi   : 0x3938373635343332 ("23456789"?)
$rdi   : 0x007fffffffe810  →  "1234567890\n"
$rip   : 0x005555555552f5  →  <encrypt+24> jmp 0x55555555535e <encrypt+129>
$r8    : 0x0               
$r9    : 0x005555555592a0  →  "1234567890\n"
$r10   : 0x77              
$r11   : 0x246             
$r12   : 0x007fffffffe958  →  0x007fffffffec17  →  "/home/jylsec/sora"
$r13   : 0x00555555555229  →  <main+0> endbr64 
$r14   : 0x0               
$r15   : 0x007ffff7ffd040  →  0x007ffff7ffe2e0  →  0x00555555554000  →   jg 0x555555554047
$eflags: [zero carry parity adjust sign trap INTERRUPT direction overflow resume virtualx86 identification]
$cs: 0x33 $ss: 0x2b $ds: 0x00 $es: 0x00 $fs: 0x00 $gs: 0x00

However
print $_stack() command show

gef➤  print $_stack()
$5 = 0x7ffffffde000

I think $_stack() should equal $rbp

Do you read the docs and look at previously closed issues/PRs for similar cases?

yes

Architecture impacted

  • X86
  • X64
  • ARM
  • ARM64
  • MIPS
  • MIPS64
  • PPC
  • PPC64
  • RISCV

Describe your issue. Without a proper reproduction step-by-step, your issue will be ignored.

context shows

$rax   : 0x007fffffffe810  →  "1234567890\n"
$rbx   : 0x0               
$rcx   : 0x005555555592ab  →  0x0000000000000000
$rdx   : 0xfbad2288        
$rsp   : 0x007fffffffe7b0  →  0x007ffff7ffd040  →  0x007ffff7ffe2e0  →  0x00555555554000  →   jg 0x555555554047
$rbp   : 0x007fffffffe7e0  →  0x007fffffffe840  →  0x0000000000000001
$rsi   : 0x3938373635343332 ("23456789"?)
$rdi   : 0x007fffffffe810  →  "1234567890\n"
$rip   : 0x005555555552f5  →  <encrypt+24> jmp 0x55555555535e <encrypt+129>
$r8    : 0x0               
$r9    : 0x005555555592a0  →  "1234567890\n"
$r10   : 0x77              
$r11   : 0x246             
$r12   : 0x007fffffffe958  →  0x007fffffffec17  →  "/home/jylsec/sora"
$r13   : 0x00555555555229  →  <main+0> endbr64 
$r14   : 0x0               
$r15   : 0x007ffff7ffd040  →  0x007ffff7ffe2e0  →  0x00555555554000  →   jg 0x555555554047
$eflags: [zero carry parity adjust sign trap INTERRUPT direction overflow resume virtualx86 identification]
$cs: 0x33 $ss: 0x2b $ds: 0x00 $es: 0x00 $fs: 0x00 $gs: 0x00

However
print $_stack() command show

gef➤  print $_stack()
$5 = 0x7ffffffde000

I think $_stack() should equal $rbp

@hugsy
Copy link
Owner

hugsy commented Jan 24, 2023

From the docs

Return the current stack base address plus the given offset.

It points to the base address of the stack memory region, not $rsp or $rbp

@hugsy hugsy added not-a-bug and removed bug labels Jan 24, 2023
@jylsec
Copy link
Author

jylsec commented Jan 25, 2023

@hugsy
$_stack() which returns 0x7ffffffde000 is lower than $RSP whose value is 0x007fffffffe7b0. I’m now confused about what the base address of the stack memory region mean. I search its concept in chatgpt and stackoverflow.They all tell me that it means the highest memory location of call stack belonging to the program or stack frame belonging to each subroutine .

@hugsy
Copy link
Owner

hugsy commented Jan 25, 2023

Just open /proc/<pid>/maps and you'll see that $_stack() has the same value as the base address showing on the [stack] line.
Closing this issue, as it is not gef related (also it's not an issue). If you have questions to understand how memory layout works just drop by the Discord.

Cheers

@hugsy hugsy closed this as completed Jan 25, 2023
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