Commit e9b6f5c
committed
bpf: Add bpf_sock_destroy kfunc
JIRA: https://issues.redhat.com/browse/RHEL-65787
Conflicts: Context difference due to missing af9784d ("tcp: diag:
add support for TIME_WAIT sockets to tcp_abort()") and out-of-order
backport of bac76cf ("tcp: fix forever orphan socket caused by
tcp_abort")
commit 4ddbcb8
Author: Aditi Ghag <aditi.ghag@isovalent.com>
Date: Fri May 19 22:51:55 2023 +0000
bpf: Add bpf_sock_destroy kfunc
The socket destroy kfunc is used to forcefully terminate sockets from
certain BPF contexts. We plan to use the capability in Cilium
load-balancing to terminate client sockets that continue to connect to
deleted backends. The other use case is on-the-fly policy enforcement
where existing socket connections prevented by policies need to be
forcefully terminated. The kfunc also allows terminating sockets that may
or may not be actively sending traffic.
The kfunc can currently be called only from BPF TCP and UDP iterators
where users can filter, and terminate selected sockets. More
specifically, it can only be called from BPF contexts that ensure
socket locking in order to allow synchronous execution of protocol
specific `diag_destroy` handlers. The previous commit that batches UDP
sockets during iteration facilitated a synchronous invocation of the UDP
destroy callback from BPF context by skipping socket locks in
`udp_abort`. TCP iterator already supported batching of sockets being
iterated. To that end, `tracing_iter_filter` callback filter is added so
that verifier can restrict the kfunc to programs with `BPF_TRACE_ITER`
attach type, and reject other programs.
The kfunc takes `sock_common` type argument, even though it expects, and
casts them to a `sock` pointer. This enables the verifier to allow the
sock_destroy kfunc to be called for TCP with `sock_common` and UDP with
`sock` structs. Furthermore, as `sock_common` only has a subset of
certain fields of `sock`, casting pointer to the latter type might not
always be safe for certain sockets like request sockets, but these have a
special handling in the diag_destroy handlers.
Additionally, the kfunc is defined with `KF_TRUSTED_ARGS` flag to avoid the
cases where a `PTR_TO_BTF_ID` sk is obtained by following another pointer.
eg. getting a sk pointer (may be even NULL) by following another sk
pointer. The pointer socket argument passed in TCP and UDP iterators is
tagged as `PTR_TRUSTED` in {tcp,udp}_reg_info. The TRUSTED arg changes
are contributed by Martin KaFai Lau <martin.lau@kernel.org>.
Signed-off-by: Aditi Ghag <aditi.ghag@isovalent.com>
Link: https://lore.kernel.org/r/20230519225157.760788-8-aditi.ghag@isovalent.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>1 parent 692dba9 commit e9b6f5c
4 files changed
+75
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11891 | 11891 | | |
11892 | 11892 | | |
11893 | 11893 | | |
| 11894 | + | |
| 11895 | + | |
| 11896 | + | |
| 11897 | + | |
| 11898 | + | |
| 11899 | + | |
| 11900 | + | |
| 11901 | + | |
| 11902 | + | |
| 11903 | + | |
| 11904 | + | |
| 11905 | + | |
| 11906 | + | |
| 11907 | + | |
| 11908 | + | |
| 11909 | + | |
| 11910 | + | |
| 11911 | + | |
| 11912 | + | |
| 11913 | + | |
| 11914 | + | |
| 11915 | + | |
| 11916 | + | |
| 11917 | + | |
| 11918 | + | |
| 11919 | + | |
| 11920 | + | |
| 11921 | + | |
| 11922 | + | |
| 11923 | + | |
| 11924 | + | |
| 11925 | + | |
| 11926 | + | |
| 11927 | + | |
| 11928 | + | |
| 11929 | + | |
| 11930 | + | |
| 11931 | + | |
| 11932 | + | |
| 11933 | + | |
| 11934 | + | |
| 11935 | + | |
| 11936 | + | |
| 11937 | + | |
| 11938 | + | |
| 11939 | + | |
| 11940 | + | |
| 11941 | + | |
| 11942 | + | |
| 11943 | + | |
| 11944 | + | |
| 11945 | + | |
| 11946 | + | |
| 11947 | + | |
| 11948 | + | |
| 11949 | + | |
| 11950 | + | |
| 11951 | + | |
| 11952 | + | |
| 11953 | + | |
| 11954 | + | |
| 11955 | + | |
| 11956 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4716 | 4716 | | |
4717 | 4717 | | |
4718 | 4718 | | |
4719 | | - | |
4720 | | - | |
| 4719 | + | |
| 4720 | + | |
| 4721 | + | |
| 4722 | + | |
4721 | 4723 | | |
4722 | 4724 | | |
4723 | 4725 | | |
| |||
4745 | 4747 | | |
4746 | 4748 | | |
4747 | 4749 | | |
4748 | | - | |
| 4750 | + | |
| 4751 | + | |
4749 | 4752 | | |
4750 | 4753 | | |
4751 | 4754 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3302 | 3302 | | |
3303 | 3303 | | |
3304 | 3304 | | |
3305 | | - | |
| 3305 | + | |
3306 | 3306 | | |
3307 | 3307 | | |
3308 | 3308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2938 | 2938 | | |
2939 | 2939 | | |
2940 | 2940 | | |
2941 | | - | |
| 2941 | + | |
| 2942 | + | |
2942 | 2943 | | |
2943 | 2944 | | |
2944 | 2945 | | |
| |||
2951 | 2952 | | |
2952 | 2953 | | |
2953 | 2954 | | |
2954 | | - | |
| 2955 | + | |
| 2956 | + | |
2955 | 2957 | | |
2956 | 2958 | | |
2957 | 2959 | | |
| |||
3563 | 3565 | | |
3564 | 3566 | | |
3565 | 3567 | | |
3566 | | - | |
| 3568 | + | |
3567 | 3569 | | |
3568 | 3570 | | |
3569 | 3571 | | |
| |||
0 commit comments