Skip to content

Commit a353da7

Browse files
author
Luca Marturana
committed
Implementation of setns decoding
1 parent 451414c commit a353da7

5 files changed

Lines changed: 42 additions & 3 deletions

File tree

driver/event_table.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,6 @@ const struct ppm_event_info g_event_info[PPM_EVENT_MAX] = {
262262
/* PPME_SYSCALL_GETDENTS_X */{"getdents", EC_FILE, EF_USES_FD, 1, {{"res", PT_ERRNO, PF_DEC} } },
263263
/* PPME_SYSCALL_GETDENTS64_E */{"getdents64", EC_FILE, EF_USES_FD, 1, {{"fd", PT_FD, PF_NA} } },
264264
/* PPME_SYSCALL_GETDENTS64_X */{"getdents64", EC_FILE, EF_USES_FD, 1, {{"res", PT_ERRNO, PF_DEC} } },
265+
/* PPME_SYSCALL_SETNS_E */ {"setns", EC_PROCESS, EF_USES_FD, 2, {{"fd", PT_FD, PF_NA}, {"nstype", PT_FLAGS32, PF_HEX, clone_flags}}},
266+
/* PPME_SYSCALL_SETNS_X */ {"setns", EC_PROCESS, EF_USES_FD, 1, {{"res", PT_ERRNO, PF_DEC}}},
265267
};

driver/ppm_events_public.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,9 @@ enum ppm_event_type {
642642
PPME_SYSCALL_GETDENTS_X = 237,
643643
PPME_SYSCALL_GETDENTS64_E = 238,
644644
PPME_SYSCALL_GETDENTS64_X = 239,
645-
PPM_EVENT_MAX = 240
645+
PPME_SYSCALL_SETNS_E = 240,
646+
PPME_SYSCALL_SETNS_X = 241,
647+
PPM_EVENT_MAX = 242
646648
};
647649
/*@}*/
648650

driver/ppm_fillers.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ static int f_sys_getresuid_and_gid_x(struct event_filler_arguments *args);
123123
#ifdef CAPTURE_SIGNAL_DELIVERIES
124124
static int f_sys_signaldeliver_e(struct event_filler_arguments *args);
125125
#endif
126+
static int f_sys_setns_e(struct event_filler_arguments *args);
126127

127128
/*
128129
* Note, this is not part of g_event_info because we want to share g_event_info with userland.
@@ -333,6 +334,8 @@ const struct ppm_event_entry g_ppm_events[PPM_EVENT_MAX] = {
333334
[PPME_SYSCALL_GETDENTS_X] = {f_sys_single_x},
334335
[PPME_SYSCALL_GETDENTS64_E] = {f_sys_single},
335336
[PPME_SYSCALL_GETDENTS64_X] = {f_sys_single_x},
337+
[PPME_SYSCALL_SETNS_E] = {f_sys_setns_e},
338+
[PPME_SYSCALL_SETNS_X] = {PPM_AUTOFILL, 1, APT_REG, {{AF_ID_RETVAL} } },
336339
};
337340

338341
/*
@@ -3177,9 +3180,7 @@ static int f_sched_switch_e(struct event_filler_arguments *args)
31773180
steal = cputime64_to_clock_t(kcpustat_this_cpu->cpustat[CPUTIME_STEAL]);
31783181
res = val_to_ring(args, steal, 0, false);
31793182
if(unlikely(res != PPM_SUCCESS))
3180-
{
31813183
return res;
3182-
}
31833184
#endif
31843185

31853186
return add_sentinel(args);
@@ -4303,6 +4304,32 @@ static int f_sys_getresuid_and_gid_x(struct event_filler_arguments *args)
43034304
return add_sentinel(args);
43044305
}
43054306

4307+
static int f_sys_setns_e(struct event_filler_arguments *args)
4308+
{
4309+
unsigned long val;
4310+
int res;
4311+
u32 flags;
4312+
4313+
/*
4314+
* parse fd
4315+
*/
4316+
syscall_get_arguments(current, args->regs, 0, 1, &val);
4317+
res = val_to_ring(args, val, 0, true, 0);
4318+
if (unlikely(res != PPM_SUCCESS))
4319+
return res;
4320+
4321+
/*
4322+
* get type, parse as clone flags as it's a subset of it
4323+
*/
4324+
syscall_get_arguments(current, args->regs, 1, 1, &val);
4325+
flags = clone_flags_to_scap(val);
4326+
res = val_to_ring(args, flags, 0, true, 0);
4327+
if (unlikely(res != PPM_SUCCESS))
4328+
return res;
4329+
4330+
return add_sentinel(args);
4331+
}
4332+
43064333
#ifdef CAPTURE_SIGNAL_DELIVERIES
43074334
static int f_sys_signaldeliver_e(struct event_filler_arguments *args)
43084335
{

driver/syscall_table.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ const struct syscall_evt_pair g_syscall_table[SYSCALL_TABLE_SIZE] = {
243243
#endif
244244
[__NR_getdents - SYSCALL_TABLE_ID0] = {UF_USED | UF_ALWAYS_DROP, PPME_SYSCALL_GETDENTS_E, PPME_SYSCALL_GETDENTS_X},
245245
[__NR_getdents64 - SYSCALL_TABLE_ID0] = {UF_USED | UF_ALWAYS_DROP, PPME_SYSCALL_GETDENTS64_E, PPME_SYSCALL_GETDENTS64_X},
246+
#ifdef __NR_setns
247+
[__NR_setns - SYSCALL_TABLE_ID0] = {UF_USED | UF_ALWAYS_DROP, PPME_SYSCALL_SETNS_E, PPME_SYSCALL_SETNS_X},
248+
#endif
246249
};
247250

248251
/*
@@ -775,4 +778,7 @@ const enum ppm_syscall_code g_syscall_code_routing_table[SYSCALL_TABLE_SIZE] = {
775778
#ifdef __NR_getresgid32
776779
[__NR_getresgid32 - SYSCALL_TABLE_ID0] = PPM_SC_GETRESGID32,
777780
#endif
781+
#ifdef __NR_setns
782+
[__NR_setns - SYSCALL_TABLE_ID0] = PPM_SC_SETNS,
783+
#endif
778784
};

userspace/libscap/event_table.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,6 @@ const struct ppm_event_info g_event_info[PPM_EVENT_MAX] = {
262262
/* PPME_SYSCALL_GETDENTS_X */{"getdents", EC_FILE, EF_USES_FD, 1, {{"res", PT_ERRNO, PF_DEC} } },
263263
/* PPME_SYSCALL_GETDENTS64_E */{"getdents64", EC_FILE, EF_USES_FD, 1, {{"fd", PT_FD, PF_NA} } },
264264
/* PPME_SYSCALL_GETDENTS64_X */{"getdents64", EC_FILE, EF_USES_FD, 1, {{"res", PT_ERRNO, PF_DEC} } },
265+
/* PPME_SYSCALL_SETNS_E */ {"setns", EC_PROCESS, EF_USES_FD, 2, {{"fd", PT_FD, PF_NA}, {"nstype", PT_FLAGS32, PF_HEX, clone_flags}}},
266+
/* PPME_SYSCALL_SETNS_X */ {"setns", EC_PROCESS, EF_USES_FD, 1, {{"res", PT_ERRNO, PF_DEC}}},
265267
};

0 commit comments

Comments
 (0)