Skip to contentSkip to conversation

cifs_get_root shouldn't use path with tree name

PATCH In review Sachin Prabhu 4 participants 10 messages Sep 7, 2016 – Dec 14, 2016 8 messages not in the archive

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

PATCH 1/1 cifs_get_root shouldn't use path with tree name

When a server returns the optional flag SMB_SHARE_IS_IN_DFS in response to a tree connect, cifs_build_path_to_root() will return a pathname which includes the tree name. This causes problems with cifs_get_root() which separates each component and does a lookup for each component of the path.

We encountered a problem with dfs shares hosted by a Netapp. when connecting to nodes pointed to by the DFS share. The tree connect for these nodes return SMB_SHARE_IS_IN_DFS even after the DFS node is resolved and the node returned doesn't contain a DFS share. Other servers(tested with MS Win2012 R2) do not and hence do not face this problem. A workaround for Netapp servers is to mount with the nodfs flag.
The return flag results in cifs_build_path_to_root() using the tree name in building the path which is then split into its components and individual lookup done for each component in cifs_get_root(). The first component of the path in this case is the hostname which results in object not found errors.

We have tested this patch both on our internal test servers as well as the user's own servers and can confirm that it fixes the problem.

---
 fs/cifs/cifsfs.c    | 2 +-
 fs/cifs/cifsproto.h | 3 ++-
 fs/cifs/connect.c   | 3 ++-
 fs/cifs/dir.c       | 4 ++--
 4 files changed, 7 insertions(+), 5 deletions(-)
fs/cifs/cifsfs.c +1 -1
index 6bbec5e..b6f57dd 100644
@@ -610,7 +610,7 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
 	char sep;
 
 	full_path = cifs_build_path_to_root(vol, cifs_sb,
-					    cifs_sb_master_tcon(cifs_sb));
+				cifs_sb_master_tcon(cifs_sb), 0);
 	if (full_path == NULL)
 		return ERR_PTR(-ENOMEM);
 
fs/cifs/cifsproto.h +2 -1
index 1243bd3..52c307b 100644
@@ -63,7 +63,8 @@ extern void exit_cifs_spnego(void);
 extern char *build_path_from_dentry(struct dentry *);
 extern char *cifs_build_path_to_root(struct smb_vol *vol,
 				     struct cifs_sb_info *cifs_sb,
-				     struct cifs_tcon *tcon);
+				     struct cifs_tcon *tcon,
+				     int add_treename);
 extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
 extern char *cifs_compose_mount_options(const char *sb_mountdata,
 		const char *fullpath, const struct dfs_info3_param *ref,
fs/cifs/connect.c +2 -1
index 9878943..afca9ee 100644
@@ -3649,7 +3649,8 @@ remote_path_check:
 		/*
 		 * cifs_build_path_to_root works only when we have a valid tcon
 		 */
-		full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon);
+		full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon,
+					tcon->Flags & SMB_SHARE_IS_IN_DFS);
 		if (full_path == NULL) {
 			rc = -ENOMEM;
 			goto mount_fail_check;
fs/cifs/dir.c +2 -2
index 4716c54..4c0c62c 100644
@@ -47,7 +47,7 @@ renew_parental_timestamps(struct dentry *direntry)
 
 char *
 cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
-			struct cifs_tcon *tcon)
+			struct cifs_tcon *tcon, int add_treename)
 {
 	int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
 	int dfsplen;
@@ -59,7 +59,7 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
 		return full_path;
 	}
 
-	if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
+	if (add_treename)
 		dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
 	else
 		dfsplen = 0;
Signature · 1 line
2.5.5

A message that is not in the archive (sent off-list or not yet received): 1473260003-5271-1-git-send-email-sprabhu-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw

Hi Sachin,

As you said, patch is similar to what I proposed few month ago. There's only one thing that bothers me. cifs_build_path_to_root() has this bit before the DFS test:

	/* if no prefix path, simply set path to the root of share to "" */
	if (pplen == 0) {
		full_path = kzalloc(1, GFP_KERNEL);
		return full_path;
	}

I think it should be dropped. It was already inconsistent because if the share was in a DFS without a prepath it would have returned an empty string instead of a path with the tree name prefix.

I can send a patch after yours to correct that you think it should be in a separate commit.

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, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)

A message that is not in the archive (sent off-list or not yet received): mpsmvjir7hx.fsf-IBi9RG/[email protected]

#4 lore raw
Quoted 21 lines · Aurélien Aptel

Hi Sachin,

As you said, patch is similar to what I proposed few month ago. There's
only one thing that bothers me. cifs_build_path_to_root() has this bit
before the DFS test:

	/* if no prefix path, simply set path to the root of share to
"" */
	if (pplen == 0) {
		full_path = kzalloc(1, GFP_KERNEL);
		return full_path;
	}

