Skip to content

Commit 12083d7

Browse files
0x7f454c46Paolo Abeni
authored andcommitted
net/tcp: Don't add key with non-matching VRF on connected sockets
If the connection was established, don't allow adding TCP-AO keys that don't match the peer. Currently, there are checks for ip-address matching, but L3 index check is missing. Add it to restrict userspace shooting itself somewhere. Yet, nothing restricts the CAP_NET_RAW user from trying to shoot themselves by performing setsockopt(SO_BINDTODEVICE) or setsockopt(SO_BINDTOIFINDEX) over an established TCP-AO connection. So, this is just "minimum effort" to potentially save someone's debugging time, rather than a full restriction on doing weird things. Fixes: 248411b ("net/tcp: Wire up l3index to TCP-AO") Signed-off-by: Dmitry Safonov <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 965c00e commit 12083d7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

net/ipv4/tcp_ao.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,15 @@ static int tcp_ao_add_cmd(struct sock *sk, unsigned short int family,
16081608
if (!dev || !l3index)
16091609
return -EINVAL;
16101610

1611+
if (!bound_dev_if || bound_dev_if != cmd.ifindex) {
1612+
/* tcp_ao_established_key() doesn't expect having
1613+
* non peer-matching key on an established TCP-AO
1614+
* connection.
1615+
*/
1616+
if (!((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)))
1617+
return -EINVAL;
1618+
}
1619+
16111620
/* It's still possible to bind after adding keys or even
16121621
* re-bind to a different dev (with CAP_NET_RAW).
16131622
* So, no reason to return error here, rather try to be

0 commit comments

Comments
 (0)