Skip to content

Commit 04ca7f1

Browse files
ekoopspoiana
authored andcommitted
feat: extend PPME_SYSCALL_TIMERFD_CREATE_X with enter parameters
Add `PPME_SYSCALL_TIMERFD_CREATE_E` parameters to `PPME_SYSCALL_TIMERFD_CREATE_X` event definition and align all 3 kernel drivers to it. Add new rules to scap file converter table to convert events in old scap files to the new layout. Add/update timerfd_create-related drivers, scap converter and sinsp parser tests to account the new layout. Signed-off-by: Leonardo Di Giovanna <[email protected]>
1 parent 51c8323 commit 04ca7f1

File tree

19 files changed

+219
-16
lines changed

19 files changed

+219
-16
lines changed

driver/SCHEMA_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.56.0
1+
3.57.0

driver/bpf/fillers.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,6 +3987,22 @@ FILLER(sys_io_uring_register_x, true) {
39873987
return bpf_push_u32_to_ring(data, nr_args);
39883988
}
39893989

3990+
FILLER(sys_timerfd_create_x, true) {
3991+
/* Parameter 1: res (type: PT_FD) */
3992+
int64_t retval = (int64_t)(int32_t)bpf_syscall_get_retval(data->ctx);
3993+
int res = bpf_push_s64_to_ring(data, retval);
3994+
CHECK_RES(res);
3995+
3996+
/* Parameter 2: clockid (type: PT_UINT8) */
3997+
/* Send `0`. */
3998+
res = bpf_push_u8_to_ring(data, 0);
3999+
CHECK_RES(res);
4000+
4001+
/* Parameter 3: flags (type: PT_UINT8) */
4002+
/* Send `0`. */
4003+
return bpf_push_u8_to_ring(data, 0);
4004+
}
4005+
39904006
FILLER(sys_inotify_init_e, true) {
39914007
/* Parameter 1: flags (type: PT_UINT8) */
39924008
/* We have nothing to extract from the kernel here so we send `0`.

driver/event_table.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,15 +801,19 @@ const struct ppm_event_info g_event_info[] = {
801801
{"interval", PT_RELTIME, PF_DEC}}},
802802
[PPME_SYSCALL_TIMERFD_CREATE_E] = {"timerfd_create",
803803
EC_TIME | EC_SYSCALL,
804-
EF_CREATES_FD | EF_MODIFIES_STATE,
804+
EF_CREATES_FD | EF_MODIFIES_STATE |
805+
EF_TMP_CONVERTER_MANAGED,
805806
2,
806807
{{"clockid", PT_UINT8, PF_DEC},
807808
{"flags", PT_UINT8, PF_HEX}}},
808809
[PPME_SYSCALL_TIMERFD_CREATE_X] = {"timerfd_create",
809810
EC_TIME | EC_SYSCALL,
810-
EF_CREATES_FD | EF_MODIFIES_STATE,
811-
1,
812-
{{"res", PT_FD, PF_DEC}}},
811+
EF_CREATES_FD | EF_MODIFIES_STATE |
812+
EF_TMP_CONVERTER_MANAGED,
813+
3,
814+
{{"res", PT_FD, PF_DEC},
815+
{"clockid", PT_UINT8, PF_DEC},
816+
{"flags", PT_UINT8, PF_HEX}}},
813817
[PPME_SYSCALL_INOTIFY_INIT_E] = {"inotify_init",
814818
EC_IPC | EC_SYSCALL,
815819
EF_CREATES_FD | EF_MODIFIES_STATE,

driver/fillers_table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const struct ppm_event_entry g_ppm_events[PPM_EVENT_MAX] = {
144144
2,
145145
APT_REG,
146146
{{AF_ID_USEDEFAULT, 0}, {AF_ID_USEDEFAULT, 0}}},
147-
[PPME_SYSCALL_TIMERFD_CREATE_X] = {FILLER_REF(sys_single_x)},
147+
[PPME_SYSCALL_TIMERFD_CREATE_X] = {FILLER_REF(sys_timerfd_create_x)},
148148
[PPME_SYSCALL_INOTIFY_INIT_E] = {FILLER_REF(sys_inotify_init_e)},
149149
[PPME_SYSCALL_INOTIFY_INIT_X] = {FILLER_REF(sys_single_x)},
150150
[PPME_SYSCALL_GETRLIMIT_E] = {FILLER_REF(sys_getrlimit_setrlimit_e)},

driver/modern_bpf/definitions/events_dimensions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#define NANOSLEEP_E_SIZE HEADER_LEN + sizeof(uint64_t) + PARAM_LEN
9292
#define NANOSLEEP_X_SIZE HEADER_LEN + sizeof(int64_t) + sizeof(uint64_t) + PARAM_LEN * 2
9393
#define TIMERFD_CREATE_E_SIZE HEADER_LEN + sizeof(uint8_t) * 2 + PARAM_LEN * 2
94-
#define TIMERFD_CREATE_X_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
94+
#define TIMERFD_CREATE_X_SIZE HEADER_LEN + sizeof(int64_t) + sizeof(uint8_t) * 2 + PARAM_LEN * 3
9595
#define INOTIFY_INIT_E_SIZE HEADER_LEN + sizeof(uint8_t) + PARAM_LEN
9696
#define INOTIFY_INIT_X_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
9797
#define GETRLIMIT_E_SIZE HEADER_LEN + sizeof(uint8_t) + PARAM_LEN

driver/modern_bpf/programs/tail_called/events/syscall_dispatched_events/timerfd_create.bpf.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,17 @@ int BPF_PROG(timerfd_create_x, struct pt_regs *regs, long ret) {
5151

5252
/*=============================== COLLECT PARAMETERS ===========================*/
5353

54-
/* Parameter 1: res (type: PT_FD)*/
54+
/* Parameter 1: res (type: PT_FD) */
5555
ringbuf__store_s64(&ringbuf, ret);
5656

57+
/* Parameter 2: clockid (type: PT_UINT8) */
58+
/* Like in the old probe we send `0` */
59+
ringbuf__store_u8(&ringbuf, 0);
60+
61+
/* Parameter 3: flags (type: PT_UINT8) */
62+
/* Like in the old probe we send `0` */
63+
ringbuf__store_u8(&ringbuf, 0);
64+
5765
/*=============================== COLLECT PARAMETERS ===========================*/
5866

5967
ringbuf__submit_event(&ringbuf);

driver/ppm_fillers.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6524,6 +6524,28 @@ int f_sys_io_uring_register_x(struct event_filler_arguments *args) {
65246524
return add_sentinel(args);
65256525
}
65266526

6527+
int f_sys_timerfd_create_x(struct event_filler_arguments *args) {
6528+
int64_t retval;
6529+
int res;
6530+
6531+
/* Parameter 1: res (type: PT_FD) */
6532+
retval = (int64_t)(int32_t)syscall_get_return_value(current, args->regs);
6533+
res = val_to_ring(args, retval, 0, false, 0);
6534+
CHECK_RES(res);
6535+
6536+
/* Parameter 2: clockid (type: PT_UINT8) */
6537+
/* Send `0`. */
6538+
res = val_to_ring(args, 0, 0, false, 0);
6539+
CHECK_RES(res);
6540+
6541+
/* Parameter 3: flags (type: PT_UINT8) */
6542+
/* Send `0`. */
6543+
res = val_to_ring(args, 0, 0, false, 0);
6544+
CHECK_RES(res);
6545+
6546+
return add_sentinel(args);
6547+
}
6548+
65276549
int f_sys_inotify_init_e(struct event_filler_arguments *args) {
65286550
/* Parameter 1: flags (type: PT_UINT8) */
65296551
/* We have nothing to extract from the kernel here so we send `0`.

driver/ppm_fillers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ or GPL2.txt for full copies of the license.
208208
FN(sys_umount2_e) \
209209
FN(sys_umount2_x) \
210210
FN(sys_pipe2_x) \
211+
FN(sys_timerfd_create_x) \
211212
FN(sys_inotify_init_e) \
212213
FN(sys_inotify_init1_x) \
213214
FN(sys_eventfd2_e) \

test/drivers/test_suites/syscall_exit_suite/timerfd_create_x.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ TEST(SyscallExit, timerfd_createX) {
3535
/* Parameter 1: res (type: PT_FD) */
3636
evt_test->assert_numeric_param(1, (int64_t)errno_value);
3737

38+
/* Parameter 2: clockid (type: PT_UINT8) */
39+
// We always send 0 from drivers.
40+
evt_test->assert_numeric_param(2, (uint8_t)0);
41+
42+
/* Parameter 3: flags (type: PT_FLAGS8) */
43+
// We always send 0 from drivers.
44+
evt_test->assert_numeric_param(3, (uint8_t)0);
45+
3846
/*=============================== ASSERT PARAMETERS ===========================*/
3947

40-
evt_test->assert_num_params_pushed(1);
48+
evt_test->assert_num_params_pushed(3);
4149
}
4250
#endif

test/libscap/test_suites/engines/savefile/converter.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,71 @@ TEST_F(convert_event_test, PPME_SYSCALL_NANOSLEEP_X_1_to_2_params_with_enter) {
493493
create_safe_scap_event(ts, tid, PPME_SYSCALL_NANOSLEEP_X, 2, res, interval));
494494
}
495495

