Skip to content

Commit

Permalink
libbpf-tools/bitesize.bpf.c: Fix potential out-of-bounds access in co…
Browse files Browse the repository at this point in the history
…mm_allowed function

fixes a potential out-of-bounds access in the comm_allowed function. Previously, the condition
in the for loop checked the value of targ_comm[i] before ensuring that i is less than TASK_COMM_LEN.
This could lead to out-of-bounds access if i equals TASK_COMM_LEN.

The condition in the for loop has been updated to check that i is less than TASK_COMM_LEN
before accessing targ_comm[i]. This ensures that targ_comm is not accessed out-of-bounds.
  • Loading branch information
chudihuang authored and yonghong-song committed Jun 16, 2024
1 parent d13cab9 commit d4e505c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libbpf-tools/bitesize.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static __always_inline bool comm_allowed(const char *comm)
{
int i;

for (i = 0; targ_comm[i] != '\0' && i < TASK_COMM_LEN; i++) {
for (i = 0; i < TASK_COMM_LEN && targ_comm[i] != '\0'; i++) {
if (comm[i] != targ_comm[i])
return false;
}
Expand Down

0 comments on commit d4e505c

Please sign in to comment.