I think it should be dropped. It was already inconsistent because if the
share was in a DFS without a prepath it would have returned an empty string instead of a path with the tree name prefix.

Quoted 6 lines

I can send a patch after yours to correct that you think it should be in
a separate commit.

Cheers,

I suspect that is because the root of the share cannot be a DFS mount. Maybe Steve can confirm it.

Sachin Prabhu

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

What is the status on this?

If we explicitely ask for a tree name prefix via the new parameter, we should always get it. It should not return an empty string if there is no prepath.

Quoted 2 lines · Sachin Prabhu

I suspect that is because the root of the share cannot be a DFS mount. Maybe Steve can confirm it.

So that means we can safely remove that early return, IIUC.

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, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)

A message that is not in the archive (sent off-list or not yet received): mpswphl3c7r.fsf-IBi9RG/[email protected]

#8 lore raw
Quoted 8 lines · Aurélien Aptel

What is the status on this?

If we explicitely ask for a tree name prefix via the new parameter, we
should always get it. It should not return an empty string if there is
no prepath.

Quoted 8 lines
Quoted 4 lines · Sachin Prabhu

I suspect that is because the root of the share cannot be a DFS mount.
Maybe Steve can confirm it.

So that means we can safely remove that early return, IIUC.

Aurelien,

I think Steve had requested for a reproducer for this issue. The only place I've encountered this was with Netapp servers. Do you have a reproder which works with Samba or Windows servers?

Sachin Prabhu

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw
Quoted 3 lines · Sachin Prabhu

I think Steve had requested for a reproducer for this issue. The only place I've encountered this was with Netapp servers. Do you have a reproder which works with Samba or Windows servers?

The reproducer was for Samba but the root cause was something different (later fixed by your last DFS fix). The thing I used to reproduce it doesn't reproduce it anymore.

I have found that the tree name prefix is needed, at least when mounting. I guess Steve already knew this but it wasn't obvious for me so I'm sharing it.

When mounting //server/dfsroot/target with 'target' linking to //server/dfstarget

With tree name prefixed:

=> Trans2 Request, QUERY_PATH_INFO, Query File All Info, Path: //10.160.64.222/dfsroot/target <= Trans2 Response, QUERY_PATH_INFO, Error: STATUS_PATH_NOT_COVERED

Without tree name prefixed:

=> Trans2 Request, QUERY_PATH_INFO, Query File All Info, Path: /target <= Trans2 Response, QUERY_PATH_INFO, Error: STATUS_OBJECT_NAME_NOT_FOUND

PATH_NOT_COVERED is mapped to EREMOTE whereas OBJECT_NAME_NOT_FOUND is mapped to ENOENT.

So *not* prefixing with the tree name actually breaks mounting a path containing a DFS link in its components. Which is the *opposite* of what I initially thought. I did not analyze the problem and traces enough, I'm sorry.

So if we merge this patch, we have to be careful about when to not prefix the tree name.

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, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)

A message that is not in the archive (sent off-list or not yet received): mpsk2df2yu9.fsf-IBi9RG/[email protected]

#12 lore raw
Quoted 37 lines · Aurélien Aptel
Quoted 5 lines · Sachin Prabhu

I think Steve had requested for a reproducer for this issue. The only
place I've encountered this was with Netapp servers. Do you have a reproder which works with Samba or Windows servers?

The reproducer was for Samba but the root cause was something different
(later fixed by your last DFS fix). The thing I used to reproduce it doesn't reproduce it anymore.

I have found that the tree name prefix is needed, at least when mounting. I guess Steve already knew this but it wasn't obvious for me
so I'm sharing it.

When mounting //server/dfsroot/target with 'target' linking to //server/dfstarget

With tree name prefixed:

=> Trans2 Request, QUERY_PATH_INFO, Query File All Info, Path:
//10.160.64.222/dfsroot/target
<= Trans2 Response, QUERY_PATH_INFO, Error: STATUS_PATH_NOT_COVERED

Without tree name prefixed:

=> Trans2 Request, QUERY_PATH_INFO, Query File All Info, Path:
/target
<= Trans2 Response, QUERY_PATH_INFO, Error:
STATUS_OBJECT_NAME_NOT_FOUND

PATH_NOT_COVERED is mapped to EREMOTE whereas OBJECT_NAME_NOT_FOUND is
mapped to ENOENT.

Quoted 9 lines

So *not* prefixing with the tree name actually breaks mounting a path containing a DFS link in its components. Which is the *opposite* of what
I initially thought. I did not analyze the problem and traces enough, I'm sorry.

