Commit eed9aeb7 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Sasha Levin

RDMA/CMA: Canonize IPv4 on IPV6 sockets properly

[ Upstream commit 28521440 ]

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")

Cc: <stable@vger.kernel.org>
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>
Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
parent f4ccf646
...@@ -859,19 +859,27 @@ static void cma_save_ib_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id ...@@ -859,19 +859,27 @@ static void cma_save_ib_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id
memcpy(&ib->sib_addr, &path->dgid, 16); memcpy(&ib->sib_addr, &path->dgid, 16);
} }
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_ip4_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, static void cma_save_ip4_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id,
struct cma_hdr *hdr) struct cma_hdr *hdr)
{ {
struct sockaddr_in *listen4, *ip4; struct sockaddr_in *ip4;
listen4 = (struct sockaddr_in *) &listen_id->route.addr.src_addr;
ip4 = (struct sockaddr_in *) &id->route.addr.src_addr; ip4 = (struct sockaddr_in *) &id->route.addr.src_addr;
ip4->sin_family = listen4->sin_family; ip4->sin_family = AF_INET;
ip4->sin_addr.s_addr = hdr->dst_addr.ip4.addr; ip4->sin_addr.s_addr = hdr->dst_addr.ip4.addr;
ip4->sin_port = listen4->sin_port; ip4->sin_port = ss_get_port(&listen_id->route.addr.src_addr);
ip4 = (struct sockaddr_in *) &id->route.addr.dst_addr; ip4 = (struct sockaddr_in *) &id->route.addr.dst_addr;
ip4->sin_family = listen4->sin_family; ip4->sin_family = AF_INET;
ip4->sin_addr.s_addr = hdr->src_addr.ip4.addr; ip4->sin_addr.s_addr = hdr->src_addr.ip4.addr;
ip4->sin_port = hdr->port; ip4->sin_port = hdr->port;
} }
...@@ -879,16 +887,15 @@ static void cma_save_ip4_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_i ...@@ -879,16 +887,15 @@ static void cma_save_ip4_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_i
static void cma_save_ip6_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, static void cma_save_ip6_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id,
struct cma_hdr *hdr) struct cma_hdr *hdr)
{ {
struct sockaddr_in6 *listen6, *ip6; struct sockaddr_in6 *ip6;
listen6 = (struct sockaddr_in6 *) &listen_id->route.addr.src_addr;
ip6 = (struct sockaddr_in6 *) &id->route.addr.src_addr; ip6 = (struct sockaddr_in6 *) &id->route.addr.src_addr;
ip6->sin6_family = listen6->sin6_family; ip6->sin6_family = AF_INET6;
ip6->sin6_addr = hdr->dst_addr.ip6; ip6->sin6_addr = hdr->dst_addr.ip6;
ip6->sin6_port = listen6->sin6_port; ip6->sin6_port = ss_get_port(&listen_id->route.addr.src_addr);
ip6 = (struct sockaddr_in6 *) &id->route.addr.dst_addr; ip6 = (struct sockaddr_in6 *) &id->route.addr.dst_addr;
ip6->sin6_family = listen6->sin6_family; ip6->sin6_family = AF_INET6;
ip6->sin6_addr = hdr->src_addr.ip6; ip6->sin6_addr = hdr->src_addr.ip6;
ip6->sin6_port = hdr->port; ip6->sin6_port = hdr->port;
} }
......
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