Skip to contentSkip to conversation

cifs: fix check of tcon dfs in smb1

PATCH In review Paulo Alcantara 2 participants 3 messages Aug 27, 2020 – Aug 28, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix check of tcon dfs in smb1

For SMB1, the DFS flag should be checked against tcon->Flags rather than tcon->share_flags. While at it, add an is_tcon_dfs() helper to check for DFS capability in a more generic way.

---
 fs/cifs/cifsglob.h | 15 +++++++++++++++
 fs/cifs/connect.c  |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)
fs/cifs/cifsglob.h +15 -0
index b296964b8afa..b565d83ba89e 100644
@@ -2031,4 +2031,19 @@ static inline bool is_smb1_server(struct TCP_Server_Info *server)
 	return strcmp(server->vals->version_string, SMB1_VERSION_STRING) == 0;
 }
 
+static inline bool is_tcon_dfs(struct cifs_tcon *tcon)
+{
+	/*
+	 * For SMB1, see MS-CIFS 2.4.55 SMB_COM_TREE_CONNECT_ANDX (0x75) and MS-CIFS 3.3.4.4 DFS
+	 * Subsystem Notifies That a Share Is a DFS Share.
+	 *
+	 * For SMB2+, see MS-SMB2 2.2.10 SMB2 TREE_CONNECT Response and MS-SMB2 3.3.4.14 Server
+	 * Application Updates a Share.
+	 */
+	if (!tcon || !tcon->ses || !tcon->ses->server)
+		return false;
+	return is_smb1_server(tcon->ses->server) ? tcon->Flags & SMB_SHARE_IS_IN_DFS :
+		tcon->share_flags & (SHI1005_FLAGS_DFS | SHI1005_FLAGS_DFS_ROOT);
+}
+
 #endif	/* _CIFS_GLOB_H */
fs/cifs/connect.c +1 -1
index a275ee399dce..392c44d64d8a 100644
@@ -4909,7 +4909,7 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *vol)
 		if (!tcon)
 			continue;
 		/* Make sure that requests go through new root servers */
-		if (tcon->share_flags & (SHI1005_FLAGS_DFS | SHI1005_FLAGS_DFS_ROOT)) {
+		if (is_tcon_dfs(tcon)) {
 			put_root_ses(root_ses);
 			set_root_ses(cifs_sb, ses, &root_ses);
 		}
Signature · 1 line
2.28.0
#1 lore raw

These changes look good to me.
However, I see other places in the code where these flags are checked separately. Don't we want to replace all those with is_tcon_dfs() calls?

Regards,
Shyam

Quoted 51 lines · Paulo Alcantara

For SMB1, the DFS flag should be checked against tcon->Flags rather than tcon->share_flags. While at it, add an is_tcon_dfs() helper to check for DFS capability in a more generic way.

---
 fs/cifs/cifsglob.h | 15 +++++++++++++++
 fs/cifs/connect.c  |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)
fs/cifs/cifsglob.h +15 -0
index b296964b8afa..b565d83ba89e 100644
@@ -2031,4 +2031,19 @@ static inline bool is_smb1_server(struct TCP_Server_Info *server)
        return strcmp(server->vals->version_string, SMB1_VERSION_STRING) == 0;
 }
 
+static inline bool is_tcon_dfs(struct cifs_tcon *tcon)
+{
+       /*
+        * For SMB1, see MS-CIFS 2.4.55 SMB_COM_TREE_CONNECT_ANDX (0x75) and MS-CIFS 3.3.4.4 DFS
+        * Subsystem Notifies That a Share Is a DFS Share.
+        *
+        * For SMB2+, see MS-SMB2 2.2.10 SMB2 TREE_CONNECT Response and MS-SMB2 3.3.4.14 Server
+        * Application Updates a Share.
+        */
+       if (!tcon || !tcon->ses || !tcon->ses->server)
+               return false;
+       return is_smb1_server(tcon->ses->server) ? tcon->Flags & SMB_SHARE_IS_IN_DFS :
+               tcon->share_flags & (SHI1005_FLAGS_DFS | SHI1005_FLAGS_DFS_ROOT);
+}
+
 #endif /* _CIFS_GLOB_H */
fs/cifs/connect.c +1 -2
index a275ee399dce..392c44d64d8a 100644
@@ -4909,7 +4909,7 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *vol)
                if (!tcon)
                        continue;
                /* Make sure that requests go through new root servers */
-               if (tcon->share_flags & (SHI1005_FLAGS_DFS | SHI1005_FLAGS_DFS_ROOT)) {
+               if (is_tcon_dfs(tcon)) {
                        put_root_ses(root_ses);
                        set_root_ses(cifs_sb, ses, &root_ses);
                }
--

2.28.0

Signature · 1 line
-Shyam
#2 lore raw
Quoted 4 lines · Shyam Prasad N

These changes look good to me.
However, I see other places in the code where these flags are checked separately. Don't we want to replace all those with is_tcon_dfs() calls?

Yes, probably. We could do that in separate patches, however it would require a lot of testing.

I initially did it for dfs mount because it was easily reproducible when running smb1 tests against Windows 2019.

Thanks for pointing that out. I can take a look at it when time allows.