Implib.so icon indicating copy to clipboard operation
Implib.so copied to clipboard

question about cfi_adjust_cfa_offset after just entering into fuction

Open NanFeng009 opened this issue 3 years ago • 5 comments

very thanks for your useful tool, i have a question about cfi https://github.com/yugr/Implib.so/blob/bbca01e0109d51ef1b870cbc8cf953372136b8ad/arch/x86_64/table.S.tpl#L29

.cfi_adjust_cfa_offset 8; should this offset be 16, since previous instruction call also push IP to stack?

NanFeng009 avatar Aug 08 '22 01:08 NanFeng009

Thank you for using Implib.so.

.cfi_adjust_cfa_offset tells debugger that pushq changes SP value by 8. If there's any previous instruction which changes SP, it should have it's own .cfi_adjust_cfa_offset directive. Debuggers "combines" different .cfi_adjust_cfa_offset directives so for code like

inst1
.cfi_adjust_cfa_offset 8
inst2
cfi_adjust_cfa_offset 8

it will understand that the final offset is 16.

yugr avatar Aug 08 '22 06:08 yugr

https://github.com/yugr/Implib.so/blob/bbca01e0109d51ef1b870cbc8cf953372136b8ad/arch/x86_64/trampoline.S.tpl#L28 Really thank you for answering my newbie question. The call instruction will push RIP on stack and it change the SP but there is no matching .cfi_adjust_cfa_offset. where is call's .cfi_adjust_cfa_offset?

NanFeng009 avatar Aug 08 '22 09:08 NanFeng009

Hm, yes, I think you are right, I'll fix this. How did you run into this issue (so that I could test it myself locally)?

yugr avatar Aug 08 '22 09:08 yugr

Honestly, i haven't met this issue. i just review code. I tried generate a core dump in basic test, but haven't seen any different😒.

NanFeng009 avatar Aug 09 '22 02:08 NanFeng009

I've added a simple fix on a branch but I'm hesitant to commit it just yet without fully understanding how to test it.

yugr avatar Aug 09 '22 18:08 yugr

I've found a way to diagnose this issue (call stack would become broken without proper CFI directives) and was able to prepare a proper fix.

Thank you for the report and please let me know if you find other issues.

yugr avatar Aug 11 '22 19:08 yugr

Hi Yugr,

I've found a way to diagnose this issue How do you do this test? can you share some information?

NanFeng009 avatar Sep 29 '22 06:09 NanFeng009

I've put a breakpoint in _XXX_tramp_resolve and checked that backtrace command works correctly (prints whole stack up to main) and variables in main are printed correctly. This didn't work without the fix.

yugr avatar Sep 29 '22 06:09 yugr

thanks, yugr😊

NanFeng009 avatar Sep 29 '22 09:09 NanFeng009