Commit bbb55274 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Zefan Li

RDMA/CMA: Canonize IPv4 on IPV6 sockets properly

commit 28521440 upstream.

When accepting a new IPv4 connect to an IPv6 socket, the CMA tries to
canonize the address family to IPv4, but does not properly process
the listening sockaddr to get the listening port, and does not properly
set the address family of the canonized sockaddr.

Fixes: e51060f0 ("IB: IP address based RDMA connection manager")
Reported-By: default avatarYotam Kenneth <yotamke@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Tested-by: default avatarHaggai Eran <haggaie@mellanox.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
[lizf: Backported to 3.4:
 - there's no cma_save_ip4_info() and cma_save_ip6_info(), and instead
   we apply the changes to cma_save_net_info()]
Signed-off-by: default avatarZefan Li <lizefan@huawei.com>
parent df48a548
...@@ -759,36 +759,43 @@ static int cma_get_net_info(void *hdr, enum rdma_port_space ps, ...@@ -759,36 +759,43 @@ static int cma_get_net_info(void *hdr, enum rdma_port_space ps,
return 0; return 0;
} }
static __be16 ss_get_port(const struct sockaddr_storage *ss)
{
if (ss->ss_family == AF_INET)
return ((struct sockaddr_in *)ss)->sin_port;
else if (ss->ss_family == AF_INET6)
return ((struct sockaddr_in6 *)ss)->sin6_port;
BUG();
}
static void cma_save_net_info(struct rdma_addr *addr, static void cma_save_net_info(struct rdma_addr *addr,
struct rdma_addr *listen_addr, struct rdma_addr *listen_addr,
u8 ip_ver, __be16 port, u8 ip_ver, __be16 port,
union cma_ip_addr *src, union cma_ip_addr *dst) union cma_ip_addr *src, union cma_ip_addr *dst)
{ {
struct sockaddr_in *listen4, *ip4; struct sockaddr_in *ip4;
struct sockaddr_in6 *listen6, *ip6; struct sockaddr_in6 *ip6;
switch (ip_ver) { switch (ip_ver) {
case 4: case 4:
listen4 = (struct sockaddr_in *) &listen_addr->src_addr;
ip4 = (struct sockaddr_in *) &addr->src_addr; ip4 = (struct sockaddr_in *) &addr->src_addr;
ip4->sin_family = listen4->sin_family; ip4->sin_family = AF_INET;;
ip4->sin_addr.s_addr = dst->ip4.addr; ip4->sin_addr.s_addr = dst->ip4.addr;
ip4->sin_port = listen4->sin_port; ip4->sin_port = ss_get_port(&listen_addr->src_addr);
ip4 = (struct sockaddr_in *) &addr->dst_addr; ip4 = (struct sockaddr_in *) &addr->dst_addr;
ip4->sin_family = listen4->sin_family; ip4->sin_family = AF_INET;
ip4->sin_addr.s_addr = src->ip4.addr; ip4->sin_addr.s_addr = src->ip4.addr;
ip4->sin_port = port; ip4->sin_port = port;
break; break;
case 6: case 6:
listen6 = (struct sockaddr_in6 *) &listen_addr->src_addr;
ip6 = (struct sockaddr_in6 *) &addr->src_addr; ip6 = (struct sockaddr_in6 *) &addr->src_addr;
ip6->sin6_family = listen6->sin6_family; ip6->sin6_family = AF_INET6;
ip6->sin6_addr = dst->ip6; ip6->sin6_addr = dst->ip6;
ip6->sin6_port = listen6->sin6_port; ip6->sin6_port = ss_get_port(&listen_addr->src_addr);
ip6 = (struct sockaddr_in6 *) &addr->dst_addr; ip6 = (struct sockaddr_in6 *) &addr->dst_addr;
ip6->sin6_family = listen6->sin6_family; ip6->sin6_family = AF_INET6;
ip6->sin6_addr = src->ip6; ip6->sin6_addr = src->ip6;
ip6->sin6_port = port; ip6->sin6_port = port;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment