Skip to content

Commit 7dfa709

Browse files
committed
update: address review requests
Signed-off-by: rohith-raju <rohithraju488@gmail.com>
1 parent debf97a commit 7dfa709

9 files changed

Lines changed: 85 additions & 52 deletions

File tree

‎driver/SCHEMA_VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.12.4
1+
2.13.4

‎driver/bpf/fillers.h‎

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ FILLER(sys_access_e, true)
10311031
FILLER(sys_getrlimit_setrlimit_e, true)
10321032
{
10331033
/* Parameter 1: resource (type: PT_ENUMFLAGS8) */
1034-
unsigned long resource = bpf_syscall_get_argument(data, 0);
1034+
uint32_t resource = bpf_syscall_get_argument(data, 0);
10351035
return bpf_push_u8_to_ring(data, rlimit_resource_to_scap(resource));
10361036
}
10371037

@@ -1051,8 +1051,7 @@ FILLER(sys_getrlimit_x, true)
10511051
/*
10521052
* Copy the user structure and extract cur and max
10531053
*/
1054-
if(retval >= 0 || data->state->tail_ctx.evt_type == PPME_SYSCALL_SETRLIMIT_X)
1055-
{
1054+
if(retval >= 0){
10561055
struct rlimit rl;
10571056

10581057
val = bpf_syscall_get_argument(data, 1);
@@ -1061,22 +1060,21 @@ FILLER(sys_getrlimit_x, true)
10611060

10621061
cur = rl.rlim_cur;
10631062
max = rl.rlim_max;
1064-
}
1065-
else
1066-
{
1063+
1064+
} else {
10671065
cur = -1;
10681066
max = -1;
10691067
}
10701068

1071-
/* Parameter 2: cur (type: PT_ERRNO) */
1069+
/* Parameter 2: cur (type: PT_INT64) */
10721070
res = bpf_push_s64_to_ring(data, cur);
10731071
CHECK_RES(res);
10741072

10751073
/* Parameter 3: max (type: PT_ERRNO) */
10761074
return bpf_push_s64_to_ring(data, max);
10771075
}
10781076

1079-
FILLER(sys_setrlrimit_x, true)
1077+
FILLER(sys_setrlimit_x, true)
10801078
{
10811079
unsigned long val;
10821080
long retval;
@@ -1092,22 +1090,14 @@ FILLER(sys_setrlrimit_x, true)
10921090
/*
10931091
* Copy the user structure and extract cur and max
10941092
*/
1095-
if (retval >= 0 ||
1096-
data->state->tail_ctx.evt_type == PPME_SYSCALL_SETRLIMIT_X) {
1097-
struct rlimit rl;
1098-
1093+
struct rlimit rl = {0};
1094+
10991095
val = bpf_syscall_get_argument(data, 1);
1100-
if (bpf_probe_read_user(&rl, sizeof(rl), (void *)val))
1101-
return PPM_FAILURE_INVALID_USER_MEMORY;
1102-
1096+
bpf_probe_read_user(&rl, sizeof(rl), (void *)val);
11031097
cur = rl.rlim_cur;
11041098
max = rl.rlim_max;
1105-
} else {
1106-
cur = -1;
1107-
max = -1;
1108-
}
11091099

1110-
/* Parameter 2: cur (type: PT_ERRNO) */
1100+
/* Parameter 2: cur (type: PT_INT64) */
11111101
res = bpf_push_s64_to_ring(data, cur);
11121102
CHECK_RES(res);
11131103

@@ -1116,7 +1106,7 @@ FILLER(sys_setrlrimit_x, true)
11161106
CHECK_RES(res);
11171107

11181108
/* Parameter 4: resource (type: PT_ERRNO) */
1119-
unsigned long resource = bpf_syscall_get_argument(data, 0);
1109+
uint32_t resource = bpf_syscall_get_argument(data, 0);
11201110
return bpf_push_u8_to_ring(data, rlimit_resource_to_scap(resource));
11211111
}
11221112

@@ -3862,7 +3852,7 @@ FILLER(sys_prlimit_e, true)
38623852
CHECK_RES(res);
38633853

38643854
/* Parameter 2: resource (type: PT_ENUMFLAGS8) */
3865-
unsigned long resource = bpf_syscall_get_argument(data, 1);
3855+
uint32_t resource = bpf_syscall_get_argument(data, 1);
38663856
return bpf_push_u8_to_ring(data, rlimit_resource_to_scap(resource));
38673857
}
38683858

