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

[Backport 7.61.x] [CWS] fix inode i_ino offset on kernels >= 6.8 #32420

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
struct mount;

unsigned long __attribute__((always_inline)) get_inode_ino(struct inode *inode) {
u64 inode_ino_offset;
LOAD_CONSTANT("inode_ino_offset", inode_ino_offset);

unsigned long ino;
bpf_probe_read(&ino, sizeof(inode), &inode->i_ino);
bpf_probe_read(&ino, sizeof(inode), (void *)inode + inode_ino_offset);
return ino;
}

Expand Down
25 changes: 15 additions & 10 deletions pkg/security/ebpf/c/include/helpers/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,15 @@ void __attribute__((always_inline)) fill_file(struct dentry *dentry, struct file

file->dev = get_dentry_dev(dentry);

bpf_probe_read(&file->metadata.nlink, sizeof(file->metadata.nlink), (void *)&d_inode->i_nlink);
u64 inode_nlink_offset;
LOAD_CONSTANT("inode_nlink_offset", inode_nlink_offset);
u64 inode_gid_offset;
LOAD_CONSTANT("inode_gid_offset", inode_gid_offset);

bpf_probe_read(&file->metadata.nlink, sizeof(file->metadata.nlink), (void *)d_inode + inode_nlink_offset);
bpf_probe_read(&file->metadata.mode, sizeof(file->metadata.mode), &d_inode->i_mode);
bpf_probe_read(&file->metadata.uid, sizeof(file->metadata.uid), &d_inode->i_uid);
bpf_probe_read(&file->metadata.gid, sizeof(file->metadata.gid), &d_inode->i_gid);
bpf_probe_read(&file->metadata.gid, sizeof(file->metadata.gid), (void *)d_inode + inode_gid_offset);

u64 inode_ctime_sec_offset;
LOAD_CONSTANT("inode_ctime_sec_offset", inode_ctime_sec_offset);
Expand All @@ -118,10 +123,10 @@ void __attribute__((always_inline)) fill_file(struct dentry *dentry, struct file
bpf_probe_read(&nsec, sizeof(nsec), (void *)d_inode + inode_ctime_nsec_offset);
file->metadata.ctime.tv_nsec = nsec;
} else {
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0)
bpf_probe_read(&file->metadata.ctime, sizeof(file->metadata.ctime), &d_inode->i_ctime);
#elif LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
bpf_probe_read(&file->metadata.ctime, sizeof(file->metadata.ctime), &d_inode->__i_ctime);
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
u64 inode_ctime_offset;
LOAD_CONSTANT("inode_ctime_offset", inode_ctime_offset);
bpf_probe_read(&file->metadata.ctime, sizeof(file->metadata.ctime), (void *)d_inode + inode_ctime_offset);
#else
bpf_probe_read(&file->metadata.ctime.tv_sec, sizeof(file->metadata.ctime.tv_sec), &d_inode->i_ctime_sec);
bpf_probe_read(&file->metadata.ctime.tv_nsec, sizeof(file->metadata.ctime.tv_nsec), &d_inode->i_ctime_nsec);
Expand All @@ -139,10 +144,10 @@ void __attribute__((always_inline)) fill_file(struct dentry *dentry, struct file
bpf_probe_read(&nsec, sizeof(nsec), (void *)d_inode + inode_mtime_nsec_offset);
file->metadata.mtime.tv_nsec = nsec;
} else {
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0)
bpf_probe_read(&file->metadata.mtime, sizeof(file->metadata.mtime), &d_inode->i_mtime);
#elif LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
bpf_probe_read(&file->metadata.mtime, sizeof(file->metadata.mtime), &d_inode->__i_mtime);
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
u64 inode_mtime_offset;
LOAD_CONSTANT("inode_mtime_offset", inode_mtime_offset);
bpf_probe_read(&file->metadata.mtime, sizeof(file->metadata.mtime), (void *)d_inode + inode_mtime_offset);
#else
bpf_probe_read(&file->metadata.mtime.tv_sec, sizeof(file->metadata.mtime.tv_sec), &d_inode->i_mtime_sec);
bpf_probe_read(&file->metadata.mtime.tv_nsec, sizeof(file->metadata.mtime.tv_nsec), &d_inode->i_mtime_nsec);
Expand Down
2 changes: 2 additions & 0 deletions pkg/security/ebpf/kernel/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ var (
Kernel6_5 = kernel.VersionCode(6, 5, 0)
// Kernel6_6 is the KernelVersion representation of kernel version 6.6
Kernel6_6 = kernel.VersionCode(6, 6, 0)
// Kernel6_7 is the KernelVersion representation of kernel version 6.7
Kernel6_7 = kernel.VersionCode(6, 7, 0)
// Kernel6_10 is the KernelVersion representation of kernel version 6.10
Kernel6_10 = kernel.VersionCode(6, 10, 0)
// Kernel6_11 is the KernelVersion representation of kernel version 6.11
Expand Down
Loading
Loading