]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Disable non stream socket for strparser
authorJiayuan Chen <mrpre@163.com>
Wed, 22 Jan 2025 10:09:15 +0000 (18:09 +0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Wed, 29 Jan 2025 21:32:32 +0000 (13:32 -0800)
Currently, only TCP supports strparser, but sockmap doesn't intercept
non-TCP connections to attach strparser. For example, with UDP, although
the read/write handlers are replaced, strparser is not executed due to
the lack of a read_sock operation.

Furthermore, in udp_bpf_recvmsg(), it checks whether the psock has data,
and if not, it falls back to the native UDP read interface, making
UDP + strparser appear to read correctly. According to its commit history,
this behavior is unexpected.

Moreover, since UDP lacks the concept of streams, we intercept it directly.

Fixes: 1fa1fe8ff161 ("bpf, sockmap: Test shutdown() correctly exits epoll and recv()=0")
Signed-off-by: Jiayuan Chen <mrpre@163.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Jakub Sitnicki <jakub@cloudflare.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://patch.msgid.link/20250122100917.49845-4-mrpre@163.com
net/core/sock_map.c

index f1b9b3958792cd599efcb591742874e9b3f4a76b..3b0f59d9b4db8fd8d50da0ac53376afcdae6f92f 100644 (file)
@@ -303,7 +303,10 @@ static int sock_map_link(struct bpf_map *map, struct sock *sk)
 
        write_lock_bh(&sk->sk_callback_lock);
        if (stream_parser && stream_verdict && !psock->saved_data_ready) {
-               ret = sk_psock_init_strp(sk, psock);
+               if (sk_is_tcp(sk))
+                       ret = sk_psock_init_strp(sk, psock);
+               else
+                       ret = -EOPNOTSUPP;
                if (ret) {
                        write_unlock_bh(&sk->sk_callback_lock);
                        sk_psock_put(sk, psock);