Skip to contentSkip to conversation

cifs: fix handling of unc= and prefixpath= mount options

PATCH In review Jeff Layton 3 participants 18 messages Nov 16, 2012 – Dec 3, 2012 9 messages not in the archive

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

cover cifs: fix handling of unc= and prefixpath= mount options

This patch fixes up a number of problems with the handling of the unc= and prefixpath= mount options. In addition to cleaning up some really awful address parsing code, it fixes a couple of potential memory leaks and gets the unc= and prefixpath= mount options ready to be deprecated, and sets us up to be able to just use the contents of the device string instead.

This should also fix a couple of other problems:

- mounting with a unc= option that contains forward slashes as delimiters should now work. This should fix the problem that Frederico Sauter reported last week.

- a regression reported by Alex Miller should also be fixed[1]. When the new mount option parser was merged, the unc= option was inadvertantly made mandatory. Prior to that, the code would try to use the contents of the device string to construct a UNC. The final patch in this series reinstates that behavior and should allow a user to mount without the mount helper

I've tested mounting in several ways and this patchset seems to work as expected. It could use more testing, so I'd suggest allowing it to soak in -next for a bit with an eye toward merging it in 3.8.

[1]: https://bugzilla.kernel.org/show_bug.cgi?id=50631

Jeff Layton (6):
cifs: make error on lack of a unc= option more explicit
cifs: get rid of smb_vol->UNCip and smb_vol->port
cifs: make convert_delimiter use strchr instead of open-coding it
cifs: clean up handling of unc= option
cifs: fix up handling of prefixpath= option
cifs: parse the device name into UNC and prepath

 fs/cifs/cifsglob.h  |  16 +---
 fs/cifs/cifsproto.h |   4 +-
 fs/cifs/connect.c   | 260 ++++++++++++++++++++++++++++------------------------
 fs/cifs/netmisc.c   |  14 +--
 fs/cifs/smb1ops.c   |   5 +-
 fs/cifs/smb2ops.c   |   2 +-
 6 files changed, 149 insertions(+), 152 deletions(-)
Signature · 1 line
1.7.11.7
#2 lore raw

PATCH 1/6 cifs: make error on lack of a unc= option more explicit

In reply to a message not in the archive

Error out with a clear error message if there is no unc= option. The existing code doesn't handle this in a clear fashion, and the check for a UNCip option with no UNC string is just plain wrong.

Later, we'll fix the code to not require a unc= option, but for now we need this to at least clarify why people are getting errors about DFS parsing. With this change we can also get rid of some later NULL pointer checks since we know the UNC and UNCip will never be NULL there.

---
 fs/cifs/connect.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
fs/cifs/connect.c +5 -14
index 5c670b9..b9849ac 100644
@@ -1799,6 +1799,11 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 		goto cifs_parse_mount_err;
 	}
 #endif
+	if (!vol->UNC) {
+		cERROR(1, "CIFS mount error: No UNC path (e.g. -o "
+			"unc=\\\\192.168.1.100\\public) specified");
+		goto cifs_parse_mount_err;
+	}
 
 	if (vol->UNCip == NULL)
 		vol->UNCip = &vol->UNC[2];
@@ -2070,17 +2075,6 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
 			rc = -EINVAL;
 			goto out_err;
 		}
-	} else if (volume_info->UNCip) {
-		/* BB using ip addr as tcp_ses name to connect to the
-		   DFS root below */
-		cERROR(1, "Connecting to DFS root not implemented yet");
-		rc = -EINVAL;
-		goto out_err;
-	} else /* which tcp_sess DFS root would we conect to */ {
-		cERROR(1, "CIFS mount error: No UNC path (e.g. -o "
-			"unc=//192.168.1.100/public) specified");
-		rc = -EINVAL;
-		goto out_err;
 	}
 
 	/* see if we already have a matching tcp_ses */
@@ -2736,9 +2730,6 @@ cifs_match_super(struct super_block *sb, void *data)
 
 	volume_info = mnt_data->vol;
 
-	if (!volume_info->UNCip || !volume_info->UNC)
-		goto out;
-
 	rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
 				volume_info->UNCip,
 				strlen(volume_info->UNCip),
Signature · 1 line
1.7.11.7
#8 lore raw

PATCH 2/6 cifs: get rid of smb_vol->UNCip and smb_vol->port

In reply to a message not in the archive

Passing this around as a string is contorted and painful. Instead, just convert these to a sockaddr as soon as possible, since that's how we're going to work with it later anyway.

---
 fs/cifs/cifsglob.h  |  3 +-
 fs/cifs/cifsproto.h |  4 +--
 fs/cifs/connect.c   | 91 +++++++++++++++++++----------------------------------
 fs/cifs/netmisc.c   | 14 +--------
 4 files changed, 36 insertions(+), 76 deletions(-)
