Skip to content

Commit 7a26c64

Browse files
Kui-Feng LeeKernel Patches Daemon
authored andcommitted
bpf: Create fentry/fexit/fmod_ret links through BPF_LINK_CREATE
Make fentry/fexit/fmod_ret as valid attach-types for BPF_LINK_CREATE. Pass a cookie along with BPF_LINK_CREATE requests. Signed-off-by: Kui-Feng Lee <[email protected]>
1 parent c55c4ab commit 7a26c64

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

include/uapi/linux/bpf.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,13 @@ union bpf_attr {
14901490
__aligned_u64 addrs;
14911491
__aligned_u64 cookies;
14921492
} kprobe_multi;
1493+
struct {
1494+
/* black box user-provided value passed through
1495+
* to BPF program at the execution time and
1496+
* accessible through bpf_get_attach_cookie() BPF helper
1497+
*/
1498+
__u64 cookie;
1499+
} tracing;
14931500
};
14941501
} link_create;
14951502

kernel/bpf/syscall.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,6 +3189,10 @@ attach_type_to_prog_type(enum bpf_attach_type attach_type)
31893189
return BPF_PROG_TYPE_SK_LOOKUP;
31903190
case BPF_XDP:
31913191
return BPF_PROG_TYPE_XDP;
3192+
case BPF_TRACE_FENTRY:
3193+
case BPF_TRACE_FEXIT:
3194+
case BPF_MODIFY_RETURN:
3195+
return BPF_PROG_TYPE_TRACING;
31923196
default:
31933197
return BPF_PROG_TYPE_UNSPEC;
31943198
}
@@ -4254,6 +4258,11 @@ static int tracing_bpf_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
42544258
attr->link_create.target_fd,
42554259
attr->link_create.target_btf_id,
42564260
0);
4261+
else if (prog->type == BPF_PROG_TYPE_TRACING)
4262+
return bpf_tracing_prog_attach(prog,
4263+
0,
4264+
0,
4265+
attr->link_create.tracing.cookie);
42574266

42584267
return -EINVAL;
42594268
}

tools/include/uapi/linux/bpf.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,13 @@ union bpf_attr {
14901490
__aligned_u64 addrs;
14911491
__aligned_u64 cookies;
14921492
} kprobe_multi;
1493+
struct {
1494+
/* black box user-provided value passed through
1495+
* to BPF program at the execution time and
1496+
* accessible through bpf_get_attach_cookie() BPF helper
1497+
*/
1498+
__u64 cookie;
1499+
} tracing;
14931500
};
14941501
} link_create;
14951502

0 commit comments

Comments
 (0)