Skip to content

Commit 5459cce

Browse files
mrpreMartin KaFai Lau
authored andcommitted
bpf: Disable non stream socket for strparser
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: 1fa1fe8 ("bpf, sockmap: Test shutdown() correctly exits epoll and recv()=0") Signed-off-by: Jiayuan Chen <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Jakub Sitnicki <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 36b62df commit 5459cce

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/core/sock_map.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ static int sock_map_link(struct bpf_map *map, struct sock *sk)
303303

304304
write_lock_bh(&sk->sk_callback_lock);
305305
if (stream_parser && stream_verdict && !psock->saved_data_ready) {
306-
ret = sk_psock_init_strp(sk, psock);
306+
if (sk_is_tcp(sk))
307+
ret = sk_psock_init_strp(sk, psock);
308+
else
309+
ret = -EOPNOTSUPP;
307310
if (ret) {
308311
write_unlock_bh(&sk->sk_callback_lock);
309312
sk_psock_put(sk, psock);

0 commit comments

Comments
 (0)