Skip to content

Commit 269bf4f

Browse files
ekoopspoiana
authored andcommitted
feat: extend PPME_SYSCALL_INOTIFY_INIT_X with enter parameters
Add `PPME_SYSCALL_INOTIFY_INIT_E` parameters to `PPME_SYSCALL_INOTIFY_INIT_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 inotify_init-related drivers, scap converter and sinsp parser tests to account the new layout. Signed-off-by: Leonardo Di Giovanna <[email protected]>
1 parent 04ca7f1 commit 269bf4f

File tree

19 files changed

+193
-17
lines changed

19 files changed

+193
-17
lines changed

driver/SCHEMA_VERSION

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

driver/bpf/fillers.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,6 +4011,17 @@ FILLER(sys_inotify_init_e, true) {
40114011
return bpf_push_u8_to_ring(data, 0);
40124012
}
40134013

4014+
FILLER(sys_inotify_init_x, true) {
4015+
/* Parameter 1: res (type: PT_FD) */
4016+
int64_t retval = (int64_t)(int32_t)bpf_syscall_get_retval(data->ctx);
4017+
int res = bpf_push_s64_to_ring(data, retval);
4018+
CHECK_RES(res);
4019+
4020+
/* Parameter 2: flags (type: PT_UINT8) */
4021+
/* Send `0` to unify handling with inotify_init1. */
4022+
return bpf_push_u8_to_ring(data, 0);
4023+
}
4024+
40144025
FILLER(sys_inotify_init1_x, true) {
40154026
/* Parameter 1: res (type: PT_ERRNO) */
40164027
long retval = bpf_syscall_get_retval(data->ctx);

driver/event_table.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -816,14 +816,16 @@ const struct ppm_event_info g_event_info[] = {
816816
{"flags", PT_UINT8, PF_HEX}}},
817817
[PPME_SYSCALL_INOTIFY_INIT_E] = {"inotify_init",
818818
EC_IPC | EC_SYSCALL,
819-
EF_CREATES_FD | EF_MODIFIES_STATE,
819+
EF_CREATES_FD | EF_MODIFIES_STATE |
820+
EF_TMP_CONVERTER_MANAGED,
820821
1,
821822
{{"flags", PT_UINT8, PF_HEX}}},
822823
[PPME_SYSCALL_INOTIFY_INIT_X] = {"inotify_init",
823824
EC_IPC | EC_SYSCALL,
824-
EF_CREATES_FD | EF_MODIFIES_STATE,
825-
1,
826-
{{"res", PT_FD, PF_DEC}}},
825+
EF_CREATES_FD | EF_MODIFIES_STATE |
826+
EF_TMP_CONVERTER_MANAGED,
827+
2,
828+
{{"res", PT_FD, PF_DEC}, {"flags", PT_UINT8, PF_HEX}}},
827829
[PPME_SYSCALL_GETRLIMIT_E] = {"getrlimit",
828830
EC_PROCESS | EC_SYSCALL,
829831
EF_TMP_CONVERTER_MANAGED,

driver/fillers_table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const struct ppm_event_entry g_ppm_events[PPM_EVENT_MAX] = {
146146
{{AF_ID_USEDEFAULT, 0}, {AF_ID_USEDEFAULT, 0}}},
147147
[PPME_SYSCALL_TIMERFD_CREATE_X] = {FILLER_REF(sys_timerfd_create_x)},
148148
[PPME_SYSCALL_INOTIFY_INIT_E] = {FILLER_REF(sys_inotify_init_e)},
149-
[PPME_SYSCALL_INOTIFY_INIT_X] = {FILLER_REF(sys_single_x)},
149+
[PPME_SYSCALL_INOTIFY_INIT_X] = {FILLER_REF(sys_inotify_init_x)},
150150
[PPME_SYSCALL_GETRLIMIT_E] = {FILLER_REF(sys_getrlimit_setrlimit_e)},
151151
[PPME_SYSCALL_GETRLIMIT_X] = {FILLER_REF(sys_getrlimit_x)},
152152
[PPME_SYSCALL_SETRLIMIT_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
@@ -93,7 +93,7 @@
9393
#define TIMERFD_CREATE_E_SIZE HEADER_LEN + sizeof(uint8_t) * 2 + PARAM_LEN * 2
9494
#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
96-
#define INOTIFY_INIT_X_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
96+
#define INOTIFY_INIT_X_SIZE HEADER_LEN + sizeof(int64_t) + sizeof(uint8_t) + PARAM_LEN * 2
9797
#define GETRLIMIT_E_SIZE HEADER_LEN + sizeof(uint8_t) + PARAM_LEN
9898
#define GETRLIMIT_X_SIZE HEADER_LEN + sizeof(int64_t) * 3 + sizeof(uint8_t) + PARAM_LEN * 4
9999
#define SETRLIMIT_E_SIZE HEADER_LEN + sizeof(uint8_t) + PARAM_LEN

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ int BPF_PROG(inotify_init_x, struct pt_regs *regs, long ret) {
5353
/* Parameter 1: res (type: PT_FD) */
5454
ringbuf__store_s64(&ringbuf, ret);
5555

56+
/* Parameter 2: flags (type: PT_UINT8) */
57+
/* Send `0` to unify handling with inotify_init1. */
58+
uint8_t flags = 0;
59+
ringbuf__store_u8(&ringbuf, flags);
60+
5661
/*=============================== COLLECT PARAMETERS ===========================*/
5762

5863
ringbuf__submit_event(&ringbuf);

driver/ppm_fillers.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6557,6 +6557,23 @@ int f_sys_inotify_init_e(struct event_filler_arguments *args) {
65576557
return add_sentinel(args);
65586558
}
65596559

6560+
int f_sys_inotify_init_x(struct event_filler_arguments *args) {
6561+
int64_t retval;
6562+
int res;
6563+
6564+
/* Parameter 1: res (type: PT_FD) */
6565+
retval = (int64_t)(int32_t)syscall_get_return_value(current, args->regs);
6566+
res = val_to_ring(args, retval, 0, false, 0);
6567+
CHECK_RES(res);
6568+
6569+
/* Parameter 2: flags (type: PT_UINT8) */
6570+
/* Send `0` to unify handling with inotify_init1. */
6571+
res = val_to_ring(args, 0, 0, true, 0);
6572+
CHECK_RES(res);
6573+
6574+
return add_sentinel(args);
6575+
}
6576+
65606577
int f_sys_inotify_init1_x(struct event_filler_arguments *args) {
65616578
int res = 0;
65626579
unsigned long val = 0;

driver/ppm_fillers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ or GPL2.txt for full copies of the license.
210210
FN(sys_pipe2_x) \
211211
FN(sys_timerfd_create_x) \
212212
FN(sys_inotify_init_e) \
213+
FN(sys_inotify_init_x) \
213214
FN(sys_inotify_init1_x) \
214215
FN(sys_eventfd2_e) \
215216
FN(sys_eventfd2_x) \

test/drivers/test_suites/syscall_exit_suite/inotify_init_x.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ TEST(SyscallExit, inotify_initX) {
3131
/* Parameter 1: fd (type: PT_FD) */
3232
evt_test->assert_numeric_param(1, (int64_t)fd);
3333

34+
/* Parameter 2: flags (type: PT_FLAGS8) */
35+
/* All drivers always send 0. */
36+
evt_test->assert_numeric_param(2, (uint8_t)0);
37+
3438
/*=============================== ASSERT PARAMETERS ===========================*/
3539

36-
evt_test->assert_num_params_pushed(1);
40+
evt_test->assert_num_params_pushed(2);
3741
}
3842
#endif

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,54 @@ TEST_F(convert_event_test, PPME_SYSCALL_TIMERFD_CREATE_X_1_to_3_params_with_ente
558558
flags));
559559
}
560560

561+
////////////////////////////
562+
// INOTIFY_INIT
563+
////////////////////////////
564+
565+
TEST_F(convert_event_test, PPME_SYSCALL_INOTIFY_INIT_E_store) {
566+
constexpr uint64_t ts = 12;
567+
constexpr int64_t tid = 25;
568+
569+
constexpr uint8_t flags = 20;
570+
571+
const auto evt = create_safe_scap_event(ts, tid, PPME_SYSCALL_INOTIFY_INIT_E, 2, flags);
572+
assert_single_conversion_skip(evt);
573+
assert_event_storage_presence(evt);
574+
}
575+
576+
TEST_F(convert_event_test, PPME_SYSCALL_INOTIFY_INIT_X_1_to_2_params_no_enter) {
577+
constexpr uint64_t ts = 12;
578+
constexpr int64_t tid = 25;
579+
580+
constexpr int64_t res = 89;
581+
582+
// Defaulted to 0
583+
constexpr uint8_t flags = 0;
584+
585+
assert_single_conversion_success(
586+
conversion_result::CONVERSION_COMPLETED,
587+
create_safe_scap_event(ts, tid, PPME_SYSCALL_INOTIFY_INIT_X, 1, res),
588+
create_safe_scap_event(ts, tid, PPME_SYSCALL_INOTIFY_INIT_X, 2, res, flags));
589+
}
590+
591+
TEST_F(convert_event_test, PPME_SYSCALL_INOTIFY_INIT_X_1_to_2_params_with_enter) {
592+
constexpr uint64_t ts = 12;
593+
constexpr int64_t tid = 25;
594+
595+
constexpr uint8_t flags = 20;
596+
constexpr int64_t res = 89;
597+
598+
// After the first conversion we should have the storage
599+
const auto evt = create_safe_scap_event(ts, tid, PPME_SYSCALL_INOTIFY_INIT_E, 2, flags);
600+
assert_single_conversion_skip(evt);
601+
assert_event_storage_presence(evt);
602+
603+
assert_single_conversion_success(
604+
conversion_result::CONVERSION_COMPLETED,
605+
create_safe_scap_event(ts, tid, PPME_SYSCALL_INOTIFY_INIT_X, 1, res),
606+
create_safe_scap_event(ts, tid, PPME_SYSCALL_INOTIFY_INIT_X, 2, res, flags));
607+
}
608+
561609
////////////////////////////
562610
// GETRLIMIT
563611
////////////////////////////

0 commit comments

Comments
 (0)