If the socket is bound to an address of another family than the destination, rdma_resolve_addr() fails with -EINVAL. connect() of a TCP socket fails with -EAFNOSUPPORT in that case, e.g. if the server name resolves to an IPv6 address after a DNS change while the client uses an IPv4 srcaddr=. Check it in smbdirect_connect() and return -EAFNOSUPPORT, so that the callers can handle it like for TCP. This is a prerequisite for the next patch, which lets SMB Direct connections of cifs use the srcaddr= mount option. Fixes: d1f187656797 ("smb: smbdirect: introduce smbdirect_connect[_sync]()") Cc: stable@vger.kernel.org Cc: Namjae Jeon Cc: Paulo Alcantara Cc: Ronnie Sahlberg Cc: Shyam Prasad N Cc: Tom Talpey Cc: Bharath SM Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Stefan Metzmacher --- fs/smb/smbdirect/connect.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/smb/smbdirect/connect.c b/fs/smb/smbdirect/connect.c index 5a95ee80e69d..e0cc0f5c4132 100644 --- a/fs/smb/smbdirect/connect.c +++ b/fs/smb/smbdirect/connect.c @@ -46,6 +46,13 @@ int smbdirect_connect(struct smbdirect_socket *sc, const struct sockaddr *dst) if (src_addr.sa.sa_family != AF_UNSPEC) src = &src_addr.sa; + /* + * Like connect() of a socket bound to an address of another + * family, rdma_resolve_addr() would fail with -EINVAL. + */ + if (src && src->sa_family != dst->sa_family) + return -EAFNOSUPPORT; + smbdirect_log_rdma_event(sc, SMBDIRECT_LOG_INFO, "connect: src: %pISpsfc dst: %pISpsfc\n", src, dst); -- 2.43.0