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(modern): clear some arrays before using them #1869

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion driver/modern_bpf/helpers/extract/extract_from_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static __always_inline void extract__network_args(void *argv, int num, struct pt
unsigned long *dst = (unsigned long *)argv;
for (int i = 0; i < num; i++)
{
dst[i] = args_u32[i];
dst[i] = (unsigned long)args_u32[i];
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion driver/modern_bpf/helpers/interfaces/syscalls_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static __always_inline long convert_network_syscalls(struct pt_regs *regs)
*
* ----- x86 with CONFIG_IA32_EMULATION
* - `SYS_ACCEPT` is defined but `__NR_accept` is not defined
* -> In this case we return a `__NR_accept4`
* -> In this case we return a `__NR_accept`
*
* - `SYS_SEND` is defined but `__NR_send` is not defined
* -> In this case we drop the event
Expand Down
11 changes: 10 additions & 1 deletion driver/modern_bpf/helpers/store/auxmap_store_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,11 @@ static __always_inline void auxmap__store_socktuple_param(struct auxiliary_map *
return;
}
struct sock *sk = BPF_CORE_READ(socket, sk);
if(sk == NULL)
{
auxmap__store_empty_param(auxmap);
return;
}
BPF_CORE_READ_INTO(&socket_family, sk, __sk_common.skc_family);

switch(socket_family)
Expand Down Expand Up @@ -1431,7 +1436,7 @@ static __always_inline void apply_dynamic_snaplen(struct pt_regs *regs, uint16_t
* - recvmsg
* - sendmsg
*/
unsigned long args[3];
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

/* All the syscalls involved in this logic have the `fd` as first syscall argument */
Expand All @@ -1448,6 +1453,10 @@ static __always_inline void apply_dynamic_snaplen(struct pt_regs *regs, uint16_t
return;
}
struct sock *sk = BPF_CORE_READ(socket, sk);
if(sk == NULL)
{
return;
}

uint16_t port_local = 0;
uint16_t port_remote = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int BPF_PROG(accept_x,
auxmap__store_socktuple_param(auxmap, (int32_t)ret, INBOUND, NULL);

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[1];
unsigned long args[1] = {0};
extract__network_args(args, 1, regs);
Andreagit97 marked this conversation as resolved.
Show resolved Hide resolved

/* Perform some computations to get queue information. */
Expand All @@ -91,11 +91,14 @@ int BPF_PROG(accept_x,
if(socket != NULL)
{
struct sock *sk = BPF_CORE_READ(socket, sk);
BPF_CORE_READ_INTO(&queuelen, sk, sk_ack_backlog);
BPF_CORE_READ_INTO(&queuemax, sk, sk_max_ack_backlog);
if(queuelen && queuemax)
if(sk != NULL)
{
queuepct = (uint8_t)((uint64_t)queuelen * 100 / queuemax);
BPF_CORE_READ_INTO(&queuelen, sk, sk_ack_backlog);
BPF_CORE_READ_INTO(&queuemax, sk, sk_max_ack_backlog);
if(queuelen && queuemax)
{
queuepct = (uint8_t)((uint64_t)queuelen * 100 / queuemax);
}
}
}
}
Expand Down
Molter73 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int BPF_PROG(accept4_x,
auxmap__store_socktuple_param(auxmap, (int32_t)ret, INBOUND, NULL);

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[1];
unsigned long args[1] = {0};
extract__network_args(args, 1, regs);

/* Perform some computations to get queue information. */
Expand All @@ -95,11 +95,14 @@ int BPF_PROG(accept4_x,
if(socket != NULL)
{
struct sock *sk = BPF_CORE_READ(socket, sk);
BPF_CORE_READ_INTO(&queuelen, sk, sk_ack_backlog);
BPF_CORE_READ_INTO(&queuemax, sk, sk_max_ack_backlog);
if(queuelen && queuemax)
if(sk != NULL)
{
queuepct = (uint8_t)((uint64_t)queuelen * 100 / queuemax);
BPF_CORE_READ_INTO(&queuelen, sk, sk_ack_backlog);
BPF_CORE_READ_INTO(&queuemax, sk, sk_max_ack_backlog);
if(queuelen && queuemax)
{
queuepct = (uint8_t)((uint64_t)queuelen * 100 / queuemax);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int BPF_PROG(bind_e,
long id)
{
/* Collect parameters at the beginning to easily manage socketcalls */
unsigned long args[1];
unsigned long args[1] = {0};
extract__network_args(args, 1, regs);

struct ringbuf_struct ringbuf;
Expand Down Expand Up @@ -65,7 +65,7 @@ int BPF_PROG(bind_x,

/*=============================== COLLECT PARAMETERS ===========================*/
/* Collect parameters at the beginning to easily manage socketcalls */
unsigned long args[3];
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

/* Parameter 1: res (type: PT_ERRNO) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int BPF_PROG(connect_e,

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

unsigned long args[3];
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

/* Parameter 1: fd (type: PT_FD)*/
Expand Down Expand Up @@ -65,7 +65,7 @@ int BPF_PROG(connect_x,

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

unsigned long args[1];
unsigned long args[1] = {0};
extract__network_args(args, 1, regs);

/* Parameter 1: res (type: PT_ERRNO) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int BPF_PROG(getsockopt_x,
/*=============================== COLLECT PARAMETERS ===========================*/

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[5];
unsigned long args[5] = {0};
extract__network_args(args, 5, regs);

/* Parameter 1: res (type: PT_ERRNO) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int BPF_PROG(listen_e,
long id)
{
/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[2];
unsigned long args[2] = {0};
extract__network_args(args, 2, regs);

struct ringbuf_struct ringbuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int BPF_PROG(recv_e,
long id)
{
/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[3];
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

struct ringbuf_struct ringbuf;
Expand Down Expand Up @@ -70,7 +70,7 @@ int BPF_PROG(recv_x,
if(ret > 0)
{
/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[2];
unsigned long args[2] = {0};
extract__network_args(args, 2, regs);

uint16_t snaplen = maps__get_snaplen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int BPF_PROG(recvfrom_e,
long id)
{
/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[3];
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

struct ringbuf_struct ringbuf;
Expand Down Expand Up @@ -84,7 +84,7 @@ int BPF_PROG(recvfrom_x,
}

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[5];
unsigned long args[5] = {0};
extract__network_args(args, 5, regs);

/* Parameter 2: data (type: PT_BYTEBUF) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int BPF_PROG(recvmsg_e,
long id)
{
/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[1];
unsigned long args[1] = {0};
extract__network_args(args, 1, regs);

struct ringbuf_struct ringbuf;
Expand Down Expand Up @@ -84,7 +84,7 @@ int BPF_PROG(recvmsg_x,
}

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[2];
unsigned long args[2] = {0};
extract__network_args(args, 2, regs);

/* Parameter 3: data (type: PT_BYTEBUF) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int BPF_PROG(send_e,
long id)
{
/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[3];
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

struct ringbuf_struct ringbuf;
Expand Down Expand Up @@ -68,7 +68,7 @@ int BPF_PROG(send_x,
auxmap__store_s64_param(auxmap, ret);

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[3];
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

int64_t bytes_to_read = ret > 0 ? ret : args[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int BPF_PROG(sendmsg_e,
/*=============================== COLLECT PARAMETERS ===========================*/

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[2];
unsigned long args[2] = {0};
extract__network_args(args, 2, regs);

/* Parameter 1: fd (type: PT_FD) */
Expand Down Expand Up @@ -87,7 +87,7 @@ int BPF_PROG(sendmsg_x,
auxmap__store_s64_param(auxmap, ret);

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[2];
unsigned long args[2] = {0};
extract__network_args(args, 2, regs);

/* In case of failure `bytes_to_read` could be also lower than `snaplen`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int BPF_PROG(sendto_e,
/*=============================== COLLECT PARAMETERS ===========================*/

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[5];
unsigned long args[5] = {0};
extract__network_args(args, 5, regs);

/* Parameter 1: fd (type: PT_FD) */
Expand Down Expand Up @@ -85,7 +85,7 @@ int BPF_PROG(sendto_x,
auxmap__store_s64_param(auxmap, ret);

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[5];
unsigned long args[5] = {0};
extract__network_args(args, 5, regs);

/* If the syscall doesn't fail we use the return value as `size`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int BPF_PROG(setsockopt_x,
/*=============================== COLLECT PARAMETERS ===========================*/

/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[5];
unsigned long args[5] = {0};
extract__network_args(args, 5, regs);

/* Parameter 1: res (type: PT_ERRNO) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int BPF_PROG(shutdown_e,
long id)
{
/* Collect parameters at the beginning to easily manage socketcalls */
unsigned long args[2];
unsigned long args[2] = {0};
extract__network_args(args, 2, regs);

struct ringbuf_struct ringbuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int BPF_PROG(socket_e,
long id)
{
/* Collect parameters at the beginning so we can easily manage socketcalls */
unsigned long args[3];
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

struct ringbuf_struct ringbuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int BPF_PROG(socketpair_e,
long id)
{
/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[3];
unsigned long args[3] = {0};
extract__network_args(args, 3, regs);

struct ringbuf_struct ringbuf;
Expand Down Expand Up @@ -82,7 +82,7 @@ int BPF_PROG(socketpair_x,
if(ret == 0)
{
/* Collect parameters at the beginning to manage socketcalls */
unsigned long args[4];
unsigned long args[4] = {0};
extract__network_args(args, 4, regs);

/* Get new sockets. */
Expand Down
Loading