Skip to content

Commit

Permalink
chore(ebpf): remove path copy in get_path_str_buf
Browse files Browse the repository at this point in the history
The helper previously copied the path argument into a stack allocated
copy. This is an unnecessary copy, and risks copying the wrong size,
since the actual kernel specific size may differ from the compiler
allocated size.
Instead, use CORE_READ to access the necessary fields directly from the
argument.
  • Loading branch information
NDStrahilevitz committed Jun 9, 2024
1 parent 078a567 commit 32b2aab
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pkg/ebpf/c/common/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,10 @@ statfunc size_t get_path_str_buf(struct path *path, buf_t *out_buf)
return 0;
}

struct path f_path;
bpf_probe_read_kernel(&f_path, bpf_core_type_size(struct path), path);
char slash = '/';
int zero = 0;
struct dentry *dentry = f_path.dentry;
struct vfsmount *vfsmnt = f_path.mnt;
struct dentry *dentry = BPF_CORE_READ(path, dentry);
struct vfsmount *vfsmnt = BPF_CORE_READ(path, mnt);
struct mount *mnt_parent_p;
struct mount *mnt_p = real_mount(vfsmnt);
bpf_core_read(&mnt_parent_p, sizeof(struct mount *), &mnt_p->mnt_parent);
Expand Down

0 comments on commit 32b2aab

Please sign in to comment.