496+
////////////////////////////
497+
// TIMERFD_CREATE
498+
////////////////////////////
499+
500+
TEST_F(convert_event_test, PPME_SYSCALL_TIMERFD_CREATE_E_store) {
501+
constexpr uint64_t ts = 12;
502+
constexpr int64_t tid = 25;
503+
504+
constexpr uint8_t clock_id = 10;
505+
constexpr uint8_t flags = 20;
506+
507+
const auto evt =
508+
create_safe_scap_event(ts, tid, PPME_SYSCALL_TIMERFD_CREATE_E, 2, clock_id, flags);
509+
assert_single_conversion_skip(evt);
510+
assert_event_storage_presence(evt);
511+
}
512+
513+
TEST_F(convert_event_test, PPME_SYSCALL_TIMERFD_CREATE_X_1_to_3_params_no_enter) {
514+
constexpr uint64_t ts = 12;
515+
constexpr int64_t tid = 25;
516+
517+
constexpr int64_t res = 89;
518+
519+
// Defaulted to 0
520+
constexpr uint8_t clock_id = 0;
521+
constexpr uint8_t flags = 0;
522+
523+
assert_single_conversion_success(
524+
conversion_result::CONVERSION_COMPLETED,
525+
create_safe_scap_event(ts, tid, PPME_SYSCALL_TIMERFD_CREATE_X, 1, res),
526+
create_safe_scap_event(ts,
527+
tid,
528+
PPME_SYSCALL_TIMERFD_CREATE_X,
529+
3,
530+
res,
531+
clock_id,
532+
flags));
533+
}
534+
535+
TEST_F(convert_event_test, PPME_SYSCALL_TIMERFD_CREATE_X_1_to_3_params_with_enter) {
536+
constexpr uint64_t ts = 12;
537+
constexpr int64_t tid = 25;
538+
539+
constexpr uint8_t clock_id = 10;
540+
constexpr uint8_t flags = 20;
541+
constexpr int64_t res = 89;
542+
543+
// After the first conversion we should have the storage
544+
const auto evt =
545+
create_safe_scap_event(ts, tid, PPME_SYSCALL_TIMERFD_CREATE_E, 2, clock_id, flags);
546+
assert_single_conversion_skip(evt);
547+
assert_event_storage_presence(evt);
548+
549+
assert_single_conversion_success(
550+
conversion_result::CONVERSION_COMPLETED,
551+
create_safe_scap_event(ts, tid, PPME_SYSCALL_TIMERFD_CREATE_X, 1, res),
552+
create_safe_scap_event(ts,
553+
tid,
554+
PPME_SYSCALL_TIMERFD_CREATE_X,
555+
3,
556+
res,
557+
clock_id,
558+
flags));
559+
}
560+
496561
////////////////////////////
497562
// GETRLIMIT
498563
////////////////////////////

0 commit comments

Comments
 (0)