]> git.baikalelectronics.ru Git - kernel.git/commitdiff
cifs: add server conn_id to fscache client cookie
authorShyam Prasad N <sprasad@microsoft.com>
Thu, 2 Dec 2021 07:30:00 +0000 (07:30 +0000)
committerSteve French <stfrench@microsoft.com>
Fri, 3 Dec 2021 18:36:04 +0000 (12:36 -0600)
The fscache client cookie uses the server address
(and port) as the cookie key. This is a problem when
nosharesock is used. Two different connections will
use duplicate cookies. Avoid this by adding
server->conn_id to the key, so that it's guaranteed
that cookie will not be duplicated.

Also, for secondary channels of a session, copy the
fscache pointer from the primary channel. The primary
channel is guaranteed not to go away as long as secondary
channels are in use.  Also addresses minor problem found
by kernel test robot.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/connect.c
fs/cifs/fscache.c

index 7cc469e4682a4d61e1aca384161ab1d847659c08..18448dbd762a89ce92b6c70e0b55eb54c1d0f74a 100644 (file)
@@ -1562,6 +1562,10 @@ smbd_connected:
        /* fscache server cookies are based on primary channel only */
        if (!CIFS_SERVER_IS_CHAN(tcp_ses))
                cifs_fscache_get_client_cookie(tcp_ses);
+#ifdef CONFIG_CIFS_FSCACHE
+       else
+               tcp_ses->fscache = tcp_ses->primary_server->fscache;
+#endif /* CONFIG_CIFS_FSCACHE */
 
        /* queue echo request delayed work */
        queue_delayed_work(cifsiod_wq, &tcp_ses->echo, tcp_ses->echo_interval);
index f4da693760c11f56145b98307a83b1d168df4dd3..1db3437f3b7db0496e6f12dc95b8c68982a49333 100644 (file)
@@ -24,6 +24,7 @@ struct cifs_server_key {
                struct in_addr  ipv4_addr;
                struct in6_addr ipv6_addr;
        };
+       __u64 conn_id;
 } __packed;
 
 /*
@@ -37,6 +38,14 @@ void cifs_fscache_get_client_cookie(struct TCP_Server_Info *server)
        struct cifs_server_key key;
        uint16_t key_len = sizeof(key.hdr);
 
+       /*
+        * Check if cookie was already initialized so don't reinitialize it.
+        * In the future, as we integrate with newer fscache features,
+        * we may want to instead add a check if cookie has changed
+        */
+       if (server->fscache)
+               return;
+
        memset(&key, 0, sizeof(key));
 
        /*
@@ -62,6 +71,7 @@ void cifs_fscache_get_client_cookie(struct TCP_Server_Info *server)
                server->fscache = NULL;
                return;
        }
+       key.conn_id = server->conn_id;
 
        server->fscache =
                fscache_acquire_cookie(cifs_fscache_netfs.primary_index,