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] uretprobe improperly when attaching two programs onto the same function #39

Closed
Officeyutong opened this issue Oct 16, 2023 · 0 comments · Fixed by #44
Closed

[BUG] uretprobe improperly when attaching two programs onto the same function #39

Officeyutong opened this issue Oct 16, 2023 · 0 comments · Fixed by #44
Assignees
Labels
bug Something isn't working

Comments

@Officeyutong
Copy link
Contributor

Attach the following program:

// SPDX-License-Identifier: GPL-2.0
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
SEC("uretprobe/./example/simple_uretprobe_test/victim:simple_add")
int BPF_URETPROBE(simple_probe, long ret)
{
	bpf_printk("Ret=%ld\n", ret);

	return 0;
}

SEC("uretprobe/./example/simple_uretprobe_test/victim:simple_add")
int BPF_URETPROBE(simple_probe2, long ret)
{
	bpf_printk("Ret2=%ld\n", ret);

	return 0;
}

char LICENSE[] SEC("license") = "GPL";

victim:

#include <cstdint>
#include <fcntl.h>
#include <iostream>
#include <ostream>
#include <unistd.h>

extern "C" int64_t simple_add(int64_t a, int64_t b)
{
	return a + b;
}

int main()
{
	while (true) {
		for (int i = 1; i <= 10; i++) {
			for (int j = 1; j <= 10; j++) {
				int32_t ret = simple_add(i, j);
				std::cout << i << " + " << j << " = " << ret
					  << std::endl;
				usleep(1000 * 500);
			}
		}
	}
	return 0;
}

Will lead to the following output:

Ret2=1
Ret=2
1 + 1 = 2
Ret2=1
Ret=3
1 + 2 = 3
Ret2=1
Ret=4
1 + 3 = 4
Ret2=1
Ret=5
1 + 4 = 5

Where ret2 prints the first argument, not the return value, so it seems to be attached as uprobe

@Officeyutong Officeyutong added the bug Something isn't working label Oct 16, 2023
@Officeyutong Officeyutong self-assigned this Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant