Skip to content
/ linux Public

Commit 40f7c69

Browse files
hac-vgregkh
authored andcommitted
smb: client: fix iface port assignment in parse_server_interfaces
commit d4c7210 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 438e774 commit 40f7c69

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

fs/smb/client/smb2ops.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
586586
struct iface_info_ipv6 *p6;
587587
struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
588588
struct cifs_server_iface tmp_iface;
589+
__be16 port;
589590
ssize_t bytes_left;
590591
size_t next = 0;
591592
int nb_iface = 0;
@@ -620,6 +621,15 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
620621
goto out;
621622
}
622623

624+
spin_lock(&ses->server->srv_lock);
625+
if (ses->server->dstaddr.ss_family == AF_INET)
626+
port = ((struct sockaddr_in *)&ses->server->dstaddr)->sin_port;
627+
else if (ses->server->dstaddr.ss_family == AF_INET6)
628+
port = ((struct sockaddr_in6 *)&ses->server->dstaddr)->sin6_port;
629+
else
630+
port = cpu_to_be16(CIFS_PORT);
631+
spin_unlock(&ses->server->srv_lock);
632+
623633
while (bytes_left >= (ssize_t)sizeof(*p)) {
624634
memset(&tmp_iface, 0, sizeof(tmp_iface));
625635
/* default to 1Gbps when link speed is unset */
@@ -640,7 +650,7 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
640650
memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
641651

642652
/* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
643-
addr4->sin_port = cpu_to_be16(CIFS_PORT);
653+
addr4->sin_port = port;
644654

645655
cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
646656
&addr4->sin_addr);
@@ -654,7 +664,7 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
654664
/* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
655665
addr6->sin6_flowinfo = 0;
656666
addr6->sin6_scope_id = 0;
657-
addr6->sin6_port = cpu_to_be16(CIFS_PORT);
667+
addr6->sin6_port = port;
658668

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

0 commit comments

Comments
 (0)