Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup(driver): fix flags param #1469

Merged
merged 2 commits into from Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions driver/bpf/fillers.h
Expand Up @@ -6257,7 +6257,6 @@ FILLER(sys_dup3_x, true)
{
unsigned long val;
unsigned long retval;
unsigned long flags;
unsigned long res;

retval = bpf_syscall_get_retval(data->ctx);
Expand All @@ -6280,9 +6279,8 @@ 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);
int flags = bpf_syscall_get_argument(data, 2);
return bpf_push_u32_to_ring(data, dup3_flags_to_scap(flags));
}

FILLER(sys_umount_x, true)
Expand Down
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);
int32_t flags = extract__syscall_argument(regs, 2);
ringbuf__store_u32(&ringbuf, dup3_flags_to_scap(flags));

/*=============================== COLLECT PARAMETERS ===========================*/
Expand Down
3 changes: 1 addition & 2 deletions driver/ppm_fillers.c
Expand Up @@ -5696,7 +5696,6 @@ int f_sys_dup3_x(struct event_filler_arguments *args)
int res;
unsigned long val;


int64_t retval = (int64_t)syscall_get_return_value(current, args->regs);
res = val_to_ring(args, retval, 0, false, 0);
CHECK_RES(res);
Expand All @@ -5719,7 +5718,7 @@ 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);
res = val_to_ring(args, dup3_flags_to_scap((int) val), 0, false, 0);
CHECK_RES(res);

return add_sentinel(args);
Expand Down
2 changes: 1 addition & 1 deletion driver/ppm_flag_helpers.h
Expand Up @@ -2047,7 +2047,7 @@ static __always_inline uint64_t capabilities_to_scap(unsigned long caps)
return res;
}

static __always_inline uint32_t dup3_flags_to_scap(unsigned long flags)
static __always_inline uint32_t dup3_flags_to_scap(int flags)
{
uint32_t res = 0;
#ifdef O_CLOEXEC
Expand Down
2 changes: 1 addition & 1 deletion test/drivers/test_suites/syscall_enter_suite/dup3_e.cpp
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/parsers.cpp
Expand Up @@ -1472,7 +1472,7 @@ static parse_result parse_dup(const char *proto, size_t proto_size, scap_sized_b
gvisor_evt.exit().result(),
gvisor_evt.old_fd(),
gvisor_evt.new_fd(),
dup3_flags_to_scap(gvisor_evt.flags()));
dup3_flags_to_scap((int) gvisor_evt.flags()));
break;

default:
Expand Down