Skip to content

Commit 9c5bd93

Browse files
mmhalborkmann
authored andcommitted
bpf, sockmap: SK_DROP on attempted redirects of unsupported af_vsock
Don't mislead the callers of bpf_{sk,msg}_redirect_{map,hash}(): make sure to immediately and visibly fail the forwarding of unsupported af_vsock packets. Fixes: 634f1a7 ("vsock: support sockmap") Signed-off-by: Michal Luczaj <mhal@rbox.co> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20241013-vsock-fixes-for-redir-v2-1-d6577bbfe742@rbox.co
1 parent 2aa587f commit 9c5bd93

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

include/net/sock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,6 +2715,11 @@ static inline bool sk_is_stream_unix(const struct sock *sk)
27152715
return sk->sk_family == AF_UNIX && sk->sk_type == SOCK_STREAM;
27162716
}
27172717

2718+
static inline bool sk_is_vsock(const struct sock *sk)
2719+
{
2720+
return sk->sk_family == AF_VSOCK;
2721+
}
2722+
27182723
/**
27192724
* sk_eat_skb - Release a skb if it is no longer needed
27202725
* @sk: socket to eat this skb from

net/core/sock_map.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,8 @@ BPF_CALL_4(bpf_sk_redirect_map, struct sk_buff *, skb,
647647
sk = __sock_map_lookup_elem(map, key);
648648
if (unlikely(!sk || !sock_map_redirect_allowed(sk)))
649649
return SK_DROP;
650+
if ((flags & BPF_F_INGRESS) && sk_is_vsock(sk))
651+
return SK_DROP;
650652

651653
skb_bpf_set_redir(skb, sk, flags & BPF_F_INGRESS);
652654
return SK_PASS;
@@ -675,6 +677,8 @@ BPF_CALL_4(bpf_msg_redirect_map, struct sk_msg *, msg,
675677
return SK_DROP;
676678
if (!(flags & BPF_F_INGRESS) && !sk_is_tcp(sk))
677679
return SK_DROP;
680+
if (sk_is_vsock(sk))
681+
return SK_DROP;
678682

679683
msg->flags = flags;
680684
msg->sk_redir = sk;
@@ -1249,6 +1253,8 @@ BPF_CALL_4(bpf_sk_redirect_hash, struct sk_buff *, skb,
12491253
sk = __sock_hash_lookup_elem(map, key);
12501254
if (unlikely(!sk || !sock_map_redirect_allowed(sk)))
12511255
return SK_DROP;
1256+
if ((flags & BPF_F_INGRESS) && sk_is_vsock(sk))
1257+
return SK_DROP;
12521258

12531259
skb_bpf_set_redir(skb, sk, flags & BPF_F_INGRESS);
12541260
return SK_PASS;
@@ -1277,6 +1283,8 @@ BPF_CALL_4(bpf_msg_redirect_hash, struct sk_msg *, msg,
12771283
return SK_DROP;
12781284
if (!(flags & BPF_F_INGRESS) && !sk_is_tcp(sk))
12791285
return SK_DROP;
1286+
if (sk_is_vsock(sk))
1287+
return SK_DROP;
12801288

12811289
msg->flags = flags;
12821290
msg->sk_redir = sk;

0 commit comments

Comments
 (0)