iovisor / iovisor/bcc

Error when using bpf_strncmp

Open
#5,137 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

Hello,

I'm having problems when using bpf_strncmp, I have a simple ebpf program using BCC, that program uses bpf_strncmp to compare the task name to a string.
So I do the following:

```
char my_com[] = "cat";
struct task_struct *task = (struct task_struct *)bpf_get_current_task_btf();
if (bpf_strncmp(comm, sizeof(my_com), my_com) == 0){
bpf_trace_printk("Cat");
}
```

If I use this I get a permission denied error that I can't seem to understand while, if I use `strncmp` it works as expected

```
char my_com[] = "cat";
struct task_struct *task = (struct task_struct *)bpf_get_current_task_btf();
if (strncmp(comm, my_com, sizeof(my_com) -1) == 0){
bpf_trace_printk("Cat");
}
```

The error:

```
b.attach_raw_tracepoint(tp="sys_enter", fn_name="hello")
File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 1061, in attach_raw_tracepoint
fn = self.load_func(fn_name, BPF.RAW_TRACEPOINT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 526, in load_func
raise Exception("Failed to load BPF program %s: %s" %
Exception: Failed to load BPF program b'hello': Permission denied
```

In the ebpf compiled code I have the following:

```
R3 type=fp expected=map_value
```

However, the `bpf_strncmp` takes char * as mentioned in the doc so I don't understand the problem

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the minimal BCC eBPF program in the report and the bpf_strncmp call, then inspect the verifier output during attach_raw_tracepoint and load_func. Compare it with the working strncmp variant to determine why the helper is rejected. Done means the reported program loads successfully with bpf_strncmp and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
operating-systems, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.