run ./inject.py demo issues
- Dominant language
- C
- Stars
- 22.7k
- Forks
- 4.1k
- Avg merge
- 10d 4h
- Merged PRs (30d)
- 3
Description
root@localhost:/bcc/tools# ./inject.py kmalloc -v -P 0.01 'SyS_mount()'
#include
struct pid_struct {
u64 curr_call; /* book keeping to handle recursion */
u64 conds_met; /* stack pointer */
u64 stack[2];
};
BPF_HASH(m, u32, struct pid_struct);
BPF_ARRAY(count, u32, 1);
int SyS_mount_entry(struct pt_regs *ctx)
{
u32 pid = bpf_get_current_pid_tgid();
/*
* Early exit for probability case
*/
if (bpf_get_prandom_u32() > 42949672)
return 0;
/*
* Top level function init map
*/
struct pid_struct p_struct = {0, 0};
m.insert(&pid, &p_struct);
struct pid_struct *p = m.lookup(&pid);
if (!p)
return 0;
/*
* preparation for predicate, if necessary
*/
/*
* Generate entry logic
*/
if (p->conds_met >= 2)
return 0;
if (p->conds_met == 0 && (true)) {
p->stack[0] = p->curr_call;
p->conds_met++;
}
p->curr_call++;
return 0;
}
int SyS_mount_exit(struct pt_regs *ctx)
{
u32 pid = bpf_get_current_pid_tgid();
struct pid_struct *p = m.lookup(&pid);
if (!p)
return 0;
p->curr_call--;
/*
* Generate exit logic
*/
if (p->conds_met < 1 || p->conds_met >= 3)
return 0;
if (p->stack[p->conds_met - 1] == p->curr_call)
p->conds_met--;
/*
* Top level function clean up map
*/
m.delete(&pid);
return 0;
}
int should_failslab_entry(struct pt_regs *ctx, struct kmem_cache *s, gfp_t gfpflags)
{
u32 overridden = 0;
int zero = 0;
u32* val;
val = count.lookup(&zero);
if (val)
overridden = *val;
/*
* preparation for predicate, if necessary
*/
/*
* If this is the only call in the chain and predicate passes
*/
if (2 == 1 && (true) && overridden < -1) {
count.atomic_increment(zero);
bpf_override_return(ctx, -ENOMEM);
return 0;
}
u32 pid = bpf_get_current_pid_tgid();
struct pid_struct *p = m.lookup(&pid);
if (!p)
return 0;
/*
* If all conds have been met and predicate passes
*/
if (p->conds_met == 1 && (true) && overridden < -1) {
count.atomic_increment(zero);
bpf_override_return(ctx, -ENOMEM);
}
return 0;
}
cannot attach kprobe, probe entry may not exist
Traceback (most recent call last):
File "/bcc/tools/./inject.py", line 525, in
Tool().run()
File "/bcc/tools/./inject.py", line 520, in run
self._attach_probes()
File "/bcc/tools/./inject.py", line 492, in _attach_probes
p.attach(self.bpf)
File "/bcc/tools/./inject.py", line 304, in attach
bpf.attach_kprobe(event=self.event,
File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 845, in attach_kprobe
raise Exception("Failed to attach BPF program %s to kprobe %s"
Exception: Failed to attach BPF program b'SyS_mount_entry' to kprobe b'SyS_mount', it's not traceable (either non-existing, inlined, or marked as "notrace")
root@localhost:/bcc/tools#
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.