]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
smb: client: fix iface port assignment in parse_server_interfaces
authorHenrique Carvalho <henrique.carvalho@suse.com>
Wed, 11 Mar 2026 23:17:23 +0000 (20:17 -0300)
committerSteve French <stfrench@microsoft.com>
Wed, 11 Mar 2026 23:46:28 +0000 (18:46 -0500)
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: fe856be475f7 ("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>
fs/smb/client/smb2ops.c

index 7f2d3459cbf9ad4825c66a4bac18dd2b1f8fd179..612057318de2f245f640a6e23f4972855790696f 100644 (file)
@@ -628,6 +628,7 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
        struct smb_sockaddr_in6 *p6;
        struct cifs_server_iface *info = NULL, *iface = NULL, *niface = NULL;
        struct cifs_server_iface tmp_iface;
+       __be16 port;
        ssize_t bytes_left;
        size_t next = 0;
        int nb_iface = 0;
@@ -662,6 +663,15 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
                goto out;
        }
 
+       spin_lock(&ses->server->srv_lock);
+       if (ses->server->dstaddr.ss_family == AF_INET)
+               port = ((struct sockaddr_in *)&ses->server->dstaddr)->sin_port;
+       else if (ses->server->dstaddr.ss_family == AF_INET6)
+               port = ((struct sockaddr_in6 *)&ses->server->dstaddr)->sin6_port;
+       else
+               port = cpu_to_be16(CIFS_PORT);
+       spin_unlock(&ses->server->srv_lock);
+
        while (bytes_left >= (ssize_t)sizeof(*p)) {
                memset(&tmp_iface, 0, sizeof(tmp_iface));
                /* default to 1Gbps when link speed is unset */
@@ -682,7 +692,7 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
                        memcpy(&addr4->sin_addr, &p4->IPv4Address, 4);
 
                        /* [MS-SMB2] 2.2.32.5.1.1 Clients MUST ignore these */
-                       addr4->sin_port = cpu_to_be16(CIFS_PORT);
+                       addr4->sin_port = port;
 
                        cifs_dbg(FYI, "%s: ipv4 %pI4\n", __func__,
                                 &addr4->sin_addr);
@@ -696,7 +706,7 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
                        /* [MS-SMB2] 2.2.32.5.1.2 Clients MUST ignore these */
                        addr6->sin6_flowinfo = 0;
                        addr6->sin6_scope_id = 0;
-                       addr6->sin6_port = cpu_to_be16(CIFS_PORT);
+                       addr6->sin6_port = port;
 
                        cifs_dbg(FYI, "%s: ipv6 %pI6\n", __func__,
                                 &addr6->sin6_addr);