* [bpf PATCH] bpf: avoid kcm psock use and tcp_bpf from colliding
@ 2018-08-30 22:33 John Fastabend
2018-08-31 0:24 ` John Fastabend
0 siblings, 1 reply; 2+ messages in thread
From: John Fastabend @ 2018-08-30 22:33 UTC (permalink / raw)
To: ast, daniel; +Cc: netdev
Currently we check sk_user_data is non NULL to determine if the sk
exists in a map. However, this is not sufficient to ensure the psock
is not in use by another (non-ULP TCP) user, such as kcm. To avoid
this when adding a sock to a map also verify it is of the correct ULP
type.
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
0 files changed
diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c
index ce63e58..1c05794 100644
--- a/kernel/bpf/sockmap.c
+++ b/kernel/bpf/sockmap.c
@@ -1808,6 +1808,11 @@ static int sock_map_delete_elem(struct bpf_map *map, void *key)
return 0;
}
+static bool psock_is_smap_sk(struct sock *sk)
+{
+ return inet_csk(sk)->icsk_ulp_ops == &bpf_tcp_ulp_ops;
+}
+
/* Locking notes: Concurrent updates, deletes, and lookups are allowed and are
* done inside rcu critical sections. This ensures on updates that the psock
* will not be released via smap_release_sock() until concurrent updates/deletes
@@ -1892,6 +1897,10 @@ static int __sock_map_ctx_update_elem(struct bpf_map *map,
* doesn't update user data.
*/
if (psock) {
+ if (!psock_is_smap_sk(sock)) {
+ err = -EBUSY;
+ goto out_progs;
+ }
if (READ_ONCE(psock->bpf_parse) && parse) {
err = -EBUSY;
goto out_progs;
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [bpf PATCH] bpf: avoid kcm psock use and tcp_bpf from colliding
2018-08-30 22:33 [bpf PATCH] bpf: avoid kcm psock use and tcp_bpf from colliding John Fastabend
@ 2018-08-31 0:24 ` John Fastabend
0 siblings, 0 replies; 2+ messages in thread
From: John Fastabend @ 2018-08-31 0:24 UTC (permalink / raw)
To: ast, daniel; +Cc: netdev
On 08/30/2018 03:33 PM, John Fastabend wrote:
> Currently we check sk_user_data is non NULL to determine if the sk
> exists in a map. However, this is not sufficient to ensure the psock
> is not in use by another (non-ULP TCP) user, such as kcm. To avoid
> this when adding a sock to a map also verify it is of the correct ULP
> type.
>
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> ---
I'll send a v2 of this we have one more spot we need to check
the psock type in the error path.
Thanks,
John
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-08-31 4:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-30 22:33 [bpf PATCH] bpf: avoid kcm psock use and tcp_bpf from colliding John Fastabend
2018-08-31 0:24 ` John Fastabend
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox