Repository navigation
Commit a5fa25a
bpf: Change bpf_sk_release and bpf_sk_*cgroup_id to accept ARG_PTR_TO_BTF_ID_SOCK_COMMON
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.
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200925000356.3856047-1-kafai@fb.com1 parent 1df8f55 commit a5fa25a
3 files changed
Lines changed: 22 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2512 | 2512 | | |
2513 | 2513 | | |
2514 | 2514 | | |
2515 | | - | |
| 2515 | + | |
2516 | 2516 | | |
2517 | 2517 | | |
2518 | 2518 | | |
| |||
3234 | 3234 | | |
3235 | 3235 | | |
3236 | 3236 | | |
3237 | | - | |
| 3237 | + | |
3238 | 3238 | | |
3239 | 3239 | | |
3240 | 3240 | | |
3241 | | - | |
| 3241 | + | |
3242 | 3242 | | |
3243 | 3243 | | |
3244 | 3244 | | |
| |||
3248 | 3248 | | |
3249 | 3249 | | |
3250 | 3250 | | |
3251 | | - | |
| 3251 | + | |
3252 | 3252 | | |
3253 | 3253 | | |
3254 | 3254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4088 | 4088 | | |
4089 | 4089 | | |
4090 | 4090 | | |
| 4091 | + | |
| 4092 | + | |
| 4093 | + | |
| 4094 | + | |
4091 | 4095 | | |
4092 | 4096 | | |
4093 | 4097 | | |
4094 | 4098 | | |
4095 | 4099 | | |
4096 | 4100 | | |
4097 | | - | |
4098 | | - | |
4099 | | - | |
4100 | | - | |
4101 | | - | |
4102 | | - | |
| 4101 | + | |
4103 | 4102 | | |
4104 | 4103 | | |
4105 | 4104 | | |
| |||
4115 | 4114 | | |
4116 | 4115 | | |
4117 | 4116 | | |
| 4117 | + | |
| 4118 | + | |
| 4119 | + | |
| 4120 | + | |
4118 | 4121 | | |
4119 | 4122 | | |
4120 | 4123 | | |
| |||
4126 | 4129 | | |
4127 | 4130 | | |
4128 | 4131 | | |
4129 | | - | |
4130 | | - | |
4131 | | - | |
4132 | | - | |
4133 | | - | |
4134 | | - | |
| 4132 | + | |
4135 | 4133 | | |
4136 | 4134 | | |
4137 | 4135 | | |
| |||
4151 | 4149 | | |
4152 | 4150 | | |
4153 | 4151 | | |
4154 | | - | |
| 4152 | + | |
4155 | 4153 | | |
4156 | 4154 | | |
4157 | 4155 | | |
| |||
4163 | 4161 | | |
4164 | 4162 | | |
4165 | 4163 | | |
4166 | | - | |
| 4164 | + | |
4167 | 4165 | | |
4168 | 4166 | | |
4169 | 4167 | | |
| |||
5697 | 5695 | | |
5698 | 5696 | | |
5699 | 5697 | | |
5700 | | - | |
| 5698 | + | |
5701 | 5699 | | |
5702 | 5700 | | |
5703 | 5701 | | |
| |||
5706 | 5704 | | |
5707 | 5705 | | |
5708 | 5706 | | |
5709 | | - | |
| 5707 | + | |
5710 | 5708 | | |
5711 | 5709 | | |
5712 | 5710 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2512 | 2512 | | |
2513 | 2513 | | |
2514 | 2514 | | |
2515 | | - | |
| 2515 | + | |
2516 | 2516 | | |
2517 | 2517 | | |
2518 | 2518 | | |
| |||
3234 | 3234 | | |
3235 | 3235 | | |
3236 | 3236 | | |
3237 | | - | |
| 3237 | + | |
3238 | 3238 | | |
3239 | 3239 | | |
3240 | 3240 | | |
3241 | | - | |
| 3241 | + | |
3242 | 3242 | | |
3243 | 3243 | | |
3244 | 3244 | | |
| |||
3248 | 3248 | | |
3249 | 3249 | | |
3250 | 3250 | | |
3251 | | - | |
| 3251 | + | |
3252 | 3252 | | |
3253 | 3253 | | |
3254 | 3254 | | |
| |||
0 commit comments