fs/cifs/cifsglob.h +1 -2
index f5af252..b141c90 100644
@@ -396,7 +396,6 @@ struct smb_vol {
 	char *password;
 	char *domainname;
 	char *UNC;
-	char *UNCip;
 	char *iocharset;  /* local code page for mapping to and from Unicode */
 	char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
 	char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
@@ -444,11 +443,11 @@ struct smb_vol {
 	unsigned int rsize;
 	unsigned int wsize;
 	bool sockopt_tcp_nodelay:1;
-	unsigned short int port;
 	unsigned long actimeo; /* attribute cache timeout (jiffies) */
 	struct smb_version_operations *ops;
 	struct smb_version_values *vals;
 	char *prepath;
+	struct sockaddr_storage dstaddr; /* destination address */
 	struct sockaddr_storage srcaddr; /* allow binding to a local IP */
 	struct nls_table *local_nls;
 };
fs/cifs/cifsproto.h +1 -3
index 2d2ae69..a69cace 100644
@@ -106,9 +106,7 @@ extern unsigned int smbCalcSize(void *buf);
 extern int decode_negTokenInit(unsigned char *security_blob, int length,
 			struct TCP_Server_Info *server);
 extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
-extern int cifs_set_port(struct sockaddr *addr, const unsigned short int port);
-extern int cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len,
-				const unsigned short int port);
+extern void cifs_set_port(struct sockaddr *addr, const unsigned short int port);
 extern int map_smb_to_linux_error(char *buf, bool logErr);
 extern void header_assemble(struct smb_hdr *, char /* command */ ,
 			    const struct cifs_tcon *, int /* length of
fs/cifs/connect.c +33 -58

162 lines not on this page · raw message

fs/cifs/netmisc.c +1 -13
index d5ce9e2..a82bc51 100644
@@ -204,7 +204,7 @@ cifs_convert_address(struct sockaddr *dst, const char *src, int len)
 	return rc;
 }
 
-int
+void
 cifs_set_port(struct sockaddr *addr, const unsigned short int port)
 {
 	switch (addr->sa_family) {
@@ -214,19 +214,7 @@ cifs_set_port(struct sockaddr *addr, const unsigned short int port)
 	case AF_INET6:
 		((struct sockaddr_in6 *)addr)->sin6_port = htons(port);
 		break;
-	default:
-		return 0;
 	}
-	return 1;
-}
-
-int
-cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len,
-		   const unsigned short int port)
-{
-	if (!cifs_convert_address(dst, src, len))
-		return 0;
-	return cifs_set_port(dst, port);
 }
 
 /*****************************************************************************
Signature · 1 line
1.7.11.7
#11 lore raw

PATCH 3/6 cifs: make convert_delimiter use strchr instead of open-coding it

In reply to a message not in the archive

Take advantage of accelerated strchr() on arches that support it.

Also, no caller ever passes in a NULL pointer. Get rid of the unneeded NULL pointer check.

---
 fs/cifs/cifsglob.h | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
fs/cifs/cifsglob.h +4 -9
index b141c90..414d93b 100644
@@ -1066,21 +1066,16 @@ static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
 static inline void
 convert_delimiter(char *path, char delim)
 {
-	int i;
-	char old_delim;
-
-	if (path == NULL)
-		return;
+	char old_delim, *pos;
 
 	if (delim == '/')
 		old_delim = '\\';
 	else
 		old_delim = '/';
 
-	for (i = 0; path[i] != '\0'; i++) {
-		if (path[i] == old_delim)
-			path[i] = delim;
-	}
+	pos = path;
+	while ((pos = strchr(pos, old_delim)))
+		*pos = delim;
 }
 
 static inline char *
Signature · 1 line
1.7.11.7
#14 lore raw

PATCH 4/6 cifs: clean up handling of unc= option

In reply to a message not in the archive

Make sure we free any existing memory allocated for vol->UNC, just in case someone passes in multiple unc= options.

Get rid of the check for too long a UNC. The check for >300 bytes seems arbitrary. We later copy this into the tcon->treeName, for instance and it's a lot shorter than 300 bytes.

Eliminate an extra kmalloc and copy as well. Just set the vol->UNC directly with the contents of match_strdup.

Establish that the UNC should be stored with '\\' delimiters. Use convert_delimiter to change it in place in the vol->UNC.

Finally, move the check for a malformed UNC into cifs_parse_mount_options so we can catch that situation earlier.

---
 fs/cifs/connect.c | 39 ++++++++++++---------------------------
 1 file changed, 12 insertions(+), 27 deletions(-)
fs/cifs/connect.c +12 -27
index 7d95206..89f426f 100644
@@ -1557,29 +1557,15 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 			got_ip = true;
 			break;
 		case Opt_unc:
-			string = match_strdup(args);
-			if (string == NULL)
+			kfree(vol->UNC);
+			vol->UNC = match_strdup(args);
+			if (vol->UNC == NULL)
 				goto out_nomem;
 
-			temp_len = strnlen(string, 300);
-			if (temp_len  == 300) {
-				printk(KERN_WARNING "CIFS: UNC name too long\n");
-				goto cifs_parse_mount_err;
-			}
-
-			vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
-			if (vol->UNC == NULL) {
-				printk(KERN_WARNING "CIFS: no memory for UNC\n");
-				goto cifs_parse_mount_err;
-			}
-			strcpy(vol->UNC, string);
-
-			if (strncmp(string, "//", 2) == 0) {
-				vol->UNC[0] = '\\';
-				vol->UNC[1] = '\\';
-			} else if (strncmp(string, "\\\\", 2) != 0) {
+			convert_delimiter(vol->UNC, '\\');
+			if (vol->UNC[0] != '\\' || vol->UNC[1] != '\\') {
 				printk(KERN_WARNING "CIFS: UNC Path does not "
-						    "begin with // or \\\\\n");
+						"begin with // or \\\\\n");
 				goto cifs_parse_mount_err;
 			}
 
@@ -1804,6 +1790,12 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 		goto cifs_parse_mount_err;
 	}
 
+	/* make sure UNC has a share name */
+	if (!strchr(vol->UNC + 3, '\\')) {
+		cERROR(1, "Malformed UNC. Unable to find share name.");
+		goto cifs_parse_mount_err;
+	}
+
 	if (!got_ip) {
 		/* No ip= option specified? Try to get it from UNC */
 		if (!cifs_convert_address(dstaddr, &vol->UNC[2],
@@ -2577,13 +2569,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)
 		}
 	}
 
-	if (strchr(volume_info->UNC + 3, '\\') == NULL
-	    && strchr(volume_info->UNC + 3, '/') == NULL) {
-		cERROR(1, "Missing share name");
-		rc = -ENODEV;
-		goto out_fail;
-	}
-
 	/*
 	 * BB Do we need to wrap session_mutex around this TCon call and Unix
 	 * SetFS as we do on SessSetup and reconnect?
Signature · 1 line
1.7.11.7
#17 lore raw

PATCH 5/6 cifs: fix up handling of prefixpath= option

In reply to a message not in the archive

Currently the code takes care to ensure that the prefixpath has a leading '/' delimiter. What if someone passes us a prefixpath with a leading '\\' instead? The code doesn't properly handle that currently AFAICS.

Let's just change the code to skip over any leading delimiter character when copying the prepath. Then, fix up the users of the prepath option to prefix it with the correct delimiter when they use it.

Also, there's no need to limit the length of the prefixpath to 1k. If the server can handle it, why bother forbidding it?

---
 fs/cifs/connect.c | 34 +++++++++-------------------------
 fs/cifs/smb1ops.c |  5 +++--
 fs/cifs/smb2ops.c |  2 +-
 3 files changed, 13 insertions(+), 28 deletions(-)
fs/cifs/connect.c +9 -25
index 89f426f..b1f352a 100644
@@ -1603,31 +1603,14 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 			}
 			break;
 		case Opt_prefixpath:
-			string = match_strdup(args);
-			if (string == NULL)
-				goto out_nomem;
-
-			temp_len = strnlen(string, 1024);
-			if (string[0] != '/')
-				temp_len++; /* missing leading slash */
-			if (temp_len > 1024) {
-				printk(KERN_WARNING "CIFS: prefix too long\n");
-				goto cifs_parse_mount_err;
-			}
-
-			vol->prepath = kmalloc(temp_len+1, GFP_KERNEL);
-			if (vol->prepath == NULL) {
-				printk(KERN_WARNING "CIFS: no memory "
-						    "for path prefix\n");
-				goto cifs_parse_mount_err;
-			}
-
-			if (string[0] != '/') {
-				vol->prepath[0] = '/';
-				strcpy(vol->prepath+1, string);
-			} else
-				strcpy(vol->prepath, string);
+			/* skip over any leading delimiter */
+			if (*args[0].from == '/' || *args[0].from == '\\')
+				args[0].from++;
 
+			kfree(vol->prepath);
+			vol->prepath = match_strdup(args);
+			if (vol->prepath == NULL)
+				goto out_nomem;
 			break;
 		case Opt_iocharset:
 			string = match_strdup(args);
@@ -3238,7 +3221,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
 		const struct cifs_sb_info *cifs_sb)
 {
 	char *full_path, *pos;
-	unsigned int pplen = vol->prepath ? strlen(vol->prepath) : 0;
+	unsigned int pplen = vol->prepath ? strlen(vol->prepath) + 1: 0;
 	unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
 
 	full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
@@ -3249,6 +3232,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
 	pos = full_path + unc_len;
 
 	if (pplen) {
+		*pos++ = CIFS_DIR_SEP(cifs_sb);
 		strncpy(pos, vol->prepath, pplen);
 		pos += pplen;
 	}
fs/cifs/smb1ops.c +3 -2
index 56cc4be..50e9613 100644
@@ -579,7 +579,7 @@ static char *
 cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
 			struct cifs_tcon *tcon)
 {
-	int pplen = vol->prepath ? strlen(vol->prepath) : 0;
+	int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
 	int dfsplen;
 	char *full_path = NULL;
 
@@ -600,7 +600,8 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
 
 	if (dfsplen)
 		strncpy(full_path, tcon->treeName, dfsplen);
-	strncpy(full_path + dfsplen, vol->prepath, pplen);
+	full_path[dfsplen] = CIFS_DIR_SEP(cifs_sb);
+	strncpy(full_path + dfsplen + 1, vol->prepath, pplen);
 	convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
 	full_path[dfsplen + pplen] = 0; /* add trailing null */
 	return full_path;
fs/cifs/smb2ops.c +1 -1
index 4d9dbe0..1baa82d 100644
@@ -266,7 +266,7 @@ static char *
 smb2_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
 			struct cifs_tcon *tcon)
 {
-	int pplen = vol->prepath ? strlen(vol->prepath) : 0;
+	int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
 	char *full_path = NULL;
 
 	/* if no prefix path, simply set path to the root of share to "" */
Signature · 1 line
1.7.11.7
#21 lore raw

PATCH 6/6 cifs: parse the device name into UNC and prepath

In reply to a message not in the archive

This should fix a regression that was introduced when the new mount option parser went in. Also, when the unc= and prefixpath= options are provided, check their values against the ones we parsed from the device string. If they differ, then throw a warning that tells the user that we're using the values from the unc= option for now, but that that will change in 3.10.

---
 fs/cifs/connect.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 88 insertions(+), 7 deletions(-)
fs/cifs/connect.c +88 -7
index b1f352a..b9f3dd7 100644
@@ -1090,6 +1090,52 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol)
 	return 0;
 }
 
