Skip to contentSkip to conversation

tcp: restrict SO_ATTACH_FILTER to priv users

PATCH Applied Eric Dumazet 4 participants 4 messages Jun 5 – Jun 8

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: restrict SO_ATTACH_FILTER to priv users

This patch restricts the use of SO_ATTACH_FILTER (cBPF) on TCP sockets to users with CAP_NET_ADMIN capability.

This blocks potential side-channel attack where an unprivileged application attaches a filter to leak TCP sequence/acknowledgment numbers.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc Willem de Bruijn <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Eduard Zingerman <[email protected]>
Cc Kumar Kartikeya Dwivedi <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc John Fastabend <[email protected]>
Cc Stanislav Fomichev <[email protected]>
---
 net/core/sock.c | 5 +++++
 1 file changed, 5 insertions(+)
net/core/sock.c +5 -0
index d097025c116a863b29346c12470a9c81ec38ac56..cab041b57d286536cd4299c98f0d7d3bf7499501 100644
@@ -1465,6 +1465,11 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
 	case SO_ATTACH_FILTER: {
 		struct sock_fprog fprog;
 
+		if (sk_is_tcp(sk) &&
+		    !sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
+			ret = -EPERM;
+			break;
+		}
 		ret = copy_bpf_fprog_from_user(&fprog, optval, optlen);
 		if (!ret)
 			ret = sk_attach_filter(&fprog, sk);
Signature · 1 line
2.54.0.1032.g2f8565e1d1-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Eric Dumazet

This patch restricts the use of SO_ATTACH_FILTER (cBPF) on TCP sockets to users with CAP_NET_ADMIN capability.

This blocks potential side-channel attack where an unprivileged application attaches a filter to leak TCP sequence/acknowledgment numbers.

Quoted 16 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc Willem de Bruijn <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Eduard Zingerman <[email protected]>
Cc Kumar Kartikeya Dwivedi <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc John Fastabend <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Reviewed-by
#2 lore raw
Quoted 24 lines · Daniel Borkmann
Quoted 6 lines · Eric Dumazet

This patch restricts the use of SO_ATTACH_FILTER (cBPF) on TCP sockets to users with CAP_NET_ADMIN capability.

This blocks potential side-channel attack where an unprivileged application attaches a filter to leak TCP sequence/acknowledgment numbers.

Quoted 16 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc Willem de Bruijn <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Eduard Zingerman <[email protected]>
Cc Kumar Kartikeya Dwivedi <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc John Fastabend <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Quoted 1 line
#3 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 23 lines · On Fri, 5 Jun 2026 11:21:34 +0000 you wrote:

This patch restricts the use of SO_ATTACH_FILTER (cBPF) on TCP sockets to users with CAP_NET_ADMIN capability.

This blocks potential side-channel attack where an unprivileged application attaches a filter to leak TCP sequence/acknowledgment numbers.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc Willem de Bruijn <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Eduard Zingerman <[email protected]>
Cc Kumar Kartikeya Dwivedi <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc John Fastabend <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Quoted 1 line

[...]

Here is the summary with links:
- [net] tcp: restrict SO_ATTACH_FILTER to priv users

    https://git.kernel.org/netdev/net/c/5d39580f68e6

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html