History

bpf: Add support for forced LINK_DETACH command

Add LINK_DETACH command to force-detach bpf_link without destroying it. It has the same behavior as auto-detaching of bpf_link due to cgroup dying for bpf_cgroup_link or net_device being destroyed for bpf_xdp_link. In such case, bpf_link is still a valid kernel object, but is defuncts and doesn't hold BPF program attached to corresponding BPF hook. This functionality allows users with enough access rights to manually force-detach attached bpf_link without killing respective owner process. This patch implements LINK_DETACH for cgroup, xdp, and netns links, mostly re-using existing link release handling code.

Andrii Nakryiko committed 6 years ago

Commit 73b11c21 parent 4939b286 files · +64 −2Browse files

Showing the changes to include/uapi/linux (1 of 6 files). Show all

Unified · Split

include/uapi/linux/bpf.h+5−0
@@ -117,6 +117,7 @@ enum bpf_cmd { · 116 unmodified lines
117117 BPF_LINK_GET_NEXT_ID,
118118 BPF_ENABLE_STATS,
119119 BPF_ITER_CREATE,
120+ BPF_LINK_DETACH,
120121 };
121122
122123 enum bpf_map_type {
@@ -634,6 +635,10 @@ union bpf_attr { · 511 unmodified lines
634635 __u32 old_prog_fd;
635636 } link_update;
636637
638+ struct {
639+ __u32 link_fd;
640+ } link_detach;
641+
637642 struct { /* struct used by BPF_ENABLE_STATS command */
638643 __u32 type;
639644 } enable_stats;