The previous patch allows the networking bpf prog to use the bpf_skc_to_*() helpers to get a PTR_TO_BTF_ID socket pointer, e.g. "struct tcp_sock *". It allows the bpf prog to read all the fields of the tcp_sock. This patch changes the bpf_sk_release() and bpf_sk_*cgroup_id() to take ARG_PTR_TO_BTF_ID_SOCK_COMMON such that they will work with the pointer returned by the bpf_skc_to_*() helpers also. For example, the following will work: sk = bpf_skc_lookup_tcp(skb, tuple, tuplen, BPF_F_CURRENT_NETNS, 0); if (!sk) return; tp = bpf_skc_to_tcp_sock(sk); if (!tp) { bpf_sk_release(sk); return; } lsndtime = tp->lsndtime; /* Pass tp to bpf_sk_release() will also work */ bpf_sk_release(tp); Since PTR_TO_BTF_ID could be NULL, the helper taking ARG_PTR_TO_BTF_ID_SOCK_COMMON has to check for NULL at runtime. A btf_id of "struct sock" may not always mean a fullsock. Regardless the helper's running context may get a non-fullsock or not, considering fullsock check/handling is pretty cheap, it is better to keep the same verifier expectation on helper that takes ARG_PTR_TO_BTF_ID* will be able to handle the minisock situation. In the bpf_sk_*cgroup_id() case, it will try to get a fullsock by using sk_to_full_sk() as its skb variant bpf_sk"b"_*cgroup_id() has already been doing. bpf_sk_release can already handle minisock, so nothing special has to be done.
Showing the changes to include/uapi (1 of 3 files). Show all
Unified · Split
| @@ -2512,7 +2512,7 @@ union bpf_attr { · 2511 unmodified lines | ||
| 2512 | 2512 | * result is from *reuse*\ **->socks**\ [] using the hash of the |
| 2513 | 2513 | * tuple. |
| 2514 | 2514 | * |
| 2515 | − * long bpf_sk_release(struct bpf_sock *sock) | |
| 2515 | + * long bpf_sk_release(void *sock) | |
| 2516 | 2516 | * Description |
| 2517 | 2517 | * Release the reference held by *sock*. *sock* must be a |
| 2518 | 2518 | * non-**NULL** pointer that was returned from |
| @@ -3234,11 +3234,11 @@ union bpf_attr { · 715 unmodified lines | ||
| 3234 | 3234 | * |
| 3235 | 3235 | * **-EOVERFLOW** if an overflow happened: The same object will be tried again. |
| 3236 | 3236 | * |
| 3237 | − * u64 bpf_sk_cgroup_id(struct bpf_sock *sk) | |
| 3237 | + * u64 bpf_sk_cgroup_id(void *sk) | |
| 3238 | 3238 | * Description |
| 3239 | 3239 | * Return the cgroup v2 id of the socket *sk*. |
| 3240 | 3240 | * |
| 3241 | − * *sk* must be a non-**NULL** pointer to a full socket, e.g. one | |
| 3241 | + * *sk* must be a non-**NULL** pointer to a socket, e.g. one | |
| 3242 | 3242 | * returned from **bpf_sk_lookup_xxx**\ (), |
| 3243 | 3243 | * **bpf_sk_fullsock**\ (), etc. The format of returned id is |
| 3244 | 3244 | * same as in **bpf_skb_cgroup_id**\ (). |
| @@ -3248,7 +3248,7 @@ union bpf_attr { · 3 unmodified lines | ||
| 3248 | 3248 | * Return |
| 3249 | 3249 | * The id is returned or 0 in case the id could not be retrieved. |
| 3250 | 3250 | * |
| 3251 | − * u64 bpf_sk_ancestor_cgroup_id(struct bpf_sock *sk, int ancestor_level) | |
| 3251 | + * u64 bpf_sk_ancestor_cgroup_id(void *sk, int ancestor_level) | |
| 3252 | 3252 | * Description |
| 3253 | 3253 | * Return id of cgroup v2 that is ancestor of cgroup associated |
| 3254 | 3254 | * with the *sk* at the *ancestor_level*. The root cgroup is at |