Skip to contentSkip to conversation

cifs: fix crash in cifs_dfs_do_automount

PATCH In review Ronnie Sahlberg 3 participants 3 messages Jul 11, 2019 – Jul 13, 2019

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

PATCH 1/1 cifs: fix crash in cifs_dfs_do_automount

RHBZ: 1649907

Fix a crash that happens while attempting to mount a DFS referral from the same server on the root of a filesystem.

---
 fs/cifs/connect.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
fs/cifs/connect.c +11 -4
index 8ad8bbe8003b..9b0f9f346c5b 100644
@@ -4484,11 +4484,13 @@ cifs_are_all_path_components_accessible(struct TCP_Server_Info *server,
 					unsigned int xid,
 					struct cifs_tcon *tcon,
 					struct cifs_sb_info *cifs_sb,
-					char *full_path)
+					char *full_path,
+					int added_treename)
 {
 	int rc;
 	char *s;
 	char sep, tmp;
+	int skip = added_treename ? 1 : 0;
 
 	sep = CIFS_DIR_SEP(cifs_sb);
 	s = full_path;
@@ -4503,7 +4505,13 @@ cifs_are_all_path_components_accessible(struct TCP_Server_Info *server,
 		/* next separator */
 		while (*s && *s != sep)
 			s++;
-
+		/* if the treename is added, we then have to skip the first
+		 * part within the separators
+		 */
+		if (skip) {
+			skip = 0;
+			continue;
+		}
 		/*
 		 * temporarily null-terminate the path at the end of
 		 * the current component
@@ -4551,8 +4559,7 @@ static int is_path_remote(struct cifs_sb_info *cifs_sb, struct smb_vol *vol,
 
 	if (rc != -EREMOTE) {
 		rc = cifs_are_all_path_components_accessible(server, xid, tcon,
-							     cifs_sb,
-							     full_path);
+			cifs_sb, full_path, tcon->Flags & SMB_SHARE_IS_IN_DFS);
 		if (rc != 0) {
 			cifs_dbg(VFS, "cannot query dirs between root and final path, "
 				 "enabling CIFS_MOUNT_USE_PREFIX_PATH\n");
Signature · 1 line
2.13.6
#1 lore raw

Hi Ronnie,

Quoted 29 lines · Ronnie Sahlberg

RHBZ: 1649907

Fix a crash that happens while attempting to mount a DFS referral from the same server on the root of a filesystem.

---
 fs/cifs/connect.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
fs/cifs/connect.c +3 -1
index 8ad8bbe8003b..9b0f9f346c5b 100644
@@ -4484,11 +4484,13 @@ cifs_are_all_path_components_accessible(struct TCP_Server_Info *server,
 					unsigned int xid,
 					struct cifs_tcon *tcon,
 					struct cifs_sb_info *cifs_sb,
-					char *full_path)
+					char *full_path,
+					int added_treename)
 {
 	int rc;
 	char *s;
 	char sep, tmp;
+	int skip = added_treename ? 1 : 0;
 
 	sep = CIFS_DIR_SEP(cifs_sb);
 	s = full_path;

fs/cifs/connect.c cifs_are_all_path_components_accessible(struct TCP_Server_Info *server, · line 4510

Quoted 7 lines
fs/cifs/connect.c +3 -1
@@ -4503,7 +4505,13 @@ cifs_are_all_path_components_accessible(struct TCP_Server_Info *server,
 		/* next separator */
 		while (*s && *s != sep)
 			s++;
-
+		/* if the treename is added, we then have to skip the first
+		 * part within the separators
+		 */

Nitpicking (Steve can probably fix this when he applies) but comment style should be

/*
* foo
*/

Quoted 8 lines
fs/cifs/connect.c +4 -0
+		if (skip) {
+			skip = 0;
+			continue;
+		}
 		/*
 		 * temporarily null-terminate the path at the end of
 		 * the current component

fs/cifs/connect.c static int is_path_remote(struct cifs_sb_info *cifs_sb, struct smb_vol *vol, · line 4562

Quoted 6 lines
fs/cifs/connect.c +1 -2
@@ -4551,8 +4559,7 @@ static int is_path_remote(struct cifs_sb_info *cifs_sb, struct smb_vol *vol,
 
 	if (rc != -EREMOTE) {
 		rc = cifs_are_all_path_components_accessible(server, xid, tcon,
-							     cifs_sb,
-							     full_path);
+			cifs_sb, full_path, tcon->Flags & SMB_SHARE_IS_IN_DFS);

Just FYI this flag is just set in SMB1. Can we test this change in the buildbot?

Quoted 7 lines
fs/cifs/connect.c +0 -0
 		if (rc != 0) {
 			cifs_dbg(VFS, "cannot query dirs between root and final path, "
 				 "enabling CIFS_MOUNT_USE_PREFIX_PATH\n");
Signature · 1 line
2.13.6

Cheers,

Signature · 4 lines
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
SUSE Linux GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
#2 lore raw

fixed comment and pushed to cifs-2.6.git for-next

Quoted 81 lines · Aurélien Aptel

Hi Ronnie,

Quoted 29 lines · Ronnie Sahlberg

RHBZ: 1649907

Fix a crash that happens while attempting to mount a DFS referral from the same server on the root of a filesystem.

---
 fs/cifs/connect.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
fs/cifs/connect.c +3 -1
index 8ad8bbe8003b..9b0f9f346c5b 100644
@@ -4484,11 +4484,13 @@ cifs_are_all_path_components_accessible(struct TCP_Server_Info *server,
                                      unsigned int xid,
                                      struct cifs_tcon *tcon,
                                      struct cifs_sb_info *cifs_sb,
-                                     char *full_path)
+                                     char *full_path,
+                                     int added_treename)
 {
      int rc;
      char *s;
      char sep, tmp;
+     int skip = added_treename ? 1 : 0;
 
      sep = CIFS_DIR_SEP(cifs_sb);
      s = full_path;

fs/cifs/connect.c cifs_are_all_path_components_accessible(struct TCP_Server_Info *server, · line 4510

Quoted 7 lines
fs/cifs/connect.c +3 -1
@@ -4503,7 +4505,13 @@ cifs_are_all_path_components_accessible(struct TCP_Server_Info *server,
              /* next separator */
              while (*s && *s != sep)
                      s++;
-
+             /* if the treename is added, we then have to skip the first
+              * part within the separators
+              */

Nitpicking (Steve can probably fix this when he applies) but comment style should be

/*
* foo
*/

Quoted 8 lines
fs/cifs/connect.c +4 -0
+             if (skip) {
+                     skip = 0;
+                     continue;
+             }
              /*
               * temporarily null-terminate the path at the end of
               * the current component

fs/cifs/connect.c static int is_path_remote(struct cifs_sb_info *cifs_sb, struct smb_vol *vol, · line 4562

Quoted 6 lines
fs/cifs/connect.c +1 -2
@@ -4551,8 +4559,7 @@ static int is_path_remote(struct cifs_sb_info *cifs_sb, struct smb_vol *vol,
 
      if (rc != -EREMOTE) {
              rc = cifs_are_all_path_components_accessible(server, xid, tcon,
-                                                          cifs_sb,
-                                                          full_path);
+                     cifs_sb, full_path, tcon->Flags & SMB_SHARE_IS_IN_DFS);

Just FYI this flag is just set in SMB1. Can we test this change in the buildbot?

Quoted 7 lines
fs/cifs/connect.c +0 -1
              if (rc != 0) {
                      cifs_dbg(VFS, "cannot query dirs between root and final path, "
                               "enabling CIFS_MOUNT_USE_PREFIX_PATH\n");
--

2.13.6

Cheers,
--
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97 8C99 03C8 A49B 521B D5D3
SUSE Linux GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)

Signature · 3 lines
Thanks,

Steve