|
60 | 60 | #define BPF_FS_MAGIC 0xcafe4a11
|
61 | 61 | #endif
|
62 | 62 |
|
| 63 | +#define MAX_EVENT_NAME_LEN 64 |
| 64 | + |
63 | 65 | #define BPF_FS_DEFAULT_PATH "/sys/fs/bpf"
|
64 | 66 |
|
65 | 67 | #define BPF_INSN_SZ (sizeof(struct bpf_insn))
|
@@ -11142,10 +11144,10 @@ static void gen_kprobe_legacy_event_name(char *buf, size_t buf_sz,
|
11142 | 11144 | static int index = 0;
|
11143 | 11145 | int i;
|
11144 | 11146 |
|
11145 |
| - snprintf(buf, buf_sz, "libbpf_%u_%s_0x%zx_%d", getpid(), kfunc_name, offset, |
11146 |
| - __sync_fetch_and_add(&index, 1)); |
| 11147 | + snprintf(buf, buf_sz, "libbpf_%u_%d_%s_0x%zx", getpid(), |
| 11148 | + __sync_fetch_and_add(&index, 1), kfunc_name, offset); |
11147 | 11149 |
|
11148 |
| - /* sanitize binary_path in the probe name */ |
| 11150 | + /* sanitize kfunc_name in the probe name */ |
11149 | 11151 | for (i = 0; buf[i]; i++) {
|
11150 | 11152 | if (!isalnum(buf[i]))
|
11151 | 11153 | buf[i] = '_';
|
@@ -11270,7 +11272,7 @@ int probe_kern_syscall_wrapper(int token_fd)
|
11270 | 11272 |
|
11271 | 11273 | return pfd >= 0 ? 1 : 0;
|
11272 | 11274 | } else { /* legacy mode */
|
11273 |
| - char probe_name[128]; |
| 11275 | + char probe_name[MAX_EVENT_NAME_LEN]; |
11274 | 11276 |
|
11275 | 11277 | gen_kprobe_legacy_event_name(probe_name, sizeof(probe_name), syscall_name, 0);
|
11276 | 11278 | if (add_kprobe_event_legacy(probe_name, false, syscall_name, 0) < 0)
|
@@ -11328,7 +11330,7 @@ bpf_program__attach_kprobe_opts(const struct bpf_program *prog,
|
11328 | 11330 | func_name, offset,
|
11329 | 11331 | -1 /* pid */, 0 /* ref_ctr_off */);
|
11330 | 11332 | } else {
|
11331 |
| - char probe_name[256]; |
| 11333 | + char probe_name[MAX_EVENT_NAME_LEN]; |
11332 | 11334 |
|
11333 | 11335 | gen_kprobe_legacy_event_name(probe_name, sizeof(probe_name),
|
11334 | 11336 | func_name, offset);
|
@@ -11878,9 +11880,12 @@ static int attach_uprobe_multi(const struct bpf_program *prog, long cookie, stru
|
11878 | 11880 | static void gen_uprobe_legacy_event_name(char *buf, size_t buf_sz,
|
11879 | 11881 | const char *binary_path, uint64_t offset)
|
11880 | 11882 | {
|
| 11883 | + static int index = 0; |
11881 | 11884 | int i;
|
11882 | 11885 |
|
11883 |
| - snprintf(buf, buf_sz, "libbpf_%u_%s_0x%zx", getpid(), binary_path, (size_t)offset); |
| 11886 | + snprintf(buf, buf_sz, "libbpf_%u_%d_%s_0x%zx", getpid(), |
| 11887 | + __sync_fetch_and_add(&index, 1), |
| 11888 | + basename((void *)binary_path), (size_t)offset); |
11884 | 11889 |
|
11885 | 11890 | /* sanitize binary_path in the probe name */
|
11886 | 11891 | for (i = 0; buf[i]; i++) {
|
@@ -12312,7 +12317,7 @@ bpf_program__attach_uprobe_opts(const struct bpf_program *prog, pid_t pid,
|
12312 | 12317 | pfd = perf_event_open_probe(true /* uprobe */, retprobe, binary_path,
|
12313 | 12318 | func_offset, pid, ref_ctr_off);
|
12314 | 12319 | } else {
|
12315 |
| - char probe_name[PATH_MAX + 64]; |
| 12320 | + char probe_name[MAX_EVENT_NAME_LEN]; |
12316 | 12321 |
|
12317 | 12322 | if (ref_ctr_off)
|
12318 | 12323 | return libbpf_err_ptr(-EINVAL);
|
|
0 commit comments