Skip to content

Commit

Permalink
update(driver): address review requests
Browse files Browse the repository at this point in the history
Signed-off-by: rohith-raju <[email protected]>
  • Loading branch information
Rohith-Raju committed Jul 18, 2023
1 parent 42d6c18 commit ad70eac
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 34 deletions.
15 changes: 5 additions & 10 deletions driver/bpf/fillers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7053,25 +7053,20 @@ FILLER(sys_pidfd_getfd_x, true)

FILLER(sys_pidfd_open_x, true)
{
int retval;
unsigned long val;
unsigned long res;
unsigned long flags;

/* Parameter 1: ret (type: PT_FD) */
retval = bpf_syscall_get_retval(data->ctx);
res = bpf_push_s64_to_ring(data, retval);
long retval = bpf_syscall_get_retval(data->ctx);
int res = bpf_push_s64_to_ring(data, retval);
CHECK_RES(res);

/* Parameter 2: pid (type: PT_PID)*/
pid_t pid = (s32)bpf_syscall_get_argument(data, 0);
res = bpf_push_s64_to_ring(data, (s64)pid);
int res = bpf_push_s64_to_ring(data, (s64)pid);
CHECK_RES(res);

/* Parameter 3: flags (type: PT_FLAGS32)*/
val = bpf_syscall_get_argument(data, 1);
flags = pidfd_open_flags_to_scap(val);
return bpf_push_u32_to_ring(data, flags);
u32 flags = bpf_syscall_get_argument(data, 1);
return bpf_push_u32_to_ring(data, pidfd_open_flags_to_scap(flags));

}
#endif
2 changes: 1 addition & 1 deletion driver/modern_bpf/definitions/missing_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@
//////////////////////////
// pidfd_open flags
//////////////////////////
# define PIDFD_NONBLOCK 1U
# define PIDFD_NONBLOCK O_NONBLOCK

/*=============================== FLAGS ===========================*/

Expand Down
1 change: 0 additions & 1 deletion driver/ppm_events_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -2098,7 +2098,6 @@ extern const struct ppm_param_info sockopt_dynamic_param[];
extern const struct ppm_param_info ptrace_dynamic_param[];
extern const struct ppm_param_info bpf_dynamic_param[];


/*!
\brief Process information as returned by the PPM_IOCTL_GET_PROCLIST IOCTL.
*/
Expand Down
14 changes: 1 addition & 13 deletions driver/ppm_flag_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ or GPL2.txt for full copies of the license.
#include <linux/capability.h>
#include <linux/eventpoll.h>
#include <linux/prctl.h>
#if (LINUX_VERSION_CODE > KERNEL_VERSION(5, 10, 0))
#include <linux/pidfd.h>
#endif
#include "ppm.h"
#ifdef __NR_memfd_create
#include <uapi/linux/memfd.h>
Expand Down Expand Up @@ -2084,19 +2081,10 @@ static __always_inline uint32_t splice_flags_to_scap(uint32_t flags)
static __always_inline uint32_t pidfd_open_flags_to_scap(uint32_t flags)
{
uint32_t res = 0;
#ifdef PIDFD_NONBLOCK
if(flags & PIDFD_NONBLOCK) res |= PPM_PIDFD_NONBLOCK;
#endif

/*
PIDFD_NONBLOCK is available only on kernal versions > 5.10.00, hence used O_NONBLOCK
See https://elixir.bootlin.com/linux/v5.10.185/source/include/uapi/linux/pidfd.h#L10
*/

// See https://elixir.bootlin.com/linux/v5.10.185/source/include/uapi/linux/pidfd.h#L10
#ifdef O_NONBLOCK
if(flags & O_NONBLOCK) res |= PPM_PIDFD_NONBLOCK;
#endif

return res;
}

Expand Down
14 changes: 5 additions & 9 deletions test/drivers/test_suites/syscall_exit_suite/pidfd_open_x.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "../../event_class/event_class.h"

#include <unistd.h>
#include <linux/version.h>


#ifdef __NR_pidfd_open
Expand All @@ -20,7 +19,9 @@ TEST(SyscallExit, pidfd_openX_success)
*/

int flags = 0;
#if (LINUX_VERSION_CODE > KERNEL_VERSION(5, 10, 0))
#ifdef PIDFD_NONBLOCK
flags = PIDFD_NONBLOCK;
#else
flags = O_NONBLOCK;
#endif
pid_t pid = syscall(__NR_fork);
Expand Down Expand Up @@ -57,13 +58,8 @@ TEST(SyscallExit, pidfd_openX_success)
/* Parameter 1: pid (type: PT_PID)*/
evt_test->assert_numeric_param(2, (int64_t)pid);

#if (LINUX_VERSION_CODE > KERNEL_VERSION(5, 10, 0))
/* Parameter 3: flags (type: PT_FLAGS32) */
/* Parameter 3: flags (type: PT_FLAGS32) */
evt_test->assert_numeric_param(3, (uint32_t)PPM_PIDFD_NONBLOCK);
#endif
/* Parameter 3: flags (type: PT_FLAGS32) */
evt_test->assert_numeric_param(3, 0);

/*=============================== ASSERT PARAMETERS ===========================*/

}
Expand Down Expand Up @@ -102,7 +98,7 @@ TEST(SyscallExit, pidfd_openX_failure)
/* Parameter 1: ret (type: PT_FD)*/
evt_test->assert_numeric_param(1, (int64_t)errno_value);

/* Parameter 1: pid (type: PT_PID)*/
/* Parameter 2: pid (type: PT_PID)*/
evt_test->assert_numeric_param(2, (int64_t)pid);

/* Parameter 3: flags (type: PT_FLAGS32) */
Expand Down

0 comments on commit ad70eac

Please sign in to comment.