+/*
+ * Parse a devname into substrings and populate the vol->UNC and vol->prepath
+ * fields with the result. Returns 0 on success and an error otherwise.
+ */
+static int
+cifs_parse_devname(const char *devname, struct smb_vol *vol)
+{
+	char *pos;
+	const char *delims = "/\\";
+	size_t len;
+
+	/* make sure we have a valid UNC double delimiter prefix */
+	len = strspn(devname, delims);
+	if (len != 2)
+		return -EINVAL;
+
+	/* find delimiter between host and sharename */
+	pos = strpbrk(devname + 2, delims);
+	if (!pos)
+		return -EINVAL;
+
+	/* skip past delimiter */
+	++pos;
+
+	/* now go until next delimiter or end of string */
+	len = strcspn(pos, delims);
+
+	/* move "pos" up to delimiter or NULL */
+	pos += len;
+	vol->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
+	if (!vol->UNC)
+		return -ENOMEM;
+
+	convert_delimiter(vol->UNC, '\\');
+
+	/* If pos is NULL, or is a bogus trailing delimiter then no prepath */
+	if (!*pos++ || !*pos)
+		return 0;
+
+	vol->prepath = kstrdup(pos, GFP_KERNEL);
+	if (!vol->prepath)
+		return -ENOMEM;
+
+	return 0;
+}
+
 static int
 cifs_parse_mount_options(const char *mountdata, const char *devname,
 			 struct smb_vol *vol)
@@ -1172,6 +1218,16 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 	vol->backupuid_specified = false; /* no backup intent for a user */
 	vol->backupgid_specified = false; /* no backup intent for a group */
 
+	/*
+	 * For now, we ignore -EINVAL errors under the assumption that the
+	 * unc= and prefixpath= options will be usable.
+	 */
+	if (cifs_parse_devname(devname, vol) == -ENOMEM) {
+		printk(KERN_ERR "CIFS: Unable to allocate memory to parse "
+				"device string.\n");
+		goto out_nomem;
+	}
+
 	while ((data = strsep(&options, separator)) != NULL) {
 		substring_t args[MAX_OPT_ARGS];
 		unsigned long option;
@@ -1557,18 +1613,31 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 			got_ip = true;
 			break;
 		case Opt_unc:
-			kfree(vol->UNC);
+			string = vol->UNC;
 			vol->UNC = match_strdup(args);
-			if (vol->UNC == NULL)
+			if (vol->UNC == NULL) {
+				kfree(string);
 				goto out_nomem;
+			}
 
 			convert_delimiter(vol->UNC, '\\');
 			if (vol->UNC[0] != '\\' || vol->UNC[1] != '\\') {
-				printk(KERN_WARNING "CIFS: UNC Path does not "
+				kfree(string);
+				printk(KERN_ERR "CIFS: UNC Path does not "
 						"begin with // or \\\\\n");
 				goto cifs_parse_mount_err;
 			}
 
+			/* Compare old unc= option to new one */
+			if (!string || strcmp(string, vol->UNC))
+				printk(KERN_WARNING "CIFS: the value of the "
+					"unc= mount option does not match the "
+					"device string. Using the unc= option "
+					"for now. In 3.10, that option will "
+					"be ignored and the contents of the "
+					"device string will be used "
+					"instead. (%s != %s)\n", string,
+					vol->UNC);
 			break;
 		case Opt_domain:
 			string = match_strdup(args);
@@ -1607,10 +1676,22 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 			if (*args[0].from == '/' || *args[0].from == '\\')
 				args[0].from++;
 
-			kfree(vol->prepath);
+			string = vol->prepath;
 			vol->prepath = match_strdup(args);
-			if (vol->prepath == NULL)
+			if (vol->prepath == NULL) {
+				kfree(string);
 				goto out_nomem;
+			}
+			/* Compare old prefixpath= option to new one */
+			if (!string || strcmp(string, vol->prepath))
+				printk(KERN_WARNING "CIFS: the value of the "
+					"prefixpath= mount option does not "
+					"match the device string. Using the "
+					"prefixpath= option for now. In 3.10, "
+					"that option will be ignored and the "
+					"contents of the device string will be "
+					"used instead.(%s != %s)\n", string,
+					vol->prepath);
 			break;
 		case Opt_iocharset:
 			string = match_strdup(args);
@@ -1768,8 +1849,8 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 	}
 #endif
 	if (!vol->UNC) {
-		cERROR(1, "CIFS mount error: No UNC path (e.g. -o "
-			"unc=\\\\192.168.1.100\\public) specified");
+		cERROR(1, "CIFS mount error: No usable UNC path provided in "
+			  "device string or in unc= option!");
 		goto cifs_parse_mount_err;
 	}
 
Signature · 1 line
1.7.11.7
#4 lore raw

Re: [PATCH 1/6] cifs: make error on lack of a unc= option more explicit

In reply to a message not in the archive

2012/11/16 Jeff Layton <[email protected]>:

Quoted 61 lines

Error out with a clear error message if there is no unc= option. The existing code doesn't handle this in a clear fashion, and the check for a UNCip option with no UNC string is just plain wrong.

Later, we'll fix the code to not require a unc= option, but for now we need this to at least clarify why people are getting errors about DFS parsing. With this change we can also get rid of some later NULL pointer checks since we know the UNC and UNCip will never be NULL there.

---
 fs/cifs/connect.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
fs/cifs/connect.c +5 -15
index 5c670b9..b9849ac 100644
@@ -1799,6 +1799,11 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
                goto cifs_parse_mount_err;
        }
 #endif
+       if (!vol->UNC) {
+               cERROR(1, "CIFS mount error: No UNC path (e.g. -o "
+                       "unc=\\\\192.168.1.100\\public) specified");
+               goto cifs_parse_mount_err;
+       }
 
        if (vol->UNCip == NULL)
                vol->UNCip = &vol->UNC[2];
@@ -2070,17 +2075,6 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
                        rc = -EINVAL;
                        goto out_err;
                }
