Skip to content

Commit 14d85dd

Browse files
committed
update: add cmd to bpf exit event
Signed-off-by: rohith-raju <[email protected]>
1 parent 4e9a3cc commit 14d85dd

File tree

7 files changed

+110
-16
lines changed

7 files changed

+110
-16
lines changed

Diff for: driver/SCHEMA_VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.13.0
1+
2.14.0

Diff for: driver/bpf/fillers.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -5778,11 +5778,13 @@ FILLER(sys_bpf_e, true)
57785778

57795779
FILLER(sys_bpf_x, true)
57805780
{
5781-
/*
5782-
* fd
5783-
*/
5781+
/* Parameter 1: fd (type: PT_DEC) */
57845782
long fd = bpf_syscall_get_retval(data->ctx);
5785-
return bpf_push_s64_to_ring(data, fd);
5783+
bpf_push_s64_to_ring(data, fd);
5784+
5785+
/* Parameter 2: cmd (type: PT_INT64) */
5786+
int32_t cmd = (int32_t)bpf_syscall_get_argument(data, 0);
5787+
return bpf_push_s64_to_ring(data,(int64_t)cmd);
57865788
}
57875789

57885790
FILLER(sys_unlinkat_x, true)

Diff for: driver/event_table.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ const struct ppm_event_info g_event_info[] = {
347347
[PPME_SYSCALL_SETPGID_E] = {"setpgid", EC_PROCESS | EC_SYSCALL, EF_MODIFIES_STATE, 2, {{"pid", PT_PID, PF_DEC}, {"pgid", PT_PID, PF_DEC} } },
348348
[PPME_SYSCALL_SETPGID_X] = {"setpgid", EC_PROCESS | EC_SYSCALL, EF_MODIFIES_STATE, 1, {{"res", PT_PID, PF_DEC} } },
349349
[PPME_SYSCALL_BPF_E] = {"bpf", EC_OTHER | EC_SYSCALL, EF_CREATES_FD | EF_OLD_VERSION, 1, {{"cmd", PT_INT64, PF_DEC} } },
350-
[PPME_SYSCALL_BPF_X] = {"bpf", EC_OTHER | EC_SYSCALL, EF_CREATES_FD | EF_OLD_VERSION, 1, {{"res_or_fd", PT_DYN, PF_DEC, bpf_dynamic_param, PPM_BPF_IDX_MAX} } },
350+
[PPME_SYSCALL_BPF_X] = {"bpf", EC_OTHER | EC_SYSCALL, EF_CREATES_FD | EF_OLD_VERSION, 1, {{"res_or_fd", PT_DYN, PF_DEC, bpf_dynamic_param, PPM_BPF_IDX_MAX}} },
351351
[PPME_SYSCALL_SECCOMP_E] = {"seccomp", EC_OTHER | EC_SYSCALL, EF_NONE, 2, {{"op", PT_UINT64, PF_DEC}, {"flags", PT_UINT64, PF_HEX} } },
352352
[PPME_SYSCALL_SECCOMP_X] = {"seccomp", EC_OTHER | EC_SYSCALL, EF_NONE, 1, {{"res", PT_ERRNO, PF_DEC} } },
353353
[PPME_SYSCALL_UNLINK_2_E] = {"unlink", EC_FILE | EC_SYSCALL, EF_NONE, 0},
@@ -419,7 +419,7 @@ const struct ppm_event_info g_event_info[] = {
419419
[PPME_SYSCALL_DUP_1_E] = {"dup", EC_IO_OTHER | EC_SYSCALL, EF_CREATES_FD | EF_USES_FD | EF_MODIFIES_STATE, 1, {{"fd", PT_FD, PF_DEC} } },
420420
[PPME_SYSCALL_DUP_1_X] = {"dup", EC_IO_OTHER | EC_SYSCALL, EF_CREATES_FD | EF_USES_FD | EF_MODIFIES_STATE, 2, {{"res", PT_FD, PF_DEC}, {"oldfd", PT_FD, PF_DEC} } },
421421
[PPME_SYSCALL_BPF_2_E] = {"bpf", EC_OTHER | EC_SYSCALL, EF_CREATES_FD, 1, {{"cmd", PT_INT64, PF_DEC} } },
422-
[PPME_SYSCALL_BPF_2_X] = {"bpf", EC_OTHER | EC_SYSCALL, EF_CREATES_FD, 1, { {"fd", PT_FD, PF_DEC} } },
422+
[PPME_SYSCALL_BPF_2_X] = {"bpf", EC_OTHER | EC_SYSCALL, EF_CREATES_FD, 2, { {"fd", PT_FD, PF_DEC}, {"cmd",PT_INT64, PF_DEC} } },
423423
[PPME_SYSCALL_MLOCK2_E] = {"mlock2", EC_MEMORY | EC_SYSCALL, EF_NONE, 0},
424424
[PPME_SYSCALL_MLOCK2_X] = {"mlock2", EC_MEMORY | EC_SYSCALL, EF_NONE, 4, {{"res", PT_ERRNO, PF_DEC}, {"addr", PT_UINT64, PF_HEX}, {"len", PT_UINT64, PF_DEC}, {"flags", PT_UINT32, PF_HEX, mlock2_flags}}},
425425
[PPME_SYSCALL_FSCONFIG_E] = {"fsconfig", EC_SYSTEM | EC_SYSCALL, EF_NONE, 0},

Diff for: driver/modern_bpf/definitions/events_dimensions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
#define PIPE_E_SIZE HEADER_LEN
106106
#define PIPE_X_SIZE HEADER_LEN + sizeof(int64_t) * 3 + sizeof(uint64_t) + PARAM_LEN * 4
107107
#define BPF_E_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
108-
#define BPF_X_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
108+
#define BPF_X_SIZE HEADER_LEN + sizeof(int64_t) * 2 + PARAM_LEN * 2
109109
#define FLOCK_E_SIZE HEADER_LEN + sizeof(int64_t) + sizeof(uint32_t) + PARAM_LEN * 2
110110
#define FLOCK_X_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
111111
#define IOCTL_E_SIZE HEADER_LEN + sizeof(int64_t) + sizeof(uint64_t) * 2 + PARAM_LEN * 3

Diff for: driver/modern_bpf/programs/tail_called/events/syscall_dispatched_events/bpf.bpf.c

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ int BPF_PROG(bpf_x,
5858
/* Parameter 1: fd (type: PT_FD) */
5959
ringbuf__store_s64(&ringbuf, ret);
6060

61+
/* Parameter 2: cmd (type: PT_INT64) */
62+
int32_t cmd = (int32_t)extract__syscall_argument(regs, 0);
63+
ringbuf__store_s64(&ringbuf, (int64_t)cmd);
64+
65+
6166
/*=============================== COLLECT PARAMETERS ===========================*/
6267

6368
ringbuf__submit_event(&ringbuf);

Diff for: driver/ppm_fillers.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -6721,16 +6721,21 @@ int f_sys_bpf_e(struct event_filler_arguments *args)
67216721

67226722
int f_sys_bpf_x(struct event_filler_arguments *args)
67236723
{
6724-
int res;
6725-
int64_t fd;
6724+
int res = 0;
6725+
int64_t fd = 0;
6726+
unsigned long val = 0;
6727+
int32_t cmd = 0;
67266728

6727-
/*
6728-
* fd
6729-
*/
6729+
/* Parameter 1: fd (type: PT_DEC) */
67306730
fd = (int64_t)syscall_get_return_value(current, args->regs);
67316731
res = val_to_ring(args, fd, 0, false, 0);
67326732
CHECK_RES(res);
67336733

6734+
/* Parameter 2: cmd (type: PT_INT64) */
6735+
syscall_get_arguments_deprecated(args, 0, 1, &val);
6736+
cmd = (int32_t)val;
6737+
res = val_to_ring(args, (int64_t)cmd, 0, false, 0);
6738+
CHECK_RES(res);
67346739
return add_sentinel(args);
67356740
}
67366741

Diff for: test/drivers/test_suites/syscall_exit_suite/bpf_x.cpp

+85-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
#include <linux/sched.h>
66
#include <linux/bpf.h>
7+
#include <sys/mman.h>
78

8-
TEST(SyscallExit, bpfX)
9+
TEST(SyscallExit, bpfX_invalid_cmd)
910
{
1011
auto evt_test = get_syscall_event_test(__NR_bpf, EXIT_EVENT);
1112

@@ -72,8 +73,89 @@ TEST(SyscallExit, bpfX)
7273
/* Parameter 1: fd (type: PT_FD) */
7374
evt_test->assert_numeric_param(1, (int64_t)errno_value);
7475

76+
/* Parameter 2: cmd (type: PT_FD) */
77+
evt_test->assert_numeric_param(2, (int64_t)cmd);
78+
79+
/*=============================== ASSERT PARAMETERS ===========================*/
80+
81+
evt_test->assert_num_params_pushed(2);
82+
}
83+
84+
85+
TEST(SyscallExit, bpfX_MAP_CREATE)
86+
{
87+
auto evt_test = get_syscall_event_test(__NR_bpf, EXIT_EVENT);
88+
89+
evt_test->enable_capture();
90+
91+
/*=============================== TRIGGER SYSCALL ===========================*/
92+
93+
int32_t cmd = BPF_MAP_CREATE;
94+
union bpf_attr attr = {
95+
.map_type = BPF_MAP_TYPE_ARRAY,
96+
.key_size = sizeof(int),
97+
.value_size = sizeof(int),
98+
.max_entries = 1024
99+
};
100+
//
101+
int *ret = (int*) mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
102+
/* Here we need to call the `bpf` from a child because the main process throws lots of
103+
* `bpf` syscalls to manage the bpf drivers.
104+
*/
105+
struct clone_args cl_args = {0};
106+
cl_args.exit_signal = SIGCHLD;
107+
pid_t ret_pid = syscall(__NR_clone3, &cl_args, sizeof(cl_args));
108+
109+
if(ret_pid == 0)
110+
{
111+
/* When BPF_MAP_CREATE is used, the new file descriptor associated with the eBPF map is returned.*/
112+
113+
*ret = syscall(__NR_bpf, cmd, &attr, sizeof(attr));
114+
/* In this way in the father we know if the call was successful or not. */
115+
if(*ret != -1)
116+
{
117+
exit(EXIT_SUCCESS);
118+
}
119+
else
120+
{
121+
exit(EXIT_FAILURE);
122+
}
123+
}
124+
125+
assert_syscall_state(SYSCALL_SUCCESS, "clone3", ret_pid, NOT_EQUAL, -1);
126+
/* Catch the child before doing anything else. */
127+
int status = 0;
128+
int options = 0;
129+
assert_syscall_state(SYSCALL_SUCCESS, "wait4", syscall(__NR_wait4, ret_pid, &status, options, NULL), NOT_EQUAL, -1);
130+
int fd = *ret;
131+
if (munmap(ret, sizeof(ret) != -1)){
132+
//munmap returns -1 when failed
133+
FAIL() << "Shared memory failed to clear..."<<std::endl;
134+
};
135+
136+
/*=============================== TRIGGER SYSCALL ===========================*/
137+
138+
evt_test->disable_capture();
139+
140+
evt_test->assert_event_presence(ret_pid);
141+
142+
if(HasFatalFailure())
143+
{
144+
return;
145+
}
146+
147+
evt_test->parse_event();
148+
149+
evt_test->assert_header();
150+
151+
/*=============================== ASSERT PARAMETERS ===========================*/
152+
153+
/* Parameter 1: fd (type: PT_FD) */
154+
evt_test->assert_numeric_param(1, (int64_t)fd);
155+
evt_test->assert_numeric_param(2, (int64_t)cmd);
156+
75157
/*=============================== ASSERT PARAMETERS ===========================*/
76158

77-
evt_test->assert_num_params_pushed(1);
159+
evt_test->assert_num_params_pushed(2);
78160
}
79-
#endif
161+
#endif

0 commit comments

Comments
 (0)