iovisor / iovisor/bcc

strncmp: invalid BPF_LD_IMM insn

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

Description

I met an issue of invalid BPF_LD_IMM insn when use strncmp(key.comm, "xxx", sizeof(key.comm));
After I rewrite the strncmp function with C language, it works well, but I feel it is inconvenient, so I want ask whether you have good idea, thank you.

```
static int du_strncmp(const char *cs, const char *ct, size_t count)
{
unsigned char c1, c2;

while (count) {
c1 = *cs++;
c2 = *ct++;
if (c1 != c2)
return c1 < c2 ? -1 : 1;
if (!c1)
break;
count--;
}
return 0;
}

int print_submit_bio(struct pt_regs *ctx, struct bio *bio)
{
struct key_t key = {};
bpf_get_current_comm(&key.comm, sizeof(key.comm));
//du_strncmp(key.comm, "xxx", sizeof(xxx));
strncmp(key.comm, "xxx", sizeof(xxx));
....
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the print_submit_bio example using strncmp(key.comm, "xxx", sizeof(xxx)) and compare it with the provided C implementation. Inspect the generated BPF around the reported BPF_LD_IMM instruction; done means the strncmp form loads as valid BPF and works without requiring the custom replacement.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
devtools, operating-systems
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.