ovpn accepts a userspace-provided socket and a peer remote endpoint through netlink. For UDP peers, the remote endpoint family selects the transmit path used later by ovpn_udp_output.
Accepting an IPv6 remote on an AF_INET socket is unsafe. On TX, ovpn_udp6_output() hands the socket to ip6_dst_lookup_flow(), which dereferences inet6_sk(sk), e.g. to read srcprefs in ip6_route_output_flags() when no local address is set. inet6_sk() is NULL for AF_INET sockets, therefore the first packet sent to such a peer triggers a NULL pointer dereference. When a remote is configured through peer new or peer set, reject it if the socket cannot send to it: an IPv6 remote on a non-AF_INET6 socket, or an IPv4 remote on an IPv6-only socket. This gives userspace a clear extack instead of installing a peer that cannot work. The socket remains owned by userspace after it is attached to ovpn, so this only covers the socket state visible while the netlink request is handled. The transmit path still has to re-check socket/remote compatibility before sending. Signed-off-by: Ralf Lici <[email protected]> --- Changes since netdev PR 2026-11-24 https://lore.kernel.org/netdev/[email protected]/ - Slim down for net by dropping the parse-once refactor of the peer new/set paths and the new helper, and doing the check inline in ovpn_nl_peer_modify. (Paolo) drivers/net/ovpn/netlink.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/net/ovpn/netlink.c b/drivers/net/ovpn/netlink.c index 5432bc2eb8e8..1013810946ee 100644 --- a/drivers/net/ovpn/netlink.c +++ b/drivers/net/ovpn/netlink.c @@ -319,6 +319,7 @@ static int ovpn_nl_peer_modify(struct ovpn_peer *peer, struct genl_info *info, struct nlattr **attrs) { struct sockaddr_storage ss = {}; + struct ovpn_socket *sock; void *local_ip = NULL; u32 interv, timeout; bool rehash = false; @@ -327,6 +328,22 @@ static int ovpn_nl_peer_modify(struct ovpn_peer *peer, struct genl_info *info, spin_lock_bh(&peer->lock); if (ovpn_nl_attr_sockaddr_remote(attrs, &ss)) { + /* The socket is owned by userspace: make sure it can reach the + * remote. An IPv6 remote on a socket without IPv6 state would + * crash the TX path in ip6_dst_lookup_flow. + */ + sock = rcu_dereference_bh(peer->sock); + if (sock && ((ss.ss_family == AF_INET6 && + sock->sk->sk_family != AF_INET6) || + (ss.ss_family == AF_INET && + sock->sk->sk_family == AF_INET6 && + ipv6_only_sock(sock->sk)))) { + NL_SET_ERR_MSG_MOD(info->extack, + "remote address family not supported by socket"); + ret = -EAFNOSUPPORT; + goto err_unlock; + } + /* we carry the local IP in a generic container. * ovpn_peer_reset_sockaddr() will properly interpret it * based on ss.ss_family -- 2.56.1 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
