Skip to content

Commit 88b53e4

Browse files
committed
new(driver): update exit events PPME_SYSCALL_SETRESGID_X with enter params
This update is part of the implementation for disabling support for syscall enter events. It implements the following steps: 1. Adds enter parameters to the exit event 2. Adapt sinsp state to work just with exit events. 3. Create a scap-file conversion (in a dedicated scap-file converter) to convert ENTER events into merged EXIT ones. 4. Add some tests replaying scap-files. for the setresgid syscall. Signed-off-by: Tero Kauppinen <tero.kauppinen@est.tech>
1 parent 25df968 commit 88b53e4

File tree

20 files changed

+265
-20
lines changed

20 files changed

+265
-20
lines changed

driver/SCHEMA_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.32.0
1+
3.33.0

driver/bpf/fillers.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,6 +3236,27 @@ FILLER(sys_setpgid_x, true) {
32363236
return bpf_push_s64_to_ring(data, (int64_t)pgid);
32373237
}
32383238

3239+
FILLER(sys_setresgid_x, true) {
3240+
/* Parameter 1: res (type: PT_ERRNO) */
3241+
long retval = bpf_syscall_get_retval(data->ctx);
3242+
int res = bpf_push_s64_to_ring(data, retval);
3243+
CHECK_RES(res);
3244+
3245+
/* Parameter 2: rgid (type: PT_GID) */
3246+
uint32_t rgid = (uint32_t)bpf_syscall_get_argument(data, 0);
3247+
res = bpf_push_u32_to_ring(data, rgid);
3248+
CHECK_RES(res);
3249+
3250+
/* Parameter 3: egid (type: PT_GID) */
3251+
uint32_t egid = (uint32_t)bpf_syscall_get_argument(data, 1);
3252+
res = bpf_push_u32_to_ring(data, egid);
3253+
CHECK_RES(res);
3254+
3255+
/* Parameter 4: sgid (type: PT_GID) */
3256+
uint32_t sgid = (uint32_t)bpf_syscall_get_argument(data, 2);
3257+
return bpf_push_u32_to_ring(data, sgid);
3258+
}
3259+
32393260
FILLER(sys_unshare_e, true) {
32403261
unsigned long val;
32413262
uint32_t flags;

driver/event_table.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,16 +1205,19 @@ const struct ppm_event_info g_event_info[] = {
12051205
{{"res", PT_ERRNO, PF_DEC}}},
12061206
[PPME_SYSCALL_SETRESGID_E] = {"setresgid",
12071207
EC_USER | EC_SYSCALL,
1208-
EF_MODIFIES_STATE,
1208+
EF_MODIFIES_STATE | EF_TMP_CONVERTER_MANAGED,
12091209
3,
12101210
{{"rgid", PT_GID, PF_DEC},
12111211
{"egid", PT_GID, PF_DEC},
12121212
{"sgid", PT_GID, PF_DEC}}},
12131213
[PPME_SYSCALL_SETRESGID_X] = {"setresgid",
12141214
EC_USER | EC_SYSCALL,
1215-
EF_MODIFIES_STATE,
1216-
1,
1217-
{{"res", PT_ERRNO, PF_DEC}}},
1215+
EF_MODIFIES_STATE | EF_TMP_CONVERTER_MANAGED,
1216+
4,
1217+
{{"res", PT_ERRNO, PF_DEC},
1218+
{"rgid", PT_GID, PF_DEC},
1219+
{"egid", PT_GID, PF_DEC},
1220+
{"sgid", PT_GID, PF_DEC}}},
12181221
[PPME_SCAPEVENT_E] = {"scapevent",
12191222
EC_INTERNAL | EC_METAEVENT,
12201223
EF_SKIPPARSERESET,

driver/fillers_table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ const struct ppm_event_entry g_ppm_events[PPM_EVENT_MAX] = {
195195
[PPME_SYSCALL_SETRESUID_E] = {FILLER_REF(sys_autofill), 3, APT_REG, {{0}, {1}, {2}}},
196196
[PPME_SYSCALL_SETRESUID_X] = {FILLER_REF(sys_autofill), 1, APT_REG, {{AF_ID_RETVAL}}},
197197
[PPME_SYSCALL_SETRESGID_E] = {FILLER_REF(sys_autofill), 3, APT_REG, {{0}, {1}, {2}}},
198-
[PPME_SYSCALL_SETRESGID_X] = {FILLER_REF(sys_autofill), 1, APT_REG, {{AF_ID_RETVAL}}},
198+
[PPME_SYSCALL_SETRESGID_X] = {FILLER_REF(sys_setresgid_x)},
199199
[PPME_SCAPEVENT_E] = {FILLER_REF(sys_scapevent_e)},
200200
[PPME_SYSCALL_SETUID_E] = {FILLER_REF(sys_autofill), 1, APT_REG, {{0}}},
201201
[PPME_SYSCALL_SETUID_X] = {FILLER_REF(sys_setuid_x)},

driver/modern_bpf/definitions/events_dimensions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
#define SETRESUID_E_SIZE HEADER_LEN + sizeof(uint32_t) * 3 + PARAM_LEN * 3
130130
#define SETRESUID_X_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
131131
#define SETRESGID_E_SIZE HEADER_LEN + sizeof(uint32_t) * 3 + PARAM_LEN * 3
132-
#define SETRESGID_X_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
132+
#define SETRESGID_X_SIZE HEADER_LEN + sizeof(int64_t) + sizeof(uint32_t) * 3 + PARAM_LEN * 4
133133
#define SCAPEVENT_E_SIZE HEADER_LEN + sizeof(uint32_t) + sizeof(uint64_t) + PARAM_LEN * 2
134134
#define SCAPEVENT_X_SIZE HEADER_LEN
135135
#define SETUID_E_SIZE HEADER_LEN + sizeof(uint32_t) + PARAM_LEN

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ int BPF_PROG(setresgid_x, struct pt_regs *regs, long ret) {
5858
/* Parameter 1: res (type: PT_ERRNO)*/
5959
ringbuf__store_s64(&ringbuf, ret);
6060

61+
/* Parameter 2: rgid (type: PT_GID) */
62+
gid_t rgid = (uint32_t)extract__syscall_argument(regs, 0);
63+
ringbuf__store_u32(&ringbuf, rgid);
64+
65+
/* Parameter 3: egid (type: PT_GID) */
66+
gid_t egid = (uint32_t)extract__syscall_argument(regs, 1);
67+
ringbuf__store_u32(&ringbuf, egid);
68+
69+
/* Parameter 4: sgid (type: PT_GID) */
70+
gid_t sgid = (uint32_t)extract__syscall_argument(regs, 2);
71+
ringbuf__store_u32(&ringbuf, sgid);
72+
6173
/*=============================== COLLECT PARAMETERS ===========================*/
6274

6375
ringbuf__submit_event(&ringbuf);

driver/ppm_fillers.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7507,6 +7507,37 @@ int f_sys_setpgid_x(struct event_filler_arguments *args) {
75077507
return add_sentinel(args);
75087508
}
75097509

7510+
int f_sys_setresgid_x(struct event_filler_arguments *args) {
7511+
unsigned long val = 0;
7512+
int res = 0;
7513+
uint32_t gid = 0;
7514+
7515+
/* Parameter 1: res (type: PT_ERRNO) */
7516+
int64_t retval = (int64_t)syscall_get_return_value(current, args->regs);
7517+
res = val_to_ring(args, retval, 0, false, 0);
7518+
CHECK_RES(res);
7519+
7520+
/* Parameter 2: rgid (type: PT_GID) */
7521+
syscall_get_arguments_deprecated(args, 0, 1, &val);
7522+
gid = (uint32_t)val;
7523+
res = val_to_ring(args, gid, 0, true, 0);
7524+
CHECK_RES(res);
7525+
7526+
/* Parameter 3: egid (type: PT_GID) */
7527+
syscall_get_arguments_deprecated(args, 1, 1, &val);
7528+
gid = (uint32_t)val;
7529+
res = val_to_ring(args, gid, 0, true, 0);
7530+
CHECK_RES(res);
7531+
7532+
/* Parameter 4: sgid (type: PT_GID) */
7533+
syscall_get_arguments_deprecated(args, 2, 1, &val);
7534+
gid = (uint32_t)val;
7535+
res = val_to_ring(args, gid, 0, true, 0);
7536+
CHECK_RES(res);
7537+
7538+
return add_sentinel(args);
7539+
}
7540+
75107541
int f_sys_unshare_e(struct event_filler_arguments *args) {
75117542
unsigned long val;
75127543
int res;

driver/ppm_fillers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ or GPL2.txt for full copies of the license.
184184
FN(sys_setgid_x) \
185185
FN(sys_setpgid_e) \
186186
FN(sys_setpgid_x) \
187+
FN(sys_setresgid_x) \
187188
FN(sys_recvfrom_e) \
188189
FN(sys_recvmsg_e) \
189190
FN(sys_listen_e) \

test/drivers/test_suites/syscall_exit_suite/setresgid_x.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,17 @@ TEST(SyscallExit, setresgidX) {
3737
/* Parameter 1: res (type: PT_ERRNO) */
3838
evt_test->assert_numeric_param(1, (int64_t)0);
3939

40+
/* Parameter 2: rgid (type: PT_GID) */
41+
evt_test->assert_numeric_param(2, (uint32_t)rgid);
42+
43+
/* Parameter 3: egid (type: PT_GID) */
44+
evt_test->assert_numeric_param(3, (uint32_t)egid);
45+
46+
/* Parameter 4: sgid (type: PT_GID) */
47+
evt_test->assert_numeric_param(4, (uint32_t)sgid);
48+
4049
/*=============================== ASSERT PARAMETERS ===========================*/
4150

42-
evt_test->assert_num_params_pushed(1);
51+
evt_test->assert_num_params_pushed(4);
4352
}
4453
#endif

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,3 +2433,57 @@ TEST_F(convert_event_test, PPME_SYSCALL_SETGID_X_to_3_params_with_enter) {
24332433
create_safe_scap_event(ts, tid, PPME_SYSCALL_SETGID_X, 1, res),
24342434
create_safe_scap_event(ts, tid, PPME_SYSCALL_SETGID_X, 2, res, gid));
24352435
}
2436+
2437+
////////////////////////////
2438+
// SETRESGID
2439+
////////////////////////////
2440+
2441+
TEST_F(convert_event_test, PPME_SYSCALL_SETRESGID_E_store) {
2442+
uint64_t ts = 12;
2443+
int64_t tid = 25;
2444+
2445+
uint32_t rgid = 66;
2446+
uint32_t egid = 77;
2447+
uint32_t sgid = 88;
2448+
2449+
auto evt = create_safe_scap_event(ts, tid, PPME_SYSCALL_SETRESGID_E, 3, rgid, egid, sgid);
2450+
assert_single_conversion_skip(evt);
2451+
assert_event_storage_presence(evt);
2452+
}
2453+
2454+
TEST_F(convert_event_test, PPME_SYSCALL_SETRESGID_X_to_4_params_no_enter) {
2455+
uint64_t ts = 12;
2456+
int64_t tid = 25;
2457+
2458+
int64_t res = 89;
2459+
2460+
// Defaulted to 0
2461+
uint32_t rgid = 0;
2462+
uint32_t egid = 0;
2463+
uint32_t sgid = 0;
2464+
2465+
assert_single_conversion_success(
2466+
conversion_result::CONVERSION_COMPLETED,
2467+
create_safe_scap_event(ts, tid, PPME_SYSCALL_SETRESGID_X, 1, res),
2468+
create_safe_scap_event(ts, tid, PPME_SYSCALL_SETRESGID_X, 4, res, rgid, egid, sgid));
2469+
}
2470+
2471+
TEST_F(convert_event_test, PPME_SYSCALL_SETRESGID_X_to_4_params_with_enter) {
2472+
uint64_t ts = 12;
2473+
int64_t tid = 25;
2474+
2475+
int64_t res = 89;
2476+
uint32_t rgid = 66;
2477+
uint32_t egid = 77;
2478+
uint32_t sgid = 88;
2479+
2480+
// After the first conversion we should have the storage
2481+
auto evt = create_safe_scap_event(ts, tid, PPME_SYSCALL_SETRESGID_E, 3, rgid, egid, sgid);
2482+
assert_single_conversion_skip(evt);
2483+
assert_event_storage_presence(evt);
2484+
2485+
assert_single_conversion_success(
2486+
conversion_result::CONVERSION_COMPLETED,
2487+
create_safe_scap_event(ts, tid, PPME_SYSCALL_SETRESGID_X, 1, res),
2488+
create_safe_scap_event(ts, tid, PPME_SYSCALL_SETRESGID_X, 4, res, rgid, egid, sgid));
2489+
}

0 commit comments

Comments
 (0)