Skip to content

Commit 0f8a85f

Browse files
image-dragonKernel Patches Daemon
authored andcommitted
bpf: report probe fault to BPF stderr
Introduce the function bpf_prog_report_probe_violation(), which is used to report the memory probe fault to the user by the BPF stderr. Signed-off-by: Menglong Dong <[email protected]>
1 parent 7abc661 commit 0f8a85f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,6 +2902,7 @@ void bpf_dynptr_init(struct bpf_dynptr_kern *ptr, void *data,
29022902
void bpf_dynptr_set_null(struct bpf_dynptr_kern *ptr);
29032903
void bpf_dynptr_set_rdonly(struct bpf_dynptr_kern *ptr);
29042904
void bpf_prog_report_arena_violation(bool write, unsigned long addr, unsigned long fault_ip);
2905+
void bpf_prog_report_probe_violation(bool write, unsigned long fault_ip);
29052906

29062907
#else /* !CONFIG_BPF_SYSCALL */
29072908
static inline struct bpf_prog *bpf_prog_get(u32 ufd)

kernel/trace/bpf_trace.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,24 @@ void bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp)
20552055
module_put(mod);
20562056
}
20572057

2058+
void bpf_prog_report_probe_violation(bool write, unsigned long fault_ip)
2059+
{
2060+
struct bpf_stream_stage ss;
2061+
struct bpf_prog *prog;
2062+
2063+
rcu_read_lock();
2064+
prog = bpf_prog_ksym_find(fault_ip);
2065+
rcu_read_unlock();
2066+
if (!prog)
2067+
return;
2068+
2069+
bpf_stream_stage(ss, prog, BPF_STDERR, ({
2070+
bpf_stream_printk(ss, "ERROR: Probe %s access faule, insn=0x%lx\n",
2071+
write ? "WRITE" : "READ", fault_ip);
2072+
bpf_stream_dump_stack(ss);
2073+
}));
2074+
}
2075+
20582076
static __always_inline
20592077
void __bpf_trace_run(struct bpf_raw_tp_link *link, u64 *args)
20602078
{

0 commit comments

Comments
 (0)