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.
Showing the changes to include/uapi/linux (1 of 6 files). Show all
Unified · Split
| @@ -117,6 +117,7 @@ enum bpf_cmd { · 116 unmodified lines | ||
| 117 | 117 | BPF_LINK_GET_NEXT_ID, |
| 118 | 118 | BPF_ENABLE_STATS, |
| 119 | 119 | BPF_ITER_CREATE, |
| 120 | + BPF_LINK_DETACH, | |
| 120 | 121 | }; |
| 121 | 122 | |
| 122 | 123 | enum bpf_map_type { |
| @@ -634,6 +635,10 @@ union bpf_attr { · 511 unmodified lines | ||
| 634 | 635 | __u32 old_prog_fd; |
| 635 | 636 | } link_update; |
| 636 | 637 | |
| 638 | + struct { | |
| 639 | + __u32 link_fd; | |
| 640 | + } link_detach; | |
| 641 | + | |
| 637 | 642 | struct { /* struct used by BPF_ENABLE_STATS command */ |
| 638 | 643 | __u32 type; |
| 639 | 644 | } enable_stats; |