@@ -3930,7 +3920,7 @@ FILLER(sys_prlimit_x, true)
39303920
CHECK_RES(res);
39313921

39323922
/* Parameter 7: resource */
3933-
unsigned long resource = bpf_syscall_get_argument(data, 1);
3923+
uint32_t resource = bpf_syscall_get_argument(data, 1);
39343924
return bpf_push_u8_to_ring(data, rlimit_resource_to_scap(resource));
39353925
}
39363926

‎driver/fillers_table.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const struct ppm_event_entry g_ppm_events[PPM_EVENT_MAX] = {
147147
[PPME_SYSCALL_GETRLIMIT_E] = {FILLER_REF(sys_getrlimit_setrlimit_e)},
148148
[PPME_SYSCALL_GETRLIMIT_X] = {FILLER_REF(sys_getrlimit_x)},
149149
[PPME_SYSCALL_SETRLIMIT_E] = {FILLER_REF(sys_getrlimit_setrlimit_e)},
150-
[PPME_SYSCALL_SETRLIMIT_X] = {FILLER_REF(sys_setrlrimit_x)},
150+
[PPME_SYSCALL_SETRLIMIT_X] = {FILLER_REF(sys_setrlimit_x)},
151151
[PPME_SYSCALL_PRLIMIT_E] = {FILLER_REF(sys_prlimit_e)},
152152
[PPME_SYSCALL_PRLIMIT_X] = {FILLER_REF(sys_prlimit_x)},
153153
[PPME_DROP_E] = {FILLER_REF(sched_drop)},

‎driver/modern_bpf/programs/tail_called/events/syscall_dispatched_events/prlimit64.bpf.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int BPF_PROG(prlimit64_e,
3030
ringbuf__store_s64(&ringbuf, (int64_t)pid);
3131

3232
/* Parameter 2: resource (type: PT_ENUMFLAGS8) */
33-
unsigned long resource = extract__syscall_argument(regs, 1);
33+
uint32_t resource = extract__syscall_argument(regs, 1);
3434
ringbuf__store_u8(&ringbuf, rlimit_resource_to_scap(resource));
3535

3636
/*=============================== COLLECT PARAMETERS ===========================*/
@@ -93,7 +93,7 @@ int BPF_PROG(prlimit64_x,
9393
ringbuf__store_s64(&ringbuf, (s64)pid);
9494

9595
/* Parameter 7: resource (type: PT_ENUMFLAGS8) */
96-
unsigned long resource = extract__syscall_argument(regs, 1);
96+
uint32_t resource = extract__syscall_argument(regs, 1);
9797
ringbuf__store_u8(&ringbuf, rlimit_resource_to_scap(resource));
9898

9999
/*=============================== COLLECT PARAMETERS ===========================*/

‎driver/modern_bpf/programs/tail_called/events/syscall_dispatched_events/setrlimit.bpf.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int BPF_PROG(setrlimit_e,
2626
/*=============================== COLLECT PARAMETERS ===========================*/
2727

2828
/* Parameter 1: resource (type: PT_ENUMFLAGS8) */
29-
unsigned long resource = extract__syscall_argument(regs, 0);
29+
uint32_t resource = extract__syscall_argument(regs, 0);
3030
ringbuf__store_u8(&ringbuf, rlimit_resource_to_scap(resource));
3131

3232
/*=============================== COLLECT PARAMETERS ===========================*/
@@ -69,7 +69,7 @@ int BPF_PROG(setrlimit_x,
6969
ringbuf__store_s64(&ringbuf, rl.rlim_max);
7070

7171
/* Parameter 4: resource (type: PT_ENUMFLAGS8) */
72-
unsigned long resource = extract__syscall_argument(regs, 0);
72+
uint32_t resource = extract__syscall_argument(regs, 0);
7373
ringbuf__store_u8(&ringbuf, rlimit_resource_to_scap(resource));
7474

7575
/*=============================== COLLECT PARAMETERS ===========================*/

‎driver/ppm_fillers.c‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4073,7 +4073,7 @@ int f_sys_getrlimit_setrlimit_e(struct event_filler_arguments *args)
40734073
*/
40744074
syscall_get_arguments_deprecated(args, 0, 1, &val);
40754075

4076-
ppm_resource = rlimit_resource_to_scap(val);
4076+
ppm_resource = rlimit_resource_to_scap((uint32_t)val);
40774077

40784078
res = val_to_ring(args, (uint64_t)ppm_resource, 0, false, 0);
40794079
CHECK_RES(res);
@@ -4100,16 +4100,16 @@ int f_sys_getrlimit_x(struct event_filler_arguments *args) {
41004100
/*
41014101
* Copy the user structure and extract cur and max
41024102
*/
4103-
if(retval >= 0 || args->event_type == PPME_SYSCALL_SETRLIMIT_X)
4104-
{
4103+
if(retval >= 0) {
4104+
41054105
syscall_get_arguments_deprecated(args, 1, 1, &val);
41064106

41074107
#ifdef CONFIG_COMPAT
41084108
if(!args->compat)
41094109
{
41104110
#endif
41114111
if(unlikely(ppm_copy_from_user(&rl, (const void __user *)val, sizeof(struct rlimit))))
4112-
return PPM_FAILURE_INVALID_USER_MEMORY;
4112+
return PPM_FAILURE_INVALID_USER_MEMORY;
41134113
cur = rl.rlim_cur;
41144114
max = rl.rlim_max;
41154115
#ifdef CONFIG_COMPAT
@@ -4143,17 +4143,17 @@ int f_sys_getrlimit_x(struct event_filler_arguments *args) {
41434143

41444144

41454145

4146-
int f_sys_setrlrimit_x(struct event_filler_arguments *args)
4146+
int f_sys_setrlimit_x(struct event_filler_arguments *args)
41474147
{
41484148
unsigned long val;
41494149
int res;
41504150
int64_t retval;
4151-
struct rlimit rl;
41524151
#ifdef CONFIG_COMPAT
41534152
struct compat_rlimit compat_rl;
41544153
#endif
41554154
int64_t cur;
41564155
int64_t max;
4156+
struct rlimit rl = {0};
41574157

41584158
/* Parameter 1: res (type: PT_ERRNO) */
41594159
retval = (int64_t)(long)syscall_get_return_value(current, args->regs);
@@ -4163,14 +4163,12 @@ int f_sys_setrlrimit_x(struct event_filler_arguments *args)
41634163
/*
41644164
* Copy the user structure and extract cur and max
41654165
*/
4166-
if (retval >= 0 || args->event_type == PPME_SYSCALL_SETRLIMIT_X) {
41674166
syscall_get_arguments_deprecated(args, 1, 1, &val);
41684167

41694168
#ifdef CONFIG_COMPAT
41704169
if (!args->compat) {
41714170
#endif
4172-
if (unlikely(ppm_copy_from_user(&rl, (const void __user *)val, sizeof(struct rlimit))))
4173-
return PPM_FAILURE_INVALID_USER_MEMORY;
4171+
ppm_copy_from_user(&rl, (const void __user *)val, sizeof(struct rlimit));
41744172
cur = rl.rlim_cur;
41754173
max = rl.rlim_max;
41764174
#ifdef CONFIG_COMPAT
@@ -4181,12 +4179,8 @@ int f_sys_setrlrimit_x(struct event_filler_arguments *args)
41814179
max = compat_rl.rlim_max;
41824180
}
41834181
#endif
4184-
} else {
4185-
cur = -1;
4186-
max = -1;
4187-
}
41884182

4189-
/* Parameter 2: (type: PT_INT64) */
4183+
/* Parameter 2: curr (type: PT_INT64) */
41904184
res = val_to_ring(args, cur, 0, false, 0);
41914185
CHECK_RES(res);
41924186

@@ -4196,7 +4190,7 @@ int f_sys_setrlrimit_x(struct event_filler_arguments *args)
41964190

41974191
/* Parameter 4: resource (type: PT_ENUMFLAGS8) */
41984192
syscall_get_arguments_deprecated(args, 0, 1, &val);
4199-
res = val_to_ring(args, rlimit_resource_to_scap(val), 0, false, 0);
4193+
res = val_to_ring(args, rlimit_resource_to_scap((uint32_t)val), 0, false, 0);
42004194
CHECK_RES(res);
42014195

42024196
return add_sentinel(args);
@@ -4216,7 +4210,7 @@ int f_sys_prlimit_e(struct event_filler_arguments *args)
42164210

42174211
/* Parameter 2: resource (type: PT_ENUMFLAGS8) */
42184212
syscall_get_arguments_deprecated(args, 1, 1, &val);
4219-
res = val_to_ring(args, rlimit_resource_to_scap(val), 0, false, 0);
4213+
res = val_to_ring(args, rlimit_resource_to_scap((uint32_t)val), 0, false, 0);
42204214
CHECK_RES(res);
42214215

42224216
return add_sentinel(args);
@@ -4321,7 +4315,7 @@ int f_sys_prlimit_x(struct event_filler_arguments *args)
43214315

43224316
/* Parameter 7: resource (type: PT_ENUMFLAGS8) */
43234317
syscall_get_arguments_deprecated(args, 1, 1, &val);
4324-
res = val_to_ring(args, rlimit_resource_to_scap(val), 0, false, 0);
4318+
res = val_to_ring(args, rlimit_resource_to_scap((uint32_t)val), 0, false, 0);
43254319
CHECK_RES(res);
43264320

43274321
return add_sentinel(args);

‎driver/ppm_fillers.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ or GPL2.txt for full copies of the license.
6868
FN(sys_nanosleep_e) \
6969
FN(sys_getrlimit_setrlimit_e) \
7070
FN(sys_getrlimit_x) \
71-
FN(sys_setrlrimit_x) \
71+
FN(sys_setrlimit_x) \
7272
FN(sys_prlimit_e) \
7373
FN(sys_prlimit_x) \
7474
FN(sched_switch_e) \

‎driver/ppm_flag_helpers.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ static __always_inline uint32_t access_flags_to_scap(unsigned flags)
12931293
return res;
12941294
}
12951295

1296-
static __always_inline uint8_t rlimit_resource_to_scap(unsigned long rresource)
1296+
static __always_inline u8 rlimit_resource_to_scap(uint32_t rresource)
12971297
{
12981298
switch (rresource) {
12991299
case RLIMIT_CPU:

‎test/drivers/test_suites/syscall_exit_suite/setrlimit_x.cpp‎

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <sys/resource.h>
66

7-
TEST(SyscallExit, setrlimitX)
7+
TEST(SyscallExit, setrlimitX_failure)
88
{
99
auto evt_test = get_syscall_event_test(__NR_setrlimit, EXIT_EVENT);
1010

@@ -13,9 +13,7 @@ TEST(SyscallExit, setrlimitX)
1313
/*=============================== TRIGGER SYSCALL ===========================*/
1414

1515
int resource = -1;
16-
struct rlimit rlim;
17-
rlim.rlim_cur = 50;
18-
rlim.rlim_max = 10020;
16+
struct rlimit rlim = {0};
1917
assert_syscall_state(SYSCALL_FAILURE, "setrlimit", syscall(__NR_setrlimit, resource, &rlim));
2018
int64_t errno_value = -errno;
2119

@@ -52,4 +50,55 @@ TEST(SyscallExit, setrlimitX)
5250

5351
evt_test->assert_num_params_pushed(4);
5452
}
53+
54+
TEST(SyscallExit, setrlimitX_success)
55+
{
56+
auto evt_test = get_syscall_event_test(__NR_setrlimit, EXIT_EVENT);
57+
58+
evt_test->enable_capture();
59+
60+
/*=============================== TRIGGER SYSCALL ===========================*/
61+
62+
int resource = RLIMIT_MEMLOCK;
63+
struct rlimit rlim;
64+
rlim.rlim_cur = 50;
65+
rlim.rlim_max = 10020;
66+
67+
int ret = syscall(__NR_setrlimit, resource, &rlim);
68+
assert_syscall_state(SYSCALL_SUCCESS, "setrlimit", ret, NOT_EQUAL, -1);
69+
// On success, setrlimit return 0.
70+
71+
/*=============================== TRIGGER SYSCALL ===========================*/
72+
73+
evt_test->disable_capture();
74+
75+
evt_test->assert_event_presence();
76+
77+
if(HasFatalFailure())
78+
{
79+
return;
80+
}
81+
82+
evt_test->parse_event();
83+
84+
evt_test->assert_header();
85+
86+
/*=============================== ASSERT PARAMETERS ===========================*/
87+
88+
/* Parameter 1: res (type: PT_ERRNO) */
89+
evt_test->assert_numeric_param(1, (int64_t)ret);
90+
91+
/* Parameter 2: cur (type: PT_INT64) */
92+
evt_test->assert_numeric_param(2, (int64_t)rlim.rlim_cur);
93+
94+
/* Parameter 3: max (type: PT_INT64) */
95+
evt_test->assert_numeric_param(3, (int64_t)rlim.rlim_max);
96+
97+
/* Parameter 4: resource (type: PT_ENUMFLAGS8) */
98+
evt_test->assert_numeric_param(4, (uint8_t)resource);
99+
100+
/*=============================== ASSERT PARAMETERS ===========================*/
101+
102+
evt_test->assert_num_params_pushed(4);
103+
}
55104
#endif

0 commit comments

Comments
 (0)