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

Attaching uprobes with special characters in function names fails #2388

Closed
stevenjohnstone opened this issue Oct 12, 2022 · 1 comment · Fixed by #2390 or fengjixuchui/bpftrace#3
Closed
Labels
bug Something isn't working

Comments

@stevenjohnstone
Copy link
Contributor

What reproduces the bug?

Using version bpftrace v0.16.0-20-g720b try to attach to a uprobe to a golang function e.g.

uprobe:"/home/stevie/code/go-bpf-gen/tests/tests":"crypto/rand.(*devReader).Read" {

}

This fails with

ERROR: Error loading program: uprobe:/home/stevie/code/go-bpf-gen/tests/tests:crypto/rand.(*devReader).Read (try -v)

With strace I see

bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_KPROBE, insn_cnt=29, insns=0x55c0cf700040, license="GPL", log_level=1, log_size=1000000, log_buf="", kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="crypto/rand.(*d", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0, fd_array=NULL}, 128) = -1 EINVAL (Invalid argument)

It looks like there are symbols in prog_name="crypto/rand.(*d which will be rejected.

The last working revision seems to be 5ab53fa, just before changes to replace bcc loading with libbpf.

This patch fixes the issue for me:

diff --git a/src/attached_probe.cpp b/src/attached_probe.cpp
index 1e079039..2ef23ba3 100644
--- a/src/attached_probe.cpp
+++ b/src/attached_probe.cpp
@@ -690,11 +690,7 @@ void AttachedProbe::load_prog(BPFfeature &feature)
     // start the name after the probe type, after ':'
     if (auto last_colon = name.rfind(':'); last_colon != std::string::npos)
       name = name.substr(last_colon + 1);
-    // replace '+' and ',' by '.'
-    std::replace(name.begin(), name.end(), '+', '.');
-    std::replace(name.begin(), name.end(), ',', '.');
-    // remove quotes
-    name.erase(std::remove(name.begin(), name.end(), '"'), name.end());
+    name = sanitise(name);
 
     auto prog_type = progtype(probe_.type);
     if (probe_.type == ProbeType::special && !feature.has_raw_tp_special())

bpftrace --info

@viktormalik
Copy link
Contributor

Your patch looks good, could you submit it as a PR? Thanks!

stevenjohnstone added a commit to stevenjohnstone/bpftrace that referenced this issue Oct 13, 2022
bpf objects may only have names containing alphanumeric characters, '.'
and '_'. Golang programs, in particular, have symbol names which cause
problems e.g. "os.(*File).Read".

Fixes bpftrace#2388.
viktormalik pushed a commit that referenced this issue Oct 14, 2022
bpf objects may only have names containing alphanumeric characters, '.'
and '_'. Golang programs, in particular, have symbol names which cause
problems e.g. "os.(*File).Read".

Fixes #2388.
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.

2 participants