-       } else if (volume_info->UNCip) {
-               /* BB using ip addr as tcp_ses name to connect to the
-                  DFS root below */
-               cERROR(1, "Connecting to DFS root not implemented yet");
-               rc = -EINVAL;
-               goto out_err;
-       } else /* which tcp_sess DFS root would we conect to */ {
-               cERROR(1, "CIFS mount error: No UNC path (e.g. -o "
-                       "unc=//192.168.1.100/public) specified");
-               rc = -EINVAL;
-               goto out_err;
        }
 
        /* see if we already have a matching tcp_ses */
@@ -2736,9 +2730,6 @@ cifs_match_super(struct super_block *sb, void *data)
 
        volume_info = mnt_data->vol;
 
-       if (!volume_info->UNCip || !volume_info->UNC)
-               goto out;
-
        rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
                                volume_info->UNCip,
                                strlen(volume_info->UNCip),
--

1.7.11.7

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#10 lore raw

Re: [PATCH 2/6] cifs: get rid of smb_vol->UNCip and smb_vol->port

In reply to a message not in the archive

2012/11/16 Jeff Layton <[email protected]>:

Quoted 263 lines

Passing this around as a string is contorted and painful. Instead, just convert these to a sockaddr as soon as possible, since that's how we're going to work with it later anyway.

---
 fs/cifs/cifsglob.h  |  3 +-
 fs/cifs/cifsproto.h |  4 +--
 fs/cifs/connect.c   | 91 +++++++++++++++++++----------------------------------
 fs/cifs/netmisc.c   | 14 +--------
 4 files changed, 36 insertions(+), 76 deletions(-)
