Skip to content

Commit 8ec86c6

Browse files
ebpf: arm improvements
- better process interception on aarch64 and armhf. - on armhf getting proc arguments is ignored due to an error, but we were not marking the event as INCOMPLETE_ARGS, so we were not reading the compete cmdline.
1 parent 566f7b4 commit 8ec86c6

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

daemon/procmon/ebpf/events.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ type execEvent struct {
3535
UID uint32
3636
PPID uint32
3737
RetCode uint32
38+
Pad uint16
3839
ArgsCount uint8
3940
ArgsPartial uint8
4041
Filename [MaxPathLen]byte
4142
Args [MaxArgs][MaxArgLen]byte
4243
Comm [TaskCommLen]byte
43-
Pad1 uint16
44-
Pad2 uint32
4544
}
4645

4746
// Struct that holds the metadata of a connection.

ebpf_prog/common.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,12 @@ struct data_t {
7474
// Parent PID as in the userspace term (i.e task->real_parent->tgid in kernel)
7575
u32 ppid;
7676
u32 ret_code;
77+
u16 _pad;
7778
u8 args_count;
7879
u8 args_partial;
7980
char filename[MAX_PATH_LEN];
8081
char args[MAX_ARGS][MAX_ARG_SIZE];
8182
char comm[TASK_COMM_LEN];
82-
u16 pad1;
83-
u32 pad2;
8483
};
8584

8685
//-----------------------------------------------------------------------------

ebpf_prog/opensnitch-procs.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,14 @@ int tracepoint__syscalls_sys_enter_execve(struct trace_sys_enter_execve* ctx)
111111
}
112112
new_event(data);
113113
data->type = EVENT_EXEC;
114-
// bpf_probe_read_user* helpers were introduced in kernel 5.5
115-
// Since the args can be overwritten anyway, maybe we could get them from
116-
// mm_struct instead for a wider kernel version support range?
114+
115+
data->args_count = 0;
116+
data->args_partial = INCOMPLETE_ARGS;
117117
bpf_probe_read_user_str(&data->filename, sizeof(data->filename), (const char *)ctx->filename);
118118

119119
// FIXME: on i386 arch, the following code fails with permission denied.
120120
#if !defined(__arm__) && !defined(__i386__)
121121
const char *argp={0};
122-
data->args_count = 0;
123-
data->args_partial = INCOMPLETE_ARGS;
124122

125123
#pragma unroll
126124
for (int i = 0; i < MAX_ARGS; i++) {
@@ -157,6 +155,7 @@ int tracepoint__syscalls_sys_enter_execve(struct trace_sys_enter_execve* ctx)
157155
// -28 ENOSPC (no space left)
158156
// -> perf reader buffer too small.
159157
// -> also happens after coming back from suspend state.
158+
// -11 EAGAIN - ringbuf full?
160159
// -7 E2BIG (arg list too long) -> too much args?
161160
// -2 ENOENT (no such file or directory) -> map index not found. on different cpu?
162161

@@ -182,11 +181,12 @@ int tracepoint__syscalls_sys_enter_execveat(struct trace_sys_enter_execveat* ctx
182181
data->type = EVENT_EXECVEAT;
183182
bpf_probe_read_user_str(&data->filename, sizeof(data->filename), (const char *)ctx->filename);
184183

184+
data->args_count = 0;
185+
data->args_partial = INCOMPLETE_ARGS;
186+
185187
// FIXME: on i386 arch, the following code fails with permission denied.
186188
#if !defined(__arm__) && !defined(__i386__)
187189
const char *argp={0};
188-
data->args_count = 0;
189-
data->args_partial = INCOMPLETE_ARGS;
190190

191191
#pragma unroll
192192
for (int i = 0; i < MAX_ARGS; i++) {

0 commit comments

Comments
 (0)