redbpf icon indicating copy to clipboard operation
redbpf copied to clipboard

sym_offset calculation in attach uprobe fails to account to address differences

Open ajwerner opened this issue 2 years ago • 1 comments

BPF probes want the offset of a symbol in the object file. In shared object and executable files, at least, the current logic seems to return the virtual address of the symbol as opposed to the offset in the object file.

The st_value for a goblin::elf:sym::Sym with st_info of STT_FUNC (2) refers to the virtual memory address. In order to compute the offset, one needs to find the offset by translating it to be relative to the address of the section containing the symbol and then adding the offset of the section in the file.

The offending code is:

https://github.com/foniod/redbpf/blob/55331987dc31a26feb192e4a668bf9bfc336e1e0/redbpf/src/lib.rs#L965

In some cases, the address of the symbol is its offset, but certainly not in all cases.

See: https://github.com/iovisor/bpftrace/issues/1763#issuecomment-1238935968

ajwerner avatar Dec 28 '22 14:12 ajwerner

Fixed by https://github.com/foniod/redbpf/pull/308; would it be possible to release a new version containing this fix?

ajwerner avatar Dec 28 '22 15:12 ajwerner