[PATCH v2 10/12] smb: smbdirect: fail a connect from another address family
From: Stefan Metzmacher
Date: Fri Dec 04 2026 - 08:35:03 EST
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, and so carries its Fixes tag.
Fixes: 2f8946464b11 ("CIFS: SMBD: Upper layer connects to SMBDirect session")
Cc: stable@xxxxxxxxxxxxxxx
Cc: Namjae Jeon <linkinjeon@xxxxxxxxxx>
Cc: Paulo Alcantara <pc@xxxxxxxxxxxxx>
Cc: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
Cc: Shyam Prasad N <sprasad@xxxxxxxxxxxxx>
Cc: Tom Talpey <tom@xxxxxxxxxx>
Cc: Bharath SM <bharathsm@xxxxxxxxxxxxx>
Cc: linux-cifs@xxxxxxxxxxxxxxx
Cc: samba-technical@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Signed-off-by: Stefan Metzmacher <metze@xxxxxxxxx>
---
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 0d02f03063ac..ef03b70836ab 100644
--- a/fs/smb/smbdirect/connect.c
+++ b/fs/smb/smbdirect/connect.c
@@ -42,6 +42,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