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

Temporary fix for [BUG] incorrect stdout/stdin name #46 #47

Merged
merged 4 commits into from
Jul 14, 2022
Merged
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
27 changes: 23 additions & 4 deletions plugin/driver/eBPF/kern/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
#include "bpf_core_read.h"
#include "bpf_endian.h"

#ifdef CORE
#define PIPEFS_MAGIC 0x50495045
#endif


// TODO: 后期改成动态的
/* R3 max value is outside of the array range */
// 这个地方非常非常的坑,都因为 bpf_verifier 机制, 之前 buf_off > MAX_PERCPU_BUFSIZE - sizeof(int) 本身都是成立的
Expand Down Expand Up @@ -144,7 +149,8 @@ static __always_inline void *get_path_str(struct path *path)
buf_t *string_p = get_buf(STRING_BUF_IDX);
if (string_p == NULL)
return NULL;
#pragma unroll

#pragma unroll
for (int i = 0; i < MAX_PATH_COMPONENTS; i++) {
mnt_root = READ_KERN(vfsmnt->mnt_root);
d_parent = READ_KERN(dentry->d_parent);
Expand Down Expand Up @@ -200,9 +206,21 @@ static __always_inline void *get_path_str(struct path *path)
// memfd files have no path in the filesystem -> extract their name
buf_off = 0;
d_name = READ_KERN(dentry->d_name);
bpf_probe_read_str(&(string_p->buf[0]), MAX_STRING_SIZE,
(void *)d_name.name);
// 2022-02-24 added. return "-1" if it's added
if (d_name.len > 0) {
bpf_probe_read_str(&(string_p->buf[0]), MAX_STRING_SIZE,
(void *)d_name.name);
goto out;
}
// Handle pipe with d_name.len = 0
struct super_block *d_sb = READ_KERN(dentry->d_sb);
if (d_sb != 0) {
unsigned long s_magic = READ_KERN(d_sb->s_magic);
if (s_magic == PIPEFS_MAGIC) {
// TODO: Get PIPE INODE NAME like pipe:[%lu], currently use pipe:[]
char pipe_prefix[] = "pipe:[]";
bpf_probe_read_str(&(string_p->buf[0]), MAX_STRING_SIZE, (void *)pipe_prefix);
}
}
} else {
// Add leading slash
buf_off -= 1;
Expand All @@ -213,6 +231,7 @@ static __always_inline void *get_path_str(struct path *path)
&zero);
}

out:
set_buf_off(STRING_BUF_IDX, buf_off);
return &string_p->buf[buf_off];
}
Expand Down