Skip to content

Commit d4c7210

Browse files
hac-vsmfrench
authored andcommitted
smb: client: fix iface port assignment in parse_server_interfaces
parse_server_interfaces() initializes interface socket addresses with CIFS_PORT. When the mount uses a non-default port this overwrites the configured destination port. Later, cifs_chan_update_iface() copies this sockaddr into server->dstaddr, causing reconnect attempts to use the wrong port after server interface updates. Use the existing port from server->dstaddr instead. Cc: stable@vger.kernel.org Fixes: fe856be ("CIFS: parse and store info on iface queries") Tested-by: Dr. Thomas Orgis <thomas.orgis@uni-hamburg.de> Reviewed-by: Enzo Matsumiya <ematsumiya@suse.de> Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 88d37ab commit d4c7210

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

fs/smb/client/smb2ops.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
628628
struct smb_sockaddr_in6 *p6;
629629
struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
630630
struct cifs_server_iface tmp_iface;
631+
__be16 port;
631632
ssize_t bytes_left;
632633
size_t next = 0;
633634
int nb_iface = 0;
@@ -662,6 +663,15 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
662663
goto out;
663664
}
664665

666+
spin_lock(&ses->server->srv_lock);
667+
if (ses->server->dstaddr.ss_family == AF_INET)
668+
port = ((struct sockaddr_in *)&ses->server->dstaddr)->sin_port;
669+
else if (ses->server->dstaddr.ss_family == AF_INET6)
670+
port = ((struct sockaddr_in6 *)&ses->server->dstaddr)->sin6_port;
671+
else
672+
port = cpu_to_be16(CIFS_PORT);
673+
spin_unlock(&ses->server->srv_lock);
674+
665675
while (bytes_left >= (ssize_t)sizeof(*p)) {
666676
memset(&tmp_iface, 0, sizeof(tmp_iface));
667677
/* default to 1Gbps when link speed is unset */
@@ -682,7 +692,7 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
682692
memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
683693

684694
/* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
685-
addr4->sin_port = cpu_to_be16(CIFS_PORT);
695+
addr4->sin_port = port;
686696

687697
cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
688698
&addr4->sin_addr);
@@ -696,7 +706,7 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
696706
/* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
697707
addr6->sin6_flowinfo = 0;
698708
addr6->sin6_scope_id = 0;
699-
addr6->sin6_port = cpu_to_be16(CIFS_PORT);
709+
addr6->sin6_port = port;
700710

701711
cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
702712
&addr6->sin6_addr);

0 commit comments

Comments
 (0)