Skip to content

Commit

Permalink
explain 'unnecessary' bounds checks, ensure minimum path length
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Nov 13, 2024
1 parent 79382be commit 51194af
Show file tree
Hide file tree
Showing 2 changed files with 9,714 additions and 9,880 deletions.
8 changes: 6 additions & 2 deletions internal/pkg/daemon/bpfrecorder/bpf/recorder.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ static __always_inline int register_file_event(struct file * file, u64 flags)
}

if (file->f_inode->i_mode & S_IFDIR) {
// overly pedantic check to make ebpf verifier happy
if (pathlen - 2 < sizeof(event->data) && pathlen - 1 < sizeof(event->data) && pathlen < sizeof(event->data)){
// more checks than necessary, but only checking each offset individually makes the ebpf verifier happy.
if (pathlen >= 2
&& pathlen - 2 < sizeof(event->data)
&& pathlen - 1 < sizeof(event->data)
&& pathlen < sizeof(event->data)
){
if(event->data[pathlen - 2] != '/') {
// No trailing slash, add `/` and move null byte.
event->data[pathlen - 1] = '/';
Expand Down
Loading

0 comments on commit 51194af

Please sign in to comment.