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] Need more details on frida uprobe attach failures #191

Open
agentzh opened this issue Jan 28, 2024 · 1 comment
Open

[BUG] Need more details on frida uprobe attach failures #191

agentzh opened this issue Jan 28, 2024 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@agentzh
Copy link

agentzh commented Jan 28, 2024

I'm getting the following error with uprobe + llvm jit:

[2024-01-28 01:12:03][info][707874] Created uprobe/uretprobe perf event handler, module name /500g-a/git/ebpf-plus/libbpf/uprobes/a.out, offset 1126
[2024-01-28 01:12:03.112] [info] [agent.cpp:66] Entering bpftime agent
[2024-01-28 01:12:03.112] [info] [bpftime_shm_internal.cpp:618] Global shm constructed. shm_open_type 1 for bpftime_maps_shm
[2024-01-28 01:12:03.112] [info] [agent.cpp:81] Initializing agent..
[2024-01-28 01:12:03][info][707879] Initializing llvm
[2024-01-28 01:12:03][info][707879] Executable path: /500g-a/git/ebpf-plus/libbpf/uprobes/a.out
[2024-01-28 01:12:03][info][707879] Attached 1 uprobe programs to function 401126
[2024-01-28 01:12:03][error][707879] Failed to execute frida gum_interceptor_attach for function 401126
terminate called after throwing an instance of 'std::runtime_error'
  what():  Failed to attach uprobe/uretprpbe

How can I get more details and reasons for the failure? The 0x401126 address is correct for the foo() function in the target program a.out:

$ nm a.out|grep foo
0000000000401126 T foo

It always fails on my side (but just succeeded for only once). How to troubleshoot this further?

@agentzh agentzh added the bug Something isn't working label Jan 28, 2024
@agentzh
Copy link
Author

agentzh commented Jan 28, 2024

Seems like this is a known issue with short functions in Frida. Alas. See frida/frida-gum#273 (comment). If I make the function foo bigger (by either adding more statements or use -O0 instead), then it succeeds:

[2024-01-28 01:26:44][info][708488] Created uprobe/uretprobe perf event handler, module name /500g-a/git/ebpf-plus/libbpf/uprobes/a.out, offset 1126
[2024-01-28 01:26:44.811] [info] [agent.cpp:66] Entering bpftime agent
[2024-01-28 01:26:44.811] [info] [bpftime_shm_internal.cpp:618] Global shm constructed. shm_open_type 1 for bpftime_maps_shm
[2024-01-28 01:26:44.811] [info] [agent.cpp:81] Initializing agent..
[2024-01-28 01:26:44][info][708493] Initializing llvm
[2024-01-28 01:26:44][info][708493] Executable path: /500g-a/git/ebpf-plus/libbpf/uprobes/a.out
[2024-01-28 01:26:44][info][708493] Attached 1 uprobe programs to function 401126
[2024-01-28 01:26:44][info][708493] Attach successfully

Here is the original foo function definition in C:

int __attribute__((noinline)) foo(int a) {
    return a + 1;
}

With gcc -O0, it has 7 instructions:

0000000000401126 <foo>:
foo():
  401126:	55                   	push   rbp
  401127:	48 89 e5             	mov    rbp,rsp
  40112a:	89 7d fc             	mov    DWORD PTR [rbp-0x4],edi
  40112d:	8b 45 fc             	mov    eax,DWORD PTR [rbp-0x4]
  401130:	83 c0 01             	add    eax,0x1
  401133:	5d                   	pop    rbp
  401134:	c3                   	ret

But with gcc -O1, it has only 2 instructions:

0000000000401126 <foo>:
foo():
  401126:	8d 47 01             	lea    eax,[rdi+0x1]
  401129:	c3                   	ret

And for this short foo() function, Frida always fails.

@yunwei37 yunwei37 added good first issue Good for newcomers help wanted Extra attention is needed labels Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants