Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chapter2/hello-buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
data.pid = bpf_get_current_pid_tgid() >> 32;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;

bpf_get_current_comm(&data.command, sizeof(data.command));
bpf_probe_read_kernel(&data.message, sizeof(data.message), message);
bpf_get_current_comm(data.command, sizeof(data.command));
bpf_probe_read_kernel(data.message, sizeof(data.message), message);

output.perf_submit(ctx, &data, sizeof(data));

Expand Down
4 changes: 2 additions & 2 deletions chapter2/hello-file-ring-buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
struct event_t event = {};

event.dfd = args->dfd;
bpf_probe_read_user_str(&event.filename, sizeof(event.filename), args->filename);
bpf_get_current_comm(&event.command, sizeof(event.command));
bpf_probe_read_user_str(event.filename, sizeof(event.filename), args->filename);
bpf_get_current_comm(event.command, sizeof(event.command));

bpf_trace_printk("File %d - %s", event.dfd, event.filename);
bpf_trace_printk(" opened by:%s", event.command);
Expand Down
6 changes: 3 additions & 3 deletions chapter4/hello-buffer-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
data.pid = bpf_get_current_pid_tgid() >> 32;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;

bpf_get_current_comm(&data.command, sizeof(data.command));
bpf_get_current_comm(data.command, sizeof(data.command));

p = config.lookup(&data.uid);
if (p != 0) {
bpf_probe_read_kernel(&data.message, sizeof(data.message), p->message);
bpf_probe_read_kernel(data.message, sizeof(data.message), p->message);
} else {
bpf_probe_read_kernel(&data.message, sizeof(data.message), message);
bpf_probe_read_kernel(data.message, sizeof(data.message), message);
}

output.perf_submit(ctx, &data, sizeof(data));
Expand Down
6 changes: 3 additions & 3 deletions chapter4/hello-ring-buffer-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
data.pid = bpf_get_current_pid_tgid() >> 32;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;

bpf_get_current_comm(&data.command, sizeof(data.command));
bpf_get_current_comm(data.command, sizeof(data.command));

p = config.lookup(&data.uid);
if (p != 0) {
bpf_probe_read_kernel(&data.message, sizeof(data.message), p->message);
bpf_probe_read_kernel(data.message, sizeof(data.message), p->message);
} else {
bpf_probe_read_kernel(&data.message, sizeof(data.message), message);
bpf_probe_read_kernel(data.message, sizeof(data.message), message);
}

output.ringbuf_output(&data, sizeof(data), 0);
Expand Down
2 changes: 1 addition & 1 deletion chapter5/find-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ int main()
printf("No FD\n");
} else {
bpf_obj_get_info_by_fd(findme, &info, &len);
printf("name %s\n", info.name);
printf("Name: %s\n", info.name);
}
}
Binary file removed chapter5/hello-buffer-config
Binary file not shown.
8 changes: 4 additions & 4 deletions chapter5/hello-buffer-config.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ int BPF_KPROBE_SYSCALL(hello, const char *pathname)
data.pid = bpf_get_current_pid_tgid() >> 32;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;

bpf_get_current_comm(&data.command, sizeof(data.command));
bpf_probe_read_user_str(&data.path, sizeof(data.path), pathname);
bpf_get_current_comm(data.command, sizeof(data.command));
bpf_probe_read_user_str(data.path, sizeof(data.path), pathname);

p = bpf_map_lookup_elem(&my_config, &data.uid);
if (p != 0) {
bpf_probe_read_kernel_str(&data.message, sizeof(data.message), p->message);
bpf_probe_read_kernel_str(data.message, sizeof(data.message), p->message);
} else {
bpf_probe_read_kernel_str(&data.message, sizeof(data.message), message);
bpf_probe_read_kernel_str(data.message, sizeof(data.message), message);
}

bpf_perf_event_output(ctx, &output, BPF_F_CURRENT_CPU, &data, sizeof(data));
Expand Down
6 changes: 3 additions & 3 deletions chapter6/hello-verifier.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ int kprobe_exec(void *ctx)
}

if (p != 0) {
bpf_probe_read_kernel(&data.message, sizeof(data.message), p->message);
bpf_probe_read_kernel_str(data.message, sizeof(data.message), p->message);
} else {
bpf_probe_read_kernel(&data.message, sizeof(data.message), message);
bpf_probe_read_kernel_str(data.message, sizeof(data.message), message);
}
Comment thread
lizrice marked this conversation as resolved.

// Changing this to <= means and c could have value beyond the bounds of the
Expand All @@ -66,7 +66,7 @@ int kprobe_exec(void *ctx)
bpf_printk("%c", a);
}

bpf_get_current_comm(&data.command, sizeof(data.command));
bpf_get_current_comm(data.command, sizeof(data.command));
bpf_perf_event_output(ctx, &output, BPF_F_CURRENT_CPU, &data, sizeof(data));

return 0;
Expand Down
30 changes: 15 additions & 15 deletions chapter7/hello.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ int BPF_KPROBE_SYSCALL(kprobe_sys_execve, const char *pathname)
{
struct data_t data = {};

bpf_probe_read_kernel(&data.message, sizeof(data.message), kprobe_sys_msg);
bpf_probe_read_kernel(data.message, sizeof(data.message), kprobe_sys_msg);
bpf_printk("%s: pathname: %s", kprobe_sys_msg, pathname);

data.pid = bpf_get_current_pid_tgid() >> 32;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;
bpf_get_current_comm(&data.command, sizeof(data.command));
bpf_probe_read_user(&data.path, sizeof(data.path), pathname);
bpf_get_current_comm(data.command, sizeof(data.command));
bpf_probe_read_user_str(data.path, sizeof(data.path), pathname);

bpf_perf_event_output(ctx, &output, BPF_F_CURRENT_CPU, &data, sizeof(data));
return 0;
Expand All @@ -46,14 +46,14 @@ SEC("kprobe/do_execve")
int BPF_KPROBE(kprobe_do_execve, struct filename *filename) {
struct data_t data = {};

bpf_probe_read_kernel(&data.message, sizeof(data.message), kprobe_msg);
bpf_probe_read_kernel(data.message, sizeof(data.message), kprobe_msg);

data.pid = bpf_get_current_pid_tgid() >> 32;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;

bpf_get_current_comm(&data.command, sizeof(data.command));
bpf_get_current_comm(data.command, sizeof(data.command));
const char *name = BPF_CORE_READ(filename, name);
bpf_probe_read_kernel(&data.path, sizeof(data.path), name);
bpf_probe_read_kernel_str(data.path, sizeof(data.path), name);

Comment thread
lizrice marked this conversation as resolved.
bpf_printk("%s: filename->name: %s", kprobe_msg, name);

Expand All @@ -69,14 +69,14 @@ SEC("fentry/do_execve")
int BPF_PROG(fentry_execve, struct filename *filename) {
struct data_t data = {};

bpf_probe_read_kernel(&data.message, sizeof(data.message), fentry_msg);
bpf_probe_read_kernel(data.message, sizeof(data.message), fentry_msg);

data.pid = bpf_get_current_pid_tgid() >> 32;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;

bpf_get_current_comm(&data.command, sizeof(data.command));
bpf_get_current_comm(data.command, sizeof(data.command));
const char *name = BPF_CORE_READ(filename, name);
bpf_probe_read_kernel(&data.path, sizeof(data.path), name);
bpf_probe_read_kernel_str(data.path, sizeof(data.path), name);

bpf_printk("%s: filename->name: %s", fentry_msg, name);

Expand Down Expand Up @@ -113,14 +113,14 @@ SEC("tp/syscalls/sys_enter_execve")
int tp_sys_enter_execve(struct my_syscalls_enter_execve *ctx) {
struct data_t data = {};

bpf_probe_read_kernel(&data.message, sizeof(data.message), tp_msg);
bpf_probe_read_kernel(data.message, sizeof(data.message), tp_msg);
bpf_printk("%s: ctx->filename_ptr: %s", tp_msg, ctx->filename_ptr);

data.pid = bpf_get_current_pid_tgid() >> 32;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;

bpf_get_current_comm(&data.command, sizeof(data.command));
bpf_probe_read_user(&data.path, sizeof(data.path), ctx->filename_ptr);
bpf_get_current_comm(data.command, sizeof(data.command));
bpf_probe_read_user_str(data.path, sizeof(data.path), ctx->filename_ptr);

bpf_perf_event_output(ctx, &output, BPF_F_CURRENT_CPU, &data, sizeof(data));
return 0;
Expand All @@ -134,14 +134,14 @@ int tp_btf_exec(struct trace_event_raw_sched_process_exec *ctx)
struct data_t data = {};
// pid_t pid = ctx->pid;

bpf_probe_read_kernel(&data.message, sizeof(data.message), tp_btf_exec_msg);
bpf_probe_read_kernel(data.message, sizeof(data.message), tp_btf_exec_msg);

data.pid = bpf_get_current_pid_tgid() >> 32;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;

// TODO!! Resolve issues accessing data that isn't aligned to an 8-byte boundary
// bpf_printk("%s %d\n", tp_btf_exec_msg, pid);
// bpf_probe_read_kernel_str(&data.command, sizeof(data.command), ctx->pid);
// bpf_probe_read_kernel_str(data.command, sizeof(data.command), ctx->pid);

bpf_perf_event_output(ctx, &output, BPF_F_CURRENT_CPU, &data, sizeof(data));
return 0;
Expand All @@ -152,7 +152,7 @@ int raw_tp_exec(struct bpf_raw_tracepoint_args *ctx)
{
struct data_t data = {};

bpf_probe_read_kernel(&data.message, sizeof(data.message), raw_tp_exec_msg);
bpf_probe_read_kernel(data.message, sizeof(data.message), raw_tp_exec_msg);

data.pid = bpf_get_current_pid_tgid() >> 32;
data.uid = bpf_get_current_uid_gid() & 0xFFFFFFFF;
Expand Down