So if we merge this patch, we have to be careful about when to not prefix the tree name.

Hello Aurelien,

The patch maintains current behaviour except for the call to cifs_build_path_to_root in cifs_get_root() where the logic expects the full path to the file/directory without the hostname as it iterates over each component of the path. This fixes a behaviour seen with Netapp where the tcon connect returns a SMB_SHARE_IS_IN_DFS even though there doesn't isn't a DFS share in the path.

Sachin Prabhu

#13 lore raw
In reply to a message not in the archive
Quoted 36 lines · Sachin Prabhu

When a server returns the optional flag SMB_SHARE_IS_IN_DFS in response to a tree connect, cifs_build_path_to_root() will return a pathname which includes the tree name. This causes problems with cifs_get_root() which separates each component and does a lookup for each component of the path.

We encountered a problem with dfs shares hosted by a Netapp. when connecting to nodes pointed to by the DFS share. The tree connect for these nodes return SMB_SHARE_IS_IN_DFS even after the DFS node is resolved and the node returned doesn't contain a DFS share. Other servers(tested with MS Win2012 R2) do not and hence do not face this problem. A workaround for Netapp servers is to mount with the nodfs flag.
The return flag results in cifs_build_path_to_root() using the tree name in building the path which is then split into its components and individual lookup done for each component in cifs_get_root(). The first component of the path in this case is the hostname which results in object not found errors.

We have tested this patch both on our internal test servers as well as the user's own servers and can confirm that it fixes the problem.

---
 fs/cifs/cifsfs.c    | 2 +-
 fs/cifs/cifsproto.h | 3 ++-
 fs/cifs/connect.c   | 3 ++-
 fs/cifs/dir.c       | 4 ++--
 4 files changed, 7 insertions(+), 5 deletions(-)
fs/cifs/cifsfs.c +0 -0
index 6bbec5e..b6f57dd 100644

fs/cifs/cifsfs.c cifs_get_root(struct smb_vol *vol, struct super_block *sb) · line 613

Quoted 5 lines
fs/cifs/cifsfs.c +1 -1
@@ -610,7 +610,7 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
 	char sep;
 
 	full_path = cifs_build_path_to_root(vol, cifs_sb,
-					    cifs_sb_master_tcon(cifs_sb));
+				cifs_sb_master_tcon(cifs_sb), 0);

Ok, sorry if I'm being dense here, but I haven't been following the various patches in this area closely...

cifs_get_root basically does a lookup of the dentry that we want to be the root of the mount on the client.

You're saying here that we need to _not_ send a DFS style path query when doing that lookup, even though the server is setting the SMB_SHARE_IS_IN_DFS flag in the tcon response?

Is this just a workaround for misbehaving servers, or is the client actually doing this wrong?

Quoted 53 lines
fs/cifs/cifsfs.c +0 -0
 	if (full_path == NULL)
 		return ERR_PTR(-ENOMEM);
 
fs/cifs/cifsproto.h +2 -1
index 1243bd3..52c307b 100644
@@ -63,7 +63,8 @@ extern void exit_cifs_spnego(void);
 extern char *build_path_from_dentry(struct dentry *);
 extern char *cifs_build_path_to_root(struct smb_vol *vol,
 				     struct cifs_sb_info *cifs_sb,
-				     struct cifs_tcon *tcon);
+				     struct cifs_tcon *tcon,
+				     int add_treename);
 extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
 extern char *cifs_compose_mount_options(const char *sb_mountdata,
 		const char *fullpath, const struct dfs_info3_param *ref,
fs/cifs/connect.c +2 -1
index 9878943..afca9ee 100644
@@ -3649,7 +3649,8 @@ remote_path_check:
 		/*
 		 * cifs_build_path_to_root works only when we have a valid tcon
 		 */
-		full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon);
+		full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon,
+					tcon->Flags & SMB_SHARE_IS_IN_DFS);
 		if (full_path == NULL) {
 			rc = -ENOMEM;
 			goto mount_fail_check;
fs/cifs/dir.c +2 -2
index 4716c54..4c0c62c 100644
@@ -47,7 +47,7 @@ renew_parental_timestamps(struct dentry *direntry)
 
 char *
 cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
-			struct cifs_tcon *tcon)
+			struct cifs_tcon *tcon, int add_treename)
 {
 	int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
 	int dfsplen;
@@ -59,7 +59,7 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
 		return full_path;
 	}
 
-	if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
+	if (add_treename)
 		dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
 	else
 		dfsplen = 0;
Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by
#15 lore raw
Quoted 50 lines · Jeff Layton
Quoted 37 lines · Sachin Prabhu