fs/cifs/cifsglob.h +1 -2
index f5af252..b141c90 100644
@@ -396,7 +396,6 @@ struct smb_vol {
        char *password;
        char *domainname;
        char *UNC;
-       char *UNCip;
        char *iocharset;  /* local code page for mapping to and from Unicode */
        char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
        char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
@@ -444,11 +443,11 @@ struct smb_vol {
        unsigned int rsize;
        unsigned int wsize;
        bool sockopt_tcp_nodelay:1;
-       unsigned short int port;
        unsigned long actimeo; /* attribute cache timeout (jiffies) */
        struct smb_version_operations *ops;
        struct smb_version_values *vals;
        char *prepath;
+       struct sockaddr_storage dstaddr; /* destination address */
        struct sockaddr_storage srcaddr; /* allow binding to a local IP */
        struct nls_table *local_nls;
 };
fs/cifs/cifsproto.h +1 -3
index 2d2ae69..a69cace 100644
@@ -106,9 +106,7 @@ extern unsigned int smbCalcSize(void *buf);
 extern int decode_negTokenInit(unsigned char *security_blob, int length,
                        struct TCP_Server_Info *server);
 extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
-extern int cifs_set_port(struct sockaddr *addr, const unsigned short int port);
-extern int cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len,
-                               const unsigned short int port);
+extern void cifs_set_port(struct sockaddr *addr, const unsigned short int port);
 extern int map_smb_to_linux_error(char *buf, bool logErr);
 extern void header_assemble(struct smb_hdr *, char /* command */ ,
                            const struct cifs_tcon *, int /* length of
fs/cifs/connect.c +33 -58
index b9849ac..7d95206 100644
@@ -1108,6 +1108,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
        char *string = NULL;
        char *tmp_end, *value;
        char delim;
+       bool got_ip = false;
+       unsigned short port = 0;
+       struct sockaddr *dstaddr = (struct sockaddr *)&vol->dstaddr;
 
        separator[0] = ',';
        separator[1] = 0;
@@ -1416,12 +1419,12 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
                        vol->dir_mode = option;
                        break;
                case Opt_port:
-                       if (get_option_ul(args, &option)) {
-                               cERROR(1, "%s: Invalid port value",
-                                       __func__);
+                       if (get_option_ul(args, &option) ||
+                           option > USHRT_MAX) {
+                               cERROR(1, "%s: Invalid port value", __func__);
                                goto cifs_parse_mount_err;
                        }
-                       vol->port = option;
+                       port = (unsigned short)option;
                        break;
                case Opt_rsize:
                        if (get_option_ul(args, &option)) {
@@ -1537,25 +1540,21 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
                        vol->password[j] = '\0';
                        break;
                case Opt_blank_ip:
-                       vol->UNCip = NULL;
+                       /* FIXME: should this be an error instead? */
+                       got_ip = false;
                        break;
                case Opt_ip:
                        string = match_strdup(args);
                        if (string == NULL)
                                goto out_nomem;
 
-                       if (strnlen(string, INET6_ADDRSTRLEN) >
-                                               INET6_ADDRSTRLEN) {
-                               printk(KERN_WARNING "CIFS: ip address "
-                                                   "too long\n");
-                               goto cifs_parse_mount_err;
-                       }
-                       vol->UNCip = kstrdup(string, GFP_KERNEL);
-                       if (!vol->UNCip) {
-                               printk(KERN_WARNING "CIFS: no memory "
-                                                   "for UNC IP\n");
+                       if (!cifs_convert_address(dstaddr, string,
+                                       strlen(string))) {
+                               printk(KERN_ERR "CIFS: bad ip= option (%s).\n",
+                                       string);
                                goto cifs_parse_mount_err;
                        }
+                       got_ip = true;
                        break;
                case Opt_unc:
                        string = match_strdup(args);
@@ -1805,8 +1804,18 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
                goto cifs_parse_mount_err;
        }
 
-       if (vol->UNCip == NULL)
-               vol->UNCip = &vol->UNC[2];
+       if (!got_ip) {
+               /* No ip= option specified? Try to get it from UNC */
+               if (!cifs_convert_address(dstaddr, &vol->UNC[2],
+                                               strlen(&vol->UNC[2]))) {
+                       printk(KERN_ERR "Unable to determine destination "
+                                       "address.\n");
+                       goto cifs_parse_mount_err;
+               }
+       }
+
+       /* set the port that we got earlier */
+       cifs_set_port(dstaddr, port);
 
        if (uid_specified)
                vol->override_uid = override_uid;
@@ -2056,29 +2065,13 @@ static struct TCP_Server_Info *
 cifs_get_tcp_session(struct smb_vol *volume_info)
 {
        struct TCP_Server_Info *tcp_ses = NULL;
-       struct sockaddr_storage addr;
-       struct sockaddr_in *sin_server = (struct sockaddr_in *) &addr;
-       struct sockaddr_in6 *sin_server6 = (struct sockaddr_in6 *) &addr;
+       struct sockaddr *dstaddr = (struct sockaddr *)&volume_info->dstaddr;
        int rc;
 
-       memset(&addr, 0, sizeof(struct sockaddr_storage));
-
-       cFYI(1, "UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip);
-
-       if (volume_info->UNCip && volume_info->UNC) {
-               rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
-                                       volume_info->UNCip,
-                                       strlen(volume_info->UNCip),
-                                       volume_info->port);
-               if (!rc) {
-                       /* we failed translating address */
-                       rc = -EINVAL;
-                       goto out_err;
-               }
-       }
+       cFYI(1, "UNC: %s", volume_info->UNC);
 
        /* see if we already have a matching tcp_ses */
-       tcp_ses = cifs_find_tcp_session((struct sockaddr *)&addr, volume_info);
+       tcp_ses = cifs_find_tcp_session(dstaddr, volume_info);
        if (tcp_ses)
                return tcp_ses;
 
@@ -2134,15 +2127,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
               sizeof(tcp_ses->srcaddr));
        ++tcp_ses->srv_count;
 
-       if (addr.ss_family == AF_INET6) {
-               cFYI(1, "attempting ipv6 connect");
-               /* BB should we allow ipv6 on port 139? */
-               /* other OS never observed in Wild doing 139 with v6 */
-               memcpy(&tcp_ses->dstaddr, sin_server6,
-                      sizeof(struct sockaddr_in6));
-       } else
-               memcpy(&tcp_ses->dstaddr, sin_server,
-                      sizeof(struct sockaddr_in));
+       memcpy(&tcp_ses->dstaddr, dstaddr, sizeof(tcp_ses->dstaddr));
 
        rc = ip_connect(tcp_ses);
        if (rc < 0) {
@@ -2712,11 +2697,9 @@ cifs_match_super(struct super_block *sb, void *data)
        struct cifs_ses *ses;
        struct cifs_tcon *tcon;
        struct tcon_link *tlink;
-       struct sockaddr_storage addr;
+       struct sockaddr *dstaddr;
        int rc = 0;
 
-       memset(&addr, 0, sizeof(struct sockaddr_storage));
-
        spin_lock(&cifs_tcp_ses_lock);
        cifs_sb = CIFS_SB(sb);
        tlink = cifs_get_tlink(cifs_sb_master_tlink(cifs_sb));
@@ -2729,15 +2712,9 @@ cifs_match_super(struct super_block *sb, void *data)
        tcp_srv = ses->server;
 
        volume_info = mnt_data->vol;
+       dstaddr = (struct sockaddr *)&volume_info->dstaddr;
 
-       rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
-                               volume_info->UNCip,
-                               strlen(volume_info->UNCip),
-                               volume_info->port);
-       if (!rc)
-               goto out;
-
-       if (!match_server(tcp_srv, (struct sockaddr *)&addr, volume_info) ||
+       if (!match_server(tcp_srv, dstaddr, volume_info) ||
            !match_session(ses, volume_info) ||
            !match_tcon(tcon, volume_info->UNC)) {
                rc = 0;
@@ -3252,8 +3229,6 @@ cleanup_volume_info_contents(struct smb_vol *volume_info)
 {
        kfree(volume_info->username);
        kzfree(volume_info->password);
-       if (volume_info->UNCip != volume_info->UNC + 2)
-               kfree(volume_info->UNCip);
        kfree(volume_info->UNC);
        kfree(volume_info->domainname);
        kfree(volume_info->iocharset);
fs/cifs/netmisc.c +1 -14
index d5ce9e2..a82bc51 100644
@@ -204,7 +204,7 @@ cifs_convert_address(struct sockaddr *dst, const char *src, int len)
        return rc;
 }
 
-int
+void
 cifs_set_port(struct sockaddr *addr, const unsigned short int port)
 {
        switch (addr->sa_family) {
@@ -214,19 +214,7 @@ cifs_set_port(struct sockaddr *addr, const unsigned short int port)
        case AF_INET6:
                ((struct sockaddr_in6 *)addr)->sin6_port = htons(port);
                break;
-       default:
-               return 0;
        }
-       return 1;
-}
-
-int
-cifs_fill_sockaddr(struct sockaddr *dst, const char *src, int len,
-                  const unsigned short int port)
-{
-       if (!cifs_convert_address(dst, src, len))
-               return 0;
-       return cifs_set_port(dst, port);
 }
 
 /*****************************************************************************
--

1.7.11.7

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#13 lore raw

Re: [PATCH 3/6] cifs: make convert_delimiter use strchr instead of open-coding it

In reply to a message not in the archive

2012/11/16 Jeff Layton <[email protected]>:

Quoted 43 lines

Take advantage of accelerated strchr() on arches that support it.

Also, no caller ever passes in a NULL pointer. Get rid of the unneeded NULL pointer check.

---
 fs/cifs/cifsglob.h | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
fs/cifs/cifsglob.h +4 -10
index b141c90..414d93b 100644
@@ -1066,21 +1066,16 @@ static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
 static inline void
 convert_delimiter(char *path, char delim)
 {
-       int i;
-       char old_delim;
-
-       if (path == NULL)
-               return;
+       char old_delim, *pos;
 
        if (delim == '/')
                old_delim = '\\';
        else
                old_delim = '/';
 
-       for (i = 0; path[i] != '\0'; i++) {
-               if (path[i] == old_delim)
-                       path[i] = delim;
-       }
+       pos = path;
+       while ((pos = strchr(pos, old_delim)))
+               *pos = delim;
 }
 
 static inline char *
--

1.7.11.7

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#16 lore raw

Re: [PATCH 4/6] cifs: clean up handling of unc= option

In reply to a message not in the archive

2012/11/16 Jeff Layton <[email protected]>:

Quoted 91 lines

Make sure we free any existing memory allocated for vol->UNC, just in case someone passes in multiple unc= options.

Get rid of the check for too long a UNC. The check for >300 bytes seems arbitrary. We later copy this into the tcon->treeName, for instance and it's a lot shorter than 300 bytes.

Eliminate an extra kmalloc and copy as well. Just set the vol->UNC directly with the contents of match_strdup.

Establish that the UNC should be stored with '\\' delimiters. Use convert_delimiter to change it in place in the vol->UNC.

Finally, move the check for a malformed UNC into cifs_parse_mount_options so we can catch that situation earlier.

---
 fs/cifs/connect.c | 39 ++++++++++++---------------------------
 1 file changed, 12 insertions(+), 27 deletions(-)
fs/cifs/connect.c +12 -28
index 7d95206..89f426f 100644
@@ -1557,29 +1557,15 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
                        got_ip = true;
                        break;
                case Opt_unc:
-                       string = match_strdup(args);
-                       if (string == NULL)
+                       kfree(vol->UNC);
+                       vol->UNC = match_strdup(args);
+                       if (vol->UNC == NULL)
                                goto out_nomem;
 
-                       temp_len = strnlen(string, 300);
-                       if (temp_len  == 300) {
-                               printk(KERN_WARNING "CIFS: UNC name too long\n");
-                               goto cifs_parse_mount_err;
-                       }
-
-                       vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
-                       if (vol->UNC == NULL) {
-                               printk(KERN_WARNING "CIFS: no memory for UNC\n");
-                               goto cifs_parse_mount_err;
-                       }
-                       strcpy(vol->UNC, string);
-
-                       if (strncmp(string, "//", 2) == 0) {
-                               vol->UNC[0] = '\\';
-                               vol->UNC[1] = '\\';
-                       } else if (strncmp(string, "\\\\", 2) != 0) {
+                       convert_delimiter(vol->UNC, '\\');
+                       if (vol->UNC[0] != '\\' || vol->UNC[1] != '\\') {
                                printk(KERN_WARNING "CIFS: UNC Path does not "
-                                                   "begin with // or \\\\\n");
+                                               "begin with // or \\\\\n");
                                goto cifs_parse_mount_err;
                        }
 
@@ -1804,6 +1790,12 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
                goto cifs_parse_mount_err;
        }
 
+       /* make sure UNC has a share name */
+       if (!strchr(vol->UNC + 3, '\\')) {
+               cERROR(1, "Malformed UNC. Unable to find share name.");
+               goto cifs_parse_mount_err;
+       }
+
        if (!got_ip) {
                /* No ip= option specified? Try to get it from UNC */
                if (!cifs_convert_address(dstaddr, &vol->UNC[2],
@@ -2577,13 +2569,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)
                }
        }
 
-       if (strchr(volume_info->UNC + 3, '\\') == NULL
-           && strchr(volume_info->UNC + 3, '/') == NULL) {
-               cERROR(1, "Missing share name");
-               rc = -ENODEV;
-               goto out_fail;
-       }
-
        /*
         * BB Do we need to wrap session_mutex around this TCon call and Unix
         * SetFS as we do on SessSetup and reconnect?
--

1.7.11.7

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#19 lore raw

Re: [PATCH 5/6] cifs: fix up handling of prefixpath= option

In reply to a message not in the archive

2012/11/16 Jeff Layton <[email protected]>:

Quoted 118 lines

Currently the code takes care to ensure that the prefixpath has a leading '/' delimiter. What if someone passes us a prefixpath with a leading '\\' instead? The code doesn't properly handle that currently AFAICS.

Let's just change the code to skip over any leading delimiter character when copying the prepath. Then, fix up the users of the prepath option to prefix it with the correct delimiter when they use it.

Also, there's no need to limit the length of the prefixpath to 1k. If the server can handle it, why bother forbidding it?

---
 fs/cifs/connect.c | 34 +++++++++-------------------------
 fs/cifs/smb1ops.c |  5 +++--
 fs/cifs/smb2ops.c |  2 +-
 3 files changed, 13 insertions(+), 28 deletions(-)
fs/cifs/connect.c +9 -25
index 89f426f..b1f352a 100644
@@ -1603,31 +1603,14 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
                        }
                        break;
                case Opt_prefixpath:
-                       string = match_strdup(args);
-                       if (string == NULL)
-                               goto out_nomem;
-
-                       temp_len = strnlen(string, 1024);
-                       if (string[0] != '/')
-                               temp_len++; /* missing leading slash */
-                       if (temp_len > 1024) {
-                               printk(KERN_WARNING "CIFS: prefix too long\n");
-                               goto cifs_parse_mount_err;
-                       }
-
-                       vol->prepath = kmalloc(temp_len+1, GFP_KERNEL);
-                       if (vol->prepath == NULL) {
-                               printk(KERN_WARNING "CIFS: no memory "
-                                                   "for path prefix\n");
-                               goto cifs_parse_mount_err;
-                       }
-
-                       if (string[0] != '/') {
-                               vol->prepath[0] = '/';
-                               strcpy(vol->prepath+1, string);
-                       } else
-                               strcpy(vol->prepath, string);
+                       /* skip over any leading delimiter */
+                       if (*args[0].from == '/' || *args[0].from == '\\')
+                               args[0].from++;
 
+                       kfree(vol->prepath);
+                       vol->prepath = match_strdup(args);
+                       if (vol->prepath == NULL)
+                               goto out_nomem;
                        break;
                case Opt_iocharset:
                        string = match_strdup(args);
@@ -3238,7 +3221,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
                const struct cifs_sb_info *cifs_sb)
 {
        char *full_path, *pos;
-       unsigned int pplen = vol->prepath ? strlen(vol->prepath) : 0;
+       unsigned int pplen = vol->prepath ? strlen(vol->prepath) + 1: 0;
        unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
 
        full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
@@ -3249,6 +3232,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
        pos = full_path + unc_len;
 
        if (pplen) {
+               *pos++ = CIFS_DIR_SEP(cifs_sb);
                strncpy(pos, vol->prepath, pplen);
                pos += pplen;
        }
fs/cifs/smb1ops.c +3 -2
index 56cc4be..50e9613 100644
@@ -579,7 +579,7 @@ static char *
 cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
                        struct cifs_tcon *tcon)
 {
-       int pplen = vol->prepath ? strlen(vol->prepath) : 0;
+       int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
        int dfsplen;
        char *full_path = NULL;
 
@@ -600,7 +600,8 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
 
        if (dfsplen)
                strncpy(full_path, tcon->treeName, dfsplen);
-       strncpy(full_path + dfsplen, vol->prepath, pplen);
+       full_path[dfsplen] = CIFS_DIR_SEP(cifs_sb);
+       strncpy(full_path + dfsplen + 1, vol->prepath, pplen);
        convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
        full_path[dfsplen + pplen] = 0; /* add trailing null */
        return full_path;
fs/cifs/smb2ops.c +1 -2
index 4d9dbe0..1baa82d 100644
@@ -266,7 +266,7 @@ static char *
 smb2_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
                        struct cifs_tcon *tcon)
 {
-       int pplen = vol->prepath ? strlen(vol->prepath) : 0;
+       int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
        char *full_path = NULL;
 
        /* if no prefix path, simply set path to the root of share to "" */
--

1.7.11.7

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#23 lore raw

Re: [PATCH 6/6] cifs: parse the device name into UNC and prepath

In reply to a message not in the archive

2012/11/16 Jeff Layton <[email protected]>:

Quoted 108 lines

This should fix a regression that was introduced when the new mount option parser went in. Also, when the unc= and prefixpath= options are provided, check their values against the ones we parsed from the device string. If they differ, then throw a warning that tells the user that we're using the values from the unc= option for now, but that that will change in 3.10.

---
 fs/cifs/connect.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 88 insertions(+), 7 deletions(-)
fs/cifs/connect.c +62 -3
index b1f352a..b9f3dd7 100644
@@ -1090,6 +1090,52 @@ cifs_parse_smb_version(char *value, struct smb_vol *vol)
        return 0;
 }
 
+/*
+ * Parse a devname into substrings and populate the vol->UNC and vol->prepath
+ * fields with the result. Returns 0 on success and an error otherwise.
+ */
+static int
+cifs_parse_devname(const char *devname, struct smb_vol *vol)
+{
+       char *pos;
+       const char *delims = "/\\";
+       size_t len;
+
+       /* make sure we have a valid UNC double delimiter prefix */
+       len = strspn(devname, delims);
+       if (len != 2)
+               return -EINVAL;
+
+       /* find delimiter between host and sharename */
+       pos = strpbrk(devname + 2, delims);
+       if (!pos)
+               return -EINVAL;
+
+       /* skip past delimiter */
+       ++pos;
+
+       /* now go until next delimiter or end of string */
+       len = strcspn(pos, delims);
+
+       /* move "pos" up to delimiter or NULL */
+       pos += len;
+       vol->UNC = kstrndup(devname, pos - devname, GFP_KERNEL);
+       if (!vol->UNC)
+               return -ENOMEM;
+
+       convert_delimiter(vol->UNC, '\\');
+
+       /* If pos is NULL, or is a bogus trailing delimiter then no prepath */
+       if (!*pos++ || !*pos)
+               return 0;
+
+       vol->prepath = kstrdup(pos, GFP_KERNEL);
+       if (!vol->prepath)
+               return -ENOMEM;
+
+       return 0;
+}
+
 static int
 cifs_parse_mount_options(const char *mountdata, const char *devname,
                         struct smb_vol *vol)
@@ -1172,6 +1218,16 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
        vol->backupuid_specified = false; /* no backup intent for a user */
        vol->backupgid_specified = false; /* no backup intent for a group */
 
+       /*
+        * For now, we ignore -EINVAL errors under the assumption that the
+        * unc= and prefixpath= options will be usable.
+        */
+       if (cifs_parse_devname(devname, vol) == -ENOMEM) {
+               printk(KERN_ERR "CIFS: Unable to allocate memory to parse "
+                               "device string.\n");
+               goto out_nomem;
+       }
+
        while ((data = strsep(&options, separator)) != NULL) {
                substring_t args[MAX_OPT_ARGS];
                unsigned long option;
@@ -1557,18 +1613,31 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
                        got_ip = true;
                        break;
                case Opt_unc:
-                       kfree(vol->UNC);
+                       string = vol->UNC;
                        vol->UNC = match_strdup(args);
-                       if (vol->UNC == NULL)
+                       if (vol->UNC == NULL) {
+                               kfree(string);
                                goto out_nomem;
+                       }
 
                        convert_delimiter(vol->UNC, '\\');
                        if (vol->UNC[0] != '\\' || vol->UNC[1] != '\\') {
-                               printk(KERN_WARNING "CIFS: UNC Path does not "
+                               kfree(string);
+                               printk(KERN_ERR "CIFS: UNC Path does not "
                                                "begin with // or \\\\\n");
                                goto cifs_parse_mount_err;
                        }
 

fs/cifs/connect.c cifs_parse_mount_options(const char *mountdata, const char *devname, · line 1640

Quoted 10 lines
fs/cifs/connect.c +10 -0
+                       /* Compare old unc= option to new one */
+                       if (!string || strcmp(string, vol->UNC))
+                               printk(KERN_WARNING "CIFS: the value of the "
+                                       "unc= mount option does not match the "
+                                       "device string. Using the unc= option "
+                                       "for now. In 3.10, that option will "
+                                       "be ignored and the contents of the "
+                                       "device string will be used "
+                                       "instead. (%s != %s)\n", string,
+                                       vol->UNC);

If someone specifies a devname and two unc= options (all are different) so, it will see this message twice?

Quoted 46 lines
fs/cifs/connect.c +16 -5
                        break;
                case Opt_domain:
                        string = match_strdup(args);
@@ -1607,10 +1676,22 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
                        if (*args[0].from == '/' || *args[0].from == '\\')
                                args[0].from++;
 
-                       kfree(vol->prepath);
+                       string = vol->prepath;
                        vol->prepath = match_strdup(args);
-                       if (vol->prepath == NULL)
+                       if (vol->prepath == NULL) {
+                               kfree(string);
                                goto out_nomem;
+                       }
+                       /* Compare old prefixpath= option to new one */
+                       if (!string || strcmp(string, vol->prepath))
+                               printk(KERN_WARNING "CIFS: the value of the "
+                                       "prefixpath= mount option does not "
+                                       "match the device string. Using the "
+                                       "prefixpath= option for now. In 3.10, "
+                                       "that option will be ignored and the "
+                                       "contents of the device string will be "
+                                       "used instead.(%s != %s)\n", string,
+                                       vol->prepath);
                        break;
                case Opt_iocharset:
                        string = match_strdup(args);
@@ -1768,8 +1849,8 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
        }
 #endif
        if (!vol->UNC) {
-               cERROR(1, "CIFS mount error: No UNC path (e.g. -o "
-                       "unc=\\\\192.168.1.100\\public) specified");
+               cERROR(1, "CIFS mount error: No usable UNC path provided in "
+                         "device string or in unc= option!");
                goto cifs_parse_mount_err;
        }
 
--

1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#24 lore raw

[PATCH 7/6] cifs: remove unneeded address argument from cifs_find_tcp_session and match_server

In reply to a message not in the archive

Now that the smb_vol contains the destination sockaddr, there's no need to pass it in separately.

---
 fs/cifs/connect.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
fs/cifs/connect.c +11 -14
index 2602373..60295a4 100644
@@ -2042,9 +2042,10 @@ match_security(struct TCP_Server_Info *server, struct smb_vol *vol)
 	return true;
 }
 
-static int match_server(struct TCP_Server_Info *server, struct sockaddr *addr,
-			 struct smb_vol *vol)
+static int match_server(struct TCP_Server_Info *server, struct smb_vol *vol)
 {
+	struct sockaddr *addr = (struct sockaddr *)&vol->dstaddr;
+
 	if ((server->vals != vol->vals) || (server->ops != vol->ops))
 		return 0;
 
@@ -2065,13 +2066,13 @@ static int match_server(struct TCP_Server_Info *server, struct sockaddr *addr,
 }
 
 static struct TCP_Server_Info *
-cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol)
+cifs_find_tcp_session(struct smb_vol *vol)
 {
 	struct TCP_Server_Info *server;
 
 	spin_lock(&cifs_tcp_ses_lock);
 	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
-		if (!match_server(server, addr, vol))
+		if (!match_server(server, vol))
 			continue;
 
 		++server->srv_count;
@@ -2121,13 +2122,12 @@ static struct TCP_Server_Info *
 cifs_get_tcp_session(struct smb_vol *volume_info)
 {
 	struct TCP_Server_Info *tcp_ses = NULL;
-	struct sockaddr *dstaddr = (struct sockaddr *)&volume_info->dstaddr;
 	int rc;
 
 	cFYI(1, "UNC: %s", volume_info->UNC);
 
 	/* see if we already have a matching tcp_ses */
-	tcp_ses = cifs_find_tcp_session(dstaddr, volume_info);
+	tcp_ses = cifs_find_tcp_session(volume_info);
 	if (tcp_ses)
 		return tcp_ses;
 
@@ -2172,19 +2172,18 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
 	INIT_LIST_HEAD(&tcp_ses->tcp_ses_list);
 	INIT_LIST_HEAD(&tcp_ses->smb_ses_list);
 	INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request);
-
+	memcpy(&tcp_ses->srcaddr, &volume_info->srcaddr,
+	       sizeof(tcp_ses->srcaddr));
+	memcpy(&tcp_ses->dstaddr, &volume_info->dstaddr,
+		sizeof(tcp_ses->dstaddr));
 	/*
 	 * at this point we are the only ones with the pointer
 	 * to the struct since the kernel thread not created yet
 	 * no need to spinlock this init of tcpStatus or srv_count
 	 */
 	tcp_ses->tcpStatus = CifsNew;
-	memcpy(&tcp_ses->srcaddr, &volume_info->srcaddr,
-	       sizeof(tcp_ses->srcaddr));
 	++tcp_ses->srv_count;
 
-	memcpy(&tcp_ses->dstaddr, dstaddr, sizeof(tcp_ses->dstaddr));
-
 	rc = ip_connect(tcp_ses);
 	if (rc < 0) {
 		cERROR(1, "Error connecting to socket. Aborting operation");
@@ -2736,7 +2735,6 @@ cifs_match_super(struct super_block *sb, void *data)
 	struct cifs_ses *ses;
 	struct cifs_tcon *tcon;
 	struct tcon_link *tlink;
-	struct sockaddr *dstaddr;
 	int rc = 0;
 
 	spin_lock(&cifs_tcp_ses_lock);
@@ -2751,9 +2749,8 @@ cifs_match_super(struct super_block *sb, void *data)
 	tcp_srv = ses->server;
 
 	volume_info = mnt_data->vol;
-	dstaddr = (struct sockaddr *)&volume_info->dstaddr;
 
-	if (!match_server(tcp_srv, dstaddr, volume_info) ||
+	if (!match_server(tcp_srv, volume_info) ||
 	    !match_session(ses, volume_info) ||
 	    !match_tcon(tcon, volume_info->UNC)) {
 		rc = 0;
Signature · 1 line
1.7.11.7
#26 lore raw

[PATCH 8/6] cifs: always zero out smb_vol before parsing options

In reply to a message not in the archive

Currently, the code relies on the callers to do that and they all do, but this will ensure that it's always done.

---
 fs/cifs/connect.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/cifs/connect.c +4 -3
index 60295a4..ec1c462 100644
@@ -1162,6 +1162,9 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 	separator[1] = 0;
 	delim = separator[0];
 
+	/* ensure we always start with zeroed-out smb_vol */
+	memset(vol, 0, sizeof(*vol));
+
 	/*
 	 * does not have to be perfect mapping since field is
 	 * informational, only used for servers that do not support
@@ -3356,7 +3359,6 @@ expand_dfs_referral(const unsigned int xid, struct cifs_ses *ses,
 			mdata = NULL;
 		} else {
 			cleanup_volume_info_contents(volume_info);
-			memset(volume_info, '\0', sizeof(*volume_info));
 			rc = cifs_setup_volume_info(volume_info, mdata,
 							fake_devname);
 		}
@@ -3378,7 +3380,6 @@ cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
 	if (cifs_parse_mount_options(mount_data, devname, volume_info))
 		return -EINVAL;
 
-
 	if (volume_info->nullauth) {
 		cFYI(1, "Anonymous login");
 		kfree(volume_info->username);
@@ -3415,7 +3416,7 @@ cifs_get_volume_info(char *mount_data, const char *devname)
 	int rc;
 	struct smb_vol *volume_info;
 
-	volume_info = kzalloc(sizeof(struct smb_vol), GFP_KERNEL);
+	volume_info = kmalloc(sizeof(struct smb_vol), GFP_KERNEL);
 	if (!volume_info)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
1.7.11.7
#5 lore raw

Re: [PATCH 1/6] cifs: make error on lack of a unc= option more explicit

In reply to a message not in the archive

This looks fine but wondering if you plan to add support for mounting to DFS root (which was supposed to be the only reason for allowing ip= but not unc= to be specified)?

Quoted 61 lines · Jeff Layton

Error out with a clear error message if there is no unc= option. The existing code doesn't handle this in a clear fashion, and the check for a UNCip option with no UNC string is just plain wrong.

Later, we'll fix the code to not require a unc= option, but for now we need this to at least clarify why people are getting errors about DFS parsing. With this change we can also get rid of some later NULL pointer checks since we know the UNC and UNCip will never be NULL there.

---
 fs/cifs/connect.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
fs/cifs/connect.c +5 -15
index 5c670b9..b9849ac 100644
@@ -1799,6 +1799,11 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
                goto cifs_parse_mount_err;
        }
 #endif
+       if (!vol->UNC) {
+               cERROR(1, "CIFS mount error: No UNC path (e.g. -o "
+                       "unc=\\\\192.168.1.100\\public) specified");
+               goto cifs_parse_mount_err;
+       }
 
        if (vol->UNCip == NULL)
                vol->UNCip = &vol->UNC[2];
@@ -2070,17 +2075,6 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
                        rc = -EINVAL;
                        goto out_err;
                }
-       } else if (volume_info->UNCip) {
-               /* BB using ip addr as tcp_ses name to connect to the
-                  DFS root below */
-               cERROR(1, "Connecting to DFS root not implemented yet");
-               rc = -EINVAL;
-               goto out_err;
-       } else /* which tcp_sess DFS root would we conect to */ {
-               cERROR(1, "CIFS mount error: No UNC path (e.g. -o "
-                       "unc=//192.168.1.100/public) specified");
-               rc = -EINVAL;
-               goto out_err;
        }
 
        /* see if we already have a matching tcp_ses */
@@ -2736,9 +2730,6 @@ cifs_match_super(struct super_block *sb, void *data)
 
        volume_info = mnt_data->vol;
 
-       if (!volume_info->UNCip || !volume_info->UNC)
-               goto out;
-
        rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
                                volume_info->UNCip,
                                strlen(volume_info->UNCip),
--

1.7.11.7

Signature · 3 lines
Thanks,

Steve
#7 lore raw

Re: [PATCH 1/6] cifs: make error on lack of a unc= option more explicit

In reply to a message not in the archive
Quoted 4 lines · On Sun, 25 Nov 2012 15:30:18 -0600 Steve French…

This looks fine but wondering if you plan to add support for mounting to DFS root (which was supposed to be the only reason for allowing ip= but not unc= to be specified)?

I have no plans to do so in the near future, but don't let me stop you from doing so if you choose...

Signature · 1 line
Jeff Layton <[email protected]>
#20 lore raw

PATCH v2 5/6 cifs: fix up handling of prefixpath= option

In reply to a message not in the archive

(This patch takes into account Pavel's unification of the build_path_to_root functions).

Currently the code takes care to ensure that the prefixpath has a leading '/' delimiter. What if someone passes us a prefixpath with a leading '\\' instead? The code doesn't properly handle that currently AFAICS.

Let's just change the code to skip over any leading delimiter character when copying the prepath. Then, fix up the users of the prepath option to prefix it with the correct delimiter when they use it.

Also, there's no need to limit the length of the prefixpath to 1k. If the server can handle it, why bother forbidding it?

---
 fs/cifs/connect.c | 34 +++++++++-------------------------
 fs/cifs/dir.c     |  5 +++--
 2 files changed, 12 insertions(+), 27 deletions(-)
fs/cifs/connect.c +9 -25
index dfe497e..fdd7a13 100644
@@ -1603,31 +1603,14 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
 			}
 			break;
 		case Opt_prefixpath:
-			string = match_strdup(args);
-			if (string == NULL)
-				goto out_nomem;
-
-			temp_len = strnlen(string, 1024);
-			if (string[0] != '/')
-				temp_len++; /* missing leading slash */
-			if (temp_len > 1024) {
-				printk(KERN_WARNING "CIFS: prefix too long\n");
-				goto cifs_parse_mount_err;
-			}
-
-			vol->prepath = kmalloc(temp_len+1, GFP_KERNEL);
-			if (vol->prepath == NULL) {
-				printk(KERN_WARNING "CIFS: no memory "
-						    "for path prefix\n");
-				goto cifs_parse_mount_err;
-			}
-
-			if (string[0] != '/') {
-				vol->prepath[0] = '/';
-				strcpy(vol->prepath+1, string);
-			} else
-				strcpy(vol->prepath, string);
+			/* skip over any leading delimiter */
+			if (*args[0].from == '/' || *args[0].from == '\\')
+				args[0].from++;
 
+			kfree(vol->prepath);
+			vol->prepath = match_strdup(args);
+			if (vol->prepath == NULL)
+				goto out_nomem;
 			break;
 		case Opt_iocharset:
 			string = match_strdup(args);
@@ -3240,7 +3223,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
 		const struct cifs_sb_info *cifs_sb)
 {
 	char *full_path, *pos;
-	unsigned int pplen = vol->prepath ? strlen(vol->prepath) : 0;
+	unsigned int pplen = vol->prepath ? strlen(vol->prepath) + 1: 0;
 	unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
 
 	full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
@@ -3251,6 +3234,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
 	pos = full_path + unc_len;
 
 	if (pplen) {
+		*pos++ = CIFS_DIR_SEP(cifs_sb);
 		strncpy(pos, vol->prepath, pplen);
 		pos += pplen;
 	}
fs/cifs/dir.c +3 -2
index 3b7e0c1..8719bbe 100644
@@ -48,7 +48,7 @@ char *
 cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
 			struct cifs_tcon *tcon)
 {
-	int pplen = vol->prepath ? strlen(vol->prepath) : 0;
+	int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
 	int dfsplen;
 	char *full_path = NULL;
 
@@ -69,7 +69,8 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
 
 	if (dfsplen)
 		strncpy(full_path, tcon->treeName, dfsplen);
-	strncpy(full_path + dfsplen, vol->prepath, pplen);
+	full_path[dfsplen] = CIFS_DIR_SEP(cifs_sb);
+	strncpy(full_path + dfsplen + 1, vol->prepath, pplen);
 	convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
 	full_path[dfsplen + pplen] = 0; /* add trailing null */
 	return full_path;
Signature · 1 line
1.7.11.7