Skip to content

Commit

Permalink
fix: agent - eBPF Mitigating Memory Profile Load Failures (#8961)
Browse files Browse the repository at this point in the history
In the 4.14 kernel, a memory profile loading failure can prevent the
entire eBPF program from functioning properly. This modification
eliminates such an impact.
  • Loading branch information
yinjiping authored Jan 17, 2025
1 parent 848574a commit b7ef92e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 13 additions & 2 deletions agent/src/ebpf/user/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,16 @@ static int load_obj__progs(struct ebpf_object *obj)
// Modify eBPF instructions based on BTF relocation information.
obj_relocate_core(new_prog);

int stderr_fd = suspend_stderr();
if (stderr_fd < 0) {
ebpf_warning("Failed to suspend stderr\n");
}
new_prog->prog_fd =
bcc_prog_load(new_prog->type, new_prog->name,
new_prog->insns, desc->size, obj->license,
obj->kern_version, 0, NULL,
0 /*EBPF_LOG_LEVEL, log_buf, LOG_BUF_SZ */ );

resume_stderr(stderr_fd);
if (new_prog->prog_fd < 0) {
ebpf_warning
("bcc_prog_load() failed. name: %s, %s errno: %d\n",
Expand All @@ -608,7 +612,14 @@ static int load_obj__progs(struct ebpf_object *obj)
new_prog->insns_cnt, BPF_MAXINSNS);
}

return ETR_INVAL;
if (memcmp(desc->name, "uprobe/", 7) &&
memcmp(desc->name, "uretprobe/", 10)) {
return ETR_INVAL;
} else {
ebpf_warning("The reason for the eBPF uprobe program "
"loading failure is that the linux version "
"needs to be 3.10 or 4.17+.\n");
}
}

ebpf_debug
Expand Down
9 changes: 7 additions & 2 deletions agent/src/ebpf/user/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,13 @@ extern uint32_t k_version;
// Lower version kernels do not support hooking so files in containers
bool kernel_version_check(void)
{
return ((k_version == KERNEL_VERSION(3, 10, 0))
|| (k_version >= KERNEL_VERSION(4, 17, 0)));
bool ret = ((k_version == KERNEL_VERSION(3, 10, 0))
|| (k_version >= KERNEL_VERSION(4, 17, 0)));
if (!ret)
ebpf_warning("UPROBE feature requires linux "
"version of 3.10 or 4.17+.\n");

return ret;
}

bool process_probing_check(int pid)
Expand Down

0 comments on commit b7ef92e

Please sign in to comment.