When a server returns the optional flag SMB_SHARE_IS_IN_DFS in response to a tree connect, cifs_build_path_to_root() will return a pathname which includes the tree name. This causes problems with cifs_get_root() which separates each component and does a lookup for each component of the path.

We encountered a problem with dfs shares hosted by a Netapp. when connecting to nodes pointed to by the DFS share. The tree connect for these nodes return SMB_SHARE_IS_IN_DFS even after the DFS node is resolved and the node returned doesn't contain a DFS share. Other servers(tested with MS Win2012 R2) do not and hence do not face this problem. A workaround for Netapp servers is to mount with the nodfs flag.
The return flag results in cifs_build_path_to_root() using the tree name in building the path which is then split into its components and individual lookup done for each component in cifs_get_root(). The first component of the path in this case is the hostname which results in object not found errors.

We have tested this patch both on our internal test servers as well as the user's own servers and can confirm that it fixes the problem.

---
 fs/cifs/cifsfs.c    | 2 +-
 fs/cifs/cifsproto.h | 3 ++-
 fs/cifs/connect.c   | 3 ++-
 fs/cifs/dir.c       | 4 ++--
 4 files changed, 7 insertions(+), 5 deletions(-)
fs/cifs/cifsfs.c +0 -0
index 6bbec5e..b6f57dd 100644

fs/cifs/cifsfs.c cifs_get_root(struct smb_vol *vol, struct super_block *sb) · line 613

Quoted 5 lines
fs/cifs/cifsfs.c +1 -1
@@ -610,7 +610,7 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
 	char sep;
 
 	full_path = cifs_build_path_to_root(vol, cifs_sb,
-					    cifs_sb_master_tcon(cifs_sb));
+				cifs_sb_master_tcon(cifs_sb), 0);

Ok, sorry if I'm being dense here, but I haven't been following the various patches in this area closely...

cifs_get_root basically does a lookup of the dentry that we want to be the root of the mount on the client.

Quoted 7 lines

You're saying here that we need to _not_ send a DFS style path query when doing that lookup, even though the server is setting the SMB_SHARE_IS_IN_DFS flag in the tcon response?

Is this just a workaround for misbehaving servers, or is the client actually doing this wrong?

Doh! I just needed another cup of coffee...

I get it now. We build the path to root, and then try to issue a lookup on each component (a'la lookup_one_len_unlocked). That fails in this case because we're trying to lookup the DFS hostname component like we would a normal path component.

I think is this a reasonable fix for now. That said, this whole Rube Goldberg contraption could really use a serious re-think, IMO...

You can add:

Quoted 55 lines
Quoted 54 lines
fs/cifs/cifsfs.c +0 -0
 	if (full_path == NULL)
 		return ERR_PTR(-ENOMEM);
 
fs/cifs/cifsproto.h +2 -1
index 1243bd3..52c307b 100644
@@ -63,7 +63,8 @@ extern void exit_cifs_spnego(void);
 extern char *build_path_from_dentry(struct dentry *);
 extern char *cifs_build_path_to_root(struct smb_vol *vol,
 				     struct cifs_sb_info *cifs_sb,
-				     struct cifs_tcon *tcon);
+				     struct cifs_tcon *tcon,
+				     int add_treename);
 extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
 extern char *cifs_compose_mount_options(const char *sb_mountdata,
 		const char *fullpath, const struct dfs_info3_param *ref,
fs/cifs/connect.c +2 -1
index 9878943..afca9ee 100644
@@ -3649,7 +3649,8 @@ remote_path_check:
 		/*
 		 * cifs_build_path_to_root works only when we have a valid tcon
 		 */
-		full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon);
+		full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon,
+					tcon->Flags & SMB_SHARE_IS_IN_DFS);
 		if (full_path == NULL) {
 			rc = -ENOMEM;
 			goto mount_fail_check;
fs/cifs/dir.c +2 -2
index 4716c54..4c0c62c 100644
@@ -47,7 +47,7 @@ renew_parental_timestamps(struct dentry *direntry)
 
 char *
 cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
-			struct cifs_tcon *tcon)
+			struct cifs_tcon *tcon, int add_treename)
 {
 	int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
 	int dfsplen;
@@ -59,7 +59,7 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
 		return full_path;
 	}
 
-	if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
+	if (add_treename)
 		dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
 	else
 		dfsplen = 0;

A message that is not in the archive (sent off-list or not yet received): [email protected]

#17 lore raw
Quoted 3 lines · Jeff Layton

On Tue, 2016-12-13 at 07:33 -0500, Jeff Layton wrote:
I think is this a reasonable fix for now. That said, this whole Rube Goldberg contraption could really use a serious re-think, IMO...

Indeed. I find cifs_mount() in particular really hard to follow.

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, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)