Skip to content

Commit

Permalink
cleanup(dup3): fix flags param
Browse files Browse the repository at this point in the history
Signed-off-by: Everett Badeaux <[email protected]>
  • Loading branch information
ecbadeaux authored and Everett Badeaux committed Nov 20, 2023
1 parent 60e5b74 commit abc2dc4
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
9 changes: 5 additions & 4 deletions driver/bpf/fillers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6257,8 +6257,9 @@ FILLER(sys_dup3_x, true)
{
unsigned long val;
unsigned long retval;
unsigned long flags;
int flags;
unsigned long res;
unsigned int scap_flags;

retval = bpf_syscall_get_retval(data->ctx);
res = bpf_push_s64_to_ring(data, retval);
Expand All @@ -6280,9 +6281,9 @@ FILLER(sys_dup3_x, true)
/*
* flags
*/
val = bpf_syscall_get_argument(data, 2);
flags = dup3_flags_to_scap(val);
return bpf_push_u32_to_ring(data, flags);
flags = bpf_syscall_get_argument(data, 2);
scap_flags = dup3_flags_to_scap(flags);
return bpf_push_u32_to_ring(data, scap_flags);
}

FILLER(sys_umount_x, true)
Expand Down
2 changes: 1 addition & 1 deletion driver/modern_bpf/definitions/events_dimensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#define DUP2_E_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
#define DUP2_X_SIZE HEADER_LEN + sizeof(int64_t) * 3 + PARAM_LEN * 3
#define DUP3_E_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
#define DUP3_X_SIZE HEADER_LEN + sizeof(int64_t) * 3 + sizeof(uint32_t) + PARAM_LEN * 4
#define DUP3_X_SIZE HEADER_LEN + sizeof(int64_t) * 3 + sizeof(int32_t) + PARAM_LEN * 4
#define CHDIR_E_SIZE HEADER_LEN
#define CHMOD_E_SIZE HEADER_LEN
#define CHOWN_E_SIZE HEADER_LEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int BPF_PROG(dup3_x,
ringbuf__store_s64(&ringbuf, (int64_t)newfd);

/* Parameter 4: flags (type: PT_FLAGS32) */
unsigned long flags = extract__syscall_argument(regs, 2);
int flags = extract__syscall_argument(regs, 2);
ringbuf__store_u32(&ringbuf, dup3_flags_to_scap(flags));

/*=============================== COLLECT PARAMETERS ===========================*/
Expand Down
5 changes: 3 additions & 2 deletions driver/ppm_fillers.c
Original file line number Diff line number Diff line change
Expand Up @@ -5695,6 +5695,7 @@ int f_sys_dup3_x(struct event_filler_arguments *args)
{
int res;
unsigned long val;
int flags;


int64_t retval = (int64_t)syscall_get_return_value(current, args->regs);
Expand All @@ -5718,8 +5719,8 @@ int f_sys_dup3_x(struct event_filler_arguments *args)
/*
* flags
*/
syscall_get_arguments_deprecated(args, 2, 1, &val);
res = val_to_ring(args, dup3_flags_to_scap(val), 0, false, 0);
syscall_get_arguments_deprecated(args, 2, 1, &flags);
res = val_to_ring(args, dup3_flags_to_scap(flags), 0, false, 0);
CHECK_RES(res);

return add_sentinel(args);
Expand Down
2 changes: 1 addition & 1 deletion test/drivers/test_suites/syscall_enter_suite/dup3_e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST(SyscallEnter, dup3E)

/* If `oldfd` equals `newfd`, then dup3() fails with the error `EINVAL`. */
int32_t new_fd = old_fd;
uint32_t flags = O_CLOEXEC;
int32_t flags = O_CLOEXEC;
int32_t res = syscall(__NR_dup3, old_fd, new_fd, flags);
assert_syscall_state(SYSCALL_FAILURE, "dup3", res);

Expand Down
2 changes: 1 addition & 1 deletion userspace/libscap/engine/gvisor/fillers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ fill_event_dup3_x(scap_sized_buffer scap_buf, size_t* event_size, char* scap_err
int64_t res,
int64_t oldfd,
int64_t newfd,
uint32_t flags)
int32_t flags)
{
return scap_event_encode_params(
scap_buf, event_size, scap_err,
Expand Down
2 changes: 1 addition & 1 deletion userspace/libscap/engine/gvisor/fillers.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ fill_event_dup3_x(scap_sized_buffer scap_buf, size_t* event_size, char* scap_err
int64_t res,
int64_t oldfd,
int64_t newfd,
uint32_t flags);
int32_t flags);

int32_t
fill_event_signalfd_e(scap_sized_buffer scap_buf, size_t* event_size, char* scap_err,
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4960,7 +4960,7 @@ void sinsp_parser::parse_dup_exit(sinsp_evt *evt)
// If we are handling the dup3() event exit then we add the flags to the new file descriptor.
//
if (evt->get_type() == PPME_SYSCALL_DUP3_X){
uint32_t flags;
int32_t flags;

//
// Get the flags parameter.
Expand Down

0 comments on commit abc2dc4

Please sign in to comment.