aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-05-28 13:08:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-28 13:08:39 -0400
commit320b34e3e067e08331725df122583afdca10f811 (patch)
tree658423da4d7eca7962a499224642cdaa6344361e /fs
parente3bf756eb988ff03ac57fda3934c440fe4db6a73 (diff)
parentd9deef0a3f38bcc1c155e8d9a8b522404e5e648c (diff)
Merge branch 'for-3.10' of git://git.samba.org/sfrench/cifs-2.6
Pull CIFS fixes from Steve French: "Fixes for a couple of DFS problems, a problem with extended security negotiation and two other small cifs fixes" * 'for-3.10' of git://git.samba.org/sfrench/cifs-2.6: cifs: fix composing of mount options for DFS referrals cifs: stop printing the unc= option in /proc/mounts cifs: fix error handling when calling cifs_parse_devname cifs: allow sec=none mounts to work against servers that don't support extended security cifs: fix potential buffer overrun when composing a new options string cifs: only set ops for inodes in I_NEW state
Diffstat (limited to 'fs')
-rw-r--r--fs/cifs/cifs_dfs_ref.c141
-rw-r--r--fs/cifs/cifsfs.c3
-rw-r--r--fs/cifs/connect.c23
-rw-r--r--fs/cifs/dns_resolve.c4
4 files changed, 88 insertions, 83 deletions
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index 8e33ec65847b..58df174deb10 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -18,6 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/vfs.h> 19#include <linux/vfs.h>
20#include <linux/fs.h> 20#include <linux/fs.h>
21#include <linux/inet.h>
21#include "cifsglob.h" 22#include "cifsglob.h"
22#include "cifsproto.h" 23#include "cifsproto.h"
23#include "cifsfs.h" 24#include "cifsfs.h"
@@ -48,58 +49,74 @@ void cifs_dfs_release_automount_timer(void)
48} 49}
49 50
50/** 51/**
51 * cifs_get_share_name - extracts share name from UNC 52 * cifs_build_devname - build a devicename from a UNC and optional prepath
52 * @node_name: pointer to UNC string 53 * @nodename: pointer to UNC string
54 * @prepath: pointer to prefixpath (or NULL if there isn't one)
53 * 55 *
54 * Extracts sharename form full UNC. 56 * Build a new cifs devicename after chasing a DFS referral. Allocate a buffer
55 * i.e. strips from UNC trailing path that is not part of share 57 * big enough to hold the final thing. Copy the UNC from the nodename, and
56 * name and fixup missing '\' in the beginning of DFS node refferal 58 * concatenate the prepath onto the end of it if there is one.
57 * if necessary. 59 *
58 * Returns pointer to share name on success or ERR_PTR on error. 60 * Returns pointer to the built string, or a ERR_PTR. Caller is responsible
59 * Caller is responsible for freeing returned string. 61 * for freeing the returned string.
60 */ 62 */
61static char *cifs_get_share_name(const char *node_name) 63static char *
64cifs_build_devname(char *nodename, const char *prepath)
62{ 65{
63 int len; 66 size_t pplen;
64 char *UNC; 67 size_t unclen;
65 char *pSep; 68 char *dev;
66 69 char *pos;
67 len = strlen(node_name); 70
68 UNC = kmalloc(len+2 /*for term null and additional \ if it's missed */, 71 /* skip over any preceding delimiters */
69 GFP_KERNEL); 72 nodename += strspn(nodename, "\\");
70 if (!UNC) 73 if (!*nodename)
71 return ERR_PTR(-ENOMEM); 74 return ERR_PTR(-EINVAL);
72 75
73 /* get share name and server name */ 76 /* get length of UNC and set pos to last char */
74 if (node_name[1] != '\\') { 77 unclen = strlen(nodename);
75 UNC[0] = '\\'; 78 pos = nodename + unclen - 1;
76 strncpy(UNC+1, node_name, len);
77 len++;
78 UNC[len] = 0;
79 } else {
80 strncpy(UNC, node_name, len);
81 UNC[len] = 0;
82 }
83 79
84 /* find server name end */ 80 /* trim off any trailing delimiters */
85 pSep = memchr(UNC+2, '\\', len-2); 81 while (*pos == '\\') {
86 if (!pSep) { 82 --pos;
87 cifs_dbg(VFS, "%s: no server name end in node name: %s\n", 83 --unclen;
88 __func__, node_name);
89 kfree(UNC);
90 return ERR_PTR(-EINVAL);
91 } 84 }
92 85
93 /* find sharename end */ 86 /* allocate a buffer:
94 pSep++; 87 * +2 for preceding "//"
95 pSep = memchr(UNC+(pSep-UNC), '\\', len-(pSep-UNC)); 88 * +1 for delimiter between UNC and prepath
96 if (pSep) { 89 * +1 for trailing NULL
97 /* trim path up to sharename end 90 */
98 * now we have share name in UNC */ 91 pplen = prepath ? strlen(prepath) : 0;
99 *pSep = 0; 92 dev = kmalloc(2 + unclen + 1 + pplen + 1, GFP_KERNEL);
93 if (!dev)
94 return ERR_PTR(-ENOMEM);
95
96 pos = dev;
97 /* add the initial "//" */
98 *pos = '/';
99 ++pos;
100 *pos = '/';
101 ++pos;
102
103 /* copy in the UNC portion from referral */
104 memcpy(pos, nodename, unclen);
105 pos += unclen;
106
107 /* copy the prefixpath remainder (if there is one) */
108 if (pplen) {
109 *pos = '/';
110 ++pos;
111 memcpy(pos, prepath, pplen);
112 pos += pplen;
100 } 113 }
101 114
102 return UNC; 115 /* NULL terminator */
116 *pos = '\0';
117
118 convert_delimiter(dev, '/');
119 return dev;
103} 120}
104 121
105 122
@@ -123,6 +140,7 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
123{ 140{
124 int rc; 141 int rc;
125 char *mountdata = NULL; 142 char *mountdata = NULL;
143 const char *prepath = NULL;
126 int md_len; 144 int md_len;
127 char *tkn_e; 145 char *tkn_e;
128 char *srvIP = NULL; 146 char *srvIP = NULL;
@@ -132,7 +150,10 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
132 if (sb_mountdata == NULL) 150 if (sb_mountdata == NULL)
133 return ERR_PTR(-EINVAL); 151 return ERR_PTR(-EINVAL);
134 152
135 *devname = cifs_get_share_name(ref->node_name); 153 if (strlen(fullpath) - ref->path_consumed)
154 prepath = fullpath + ref->path_consumed;
155
156 *devname = cifs_build_devname(ref->node_name, prepath);
136 if (IS_ERR(*devname)) { 157 if (IS_ERR(*devname)) {
137 rc = PTR_ERR(*devname); 158 rc = PTR_ERR(*devname);
138 *devname = NULL; 159 *devname = NULL;
@@ -146,12 +167,14 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
146 goto compose_mount_options_err; 167 goto compose_mount_options_err;
147 } 168 }
148 169
149 /* md_len = strlen(...) + 12 for 'sep+prefixpath=' 170 /*
150 * assuming that we have 'unc=' and 'ip=' in 171 * In most cases, we'll be building a shorter string than the original,
151 * the original sb_mountdata 172 * but we do have to assume that the address in the ip= option may be
173 * much longer than the original. Add the max length of an address
174 * string to the length of the original string to allow for worst case.
152 */ 175 */
153 md_len = strlen(sb_mountdata) + rc + strlen(ref->node_name) + 12; 176 md_len = strlen(sb_mountdata) + INET6_ADDRSTRLEN;
154 mountdata = kzalloc(md_len+1, GFP_KERNEL); 177 mountdata = kzalloc(md_len + 1, GFP_KERNEL);
155 if (mountdata == NULL) { 178 if (mountdata == NULL) {
156 rc = -ENOMEM; 179 rc = -ENOMEM;
157 goto compose_mount_options_err; 180 goto compose_mount_options_err;
@@ -195,26 +218,6 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
195 strncat(mountdata, &sep, 1); 218 strncat(mountdata, &sep, 1);
196 strcat(mountdata, "ip="); 219 strcat(mountdata, "ip=");
197 strcat(mountdata, srvIP); 220 strcat(mountdata, srvIP);
198 strncat(mountdata, &sep, 1);
199 strcat(mountdata, "unc=");
200 strcat(mountdata, *devname);
201
202 /* find & copy prefixpath */
203 tkn_e = strchr(ref->node_name + 2, '\\');
204 if (tkn_e == NULL) {
205 /* invalid unc, missing share name*/
206 rc = -EINVAL;
207 goto compose_mount_options_err;
208 }
209
210 tkn_e = strchr(tkn_e + 1, '\\');
211 if (tkn_e || (strlen(fullpath) - ref->path_consumed)) {
212 strncat(mountdata, &sep, 1);
213 strcat(mountdata, "prefixpath=");
214 if (tkn_e)
215 strcat(mountdata, tkn_e + 1);
216 strcat(mountdata, fullpath + ref->path_consumed);
217 }
218 221
219 /*cifs_dbg(FYI, "%s: parent mountdata: %s\n", __func__, sb_mountdata);*/ 222 /*cifs_dbg(FYI, "%s: parent mountdata: %s\n", __func__, sb_mountdata);*/
220 /*cifs_dbg(FYI, "%s: submount mountdata: %s\n", __func__, mountdata );*/ 223 /*cifs_dbg(FYI, "%s: submount mountdata: %s\n", __func__, mountdata );*/
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 72e4efee1389..3752b9f6d9e4 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -372,9 +372,6 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
372 cifs_show_security(s, tcon->ses->server); 372 cifs_show_security(s, tcon->ses->server);
373 cifs_show_cache_flavor(s, cifs_sb); 373 cifs_show_cache_flavor(s, cifs_sb);
374 374
375 seq_printf(s, ",unc=");
376 seq_escape(s, tcon->treeName, " \t\n\\");
377
378 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) 375 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
379 seq_printf(s, ",multiuser"); 376 seq_printf(s, ",multiuser");
380 else if (tcon->ses->user_name) 377 else if (tcon->ses->user_name)
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 99eeaa17ee00..5b97e56ddbca 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1061,6 +1061,7 @@ static int cifs_parse_security_flavors(char *value,
1061#endif 1061#endif
1062 case Opt_sec_none: 1062 case Opt_sec_none:
1063 vol->nullauth = 1; 1063 vol->nullauth = 1;
1064 vol->secFlg |= CIFSSEC_MAY_NTLM;
1064 break; 1065 break;
1065 default: 1066 default:
1066 cifs_dbg(VFS, "bad security option: %s\n", value); 1067 cifs_dbg(VFS, "bad security option: %s\n", value);
@@ -1257,14 +1258,18 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1257 vol->backupuid_specified = false; /* no backup intent for a user */ 1258 vol->backupuid_specified = false; /* no backup intent for a user */
1258 vol->backupgid_specified = false; /* no backup intent for a group */ 1259 vol->backupgid_specified = false; /* no backup intent for a group */
1259 1260
1260 /* 1261 switch (cifs_parse_devname(devname, vol)) {
1261 * For now, we ignore -EINVAL errors under the assumption that the 1262 case 0:
1262 * unc= and prefixpath= options will be usable. 1263 break;
1263 */ 1264 case -ENOMEM:
1264 if (cifs_parse_devname(devname, vol) == -ENOMEM) { 1265 cifs_dbg(VFS, "Unable to allocate memory for devname.\n");
1265 printk(KERN_ERR "CIFS: Unable to allocate memory to parse " 1266 goto cifs_parse_mount_err;
1266 "device string.\n"); 1267 case -EINVAL:
1267 goto out_nomem; 1268 cifs_dbg(VFS, "Malformed UNC in devname.\n");
1269 goto cifs_parse_mount_err;
1270 default:
1271 cifs_dbg(VFS, "Unknown error parsing devname.\n");
1272 goto cifs_parse_mount_err;
1268 } 1273 }
1269 1274
1270 while ((data = strsep(&options, separator)) != NULL) { 1275 while ((data = strsep(&options, separator)) != NULL) {
@@ -1826,7 +1831,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
1826 } 1831 }
1827#endif 1832#endif
1828 if (!vol->UNC) { 1833 if (!vol->UNC) {
1829 cifs_dbg(VFS, "CIFS mount error: No usable UNC path provided in device string or in unc= option!\n"); 1834 cifs_dbg(VFS, "CIFS mount error: No usable UNC path provided in device string!\n");
1830 goto cifs_parse_mount_err; 1835 goto cifs_parse_mount_err;
1831 } 1836 }
1832 1837
diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c
index e7512e497611..7ede7306599f 100644
--- a/fs/cifs/dns_resolve.c
+++ b/fs/cifs/dns_resolve.c
@@ -34,7 +34,7 @@
34 34
35/** 35/**
36 * dns_resolve_server_name_to_ip - Resolve UNC server name to ip address. 36 * dns_resolve_server_name_to_ip - Resolve UNC server name to ip address.
37 * @unc: UNC path specifying the server 37 * @unc: UNC path specifying the server (with '/' as delimiter)
38 * @ip_addr: Where to return the IP address. 38 * @ip_addr: Where to return the IP address.
39 * 39 *
40 * The IP address will be returned in string form, and the caller is 40 * The IP address will be returned in string form, and the caller is
@@ -64,7 +64,7 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
64 hostname = unc + 2; 64 hostname = unc + 2;
65 65
66 /* Search for server name delimiter */ 66 /* Search for server name delimiter */
67 sep = memchr(hostname, '\\', len); 67 sep = memchr(hostname, '/', len);
68 if (sep) 68 if (sep)
69 len = sep - hostname; 69 len = sep - hostname;
70 else 70 else