aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/cifs')
-rw-r--r--fs/cifs/AUTHORS2
-rw-r--r--fs/cifs/Kconfig1
-rw-r--r--fs/cifs/Makefile2
-rw-r--r--fs/cifs/README21
-rw-r--r--fs/cifs/cache.c2
-rw-r--r--fs/cifs/cifs_debug.c53
-rw-r--r--fs/cifs/cifs_dfs_ref.c12
-rw-r--r--fs/cifs/cifs_fs_sb.h1
-rw-r--r--fs/cifs/cifs_spnego.c4
-rw-r--r--fs/cifs/cifs_unicode.c128
-rw-r--r--fs/cifs/cifs_unicode.h2
-rw-r--r--fs/cifs/cifsacl.c17
-rw-r--r--fs/cifs/cifsencrypt.c59
-rw-r--r--fs/cifs/cifsencrypt.h33
-rw-r--r--fs/cifs/cifsfs.c61
-rw-r--r--fs/cifs/cifsfs.h19
-rw-r--r--fs/cifs/cifsglob.h114
-rw-r--r--fs/cifs/cifspdu.h62
-rw-r--r--fs/cifs/cifsproto.h20
-rw-r--r--fs/cifs/cifssmb.c135
-rw-r--r--fs/cifs/connect.c322
-rw-r--r--fs/cifs/dir.c2
-rw-r--r--fs/cifs/file.c578
-rw-r--r--fs/cifs/inode.c8
-rw-r--r--fs/cifs/link.c63
-rw-r--r--fs/cifs/md4.c205
-rw-r--r--fs/cifs/md5.c366
-rw-r--r--fs/cifs/md5.h38
-rw-r--r--fs/cifs/misc.c192
-rw-r--r--fs/cifs/netmisc.c16
-rw-r--r--fs/cifs/readdir.c3
-rw-r--r--fs/cifs/sess.c46
-rw-r--r--fs/cifs/smbdes.c1
-rw-r--r--fs/cifs/smbencrypt.c92
-rw-r--r--fs/cifs/transport.c481
35 files changed, 1560 insertions, 1601 deletions
diff --git a/fs/cifs/AUTHORS b/fs/cifs/AUTHORS
index 7f7fa3c302af..ea940b1db77b 100644
--- a/fs/cifs/AUTHORS
+++ b/fs/cifs/AUTHORS
@@ -35,7 +35,7 @@ Adrian Bunk (kcalloc cleanups)
35Miklos Szeredi 35Miklos Szeredi
36Kazeon team for various fixes especially for 2.4 version. 36Kazeon team for various fixes especially for 2.4 version.
37Asser Ferno (Change Notify support) 37Asser Ferno (Change Notify support)
38Shaggy (Dave Kleikamp) for inumerable small fs suggestions and some good cleanup 38Shaggy (Dave Kleikamp) for innumerable small fs suggestions and some good cleanup
39Gunter Kukkukk (testing and suggestions for support of old servers) 39Gunter Kukkukk (testing and suggestions for support of old servers)
40Igor Mammedov (DFS support) 40Igor Mammedov (DFS support)
41Jeff Layton (many, many fixes, as well as great work on the cifs Kerberos code) 41Jeff Layton (many, many fixes, as well as great work on the cifs Kerberos code)
diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig
index ee45648b0d1a..7cb0f7f847e4 100644
--- a/fs/cifs/Kconfig
+++ b/fs/cifs/Kconfig
@@ -3,6 +3,7 @@ config CIFS
3 depends on INET 3 depends on INET
4 select NLS 4 select NLS
5 select CRYPTO 5 select CRYPTO
6 select CRYPTO_MD4
6 select CRYPTO_MD5 7 select CRYPTO_MD5
7 select CRYPTO_HMAC 8 select CRYPTO_HMAC
8 select CRYPTO_ARC4 9 select CRYPTO_ARC4
diff --git a/fs/cifs/Makefile b/fs/cifs/Makefile
index 43b19dd39191..d87558448e3d 100644
--- a/fs/cifs/Makefile
+++ b/fs/cifs/Makefile
@@ -5,7 +5,7 @@ obj-$(CONFIG_CIFS) += cifs.o
5 5
6cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \ 6cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
7 link.o misc.o netmisc.o smbdes.o smbencrypt.o transport.o asn1.o \ 7 link.o misc.o netmisc.o smbdes.o smbencrypt.o transport.o asn1.o \
8 md4.o md5.o cifs_unicode.o nterr.o xattr.o cifsencrypt.o \ 8 cifs_unicode.o nterr.o xattr.o cifsencrypt.o \
9 readdir.o ioctl.o sess.o export.o 9 readdir.o ioctl.o sess.o export.o
10 10
11cifs-$(CONFIG_CIFS_ACL) += cifsacl.o 11cifs-$(CONFIG_CIFS_ACL) += cifsacl.o
diff --git a/fs/cifs/README b/fs/cifs/README
index 46af99ab3614..74ab165fc646 100644
--- a/fs/cifs/README
+++ b/fs/cifs/README
@@ -452,6 +452,11 @@ A partial list of the supported mount options follows:
452 if oplock (caching token) is granted and held. Note that 452 if oplock (caching token) is granted and held. Note that
453 direct allows write operations larger than page size 453 direct allows write operations larger than page size
454 to be sent to the server. 454 to be sent to the server.
455 strictcache Use for switching on strict cache mode. In this mode the
456 client read from the cache all the time it has Oplock Level II,
457 otherwise - read from the server. All written data are stored
458 in the cache, but if the client doesn't have Exclusive Oplock,
459 it writes the data to the server.
455 acl Allow setfacl and getfacl to manage posix ACLs if server 460 acl Allow setfacl and getfacl to manage posix ACLs if server
456 supports them. (default) 461 supports them. (default)
457 noacl Do not allow setfacl and getfacl calls on this mount 462 noacl Do not allow setfacl and getfacl calls on this mount
@@ -680,22 +685,6 @@ LinuxExtensionsEnabled If set to one then the client will attempt to
680 support and want to map the uid and gid fields 685 support and want to map the uid and gid fields
681 to values supplied at mount (rather than the 686 to values supplied at mount (rather than the
682 actual values, then set this to zero. (default 1) 687 actual values, then set this to zero. (default 1)
683Experimental When set to 1 used to enable certain experimental
684 features (currently enables multipage writes
685 when signing is enabled, the multipage write
686 performance enhancement was disabled when
687 signing turned on in case buffer was modified
688 just before it was sent, also this flag will
689 be used to use the new experimental directory change
690 notification code). When set to 2 enables
691 an additional experimental feature, "raw ntlmssp"
692 session establishment support (which allows
693 specifying "sec=ntlmssp" on mount). The Linux cifs
694 module will use ntlmv2 authentication encapsulated
695 in "raw ntlmssp" (not using SPNEGO) when
696 "sec=ntlmssp" is specified on mount.
697 This support also requires building cifs with
698 the CONFIG_CIFS_EXPERIMENTAL configuration flag.
699 688
700These experimental features and tracing can be enabled by changing flags in 689These experimental features and tracing can be enabled by changing flags in
701/proc/fs/cifs (after the cifs module has been installed or built into the 690/proc/fs/cifs (after the cifs module has been installed or built into the
diff --git a/fs/cifs/cache.c b/fs/cifs/cache.c
index e654dfd092c3..53d57a3fe427 100644
--- a/fs/cifs/cache.c
+++ b/fs/cifs/cache.c
@@ -50,7 +50,7 @@ void cifs_fscache_unregister(void)
50 */ 50 */
51struct cifs_server_key { 51struct cifs_server_key {
52 uint16_t family; /* address family */ 52 uint16_t family; /* address family */
53 uint16_t port; /* IP port */ 53 __be16 port; /* IP port */
54 union { 54 union {
55 struct in_addr ipv4_addr; 55 struct in_addr ipv4_addr;
56 struct in6_addr ipv6_addr; 56 struct in6_addr ipv6_addr;
diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
index ede98300a8cd..30d01bc90855 100644
--- a/fs/cifs/cifs_debug.c
+++ b/fs/cifs/cifs_debug.c
@@ -79,11 +79,11 @@ void cifs_dump_mids(struct TCP_Server_Info *server)
79 spin_lock(&GlobalMid_Lock); 79 spin_lock(&GlobalMid_Lock);
80 list_for_each(tmp, &server->pending_mid_q) { 80 list_for_each(tmp, &server->pending_mid_q) {
81 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 81 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
82 cERROR(1, "State: %d Cmd: %d Pid: %d Tsk: %p Mid %d", 82 cERROR(1, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %d",
83 mid_entry->midState, 83 mid_entry->midState,
84 (int)mid_entry->command, 84 (int)mid_entry->command,
85 mid_entry->pid, 85 mid_entry->pid,
86 mid_entry->tsk, 86 mid_entry->callback_data,
87 mid_entry->mid); 87 mid_entry->mid);
88#ifdef CONFIG_CIFS_STATS2 88#ifdef CONFIG_CIFS_STATS2
89 cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld", 89 cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld",
@@ -218,11 +218,11 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
218 mid_entry = list_entry(tmp3, struct mid_q_entry, 218 mid_entry = list_entry(tmp3, struct mid_q_entry,
219 qhead); 219 qhead);
220 seq_printf(m, "\tState: %d com: %d pid:" 220 seq_printf(m, "\tState: %d com: %d pid:"
221 " %d tsk: %p mid %d\n", 221 " %d cbdata: %p mid %d\n",
222 mid_entry->midState, 222 mid_entry->midState,
223 (int)mid_entry->command, 223 (int)mid_entry->command,
224 mid_entry->pid, 224 mid_entry->pid,
225 mid_entry->tsk, 225 mid_entry->callback_data,
226 mid_entry->mid); 226 mid_entry->mid);
227 } 227 }
228 spin_unlock(&GlobalMid_Lock); 228 spin_unlock(&GlobalMid_Lock);
@@ -331,7 +331,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
331 atomic_read(&totSmBufAllocCount)); 331 atomic_read(&totSmBufAllocCount));
332#endif /* CONFIG_CIFS_STATS2 */ 332#endif /* CONFIG_CIFS_STATS2 */
333 333
334 seq_printf(m, "Operations (MIDs): %d\n", midCount.counter); 334 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
335 seq_printf(m, 335 seq_printf(m,
336 "\n%d session %d share reconnects\n", 336 "\n%d session %d share reconnects\n",
337 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter); 337 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
@@ -423,7 +423,6 @@ static const struct file_operations cifs_lookup_cache_proc_fops;
423static const struct file_operations traceSMB_proc_fops; 423static const struct file_operations traceSMB_proc_fops;
424static const struct file_operations cifs_multiuser_mount_proc_fops; 424static const struct file_operations cifs_multiuser_mount_proc_fops;
425static const struct file_operations cifs_security_flags_proc_fops; 425static const struct file_operations cifs_security_flags_proc_fops;
426static const struct file_operations cifs_experimental_proc_fops;
427static const struct file_operations cifs_linux_ext_proc_fops; 426static const struct file_operations cifs_linux_ext_proc_fops;
428 427
429void 428void
@@ -441,8 +440,6 @@ cifs_proc_init(void)
441 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops); 440 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
442 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops); 441 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
443 proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops); 442 proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops);
444 proc_create("Experimental", 0, proc_fs_cifs,
445 &cifs_experimental_proc_fops);
446 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs, 443 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
447 &cifs_linux_ext_proc_fops); 444 &cifs_linux_ext_proc_fops);
448 proc_create("MultiuserMount", 0, proc_fs_cifs, 445 proc_create("MultiuserMount", 0, proc_fs_cifs,
@@ -469,7 +466,6 @@ cifs_proc_clean(void)
469 remove_proc_entry("OplockEnabled", proc_fs_cifs); 466 remove_proc_entry("OplockEnabled", proc_fs_cifs);
470 remove_proc_entry("SecurityFlags", proc_fs_cifs); 467 remove_proc_entry("SecurityFlags", proc_fs_cifs);
471 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs); 468 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
472 remove_proc_entry("Experimental", proc_fs_cifs);
473 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs); 469 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
474 remove_proc_entry("fs/cifs", NULL); 470 remove_proc_entry("fs/cifs", NULL);
475} 471}
@@ -550,45 +546,6 @@ static const struct file_operations cifs_oplock_proc_fops = {
550 .write = cifs_oplock_proc_write, 546 .write = cifs_oplock_proc_write,
551}; 547};
552 548
553static int cifs_experimental_proc_show(struct seq_file *m, void *v)
554{
555 seq_printf(m, "%d\n", experimEnabled);
556 return 0;
557}
558
559static int cifs_experimental_proc_open(struct inode *inode, struct file *file)
560{
561 return single_open(file, cifs_experimental_proc_show, NULL);
562}
563
564static ssize_t cifs_experimental_proc_write(struct file *file,
565 const char __user *buffer, size_t count, loff_t *ppos)
566{
567 char c;
568 int rc;
569
570 rc = get_user(c, buffer);
571 if (rc)
572 return rc;
573 if (c == '0' || c == 'n' || c == 'N')
574 experimEnabled = 0;
575 else if (c == '1' || c == 'y' || c == 'Y')
576 experimEnabled = 1;
577 else if (c == '2')
578 experimEnabled = 2;
579
580 return count;
581}
582
583static const struct file_operations cifs_experimental_proc_fops = {
584 .owner = THIS_MODULE,
585 .open = cifs_experimental_proc_open,
586 .read = seq_read,
587 .llseek = seq_lseek,
588 .release = single_release,
589 .write = cifs_experimental_proc_write,
590};
591
592static int cifs_linux_ext_proc_show(struct seq_file *m, void *v) 549static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
593{ 550{
594 seq_printf(m, "%d\n", linuxExtEnabled); 551 seq_printf(m, "%d\n", linuxExtEnabled);
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index 7ed36536e754..2b68ac57d97d 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -53,7 +53,7 @@ void cifs_dfs_release_automount_timer(void)
53 * 53 *
54 * Extracts sharename form full UNC. 54 * Extracts sharename form full UNC.
55 * i.e. strips from UNC trailing path that is not part of share 55 * i.e. strips from UNC trailing path that is not part of share
56 * name and fixup missing '\' in the begining of DFS node refferal 56 * name and fixup missing '\' in the beginning of DFS node refferal
57 * if necessary. 57 * if necessary.
58 * Returns pointer to share name on success or ERR_PTR on error. 58 * Returns pointer to share name on success or ERR_PTR on error.
59 * Caller is responsible for freeing returned string. 59 * Caller is responsible for freeing returned string.
@@ -282,8 +282,6 @@ static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
282 cFYI(1, "in %s", __func__); 282 cFYI(1, "in %s", __func__);
283 BUG_ON(IS_ROOT(mntpt)); 283 BUG_ON(IS_ROOT(mntpt));
284 284
285 xid = GetXid();
286
287 /* 285 /*
288 * The MSDFS spec states that paths in DFS referral requests and 286 * The MSDFS spec states that paths in DFS referral requests and
289 * responses must be prefixed by a single '\' character instead of 287 * responses must be prefixed by a single '\' character instead of
@@ -293,20 +291,21 @@ static struct vfsmount *cifs_dfs_do_automount(struct dentry *mntpt)
293 mnt = ERR_PTR(-ENOMEM); 291 mnt = ERR_PTR(-ENOMEM);
294 full_path = build_path_from_dentry(mntpt); 292 full_path = build_path_from_dentry(mntpt);
295 if (full_path == NULL) 293 if (full_path == NULL)
296 goto free_xid; 294 goto cdda_exit;
297 295
298 cifs_sb = CIFS_SB(mntpt->d_inode->i_sb); 296 cifs_sb = CIFS_SB(mntpt->d_inode->i_sb);
299 tlink = cifs_sb_tlink(cifs_sb); 297 tlink = cifs_sb_tlink(cifs_sb);
300 mnt = ERR_PTR(-EINVAL);
301 if (IS_ERR(tlink)) { 298 if (IS_ERR(tlink)) {
302 mnt = ERR_CAST(tlink); 299 mnt = ERR_CAST(tlink);
303 goto free_full_path; 300 goto free_full_path;
304 } 301 }
305 ses = tlink_tcon(tlink)->ses; 302 ses = tlink_tcon(tlink)->ses;
306 303
304 xid = GetXid();
307 rc = get_dfs_path(xid, ses, full_path + 1, cifs_sb->local_nls, 305 rc = get_dfs_path(xid, ses, full_path + 1, cifs_sb->local_nls,
308 &num_referrals, &referrals, 306 &num_referrals, &referrals,
309 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 307 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
308 FreeXid(xid);
310 309
311 cifs_put_tlink(tlink); 310 cifs_put_tlink(tlink);
312 311
@@ -339,8 +338,7 @@ success:
339 free_dfs_info_array(referrals, num_referrals); 338 free_dfs_info_array(referrals, num_referrals);
340free_full_path: 339free_full_path:
341 kfree(full_path); 340 kfree(full_path);
342free_xid: 341cdda_exit:
343 FreeXid(xid);
344 cFYI(1, "leaving %s" , __func__); 342 cFYI(1, "leaving %s" , __func__);
345 return mnt; 343 return mnt;
346} 344}
diff --git a/fs/cifs/cifs_fs_sb.h b/fs/cifs/cifs_fs_sb.h
index 7852cd677051..ac51cd2d33ae 100644
--- a/fs/cifs/cifs_fs_sb.h
+++ b/fs/cifs/cifs_fs_sb.h
@@ -40,6 +40,7 @@
40#define CIFS_MOUNT_FSCACHE 0x8000 /* local caching enabled */ 40#define CIFS_MOUNT_FSCACHE 0x8000 /* local caching enabled */
41#define CIFS_MOUNT_MF_SYMLINKS 0x10000 /* Minshall+French Symlinks enabled */ 41#define CIFS_MOUNT_MF_SYMLINKS 0x10000 /* Minshall+French Symlinks enabled */
42#define CIFS_MOUNT_MULTIUSER 0x20000 /* multiuser mount */ 42#define CIFS_MOUNT_MULTIUSER 0x20000 /* multiuser mount */
43#define CIFS_MOUNT_STRICT_IO 0x40000 /* strict cache mode */
43 44
44struct cifs_sb_info { 45struct cifs_sb_info {
45 struct rb_root tlink_tree; 46 struct rb_root tlink_tree;
diff --git a/fs/cifs/cifs_spnego.c b/fs/cifs/cifs_spnego.c
index 4dfba8283165..33d221394aca 100644
--- a/fs/cifs/cifs_spnego.c
+++ b/fs/cifs/cifs_spnego.c
@@ -113,7 +113,7 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
113 MAX_MECH_STR_LEN + 113 MAX_MECH_STR_LEN +
114 UID_KEY_LEN + (sizeof(uid_t) * 2) + 114 UID_KEY_LEN + (sizeof(uid_t) * 2) +
115 CREDUID_KEY_LEN + (sizeof(uid_t) * 2) + 115 CREDUID_KEY_LEN + (sizeof(uid_t) * 2) +
116 USER_KEY_LEN + strlen(sesInfo->userName) + 116 USER_KEY_LEN + strlen(sesInfo->user_name) +
117 PID_KEY_LEN + (sizeof(pid_t) * 2) + 1; 117 PID_KEY_LEN + (sizeof(pid_t) * 2) + 1;
118 118
119 spnego_key = ERR_PTR(-ENOMEM); 119 spnego_key = ERR_PTR(-ENOMEM);
@@ -153,7 +153,7 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
153 sprintf(dp, ";creduid=0x%x", sesInfo->cred_uid); 153 sprintf(dp, ";creduid=0x%x", sesInfo->cred_uid);
154 154
155 dp = description + strlen(description); 155 dp = description + strlen(description);
156 sprintf(dp, ";user=%s", sesInfo->userName); 156 sprintf(dp, ";user=%s", sesInfo->user_name);
157 157
158 dp = description + strlen(description); 158 dp = description + strlen(description);
159 sprintf(dp, ";pid=0x%x", current->pid); 159 sprintf(dp, ";pid=0x%x", current->pid);
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index 430f510a1720..23d43cde4306 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -44,10 +44,14 @@ cifs_ucs2_bytes(const __le16 *from, int maxbytes,
44 int charlen, outlen = 0; 44 int charlen, outlen = 0;
45 int maxwords = maxbytes / 2; 45 int maxwords = maxbytes / 2;
46 char tmp[NLS_MAX_CHARSET_SIZE]; 46 char tmp[NLS_MAX_CHARSET_SIZE];
47 __u16 ftmp;
47 48
48 for (i = 0; i < maxwords && from[i]; i++) { 49 for (i = 0; i < maxwords; i++) {
49 charlen = codepage->uni2char(le16_to_cpu(from[i]), tmp, 50 ftmp = get_unaligned_le16(&from[i]);
50 NLS_MAX_CHARSET_SIZE); 51 if (ftmp == 0)
52 break;
53
54 charlen = codepage->uni2char(ftmp, tmp, NLS_MAX_CHARSET_SIZE);
51 if (charlen > 0) 55 if (charlen > 0)
52 outlen += charlen; 56 outlen += charlen;
53 else 57 else
@@ -58,9 +62,9 @@ cifs_ucs2_bytes(const __le16 *from, int maxbytes,
58} 62}
59 63
60/* 64/*
61 * cifs_mapchar - convert a little-endian char to proper char in codepage 65 * cifs_mapchar - convert a host-endian char to proper char in codepage
62 * @target - where converted character should be copied 66 * @target - where converted character should be copied
63 * @src_char - 2 byte little-endian source character 67 * @src_char - 2 byte host-endian source character
64 * @cp - codepage to which character should be converted 68 * @cp - codepage to which character should be converted
65 * @mapchar - should character be mapped according to mapchars mount option? 69 * @mapchar - should character be mapped according to mapchars mount option?
66 * 70 *
@@ -69,7 +73,7 @@ cifs_ucs2_bytes(const __le16 *from, int maxbytes,
69 * enough to hold the result of the conversion (at least NLS_MAX_CHARSET_SIZE). 73 * enough to hold the result of the conversion (at least NLS_MAX_CHARSET_SIZE).
70 */ 74 */
71static int 75static int
72cifs_mapchar(char *target, const __le16 src_char, const struct nls_table *cp, 76cifs_mapchar(char *target, const __u16 src_char, const struct nls_table *cp,
73 bool mapchar) 77 bool mapchar)
74{ 78{
75 int len = 1; 79 int len = 1;
@@ -82,11 +86,11 @@ cifs_mapchar(char *target, const __le16 src_char, const struct nls_table *cp,
82 * build_path_from_dentry are modified, as they use slash as 86 * build_path_from_dentry are modified, as they use slash as
83 * separator. 87 * separator.
84 */ 88 */
85 switch (le16_to_cpu(src_char)) { 89 switch (src_char) {
86 case UNI_COLON: 90 case UNI_COLON:
87 *target = ':'; 91 *target = ':';
88 break; 92 break;
89 case UNI_ASTERIK: 93 case UNI_ASTERISK:
90 *target = '*'; 94 *target = '*';
91 break; 95 break;
92 case UNI_QUESTION: 96 case UNI_QUESTION:
@@ -109,8 +113,7 @@ out:
109 return len; 113 return len;
110 114
111cp_convert: 115cp_convert:
112 len = cp->uni2char(le16_to_cpu(src_char), target, 116 len = cp->uni2char(src_char, target, NLS_MAX_CHARSET_SIZE);
113 NLS_MAX_CHARSET_SIZE);
114 if (len <= 0) { 117 if (len <= 0) {
115 *target = '?'; 118 *target = '?';
116 len = 1; 119 len = 1;
@@ -149,6 +152,7 @@ cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen,
149 int nullsize = nls_nullsize(codepage); 152 int nullsize = nls_nullsize(codepage);
150 int fromwords = fromlen / 2; 153 int fromwords = fromlen / 2;
151 char tmp[NLS_MAX_CHARSET_SIZE]; 154 char tmp[NLS_MAX_CHARSET_SIZE];
155 __u16 ftmp;
152 156
153 /* 157 /*
154 * because the chars can be of varying widths, we need to take care 158 * because the chars can be of varying widths, we need to take care
@@ -158,19 +162,23 @@ cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen,
158 */ 162 */
159 safelen = tolen - (NLS_MAX_CHARSET_SIZE + nullsize); 163 safelen = tolen - (NLS_MAX_CHARSET_SIZE + nullsize);
160 164
161 for (i = 0; i < fromwords && from[i]; i++) { 165 for (i = 0; i < fromwords; i++) {
166 ftmp = get_unaligned_le16(&from[i]);
167 if (ftmp == 0)
168 break;
169
162 /* 170 /*
163 * check to see if converting this character might make the 171 * check to see if converting this character might make the
164 * conversion bleed into the null terminator 172 * conversion bleed into the null terminator
165 */ 173 */
166 if (outlen >= safelen) { 174 if (outlen >= safelen) {
167 charlen = cifs_mapchar(tmp, from[i], codepage, mapchar); 175 charlen = cifs_mapchar(tmp, ftmp, codepage, mapchar);
168 if ((outlen + charlen) > (tolen - nullsize)) 176 if ((outlen + charlen) > (tolen - nullsize))
169 break; 177 break;
170 } 178 }
171 179
172 /* put converted char into 'to' buffer */ 180 /* put converted char into 'to' buffer */
173 charlen = cifs_mapchar(&to[outlen], from[i], codepage, mapchar); 181 charlen = cifs_mapchar(&to[outlen], ftmp, codepage, mapchar);
174 outlen += charlen; 182 outlen += charlen;
175 } 183 }
176 184
@@ -193,24 +201,21 @@ cifs_strtoUCS(__le16 *to, const char *from, int len,
193{ 201{
194 int charlen; 202 int charlen;
195 int i; 203 int i;
196 wchar_t *wchar_to = (wchar_t *)to; /* needed to quiet sparse */ 204 wchar_t wchar_to; /* needed to quiet sparse */
197 205
198 for (i = 0; len && *from; i++, from += charlen, len -= charlen) { 206 for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
199 207 charlen = codepage->char2uni(from, len, &wchar_to);
200 /* works for 2.4.0 kernel or later */
201 charlen = codepage->char2uni(from, len, &wchar_to[i]);
202 if (charlen < 1) { 208 if (charlen < 1) {
203 cERROR(1, "strtoUCS: char2uni of %d returned %d", 209 cERROR(1, "strtoUCS: char2uni of 0x%x returned %d",
204 (int)*from, charlen); 210 *from, charlen);
205 /* A question mark */ 211 /* A question mark */
206 to[i] = cpu_to_le16(0x003f); 212 wchar_to = 0x003f;
207 charlen = 1; 213 charlen = 1;
208 } else 214 }
209 to[i] = cpu_to_le16(wchar_to[i]); 215 put_unaligned_le16(wchar_to, &to[i]);
210
211 } 216 }
212 217
213 to[i] = 0; 218 put_unaligned_le16(0, &to[i]);
214 return i; 219 return i;
215} 220}
216 221
@@ -252,3 +257,78 @@ cifs_strndup_from_ucs(const char *src, const int maxlen, const bool is_unicode,
252 return dst; 257 return dst;
253} 258}
254 259
260/*
261 * Convert 16 bit Unicode pathname to wire format from string in current code
262 * page. Conversion may involve remapping up the six characters that are
263 * only legal in POSIX-like OS (if they are present in the string). Path
264 * names are little endian 16 bit Unicode on the wire
265 */
266int
267cifsConvertToUCS(__le16 *target, const char *source, int srclen,
268 const struct nls_table *cp, int mapChars)
269{
270 int i, j, charlen;
271 char src_char;
272 __le16 dst_char;
273 wchar_t tmp;
274
275 if (!mapChars)
276 return cifs_strtoUCS(target, source, PATH_MAX, cp);
277
278 for (i = 0, j = 0; i < srclen; j++) {
279 src_char = source[i];
280 switch (src_char) {
281 case 0:
282 put_unaligned(0, &target[j]);
283 goto ctoUCS_out;
284 case ':':
285 dst_char = cpu_to_le16(UNI_COLON);
286 break;
287 case '*':
288 dst_char = cpu_to_le16(UNI_ASTERISK);
289 break;
290 case '?':
291 dst_char = cpu_to_le16(UNI_QUESTION);
292 break;
293 case '<':
294 dst_char = cpu_to_le16(UNI_LESSTHAN);
295 break;
296 case '>':
297 dst_char = cpu_to_le16(UNI_GRTRTHAN);
298 break;
299 case '|':
300 dst_char = cpu_to_le16(UNI_PIPE);
301 break;
302 /*
303 * FIXME: We can not handle remapping backslash (UNI_SLASH)
304 * until all the calls to build_path_from_dentry are modified,
305 * as they use backslash as separator.
306 */
307 default:
308 charlen = cp->char2uni(source + i, srclen - i, &tmp);
309 dst_char = cpu_to_le16(tmp);
310
311 /*
312 * if no match, use question mark, which at least in
313 * some cases serves as wild card
314 */
315 if (charlen < 1) {
316 dst_char = cpu_to_le16(0x003f);
317 charlen = 1;
318 }
319 /*
320 * character may take more than one byte in the source
321 * string, but will take exactly two bytes in the
322 * target string
323 */
324 i += charlen;
325 continue;
326 }
327 put_unaligned(dst_char, &target[j]);
328 i++; /* move to next char in source string */
329 }
330
331ctoUCS_out:
332 return i;
333}
334
diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
index 7fe6b52df507..644dd882a560 100644
--- a/fs/cifs/cifs_unicode.h
+++ b/fs/cifs/cifs_unicode.h
@@ -44,7 +44,7 @@
44 * reserved symbols (along with \ and /), otherwise illegal to store 44 * reserved symbols (along with \ and /), otherwise illegal to store
45 * in filenames in NTFS 45 * in filenames in NTFS
46 */ 46 */
47#define UNI_ASTERIK (__u16) ('*' + 0xF000) 47#define UNI_ASTERISK (__u16) ('*' + 0xF000)
48#define UNI_QUESTION (__u16) ('?' + 0xF000) 48#define UNI_QUESTION (__u16) ('?' + 0xF000)
49#define UNI_COLON (__u16) (':' + 0xF000) 49#define UNI_COLON (__u16) (':' + 0xF000)
50#define UNI_GRTRTHAN (__u16) ('>' + 0xF000) 50#define UNI_GRTRTHAN (__u16) ('>' + 0xF000)
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index a437ec391a01..beeebf194234 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -41,9 +41,12 @@ static struct cifs_wksid wksidarr[NUM_WK_SIDS] = {
41; 41;
42 42
43 43
44/* security id for everyone */ 44/* security id for everyone/world system group */
45static const struct cifs_sid sid_everyone = { 45static const struct cifs_sid sid_everyone = {
46 1, 1, {0, 0, 0, 0, 0, 1}, {0} }; 46 1, 1, {0, 0, 0, 0, 0, 1}, {0} };
47/* security id for Authenticated Users system group */
48static const struct cifs_sid sid_authusers = {
49 1, 1, {0, 0, 0, 0, 0, 5}, {11} };
47/* group users */ 50/* group users */
48static const struct cifs_sid sid_user = {1, 2 , {0, 0, 0, 0, 0, 5}, {} }; 51static const struct cifs_sid sid_user = {1, 2 , {0, 0, 0, 0, 0, 5}, {} };
49 52
@@ -365,10 +368,14 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,
365 if (num_aces > 0) { 368 if (num_aces > 0) {
366 umode_t user_mask = S_IRWXU; 369 umode_t user_mask = S_IRWXU;
367 umode_t group_mask = S_IRWXG; 370 umode_t group_mask = S_IRWXG;
368 umode_t other_mask = S_IRWXO; 371 umode_t other_mask = S_IRWXU | S_IRWXG | S_IRWXO;
369 372
370 ppace = kmalloc(num_aces * sizeof(struct cifs_ace *), 373 ppace = kmalloc(num_aces * sizeof(struct cifs_ace *),
371 GFP_KERNEL); 374 GFP_KERNEL);
375 if (!ppace) {
376 cERROR(1, "DACL memory allocation error");
377 return;
378 }
372 379
373 for (i = 0; i < num_aces; ++i) { 380 for (i = 0; i < num_aces; ++i) {
374 ppace[i] = (struct cifs_ace *) (acl_base + acl_size); 381 ppace[i] = (struct cifs_ace *) (acl_base + acl_size);
@@ -390,6 +397,12 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,
390 ppace[i]->type, 397 ppace[i]->type,
391 &fattr->cf_mode, 398 &fattr->cf_mode,
392 &other_mask); 399 &other_mask);
400 if (compare_sids(&(ppace[i]->sid), &sid_authusers))
401 access_flags_to_mode(ppace[i]->access_req,
402 ppace[i]->type,
403 &fattr->cf_mode,
404 &other_mask);
405
393 406
394/* memcpy((void *)(&(cifscred->aces[i])), 407/* memcpy((void *)(&(cifscred->aces[i])),
395 (void *)ppace[i], 408 (void *)ppace[i],
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 66f3d50d0676..d1a016be73ba 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -24,24 +24,19 @@
24#include "cifspdu.h" 24#include "cifspdu.h"
25#include "cifsglob.h" 25#include "cifsglob.h"
26#include "cifs_debug.h" 26#include "cifs_debug.h"
27#include "md5.h"
28#include "cifs_unicode.h" 27#include "cifs_unicode.h"
29#include "cifsproto.h" 28#include "cifsproto.h"
30#include "ntlmssp.h" 29#include "ntlmssp.h"
31#include <linux/ctype.h> 30#include <linux/ctype.h>
32#include <linux/random.h> 31#include <linux/random.h>
33 32
34/* Calculate and return the CIFS signature based on the mac key and SMB PDU */ 33/*
35/* the 16 byte signature must be allocated by the caller */ 34 * Calculate and return the CIFS signature based on the mac key and SMB PDU.
36/* Note we only use the 1st eight bytes */ 35 * The 16 byte signature must be allocated by the caller. Note we only use the
37/* Note that the smb header signature field on input contains the 36 * 1st eight bytes and that the smb header signature field on input contains
38 sequence number before this function is called */ 37 * the sequence number before this function is called. Also, this function
39 38 * should be called with the server->srv_mutex held.
40extern void mdfour(unsigned char *out, unsigned char *in, int n); 39 */
41extern void E_md4hash(const unsigned char *passwd, unsigned char *p16);
42extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8,
43 unsigned char *p24);
44
45static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu, 40static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu,
46 struct TCP_Server_Info *server, char *signature) 41 struct TCP_Server_Info *server, char *signature)
47{ 42{
@@ -215,8 +210,10 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu,
215 cpu_to_le32(expected_sequence_number); 210 cpu_to_le32(expected_sequence_number);
216 cifs_pdu->Signature.Sequence.Reserved = 0; 211 cifs_pdu->Signature.Sequence.Reserved = 0;
217 212
213 mutex_lock(&server->srv_mutex);
218 rc = cifs_calculate_signature(cifs_pdu, server, 214 rc = cifs_calculate_signature(cifs_pdu, server,
219 what_we_think_sig_should_be); 215 what_we_think_sig_should_be);
216 mutex_unlock(&server->srv_mutex);
220 217
221 if (rc) 218 if (rc)
222 return rc; 219 return rc;
@@ -234,6 +231,7 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu,
234/* first calculate 24 bytes ntlm response and then 16 byte session key */ 231/* first calculate 24 bytes ntlm response and then 16 byte session key */
235int setup_ntlm_response(struct cifsSesInfo *ses) 232int setup_ntlm_response(struct cifsSesInfo *ses)
236{ 233{
234 int rc = 0;
237 unsigned int temp_len = CIFS_SESS_KEY_SIZE + CIFS_AUTH_RESP_SIZE; 235 unsigned int temp_len = CIFS_SESS_KEY_SIZE + CIFS_AUTH_RESP_SIZE;
238 char temp_key[CIFS_SESS_KEY_SIZE]; 236 char temp_key[CIFS_SESS_KEY_SIZE];
239 237
@@ -247,13 +245,26 @@ int setup_ntlm_response(struct cifsSesInfo *ses)
247 } 245 }
248 ses->auth_key.len = temp_len; 246 ses->auth_key.len = temp_len;
249 247
250 SMBNTencrypt(ses->password, ses->server->cryptkey, 248 rc = SMBNTencrypt(ses->password, ses->server->cryptkey,
251 ses->auth_key.response + CIFS_SESS_KEY_SIZE); 249 ses->auth_key.response + CIFS_SESS_KEY_SIZE);
250 if (rc) {
251 cFYI(1, "%s Can't generate NTLM response, error: %d",
252 __func__, rc);
253 return rc;
254 }
252 255
253 E_md4hash(ses->password, temp_key); 256 rc = E_md4hash(ses->password, temp_key);
254 mdfour(ses->auth_key.response, temp_key, CIFS_SESS_KEY_SIZE); 257 if (rc) {
258 cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc);
259 return rc;
260 }
255 261
256 return 0; 262 rc = mdfour(ses->auth_key.response, temp_key, CIFS_SESS_KEY_SIZE);
263 if (rc)
264 cFYI(1, "%s Can't generate NTLM session key, error: %d",
265 __func__, rc);
266
267 return rc;
257} 268}
258 269
259#ifdef CONFIG_CIFS_WEAK_PW_HASH 270#ifdef CONFIG_CIFS_WEAK_PW_HASH
@@ -461,15 +472,15 @@ static int calc_ntlmv2_hash(struct cifsSesInfo *ses, char *ntlmv2_hash,
461 return rc; 472 return rc;
462 } 473 }
463 474
464 /* convert ses->userName to unicode and uppercase */ 475 /* convert ses->user_name to unicode and uppercase */
465 len = strlen(ses->userName); 476 len = strlen(ses->user_name);
466 user = kmalloc(2 + (len * 2), GFP_KERNEL); 477 user = kmalloc(2 + (len * 2), GFP_KERNEL);
467 if (user == NULL) { 478 if (user == NULL) {
468 cERROR(1, "calc_ntlmv2_hash: user mem alloc failure\n"); 479 cERROR(1, "calc_ntlmv2_hash: user mem alloc failure\n");
469 rc = -ENOMEM; 480 rc = -ENOMEM;
470 goto calc_exit_2; 481 goto calc_exit_2;
471 } 482 }
472 len = cifs_strtoUCS((__le16 *)user, ses->userName, len, nls_cp); 483 len = cifs_strtoUCS((__le16 *)user, ses->user_name, len, nls_cp);
473 UniStrupr(user); 484 UniStrupr(user);
474 485
475 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, 486 crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
@@ -649,9 +660,10 @@ calc_seckey(struct cifsSesInfo *ses)
649 get_random_bytes(sec_key, CIFS_SESS_KEY_SIZE); 660 get_random_bytes(sec_key, CIFS_SESS_KEY_SIZE);
650 661
651 tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); 662 tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
652 if (!tfm_arc4 || IS_ERR(tfm_arc4)) { 663 if (IS_ERR(tfm_arc4)) {
664 rc = PTR_ERR(tfm_arc4);
653 cERROR(1, "could not allocate crypto API arc4\n"); 665 cERROR(1, "could not allocate crypto API arc4\n");
654 return PTR_ERR(tfm_arc4); 666 return rc;
655 } 667 }
656 668
657 desc.tfm = tfm_arc4; 669 desc.tfm = tfm_arc4;
@@ -700,14 +712,13 @@ cifs_crypto_shash_allocate(struct TCP_Server_Info *server)
700 unsigned int size; 712 unsigned int size;
701 713
702 server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0); 714 server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0);
703 if (!server->secmech.hmacmd5 || 715 if (IS_ERR(server->secmech.hmacmd5)) {
704 IS_ERR(server->secmech.hmacmd5)) {
705 cERROR(1, "could not allocate crypto hmacmd5\n"); 716 cERROR(1, "could not allocate crypto hmacmd5\n");
706 return PTR_ERR(server->secmech.hmacmd5); 717 return PTR_ERR(server->secmech.hmacmd5);
707 } 718 }
708 719
709 server->secmech.md5 = crypto_alloc_shash("md5", 0, 0); 720 server->secmech.md5 = crypto_alloc_shash("md5", 0, 0);
710 if (!server->secmech.md5 || IS_ERR(server->secmech.md5)) { 721 if (IS_ERR(server->secmech.md5)) {
711 cERROR(1, "could not allocate crypto md5\n"); 722 cERROR(1, "could not allocate crypto md5\n");
712 rc = PTR_ERR(server->secmech.md5); 723 rc = PTR_ERR(server->secmech.md5);
713 goto crypto_allocate_md5_fail; 724 goto crypto_allocate_md5_fail;
diff --git a/fs/cifs/cifsencrypt.h b/fs/cifs/cifsencrypt.h
deleted file mode 100644
index 15d2ec006474..000000000000
--- a/fs/cifs/cifsencrypt.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 * fs/cifs/cifsencrypt.h
3 *
4 * Copyright (c) International Business Machines Corp., 2005
5 * Author(s): Steve French (sfrench@us.ibm.com)
6 *
7 * Externs for misc. small encryption routines
8 * so we do not have to put them in cifsproto.h
9 *
10 * This library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published
12 * by the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 * the GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25/* md4.c */
26extern void mdfour(unsigned char *out, unsigned char *in, int n);
27/* smbdes.c */
28extern void E_P16(unsigned char *p14, unsigned char *p16);
29extern void E_P24(unsigned char *p21, const unsigned char *c8,
30 unsigned char *p24);
31
32
33
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index d9f652a522a6..5c412b33cd7c 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -53,7 +53,6 @@ int cifsFYI = 0;
53int cifsERROR = 1; 53int cifsERROR = 1;
54int traceSMB = 0; 54int traceSMB = 0;
55unsigned int oplockEnabled = 1; 55unsigned int oplockEnabled = 1;
56unsigned int experimEnabled = 0;
57unsigned int linuxExtEnabled = 1; 56unsigned int linuxExtEnabled = 1;
58unsigned int lookupCacheEnabled = 1; 57unsigned int lookupCacheEnabled = 1;
59unsigned int multiuser_mount = 0; 58unsigned int multiuser_mount = 0;
@@ -77,7 +76,11 @@ unsigned int cifs_max_pending = CIFS_MAX_REQ;
77module_param(cifs_max_pending, int, 0); 76module_param(cifs_max_pending, int, 0);
78MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. " 77MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
79 "Default: 50 Range: 2 to 256"); 78 "Default: 50 Range: 2 to 256");
80 79unsigned short echo_retries = 5;
80module_param(echo_retries, ushort, 0644);
81MODULE_PARM_DESC(echo_retries, "Number of echo attempts before giving up and "
82 "reconnecting server. Default: 5. 0 means "
83 "never reconnect.");
81extern mempool_t *cifs_sm_req_poolp; 84extern mempool_t *cifs_sm_req_poolp;
82extern mempool_t *cifs_req_poolp; 85extern mempool_t *cifs_req_poolp;
83extern mempool_t *cifs_mid_poolp; 86extern mempool_t *cifs_mid_poolp;
@@ -123,6 +126,7 @@ cifs_read_super(struct super_block *sb, void *data,
123 kfree(cifs_sb); 126 kfree(cifs_sb);
124 return rc; 127 return rc;
125 } 128 }
129 cifs_sb->bdi.ra_pages = default_backing_dev_info.ra_pages;
126 130
127#ifdef CONFIG_CIFS_DFS_UPCALL 131#ifdef CONFIG_CIFS_DFS_UPCALL
128 /* copy mount params to sb for use in submounts */ 132 /* copy mount params to sb for use in submounts */
@@ -405,8 +409,8 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m)
405 409
406 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) 410 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
407 seq_printf(s, ",multiuser"); 411 seq_printf(s, ",multiuser");
408 else if (tcon->ses->userName) 412 else if (tcon->ses->user_name)
409 seq_printf(s, ",username=%s", tcon->ses->userName); 413 seq_printf(s, ",username=%s", tcon->ses->user_name);
410 414
411 if (tcon->ses->domainName) 415 if (tcon->ses->domainName)
412 seq_printf(s, ",domain=%s", tcon->ses->domainName); 416 seq_printf(s, ",domain=%s", tcon->ses->domainName);
@@ -596,10 +600,17 @@ static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
596{ 600{
597 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; 601 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
598 ssize_t written; 602 ssize_t written;
603 int rc;
599 604
600 written = generic_file_aio_write(iocb, iov, nr_segs, pos); 605 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
601 if (!CIFS_I(inode)->clientCanCacheAll) 606
602 filemap_fdatawrite(inode->i_mapping); 607 if (CIFS_I(inode)->clientCanCacheAll)
608 return written;
609
610 rc = filemap_fdatawrite(inode->i_mapping);
611 if (rc)
612 cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode);
613
603 return written; 614 return written;
604} 615}
605 616
@@ -729,6 +740,25 @@ const struct file_operations cifs_file_ops = {
729 .setlease = cifs_setlease, 740 .setlease = cifs_setlease,
730}; 741};
731 742
743const struct file_operations cifs_file_strict_ops = {
744 .read = do_sync_read,
745 .write = do_sync_write,
746 .aio_read = cifs_strict_readv,
747 .aio_write = cifs_strict_writev,
748 .open = cifs_open,
749 .release = cifs_close,
750 .lock = cifs_lock,
751 .fsync = cifs_strict_fsync,
752 .flush = cifs_flush,
753 .mmap = cifs_file_strict_mmap,
754 .splice_read = generic_file_splice_read,
755 .llseek = cifs_llseek,
756#ifdef CONFIG_CIFS_POSIX
757 .unlocked_ioctl = cifs_ioctl,
758#endif /* CONFIG_CIFS_POSIX */
759 .setlease = cifs_setlease,
760};
761
732const struct file_operations cifs_file_direct_ops = { 762const struct file_operations cifs_file_direct_ops = {
733 /* no aio, no readv - 763 /* no aio, no readv -
734 BB reevaluate whether they can be done with directio, no cache */ 764 BB reevaluate whether they can be done with directio, no cache */
@@ -747,6 +777,7 @@ const struct file_operations cifs_file_direct_ops = {
747 .llseek = cifs_llseek, 777 .llseek = cifs_llseek,
748 .setlease = cifs_setlease, 778 .setlease = cifs_setlease,
749}; 779};
780
750const struct file_operations cifs_file_nobrl_ops = { 781const struct file_operations cifs_file_nobrl_ops = {
751 .read = do_sync_read, 782 .read = do_sync_read,
752 .write = do_sync_write, 783 .write = do_sync_write,
@@ -765,6 +796,24 @@ const struct file_operations cifs_file_nobrl_ops = {
765 .setlease = cifs_setlease, 796 .setlease = cifs_setlease,
766}; 797};
767 798
799const struct file_operations cifs_file_strict_nobrl_ops = {
800 .read = do_sync_read,
801 .write = do_sync_write,
802 .aio_read = cifs_strict_readv,
803 .aio_write = cifs_strict_writev,
804 .open = cifs_open,
805 .release = cifs_close,
806 .fsync = cifs_strict_fsync,
807 .flush = cifs_flush,
808 .mmap = cifs_file_strict_mmap,
809 .splice_read = generic_file_splice_read,
810 .llseek = cifs_llseek,
811#ifdef CONFIG_CIFS_POSIX
812 .unlocked_ioctl = cifs_ioctl,
813#endif /* CONFIG_CIFS_POSIX */
814 .setlease = cifs_setlease,
815};
816
768const struct file_operations cifs_file_direct_nobrl_ops = { 817const struct file_operations cifs_file_direct_nobrl_ops = {
769 /* no mmap, no aio, no readv - 818 /* no mmap, no aio, no readv -
770 BB reevaluate whether they can be done with directio, no cache */ 819 BB reevaluate whether they can be done with directio, no cache */
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index 851030f74939..a9371b6578c0 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -61,6 +61,7 @@ extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
61 struct dentry *); 61 struct dentry *);
62extern int cifs_revalidate_file(struct file *filp); 62extern int cifs_revalidate_file(struct file *filp);
63extern int cifs_revalidate_dentry(struct dentry *); 63extern int cifs_revalidate_dentry(struct dentry *);
64extern void cifs_invalidate_mapping(struct inode *inode);
64extern int cifs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 65extern int cifs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
65extern int cifs_setattr(struct dentry *, struct iattr *); 66extern int cifs_setattr(struct dentry *, struct iattr *);
66 67
@@ -72,19 +73,27 @@ extern const struct inode_operations cifs_dfs_referral_inode_operations;
72/* Functions related to files and directories */ 73/* Functions related to files and directories */
73extern const struct file_operations cifs_file_ops; 74extern const struct file_operations cifs_file_ops;
74extern const struct file_operations cifs_file_direct_ops; /* if directio mnt */ 75extern const struct file_operations cifs_file_direct_ops; /* if directio mnt */
75extern const struct file_operations cifs_file_nobrl_ops; 76extern const struct file_operations cifs_file_strict_ops; /* if strictio mnt */
76extern const struct file_operations cifs_file_direct_nobrl_ops; /* no brlocks */ 77extern const struct file_operations cifs_file_nobrl_ops; /* no brlocks */
78extern const struct file_operations cifs_file_direct_nobrl_ops;
79extern const struct file_operations cifs_file_strict_nobrl_ops;
77extern int cifs_open(struct inode *inode, struct file *file); 80extern int cifs_open(struct inode *inode, struct file *file);
78extern int cifs_close(struct inode *inode, struct file *file); 81extern int cifs_close(struct inode *inode, struct file *file);
79extern int cifs_closedir(struct inode *inode, struct file *file); 82extern int cifs_closedir(struct inode *inode, struct file *file);
80extern ssize_t cifs_user_read(struct file *file, char __user *read_data, 83extern ssize_t cifs_user_read(struct file *file, char __user *read_data,
81 size_t read_size, loff_t *poffset); 84 size_t read_size, loff_t *poffset);
85extern ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov,
86 unsigned long nr_segs, loff_t pos);
82extern ssize_t cifs_user_write(struct file *file, const char __user *write_data, 87extern ssize_t cifs_user_write(struct file *file, const char __user *write_data,
83 size_t write_size, loff_t *poffset); 88 size_t write_size, loff_t *poffset);
89extern ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov,
90 unsigned long nr_segs, loff_t pos);
84extern int cifs_lock(struct file *, int, struct file_lock *); 91extern int cifs_lock(struct file *, int, struct file_lock *);
85extern int cifs_fsync(struct file *, int); 92extern int cifs_fsync(struct file *, int);
93extern int cifs_strict_fsync(struct file *, int);
86extern int cifs_flush(struct file *, fl_owner_t id); 94extern int cifs_flush(struct file *, fl_owner_t id);
87extern int cifs_file_mmap(struct file * , struct vm_area_struct *); 95extern int cifs_file_mmap(struct file * , struct vm_area_struct *);
96extern int cifs_file_strict_mmap(struct file * , struct vm_area_struct *);
88extern const struct file_operations cifs_dir_ops; 97extern const struct file_operations cifs_dir_ops;
89extern int cifs_dir_open(struct inode *inode, struct file *file); 98extern int cifs_dir_open(struct inode *inode, struct file *file);
90extern int cifs_readdir(struct file *file, void *direntry, filldir_t filldir); 99extern int cifs_readdir(struct file *file, void *direntry, filldir_t filldir);
@@ -118,5 +127,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
118extern const struct export_operations cifs_export_ops; 127extern const struct export_operations cifs_export_ops;
119#endif /* EXPERIMENTAL */ 128#endif /* EXPERIMENTAL */
120 129
121#define CIFS_VERSION "1.68" 130#define CIFS_VERSION "1.71"
122#endif /* _CIFSFS_H */ 131#endif /* _CIFSFS_H */
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 606ca8bb7102..a5d1106fcbde 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -37,10 +37,9 @@
37 37
38#define MAX_TREE_SIZE (2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1) 38#define MAX_TREE_SIZE (2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1)
39#define MAX_SERVER_SIZE 15 39#define MAX_SERVER_SIZE 15
40#define MAX_SHARE_SIZE 64 /* used to be 20, this should still be enough */ 40#define MAX_SHARE_SIZE 80
41#define MAX_USERNAME_SIZE 32 /* 32 is to allow for 15 char names + null 41#define MAX_USERNAME_SIZE 256 /* reasonable maximum for current servers */
42 termination then *2 for unicode versions */ 42#define MAX_PASSWORD_SIZE 512 /* max for windows seems to be 256 wide chars */
43#define MAX_PASSWORD_SIZE 512 /* max for windows seems to be 256 wide chars */
44 43
45#define CIFS_MIN_RCV_POOL 4 44#define CIFS_MIN_RCV_POOL 4
46 45
@@ -92,7 +91,8 @@ enum statusEnum {
92 CifsNew = 0, 91 CifsNew = 0,
93 CifsGood, 92 CifsGood,
94 CifsExiting, 93 CifsExiting,
95 CifsNeedReconnect 94 CifsNeedReconnect,
95 CifsNeedNegotiate
96}; 96};
97 97
98enum securityEnum { 98enum securityEnum {
@@ -161,46 +161,41 @@ struct TCP_Server_Info {
161 int srv_count; /* reference counter */ 161 int srv_count; /* reference counter */
162 /* 15 character server name + 0x20 16th byte indicating type = srv */ 162 /* 15 character server name + 0x20 16th byte indicating type = srv */
163 char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; 163 char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
164 enum statusEnum tcpStatus; /* what we think the status is */
164 char *hostname; /* hostname portion of UNC string */ 165 char *hostname; /* hostname portion of UNC string */
165 struct socket *ssocket; 166 struct socket *ssocket;
166 struct sockaddr_storage dstaddr; 167 struct sockaddr_storage dstaddr;
167 struct sockaddr_storage srcaddr; /* locally bind to this IP */ 168 struct sockaddr_storage srcaddr; /* locally bind to this IP */
169#ifdef CONFIG_NET_NS
170 struct net *net;
171#endif
168 wait_queue_head_t response_q; 172 wait_queue_head_t response_q;
169 wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/ 173 wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
170 struct list_head pending_mid_q; 174 struct list_head pending_mid_q;
171 void *Server_NlsInfo; /* BB - placeholder for future NLS info */
172 unsigned short server_codepage; /* codepage for the server */
173 enum protocolEnum protocolType;
174 char versionMajor;
175 char versionMinor;
176 bool svlocal:1; /* local server or remote */
177 bool noblocksnd; /* use blocking sendmsg */ 175 bool noblocksnd; /* use blocking sendmsg */
178 bool noautotune; /* do not autotune send buf sizes */ 176 bool noautotune; /* do not autotune send buf sizes */
179 bool tcp_nodelay; 177 bool tcp_nodelay;
180 atomic_t inFlight; /* number of requests on the wire to server */ 178 atomic_t inFlight; /* number of requests on the wire to server */
181#ifdef CONFIG_CIFS_STATS2
182 atomic_t inSend; /* requests trying to send */
183 atomic_t num_waiters; /* blocked waiting to get in sendrecv */
184#endif
185 enum statusEnum tcpStatus; /* what we think the status is */
186 struct mutex srv_mutex; 179 struct mutex srv_mutex;
187 struct task_struct *tsk; 180 struct task_struct *tsk;
188 char server_GUID[16]; 181 char server_GUID[16];
189 char secMode; 182 char secMode;
183 bool session_estab; /* mark when very first sess is established */
184 u16 dialect; /* dialect index that server chose */
190 enum securityEnum secType; 185 enum securityEnum secType;
191 unsigned int maxReq; /* Clients should submit no more */ 186 unsigned int maxReq; /* Clients should submit no more */
192 /* than maxReq distinct unanswered SMBs to the server when using */ 187 /* than maxReq distinct unanswered SMBs to the server when using */
193 /* multiplexed reads or writes */ 188 /* multiplexed reads or writes */
194 unsigned int maxBuf; /* maxBuf specifies the maximum */ 189 unsigned int maxBuf; /* maxBuf specifies the maximum */
195 /* message size the server can send or receive for non-raw SMBs */ 190 /* message size the server can send or receive for non-raw SMBs */
191 /* maxBuf is returned by SMB NegotiateProtocol so maxBuf is only 0 */
192 /* when socket is setup (and during reconnect) before NegProt sent */
196 unsigned int max_rw; /* maxRw specifies the maximum */ 193 unsigned int max_rw; /* maxRw specifies the maximum */
197 /* message size the server can send or receive for */ 194 /* message size the server can send or receive for */
198 /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */ 195 /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
199 unsigned int max_vcs; /* maximum number of smb sessions, at least 196 unsigned int max_vcs; /* maximum number of smb sessions, at least
200 those that can be specified uniquely with 197 those that can be specified uniquely with
201 vcnumbers */ 198 vcnumbers */
202 char sessid[4]; /* unique token id for this session */
203 /* (returned on Negotiate */
204 int capabilities; /* allow selective disabling of caps by smb sess */ 199 int capabilities; /* allow selective disabling of caps by smb sess */
205 int timeAdj; /* Adjust for difference in server time zone in sec */ 200 int timeAdj; /* Adjust for difference in server time zone in sec */
206 __u16 CurrentMid; /* multiplex id - rotating counter */ 201 __u16 CurrentMid; /* multiplex id - rotating counter */
@@ -210,20 +205,53 @@ struct TCP_Server_Info {
210 __u32 sequence_number; /* for signing, protected by srv_mutex */ 205 __u32 sequence_number; /* for signing, protected by srv_mutex */
211 struct session_key session_key; 206 struct session_key session_key;
212 unsigned long lstrp; /* when we got last response from this server */ 207 unsigned long lstrp; /* when we got last response from this server */
213 u16 dialect; /* dialect index that server chose */
214 struct cifs_secmech secmech; /* crypto sec mech functs, descriptors */ 208 struct cifs_secmech secmech; /* crypto sec mech functs, descriptors */
215 /* extended security flavors that server supports */ 209 /* extended security flavors that server supports */
210 bool sec_ntlmssp; /* supports NTLMSSP */
211 bool sec_kerberosu2u; /* supports U2U Kerberos */
216 bool sec_kerberos; /* supports plain Kerberos */ 212 bool sec_kerberos; /* supports plain Kerberos */
217 bool sec_mskerberos; /* supports legacy MS Kerberos */ 213 bool sec_mskerberos; /* supports legacy MS Kerberos */
218 bool sec_kerberosu2u; /* supports U2U Kerberos */ 214 struct delayed_work echo; /* echo ping workqueue job */
219 bool sec_ntlmssp; /* supports NTLMSSP */
220 bool session_estab; /* mark when very first sess is established */
221#ifdef CONFIG_CIFS_FSCACHE 215#ifdef CONFIG_CIFS_FSCACHE
222 struct fscache_cookie *fscache; /* client index cache cookie */ 216 struct fscache_cookie *fscache; /* client index cache cookie */
223#endif 217#endif
218#ifdef CONFIG_CIFS_STATS2
219 atomic_t inSend; /* requests trying to send */
220 atomic_t num_waiters; /* blocked waiting to get in sendrecv */
221#endif
224}; 222};
225 223
226/* 224/*
225 * Macros to allow the TCP_Server_Info->net field and related code to drop out
226 * when CONFIG_NET_NS isn't set.
227 */
228
229#ifdef CONFIG_NET_NS
230
231static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv)
232{
233 return srv->net;
234}
235
236static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net)
237{
238 srv->net = net;
239}
240
241#else
242
243static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv)
244{
245 return &init_net;
246}
247
248static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net)
249{
250}
251
252#endif
253
254/*
227 * Session structure. One of these for each uid session with a particular host 255 * Session structure. One of these for each uid session with a particular host
228 */ 256 */
229struct cifsSesInfo { 257struct cifsSesInfo {
@@ -246,7 +274,7 @@ struct cifsSesInfo {
246 int capabilities; 274 int capabilities;
247 char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for 275 char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for
248 TCP names - will ipv6 and sctp addresses fit? */ 276 TCP names - will ipv6 and sctp addresses fit? */
249 char userName[MAX_USERNAME_SIZE + 1]; 277 char *user_name;
250 char *domainName; 278 char *domainName;
251 char *password; 279 char *password;
252 struct session_key auth_key; 280 struct session_key auth_key;
@@ -446,11 +474,11 @@ struct cifsInodeInfo {
446 /* BB add in lists for dirty pages i.e. write caching info for oplock */ 474 /* BB add in lists for dirty pages i.e. write caching info for oplock */
447 struct list_head openFileList; 475 struct list_head openFileList;
448 __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */ 476 __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
449 unsigned long time; /* jiffies of last update/check of inode */ 477 bool clientCanCacheRead; /* read oplock */
450 bool clientCanCacheRead:1; /* read oplock */ 478 bool clientCanCacheAll; /* read and writebehind oplock */
451 bool clientCanCacheAll:1; /* read and writebehind oplock */ 479 bool delete_pending; /* DELETE_ON_CLOSE is set */
452 bool delete_pending:1; /* DELETE_ON_CLOSE is set */ 480 bool invalid_mapping; /* pagecache is invalid */
453 bool invalid_mapping:1; /* pagecache is invalid */ 481 unsigned long time; /* jiffies of last update of inode */
454 u64 server_eof; /* current file size on server */ 482 u64 server_eof; /* current file size on server */
455 u64 uniqueid; /* server inode number */ 483 u64 uniqueid; /* server inode number */
456 u64 createtime; /* creation time on server */ 484 u64 createtime; /* creation time on server */
@@ -508,6 +536,18 @@ static inline void cifs_stats_bytes_read(struct cifsTconInfo *tcon,
508 536
509#endif 537#endif
510 538
539struct mid_q_entry;
540
541/*
542 * This is the prototype for the mid callback function. When creating one,
543 * take special care to avoid deadlocks. Things to bear in mind:
544 *
545 * - it will be called by cifsd
546 * - the GlobalMid_Lock will be held
547 * - the mid will be removed from the pending_mid_q list
548 */
549typedef void (mid_callback_t)(struct mid_q_entry *mid);
550
511/* one of these for every pending CIFS request to the server */ 551/* one of these for every pending CIFS request to the server */
512struct mid_q_entry { 552struct mid_q_entry {
513 struct list_head qhead; /* mids waiting on reply from this server */ 553 struct list_head qhead; /* mids waiting on reply from this server */
@@ -519,7 +559,8 @@ struct mid_q_entry {
519 unsigned long when_sent; /* time when smb send finished */ 559 unsigned long when_sent; /* time when smb send finished */
520 unsigned long when_received; /* when demux complete (taken off wire) */ 560 unsigned long when_received; /* when demux complete (taken off wire) */
521#endif 561#endif
522 struct task_struct *tsk; /* task waiting for response */ 562 mid_callback_t *callback; /* call completion callback */
563 void *callback_data; /* general purpose pointer for callback */
523 struct smb_hdr *resp_buf; /* response buffer */ 564 struct smb_hdr *resp_buf; /* response buffer */
524 int midState; /* wish this were enum but can not pass to wait_event */ 565 int midState; /* wish this were enum but can not pass to wait_event */
525 __u8 command; /* smb command code */ 566 __u8 command; /* smb command code */
@@ -613,7 +654,7 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,
613#define MID_REQUEST_SUBMITTED 2 654#define MID_REQUEST_SUBMITTED 2
614#define MID_RESPONSE_RECEIVED 4 655#define MID_RESPONSE_RECEIVED 4
615#define MID_RETRY_NEEDED 8 /* session closed while this request out */ 656#define MID_RETRY_NEEDED 8 /* session closed while this request out */
616#define MID_NO_RESP_NEEDED 0x10 657#define MID_RESPONSE_MALFORMED 0x10
617 658
618/* Types of response buffer returned from SendReceive2 */ 659/* Types of response buffer returned from SendReceive2 */
619#define CIFS_NO_BUFFER 0 /* Response buffer not returned */ 660#define CIFS_NO_BUFFER 0 /* Response buffer not returned */
@@ -622,12 +663,9 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,
622#define CIFS_IOVEC 4 /* array of response buffers */ 663#define CIFS_IOVEC 4 /* array of response buffers */
623 664
624/* Type of Request to SendReceive2 */ 665/* Type of Request to SendReceive2 */
625#define CIFS_STD_OP 0 /* normal request timeout */ 666#define CIFS_BLOCKING_OP 1 /* operation can block */
626#define CIFS_LONG_OP 1 /* long op (up to 45 sec, oplock time) */ 667#define CIFS_ASYNC_OP 2 /* do not wait for response */
627#define CIFS_VLONG_OP 2 /* sloow op - can take up to 180 seconds */ 668#define CIFS_TIMEOUT_MASK 0x003 /* only one of above set in req */
628#define CIFS_BLOCKING_OP 4 /* operation can block */
629#define CIFS_ASYNC_OP 8 /* do not wait for response */
630#define CIFS_TIMEOUT_MASK 0x00F /* only one of 5 above set in req */
631#define CIFS_LOG_ERROR 0x010 /* log NT STATUS if non-zero */ 669#define CIFS_LOG_ERROR 0x010 /* log NT STATUS if non-zero */
632#define CIFS_LARGE_BUF_OP 0x020 /* large request buffer */ 670#define CIFS_LARGE_BUF_OP 0x020 /* large request buffer */
633#define CIFS_NO_RESP 0x040 /* no response buffer required */ 671#define CIFS_NO_RESP 0x040 /* no response buffer required */
@@ -779,7 +817,6 @@ GLOBAL_EXTERN unsigned int multiuser_mount; /* if enabled allows new sessions
779 have the uid/password or Kerberos credential 817 have the uid/password or Kerberos credential
780 or equivalent for current user */ 818 or equivalent for current user */
781GLOBAL_EXTERN unsigned int oplockEnabled; 819GLOBAL_EXTERN unsigned int oplockEnabled;
782GLOBAL_EXTERN unsigned int experimEnabled;
783GLOBAL_EXTERN unsigned int lookupCacheEnabled; 820GLOBAL_EXTERN unsigned int lookupCacheEnabled;
784GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sent 821GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sent
785 with more secure ntlmssp2 challenge/resp */ 822 with more secure ntlmssp2 challenge/resp */
@@ -790,6 +827,9 @@ GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
790GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */ 827GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */
791GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/ 828GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/
792 829
830/* reconnect after this many failed echo attempts */
831GLOBAL_EXTERN unsigned short echo_retries;
832
793void cifs_oplock_break(struct work_struct *work); 833void cifs_oplock_break(struct work_struct *work);
794void cifs_oplock_break_get(struct cifsFileInfo *cfile); 834void cifs_oplock_break_get(struct cifsFileInfo *cfile);
795void cifs_oplock_break_put(struct cifsFileInfo *cfile); 835void cifs_oplock_break_put(struct cifsFileInfo *cfile);
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h
index de36b09763a8..b5c8cc5d7a7f 100644
--- a/fs/cifs/cifspdu.h
+++ b/fs/cifs/cifspdu.h
@@ -23,6 +23,7 @@
23#define _CIFSPDU_H 23#define _CIFSPDU_H
24 24
25#include <net/sock.h> 25#include <net/sock.h>
26#include <asm/unaligned.h>
26#include "smbfsctl.h" 27#include "smbfsctl.h"
27 28
28#ifdef CONFIG_CIFS_WEAK_PW_HASH 29#ifdef CONFIG_CIFS_WEAK_PW_HASH
@@ -50,6 +51,7 @@
50#define SMB_COM_SETATTR 0x09 /* trivial response */ 51#define SMB_COM_SETATTR 0x09 /* trivial response */
51#define SMB_COM_LOCKING_ANDX 0x24 /* trivial response */ 52#define SMB_COM_LOCKING_ANDX 0x24 /* trivial response */
52#define SMB_COM_COPY 0x29 /* trivial rsp, fail filename ignrd*/ 53#define SMB_COM_COPY 0x29 /* trivial rsp, fail filename ignrd*/
54#define SMB_COM_ECHO 0x2B /* echo request */
53#define SMB_COM_OPEN_ANDX 0x2D /* Legacy open for old servers */ 55#define SMB_COM_OPEN_ANDX 0x2D /* Legacy open for old servers */
54#define SMB_COM_READ_ANDX 0x2E 56#define SMB_COM_READ_ANDX 0x2E
55#define SMB_COM_WRITE_ANDX 0x2F 57#define SMB_COM_WRITE_ANDX 0x2F
@@ -425,11 +427,49 @@ struct smb_hdr {
425 __u16 Mid; 427 __u16 Mid;
426 __u8 WordCount; 428 __u8 WordCount;
427} __attribute__((packed)); 429} __attribute__((packed));
428/* given a pointer to an smb_hdr retrieve the value of byte count */ 430
429#define BCC(smb_var) (*(__u16 *)((char *)(smb_var) + sizeof(struct smb_hdr) + (2 * (smb_var)->WordCount))) 431/* given a pointer to an smb_hdr retrieve a char pointer to the byte count */
430#define BCC_LE(smb_var) (*(__le16 *)((char *)(smb_var) + sizeof(struct smb_hdr) + (2 * (smb_var)->WordCount))) 432#define BCC(smb_var) ((unsigned char *)(smb_var) + sizeof(struct smb_hdr) + \
433 (2 * (smb_var)->WordCount))
434
431/* given a pointer to an smb_hdr retrieve the pointer to the byte area */ 435/* given a pointer to an smb_hdr retrieve the pointer to the byte area */
432#define pByteArea(smb_var) ((unsigned char *)(smb_var) + sizeof(struct smb_hdr) + (2 * (smb_var)->WordCount) + 2) 436#define pByteArea(smb_var) (BCC(smb_var) + 2)
437
438/* get the converted ByteCount for a SMB packet and return it */
439static inline __u16
440get_bcc(struct smb_hdr *hdr)
441{
442 __u16 *bc_ptr = (__u16 *)BCC(hdr);
443
444 return get_unaligned(bc_ptr);
445}
446
447/* get the unconverted ByteCount for a SMB packet and return it */
448static inline __u16
449get_bcc_le(struct smb_hdr *hdr)
450{
451 __le16 *bc_ptr = (__le16 *)BCC(hdr);
452
453 return get_unaligned_le16(bc_ptr);
454}
455
456/* set the ByteCount for a SMB packet in host-byte order */
457static inline void
458put_bcc(__u16 count, struct smb_hdr *hdr)
459{
460 __u16 *bc_ptr = (__u16 *)BCC(hdr);
461
462 put_unaligned(count, bc_ptr);
463}
464
465/* set the ByteCount for a SMB packet in little-endian */
466static inline void
467put_bcc_le(__u16 count, struct smb_hdr *hdr)
468{
469 __le16 *bc_ptr = (__le16 *)BCC(hdr);
470
471 put_unaligned_le16(count, bc_ptr);
472}
433 473
434/* 474/*
435 * Computer Name Length (since Netbios name was length 16 with last byte 0x20) 475 * Computer Name Length (since Netbios name was length 16 with last byte 0x20)
@@ -760,6 +800,20 @@ typedef struct smb_com_tconx_rsp_ext {
760 * 800 *
761 */ 801 */
762 802
803typedef struct smb_com_echo_req {
804 struct smb_hdr hdr;
805 __le16 EchoCount;
806 __le16 ByteCount;
807 char Data[1];
808} __attribute__((packed)) ECHO_REQ;
809
810typedef struct smb_com_echo_rsp {
811 struct smb_hdr hdr;
812 __le16 SequenceNumber;
813 __le16 ByteCount;
814 char Data[1];
815} __attribute__((packed)) ECHO_RSP;
816
763typedef struct smb_com_logoff_andx_req { 817typedef struct smb_com_logoff_andx_req {
764 struct smb_hdr hdr; /* wct = 2 */ 818 struct smb_hdr hdr; /* wct = 2 */
765 __u8 AndXCommand; 819 __u8 AndXCommand;
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index e6d1481b16c1..8096f27ad9a8 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -61,6 +61,12 @@ extern char *cifs_compose_mount_options(const char *sb_mountdata,
61 const char *fullpath, const struct dfs_info3_param *ref, 61 const char *fullpath, const struct dfs_info3_param *ref,
62 char **devname); 62 char **devname);
63/* extern void renew_parental_timestamps(struct dentry *direntry);*/ 63/* extern void renew_parental_timestamps(struct dentry *direntry);*/
64extern struct mid_q_entry *AllocMidQEntry(const struct smb_hdr *smb_buffer,
65 struct TCP_Server_Info *server);
66extern void DeleteMidQEntry(struct mid_q_entry *midEntry);
67extern int cifs_call_async(struct TCP_Server_Info *server,
68 struct smb_hdr *in_buf, mid_callback_t *callback,
69 void *cbdata);
64extern int SendReceive(const unsigned int /* xid */ , struct cifsSesInfo *, 70extern int SendReceive(const unsigned int /* xid */ , struct cifsSesInfo *,
65 struct smb_hdr * /* input */ , 71 struct smb_hdr * /* input */ ,
66 struct smb_hdr * /* out */ , 72 struct smb_hdr * /* out */ ,
@@ -79,6 +85,8 @@ extern int checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length);
79extern bool is_valid_oplock_break(struct smb_hdr *smb, 85extern bool is_valid_oplock_break(struct smb_hdr *smb,
80 struct TCP_Server_Info *); 86 struct TCP_Server_Info *);
81extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof); 87extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof);
88extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
89 unsigned int bytes_written);
82extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); 90extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool);
83extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); 91extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool);
84extern unsigned int smbCalcSize(struct smb_hdr *ptr); 92extern unsigned int smbCalcSize(struct smb_hdr *ptr);
@@ -347,12 +355,13 @@ extern int CIFSSMBLock(const int xid, struct cifsTconInfo *tcon,
347 const __u16 netfid, const __u64 len, 355 const __u16 netfid, const __u64 len,
348 const __u64 offset, const __u32 numUnlock, 356 const __u64 offset, const __u32 numUnlock,
349 const __u32 numLock, const __u8 lockType, 357 const __u32 numLock, const __u8 lockType,
350 const bool waitFlag); 358 const bool waitFlag, const __u8 oplock_level);
351extern int CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, 359extern int CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
352 const __u16 smb_file_id, const int get_flag, 360 const __u16 smb_file_id, const int get_flag,
353 const __u64 len, struct file_lock *, 361 const __u64 len, struct file_lock *,
354 const __u16 lock_type, const bool waitFlag); 362 const __u16 lock_type, const bool waitFlag);
355extern int CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon); 363extern int CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon);
364extern int CIFSSMBEcho(struct TCP_Server_Info *server);
356extern int CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses); 365extern int CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses);
357 366
358extern struct cifsSesInfo *sesInfoAlloc(void); 367extern struct cifsSesInfo *sesInfoAlloc(void);
@@ -366,7 +375,7 @@ extern int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *,
366extern int cifs_verify_signature(struct smb_hdr *, 375extern int cifs_verify_signature(struct smb_hdr *,
367 struct TCP_Server_Info *server, 376 struct TCP_Server_Info *server,
368 __u32 expected_sequence_number); 377 __u32 expected_sequence_number);
369extern void SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *); 378extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *);
370extern int setup_ntlm_response(struct cifsSesInfo *); 379extern int setup_ntlm_response(struct cifsSesInfo *);
371extern int setup_ntlmv2_rsp(struct cifsSesInfo *, const struct nls_table *); 380extern int setup_ntlmv2_rsp(struct cifsSesInfo *, const struct nls_table *);
372extern int cifs_crypto_shash_allocate(struct TCP_Server_Info *); 381extern int cifs_crypto_shash_allocate(struct TCP_Server_Info *);
@@ -416,4 +425,11 @@ extern bool CIFSCouldBeMFSymlink(const struct cifs_fattr *fattr);
416extern int CIFSCheckMFSymlink(struct cifs_fattr *fattr, 425extern int CIFSCheckMFSymlink(struct cifs_fattr *fattr,
417 const unsigned char *path, 426 const unsigned char *path,
418 struct cifs_sb_info *cifs_sb, int xid); 427 struct cifs_sb_info *cifs_sb, int xid);
428extern int mdfour(unsigned char *, unsigned char *, int);
429extern int E_md4hash(const unsigned char *passwd, unsigned char *p16);
430extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8,
431 unsigned char *p24);
432extern void E_P16(unsigned char *p14, unsigned char *p16);
433extern void E_P24(unsigned char *p21, const unsigned char *c8,
434 unsigned char *p24);
419#endif /* _CIFSPROTO_H */ 435#endif /* _CIFSPROTO_H */
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 2f6795e524d3..df959bae6728 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -136,18 +136,15 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command)
136 } 136 }
137 } 137 }
138 138
139 if (ses->status == CifsExiting)
140 return -EIO;
141
142 /* 139 /*
143 * Give demultiplex thread up to 10 seconds to reconnect, should be 140 * Give demultiplex thread up to 10 seconds to reconnect, should be
144 * greater than cifs socket timeout which is 7 seconds 141 * greater than cifs socket timeout which is 7 seconds
145 */ 142 */
146 while (server->tcpStatus == CifsNeedReconnect) { 143 while (server->tcpStatus == CifsNeedReconnect) {
147 wait_event_interruptible_timeout(server->response_q, 144 wait_event_interruptible_timeout(server->response_q,
148 (server->tcpStatus == CifsGood), 10 * HZ); 145 (server->tcpStatus != CifsNeedReconnect), 10 * HZ);
149 146
150 /* is TCP session is reestablished now ?*/ 147 /* are we still trying to reconnect? */
151 if (server->tcpStatus != CifsNeedReconnect) 148 if (server->tcpStatus != CifsNeedReconnect)
152 break; 149 break;
153 150
@@ -156,7 +153,7 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command)
156 * retrying until process is killed or server comes 153 * retrying until process is killed or server comes
157 * back on-line 154 * back on-line
158 */ 155 */
159 if (!tcon->retry || ses->status == CifsExiting) { 156 if (!tcon->retry) {
160 cFYI(1, "gave up waiting on reconnect in smb_init"); 157 cFYI(1, "gave up waiting on reconnect in smb_init");
161 return -EHOSTDOWN; 158 return -EHOSTDOWN;
162 } 159 }
@@ -331,37 +328,35 @@ smb_init_no_reconnect(int smb_command, int wct, struct cifsTconInfo *tcon,
331 328
332static int validate_t2(struct smb_t2_rsp *pSMB) 329static int validate_t2(struct smb_t2_rsp *pSMB)
333{ 330{
334 int rc = -EINVAL; 331 unsigned int total_size;
335 int total_size; 332
336 char *pBCC; 333 /* check for plausible wct */
334 if (pSMB->hdr.WordCount < 10)
335 goto vt2_err;
337 336
338 /* check for plausible wct, bcc and t2 data and parm sizes */
339 /* check for parm and data offset going beyond end of smb */ 337 /* check for parm and data offset going beyond end of smb */
340 if (pSMB->hdr.WordCount >= 10) { 338 if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 ||
341 if ((le16_to_cpu(pSMB->t2_rsp.ParameterOffset) <= 1024) && 339 get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024)
342 (le16_to_cpu(pSMB->t2_rsp.DataOffset) <= 1024)) { 340 goto vt2_err;
343 /* check that bcc is at least as big as parms + data */ 341
344 /* check that bcc is less than negotiated smb buffer */ 342 /* check that bcc is at least as big as parms + data */
345 total_size = le16_to_cpu(pSMB->t2_rsp.ParameterCount); 343 /* check that bcc is less than negotiated smb buffer */
346 if (total_size < 512) { 344 total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount);
347 total_size += 345 if (total_size >= 512)
348 le16_to_cpu(pSMB->t2_rsp.DataCount); 346 goto vt2_err;
349 /* BCC le converted in SendReceive */ 347
350 pBCC = (pSMB->hdr.WordCount * 2) + 348 total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount);
351 sizeof(struct smb_hdr) + 349 if (total_size > get_bcc(&pSMB->hdr) ||
352 (char *)pSMB; 350 total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE)
353 if ((total_size <= (*(u16 *)pBCC)) && 351 goto vt2_err;
354 (total_size < 352
355 CIFSMaxBufSize+MAX_CIFS_HDR_SIZE)) { 353 return 0;
356 return 0; 354vt2_err:
357 }
358 }
359 }
360 }
361 cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, 355 cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB,
362 sizeof(struct smb_t2_rsp) + 16); 356 sizeof(struct smb_t2_rsp) + 16);
363 return rc; 357 return -EINVAL;
364} 358}
359
365int 360int
366CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) 361CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
367{ 362{
@@ -452,7 +447,6 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
452 server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize), 447 server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize),
453 (__u32)CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); 448 (__u32)CIFSMaxBufSize + MAX_CIFS_HDR_SIZE);
454 server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs); 449 server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs);
455 GETU32(server->sessid) = le32_to_cpu(rsp->SessionKey);
456 /* even though we do not use raw we might as well set this 450 /* even though we do not use raw we might as well set this
457 accurately, in case we ever find a need for it */ 451 accurately, in case we ever find a need for it */
458 if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { 452 if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) {
@@ -566,7 +560,6 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
566 (__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); 560 (__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE);
567 server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); 561 server->max_rw = le32_to_cpu(pSMBr->MaxRawSize);
568 cFYI(DBG2, "Max buf = %d", ses->server->maxBuf); 562 cFYI(DBG2, "Max buf = %d", ses->server->maxBuf);
569 GETU32(ses->server->sessid) = le32_to_cpu(pSMBr->SessionKey);
570 server->capabilities = le32_to_cpu(pSMBr->Capabilities); 563 server->capabilities = le32_to_cpu(pSMBr->Capabilities);
571 server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); 564 server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone);
572 server->timeAdj *= 60; 565 server->timeAdj *= 60;
@@ -706,6 +699,53 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon)
706 return rc; 699 return rc;
707} 700}
708 701
702/*
703 * This is a no-op for now. We're not really interested in the reply, but
704 * rather in the fact that the server sent one and that server->lstrp
705 * gets updated.
706 *
707 * FIXME: maybe we should consider checking that the reply matches request?
708 */
709static void
710cifs_echo_callback(struct mid_q_entry *mid)
711{
712 struct TCP_Server_Info *server = mid->callback_data;
713
714 DeleteMidQEntry(mid);
715 atomic_dec(&server->inFlight);
716 wake_up(&server->request_q);
717}
718
719int
720CIFSSMBEcho(struct TCP_Server_Info *server)
721{
722 ECHO_REQ *smb;
723 int rc = 0;
724
725 cFYI(1, "In echo request");
726
727 rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb);
728 if (rc)
729 return rc;
730
731 /* set up echo request */
732 smb->hdr.Tid = 0xffff;
733 smb->hdr.WordCount = 1;
734 put_unaligned_le16(1, &smb->EchoCount);
735 put_bcc_le(1, &smb->hdr);
736 smb->Data[0] = 'a';
737 smb->hdr.smb_buf_length += 3;
738
739 rc = cifs_call_async(server, (struct smb_hdr *)smb,
740 cifs_echo_callback, server);
741 if (rc)
742 cFYI(1, "Echo request failed: %d", rc);
743
744 cifs_small_buf_release(smb);
745
746 return rc;
747}
748
709int 749int
710CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) 750CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses)
711{ 751{
@@ -1193,7 +1233,7 @@ OldOpenRetry:
1193 pSMB->ByteCount = cpu_to_le16(count); 1233 pSMB->ByteCount = cpu_to_le16(count);
1194 /* long_op set to 1 to allow for oplock break timeouts */ 1234 /* long_op set to 1 to allow for oplock break timeouts */
1195 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 1235 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
1196 (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP); 1236 (struct smb_hdr *)pSMBr, &bytes_returned, 0);
1197 cifs_stats_inc(&tcon->num_opens); 1237 cifs_stats_inc(&tcon->num_opens);
1198 if (rc) { 1238 if (rc) {
1199 cFYI(1, "Error in Open = %d", rc); 1239 cFYI(1, "Error in Open = %d", rc);
@@ -1306,7 +1346,7 @@ openRetry:
1306 pSMB->ByteCount = cpu_to_le16(count); 1346 pSMB->ByteCount = cpu_to_le16(count);
1307 /* long_op set to 1 to allow for oplock break timeouts */ 1347 /* long_op set to 1 to allow for oplock break timeouts */
1308 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 1348 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
1309 (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP); 1349 (struct smb_hdr *)pSMBr, &bytes_returned, 0);
1310 cifs_stats_inc(&tcon->num_opens); 1350 cifs_stats_inc(&tcon->num_opens);
1311 if (rc) { 1351 if (rc) {
1312 cFYI(1, "Error in Open = %d", rc); 1352 cFYI(1, "Error in Open = %d", rc);
@@ -1388,7 +1428,7 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid,
1388 iov[0].iov_base = (char *)pSMB; 1428 iov[0].iov_base = (char *)pSMB;
1389 iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; 1429 iov[0].iov_len = pSMB->hdr.smb_buf_length + 4;
1390 rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, 1430 rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */,
1391 &resp_buf_type, CIFS_STD_OP | CIFS_LOG_ERROR); 1431 &resp_buf_type, CIFS_LOG_ERROR);
1392 cifs_stats_inc(&tcon->num_reads); 1432 cifs_stats_inc(&tcon->num_reads);
1393 pSMBr = (READ_RSP *)iov[0].iov_base; 1433 pSMBr = (READ_RSP *)iov[0].iov_base;
1394 if (rc) { 1434 if (rc) {
@@ -1663,7 +1703,8 @@ int
1663CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, 1703CIFSSMBLock(const int xid, struct cifsTconInfo *tcon,
1664 const __u16 smb_file_id, const __u64 len, 1704 const __u16 smb_file_id, const __u64 len,
1665 const __u64 offset, const __u32 numUnlock, 1705 const __u64 offset, const __u32 numUnlock,
1666 const __u32 numLock, const __u8 lockType, const bool waitFlag) 1706 const __u32 numLock, const __u8 lockType,
1707 const bool waitFlag, const __u8 oplock_level)
1667{ 1708{
1668 int rc = 0; 1709 int rc = 0;
1669 LOCK_REQ *pSMB = NULL; 1710 LOCK_REQ *pSMB = NULL;
@@ -1691,6 +1732,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon,
1691 pSMB->NumberOfLocks = cpu_to_le16(numLock); 1732 pSMB->NumberOfLocks = cpu_to_le16(numLock);
1692 pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); 1733 pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock);
1693 pSMB->LockType = lockType; 1734 pSMB->LockType = lockType;
1735 pSMB->OplockLevel = oplock_level;
1694 pSMB->AndXCommand = 0xFF; /* none */ 1736 pSMB->AndXCommand = 0xFF; /* none */
1695 pSMB->Fid = smb_file_id; /* netfid stays le */ 1737 pSMB->Fid = smb_file_id; /* netfid stays le */
1696 1738
@@ -1842,10 +1884,10 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
1842 __constant_cpu_to_le16(CIFS_WRLCK)) 1884 __constant_cpu_to_le16(CIFS_WRLCK))
1843 pLockData->fl_type = F_WRLCK; 1885 pLockData->fl_type = F_WRLCK;
1844 1886
1845 pLockData->fl_start = parm_data->start; 1887 pLockData->fl_start = le64_to_cpu(parm_data->start);
1846 pLockData->fl_end = parm_data->start + 1888 pLockData->fl_end = pLockData->fl_start +
1847 parm_data->length - 1; 1889 le64_to_cpu(parm_data->length) - 1;
1848 pLockData->fl_pid = parm_data->pid; 1890 pLockData->fl_pid = le32_to_cpu(parm_data->pid);
1849 } 1891 }
1850 } 1892 }
1851 1893
@@ -3087,7 +3129,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
3087 iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; 3129 iov[0].iov_len = pSMB->hdr.smb_buf_length + 4;
3088 3130
3089 rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, 3131 rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type,
3090 CIFS_STD_OP); 3132 0);
3091 cifs_stats_inc(&tcon->num_acl_get); 3133 cifs_stats_inc(&tcon->num_acl_get);
3092 if (rc) { 3134 if (rc) {
3093 cFYI(1, "Send error in QuerySecDesc = %d", rc); 3135 cFYI(1, "Send error in QuerySecDesc = %d", rc);
@@ -4869,7 +4911,6 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
4869 __u16 fid, __u32 pid_of_opener, bool SetAllocation) 4911 __u16 fid, __u32 pid_of_opener, bool SetAllocation)
4870{ 4912{
4871 struct smb_com_transaction2_sfi_req *pSMB = NULL; 4913 struct smb_com_transaction2_sfi_req *pSMB = NULL;
4872 char *data_offset;
4873 struct file_end_of_file_info *parm_data; 4914 struct file_end_of_file_info *parm_data;
4874 int rc = 0; 4915 int rc = 0;
4875 __u16 params, param_offset, offset, byte_count, count; 4916 __u16 params, param_offset, offset, byte_count, count;
@@ -4893,8 +4934,6 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
4893 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; 4934 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4;
4894 offset = param_offset + params; 4935 offset = param_offset + params;
4895 4936
4896 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
4897
4898 count = sizeof(struct file_end_of_file_info); 4937 count = sizeof(struct file_end_of_file_info);
4899 pSMB->MaxParameterCount = cpu_to_le16(2); 4938 pSMB->MaxParameterCount = cpu_to_le16(2);
4900 /* BB find exact max SMB PDU from sess structure BB */ 4939 /* BB find exact max SMB PDU from sess structure BB */
@@ -5208,7 +5247,7 @@ cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset,
5208 * Samba server ignores set of file size to zero due to bugs in some 5247 * Samba server ignores set of file size to zero due to bugs in some
5209 * older clients, but we should be precise - we use SetFileSize to 5248 * older clients, but we should be precise - we use SetFileSize to
5210 * set file size and do not want to truncate file size to zero 5249 * set file size and do not want to truncate file size to zero
5211 * accidently as happened on one Samba server beta by putting 5250 * accidentally as happened on one Samba server beta by putting
5212 * zero instead of -1 here 5251 * zero instead of -1 here
5213 */ 5252 */
5214 data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); 5253 data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64);
@@ -5562,7 +5601,7 @@ QAllEAsRetry:
5562 } 5601 }
5563 5602
5564 /* make sure list_len doesn't go past end of SMB */ 5603 /* make sure list_len doesn't go past end of SMB */
5565 end_of_smb = (char *)pByteArea(&pSMBr->hdr) + BCC(&pSMBr->hdr); 5604 end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr);
5566 if ((char *)ea_response_data + list_len > end_of_smb) { 5605 if ((char *)ea_response_data + list_len > end_of_smb) {
5567 cFYI(1, "EA list appears to go beyond SMB"); 5606 cFYI(1, "EA list appears to go beyond SMB");
5568 rc = -EIO; 5607 rc = -EIO;
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index a65d311d163a..db9d55b507d0 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -52,8 +52,8 @@
52#define CIFS_PORT 445 52#define CIFS_PORT 445
53#define RFC1001_PORT 139 53#define RFC1001_PORT 139
54 54
55extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, 55/* SMB echo "timeout" -- FIXME: tunable? */
56 unsigned char *p24); 56#define SMB_ECHO_INTERVAL (60 * HZ)
57 57
58extern mempool_t *cifs_req_poolp; 58extern mempool_t *cifs_req_poolp;
59 59
@@ -84,6 +84,7 @@ struct smb_vol {
84 bool no_xattr:1; /* set if xattr (EA) support should be disabled*/ 84 bool no_xattr:1; /* set if xattr (EA) support should be disabled*/
85 bool server_ino:1; /* use inode numbers from server ie UniqueId */ 85 bool server_ino:1; /* use inode numbers from server ie UniqueId */
86 bool direct_io:1; 86 bool direct_io:1;
87 bool strict_io:1; /* strict cache behavior */
87 bool remap:1; /* set to remap seven reserved chars in filenames */ 88 bool remap:1; /* set to remap seven reserved chars in filenames */
88 bool posix_paths:1; /* unset to not ask for posix pathnames. */ 89 bool posix_paths:1; /* unset to not ask for posix pathnames. */
89 bool no_linux_ext:1; 90 bool no_linux_ext:1;
@@ -152,6 +153,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
152 153
153 /* before reconnecting the tcp session, mark the smb session (uid) 154 /* before reconnecting the tcp session, mark the smb session (uid)
154 and the tid bad so they are not used until reconnected */ 155 and the tid bad so they are not used until reconnected */
156 cFYI(1, "%s: marking sessions and tcons for reconnect", __func__);
155 spin_lock(&cifs_tcp_ses_lock); 157 spin_lock(&cifs_tcp_ses_lock);
156 list_for_each(tmp, &server->smb_ses_list) { 158 list_for_each(tmp, &server->smb_ses_list) {
157 ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list); 159 ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list);
@@ -163,7 +165,9 @@ cifs_reconnect(struct TCP_Server_Info *server)
163 } 165 }
164 } 166 }
165 spin_unlock(&cifs_tcp_ses_lock); 167 spin_unlock(&cifs_tcp_ses_lock);
168
166 /* do not want to be sending data on a socket we are freeing */ 169 /* do not want to be sending data on a socket we are freeing */
170 cFYI(1, "%s: tearing down socket", __func__);
167 mutex_lock(&server->srv_mutex); 171 mutex_lock(&server->srv_mutex);
168 if (server->ssocket) { 172 if (server->ssocket) {
169 cFYI(1, "State: 0x%x Flags: 0x%lx", server->ssocket->state, 173 cFYI(1, "State: 0x%x Flags: 0x%lx", server->ssocket->state,
@@ -180,25 +184,22 @@ cifs_reconnect(struct TCP_Server_Info *server)
180 kfree(server->session_key.response); 184 kfree(server->session_key.response);
181 server->session_key.response = NULL; 185 server->session_key.response = NULL;
182 server->session_key.len = 0; 186 server->session_key.len = 0;
187 server->lstrp = jiffies;
188 mutex_unlock(&server->srv_mutex);
183 189
190 /* mark submitted MIDs for retry and issue callback */
191 cFYI(1, "%s: issuing mid callbacks", __func__);
184 spin_lock(&GlobalMid_Lock); 192 spin_lock(&GlobalMid_Lock);
185 list_for_each(tmp, &server->pending_mid_q) { 193 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
186 mid_entry = list_entry(tmp, struct 194 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
187 mid_q_entry, 195 if (mid_entry->midState == MID_REQUEST_SUBMITTED)
188 qhead);
189 if (mid_entry->midState == MID_REQUEST_SUBMITTED) {
190 /* Mark other intransit requests as needing
191 retry so we do not immediately mark the
192 session bad again (ie after we reconnect
193 below) as they timeout too */
194 mid_entry->midState = MID_RETRY_NEEDED; 196 mid_entry->midState = MID_RETRY_NEEDED;
195 } 197 list_del_init(&mid_entry->qhead);
198 mid_entry->callback(mid_entry);
196 } 199 }
197 spin_unlock(&GlobalMid_Lock); 200 spin_unlock(&GlobalMid_Lock);
198 mutex_unlock(&server->srv_mutex);
199 201
200 while ((server->tcpStatus != CifsExiting) && 202 while (server->tcpStatus == CifsNeedReconnect) {
201 (server->tcpStatus != CifsGood)) {
202 try_to_freeze(); 203 try_to_freeze();
203 204
204 /* we should try only the port we connected to before */ 205 /* we should try only the port we connected to before */
@@ -210,12 +211,11 @@ cifs_reconnect(struct TCP_Server_Info *server)
210 atomic_inc(&tcpSesReconnectCount); 211 atomic_inc(&tcpSesReconnectCount);
211 spin_lock(&GlobalMid_Lock); 212 spin_lock(&GlobalMid_Lock);
212 if (server->tcpStatus != CifsExiting) 213 if (server->tcpStatus != CifsExiting)
213 server->tcpStatus = CifsGood; 214 server->tcpStatus = CifsNeedNegotiate;
214 spin_unlock(&GlobalMid_Lock); 215 spin_unlock(&GlobalMid_Lock);
215 /* atomic_set(&server->inFlight,0);*/
216 wake_up(&server->response_q);
217 } 216 }
218 } 217 }
218
219 return rc; 219 return rc;
220} 220}
221 221
@@ -229,9 +229,8 @@ cifs_reconnect(struct TCP_Server_Info *server)
229static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize) 229static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize)
230{ 230{
231 struct smb_t2_rsp *pSMBt; 231 struct smb_t2_rsp *pSMBt;
232 int total_data_size;
233 int data_in_this_rsp;
234 int remaining; 232 int remaining;
233 __u16 total_data_size, data_in_this_rsp;
235 234
236 if (pSMB->Command != SMB_COM_TRANSACTION2) 235 if (pSMB->Command != SMB_COM_TRANSACTION2)
237 return 0; 236 return 0;
@@ -245,48 +244,45 @@ static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize)
245 244
246 pSMBt = (struct smb_t2_rsp *)pSMB; 245 pSMBt = (struct smb_t2_rsp *)pSMB;
247 246
248 total_data_size = le16_to_cpu(pSMBt->t2_rsp.TotalDataCount); 247 total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
249 data_in_this_rsp = le16_to_cpu(pSMBt->t2_rsp.DataCount); 248 data_in_this_rsp = get_unaligned_le16(&pSMBt->t2_rsp.DataCount);
250 249
251 remaining = total_data_size - data_in_this_rsp; 250 if (total_data_size == data_in_this_rsp)
252
253 if (remaining == 0)
254 return 0; 251 return 0;
255 else if (remaining < 0) { 252 else if (total_data_size < data_in_this_rsp) {
256 cFYI(1, "total data %d smaller than data in frame %d", 253 cFYI(1, "total data %d smaller than data in frame %d",
257 total_data_size, data_in_this_rsp); 254 total_data_size, data_in_this_rsp);
258 return -EINVAL; 255 return -EINVAL;
259 } else {
260 cFYI(1, "missing %d bytes from transact2, check next response",
261 remaining);
262 if (total_data_size > maxBufSize) {
263 cERROR(1, "TotalDataSize %d is over maximum buffer %d",
264 total_data_size, maxBufSize);
265 return -EINVAL;
266 }
267 return remaining;
268 } 256 }
257
258 remaining = total_data_size - data_in_this_rsp;
259
260 cFYI(1, "missing %d bytes from transact2, check next response",
261 remaining);
262 if (total_data_size > maxBufSize) {
263 cERROR(1, "TotalDataSize %d is over maximum buffer %d",
264 total_data_size, maxBufSize);
265 return -EINVAL;
266 }
267 return remaining;
269} 268}
270 269
271static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB) 270static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
272{ 271{
273 struct smb_t2_rsp *pSMB2 = (struct smb_t2_rsp *)psecond; 272 struct smb_t2_rsp *pSMB2 = (struct smb_t2_rsp *)psecond;
274 struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)pTargetSMB; 273 struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)pTargetSMB;
275 int total_data_size;
276 int total_in_buf;
277 int remaining;
278 int total_in_buf2;
279 char *data_area_of_target; 274 char *data_area_of_target;
280 char *data_area_of_buf2; 275 char *data_area_of_buf2;
281 __u16 byte_count; 276 int remaining;
277 __u16 byte_count, total_data_size, total_in_buf, total_in_buf2;
282 278
283 total_data_size = le16_to_cpu(pSMBt->t2_rsp.TotalDataCount); 279 total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
284 280
285 if (total_data_size != le16_to_cpu(pSMB2->t2_rsp.TotalDataCount)) { 281 if (total_data_size !=
282 get_unaligned_le16(&pSMB2->t2_rsp.TotalDataCount))
286 cFYI(1, "total data size of primary and secondary t2 differ"); 283 cFYI(1, "total data size of primary and secondary t2 differ");
287 }
288 284
289 total_in_buf = le16_to_cpu(pSMBt->t2_rsp.DataCount); 285 total_in_buf = get_unaligned_le16(&pSMBt->t2_rsp.DataCount);
290 286
291 remaining = total_data_size - total_in_buf; 287 remaining = total_data_size - total_in_buf;
292 288
@@ -296,28 +292,28 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
296 if (remaining == 0) /* nothing to do, ignore */ 292 if (remaining == 0) /* nothing to do, ignore */
297 return 0; 293 return 0;
298 294
299 total_in_buf2 = le16_to_cpu(pSMB2->t2_rsp.DataCount); 295 total_in_buf2 = get_unaligned_le16(&pSMB2->t2_rsp.DataCount);
300 if (remaining < total_in_buf2) { 296 if (remaining < total_in_buf2) {
301 cFYI(1, "transact2 2nd response contains too much data"); 297 cFYI(1, "transact2 2nd response contains too much data");
302 } 298 }
303 299
304 /* find end of first SMB data area */ 300 /* find end of first SMB data area */
305 data_area_of_target = (char *)&pSMBt->hdr.Protocol + 301 data_area_of_target = (char *)&pSMBt->hdr.Protocol +
306 le16_to_cpu(pSMBt->t2_rsp.DataOffset); 302 get_unaligned_le16(&pSMBt->t2_rsp.DataOffset);
307 /* validate target area */ 303 /* validate target area */
308 304
309 data_area_of_buf2 = (char *) &pSMB2->hdr.Protocol + 305 data_area_of_buf2 = (char *)&pSMB2->hdr.Protocol +
310 le16_to_cpu(pSMB2->t2_rsp.DataOffset); 306 get_unaligned_le16(&pSMB2->t2_rsp.DataOffset);
311 307
312 data_area_of_target += total_in_buf; 308 data_area_of_target += total_in_buf;
313 309
314 /* copy second buffer into end of first buffer */ 310 /* copy second buffer into end of first buffer */
315 memcpy(data_area_of_target, data_area_of_buf2, total_in_buf2); 311 memcpy(data_area_of_target, data_area_of_buf2, total_in_buf2);
316 total_in_buf += total_in_buf2; 312 total_in_buf += total_in_buf2;
317 pSMBt->t2_rsp.DataCount = cpu_to_le16(total_in_buf); 313 put_unaligned_le16(total_in_buf, &pSMBt->t2_rsp.DataCount);
318 byte_count = le16_to_cpu(BCC_LE(pTargetSMB)); 314 byte_count = get_bcc_le(pTargetSMB);
319 byte_count += total_in_buf2; 315 byte_count += total_in_buf2;
320 BCC_LE(pTargetSMB) = cpu_to_le16(byte_count); 316 put_bcc_le(byte_count, pTargetSMB);
321 317
322 byte_count = pTargetSMB->smb_buf_length; 318 byte_count = pTargetSMB->smb_buf_length;
323 byte_count += total_in_buf2; 319 byte_count += total_in_buf2;
@@ -331,7 +327,31 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
331 return 0; /* we are done */ 327 return 0; /* we are done */
332 } else /* more responses to go */ 328 } else /* more responses to go */
333 return 1; 329 return 1;
330}
334 331
332static void
333cifs_echo_request(struct work_struct *work)
334{
335 int rc;
336 struct TCP_Server_Info *server = container_of(work,
337 struct TCP_Server_Info, echo.work);
338
339 /*
340 * We cannot send an echo until the NEGOTIATE_PROTOCOL request is
341 * done, which is indicated by maxBuf != 0. Also, no need to ping if
342 * we got a response recently
343 */
344 if (server->maxBuf == 0 ||
345 time_before(jiffies, server->lstrp + SMB_ECHO_INTERVAL - HZ))
346 goto requeue_echo;
347
348 rc = CIFSSMBEcho(server);
349 if (rc)
350 cFYI(1, "Unable to send echo request to server: %s",
351 server->hostname);
352
353requeue_echo:
354 queue_delayed_work(system_nrt_wq, &server->echo, SMB_ECHO_INTERVAL);
335} 355}
336 356
337static int 357static int
@@ -345,8 +365,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
345 struct msghdr smb_msg; 365 struct msghdr smb_msg;
346 struct kvec iov; 366 struct kvec iov;
347 struct socket *csocket = server->ssocket; 367 struct socket *csocket = server->ssocket;
348 struct list_head *tmp; 368 struct list_head *tmp, *tmp2;
349 struct cifsSesInfo *ses;
350 struct task_struct *task_to_wake = NULL; 369 struct task_struct *task_to_wake = NULL;
351 struct mid_q_entry *mid_entry; 370 struct mid_q_entry *mid_entry;
352 char temp; 371 char temp;
@@ -399,7 +418,20 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
399 smb_msg.msg_control = NULL; 418 smb_msg.msg_control = NULL;
400 smb_msg.msg_controllen = 0; 419 smb_msg.msg_controllen = 0;
401 pdu_length = 4; /* enough to get RFC1001 header */ 420 pdu_length = 4; /* enough to get RFC1001 header */
421
402incomplete_rcv: 422incomplete_rcv:
423 if (echo_retries > 0 && server->tcpStatus == CifsGood &&
424 time_after(jiffies, server->lstrp +
425 (echo_retries * SMB_ECHO_INTERVAL))) {
426 cERROR(1, "Server %s has not responded in %d seconds. "
427 "Reconnecting...", server->hostname,
428 (echo_retries * SMB_ECHO_INTERVAL / HZ));
429 cifs_reconnect(server);
430 csocket = server->ssocket;
431 wake_up(&server->response_q);
432 continue;
433 }
434
403 length = 435 length =
404 kernel_recvmsg(csocket, &smb_msg, 436 kernel_recvmsg(csocket, &smb_msg,
405 &iov, 1, pdu_length, 0 /* BB other flags? */); 437 &iov, 1, pdu_length, 0 /* BB other flags? */);
@@ -550,25 +582,36 @@ incomplete_rcv:
550 else if (reconnect == 1) 582 else if (reconnect == 1)
551 continue; 583 continue;
552 584
553 length += 4; /* account for rfc1002 hdr */ 585 total_read += 4; /* account for rfc1002 hdr */
554 586
587 dump_smb(smb_buffer, total_read);
555 588
556 dump_smb(smb_buffer, length); 589 /*
557 if (checkSMB(smb_buffer, smb_buffer->Mid, total_read+4)) { 590 * We know that we received enough to get to the MID as we
558 cifs_dump_mem("Bad SMB: ", smb_buffer, 48); 591 * checked the pdu_length earlier. Now check to see
559 continue; 592 * if the rest of the header is OK. We borrow the length
560 } 593 * var for the rest of the loop to avoid a new stack var.
594 *
595 * 48 bytes is enough to display the header and a little bit
596 * into the payload for debugging purposes.
597 */
598 length = checkSMB(smb_buffer, smb_buffer->Mid, total_read);
599 if (length != 0)
600 cifs_dump_mem("Bad SMB: ", smb_buffer,
601 min_t(unsigned int, total_read, 48));
561 602
603 mid_entry = NULL;
604 server->lstrp = jiffies;
562 605
563 task_to_wake = NULL;
564 spin_lock(&GlobalMid_Lock); 606 spin_lock(&GlobalMid_Lock);
565 list_for_each(tmp, &server->pending_mid_q) { 607 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
566 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 608 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
567 609
568 if ((mid_entry->mid == smb_buffer->Mid) && 610 if ((mid_entry->mid == smb_buffer->Mid) &&
569 (mid_entry->midState == MID_REQUEST_SUBMITTED) && 611 (mid_entry->midState == MID_REQUEST_SUBMITTED) &&
570 (mid_entry->command == smb_buffer->Command)) { 612 (mid_entry->command == smb_buffer->Command)) {
571 if (check2ndT2(smb_buffer,server->maxBuf) > 0) { 613 if (length == 0 &&
614 check2ndT2(smb_buffer, server->maxBuf) > 0) {
572 /* We have a multipart transact2 resp */ 615 /* We have a multipart transact2 resp */
573 isMultiRsp = true; 616 isMultiRsp = true;
574 if (mid_entry->resp_buf) { 617 if (mid_entry->resp_buf) {
@@ -603,20 +646,24 @@ incomplete_rcv:
603 mid_entry->resp_buf = smb_buffer; 646 mid_entry->resp_buf = smb_buffer;
604 mid_entry->largeBuf = isLargeBuf; 647 mid_entry->largeBuf = isLargeBuf;
605multi_t2_fnd: 648multi_t2_fnd:
606 task_to_wake = mid_entry->tsk; 649 if (length == 0)
607 mid_entry->midState = MID_RESPONSE_RECEIVED; 650 mid_entry->midState =
651 MID_RESPONSE_RECEIVED;
652 else
653 mid_entry->midState =
654 MID_RESPONSE_MALFORMED;
608#ifdef CONFIG_CIFS_STATS2 655#ifdef CONFIG_CIFS_STATS2
609 mid_entry->when_received = jiffies; 656 mid_entry->when_received = jiffies;
610#endif 657#endif
611 /* so we do not time out requests to server 658 list_del_init(&mid_entry->qhead);
612 which is still responding (since server could 659 mid_entry->callback(mid_entry);
613 be busy but not dead) */
614 server->lstrp = jiffies;
615 break; 660 break;
616 } 661 }
662 mid_entry = NULL;
617 } 663 }
618 spin_unlock(&GlobalMid_Lock); 664 spin_unlock(&GlobalMid_Lock);
619 if (task_to_wake) { 665
666 if (mid_entry != NULL) {
620 /* Was previous buf put in mpx struct for multi-rsp? */ 667 /* Was previous buf put in mpx struct for multi-rsp? */
621 if (!isMultiRsp) { 668 if (!isMultiRsp) {
622 /* smb buffer will be freed by user thread */ 669 /* smb buffer will be freed by user thread */
@@ -625,11 +672,13 @@ multi_t2_fnd:
625 else 672 else
626 smallbuf = NULL; 673 smallbuf = NULL;
627 } 674 }
628 wake_up_process(task_to_wake); 675 } else if (length != 0) {
676 /* response sanity checks failed */
677 continue;
629 } else if (!is_valid_oplock_break(smb_buffer, server) && 678 } else if (!is_valid_oplock_break(smb_buffer, server) &&
630 !isMultiRsp) { 679 !isMultiRsp) {
631 cERROR(1, "No task to wake, unknown frame received! " 680 cERROR(1, "No task to wake, unknown frame received! "
632 "NumMids %d", midCount.counter); 681 "NumMids %d", atomic_read(&midCount));
633 cifs_dump_mem("Received Data is: ", (char *)smb_buffer, 682 cifs_dump_mem("Received Data is: ", (char *)smb_buffer,
634 sizeof(struct smb_hdr)); 683 sizeof(struct smb_hdr));
635#ifdef CONFIG_CIFS_DEBUG2 684#ifdef CONFIG_CIFS_DEBUG2
@@ -677,44 +726,16 @@ multi_t2_fnd:
677 if (smallbuf) /* no sense logging a debug message if NULL */ 726 if (smallbuf) /* no sense logging a debug message if NULL */
678 cifs_small_buf_release(smallbuf); 727 cifs_small_buf_release(smallbuf);
679 728
680 /* 729 if (!list_empty(&server->pending_mid_q)) {
681 * BB: we shouldn't have to do any of this. It shouldn't be
682 * possible to exit from the thread with active SMB sessions
683 */
684 spin_lock(&cifs_tcp_ses_lock);
685 if (list_empty(&server->pending_mid_q)) {
686 /* loop through server session structures attached to this and
687 mark them dead */
688 list_for_each(tmp, &server->smb_ses_list) {
689 ses = list_entry(tmp, struct cifsSesInfo,
690 smb_ses_list);
691 ses->status = CifsExiting;
692 ses->server = NULL;
693 }
694 spin_unlock(&cifs_tcp_ses_lock);
695 } else {
696 /* although we can not zero the server struct pointer yet,
697 since there are active requests which may depnd on them,
698 mark the corresponding SMB sessions as exiting too */
699 list_for_each(tmp, &server->smb_ses_list) {
700 ses = list_entry(tmp, struct cifsSesInfo,
701 smb_ses_list);
702 ses->status = CifsExiting;
703 }
704
705 spin_lock(&GlobalMid_Lock); 730 spin_lock(&GlobalMid_Lock);
706 list_for_each(tmp, &server->pending_mid_q) { 731 list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
707 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 732 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
708 if (mid_entry->midState == MID_REQUEST_SUBMITTED) { 733 cFYI(1, "Clearing Mid 0x%x - issuing callback",
709 cFYI(1, "Clearing Mid 0x%x - waking up ",
710 mid_entry->mid); 734 mid_entry->mid);
711 task_to_wake = mid_entry->tsk; 735 list_del_init(&mid_entry->qhead);
712 if (task_to_wake) 736 mid_entry->callback(mid_entry);
713 wake_up_process(task_to_wake);
714 }
715 } 737 }
716 spin_unlock(&GlobalMid_Lock); 738 spin_unlock(&GlobalMid_Lock);
717 spin_unlock(&cifs_tcp_ses_lock);
718 /* 1/8th of sec is more than enough time for them to exit */ 739 /* 1/8th of sec is more than enough time for them to exit */
719 msleep(125); 740 msleep(125);
720 } 741 }
@@ -732,18 +753,6 @@ multi_t2_fnd:
732 coming home not much else we can do but free the memory */ 753 coming home not much else we can do but free the memory */
733 } 754 }
734 755
735 /* last chance to mark ses pointers invalid
736 if there are any pointing to this (e.g
737 if a crazy root user tried to kill cifsd
738 kernel thread explicitly this might happen) */
739 /* BB: This shouldn't be necessary, see above */
740 spin_lock(&cifs_tcp_ses_lock);
741 list_for_each(tmp, &server->smb_ses_list) {
742 ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list);
743 ses->server = NULL;
744 }
745 spin_unlock(&cifs_tcp_ses_lock);
746
747 kfree(server->hostname); 756 kfree(server->hostname);
748 task_to_wake = xchg(&server->tsk, NULL); 757 task_to_wake = xchg(&server->tsk, NULL);
749 kfree(server); 758 kfree(server);
@@ -871,7 +880,8 @@ cifs_parse_mount_options(char *options, const char *devname,
871 /* null user, ie anonymous, authentication */ 880 /* null user, ie anonymous, authentication */
872 vol->nullauth = 1; 881 vol->nullauth = 1;
873 } 882 }
874 if (strnlen(value, 200) < 200) { 883 if (strnlen(value, MAX_USERNAME_SIZE) <
884 MAX_USERNAME_SIZE) {
875 vol->username = value; 885 vol->username = value;
876 } else { 886 } else {
877 printk(KERN_WARNING "CIFS: username too long\n"); 887 printk(KERN_WARNING "CIFS: username too long\n");
@@ -1113,6 +1123,8 @@ cifs_parse_mount_options(char *options, const char *devname,
1113 } else if (!strnicmp(data, "uid", 3) && value && *value) { 1123 } else if (!strnicmp(data, "uid", 3) && value && *value) {
1114 vol->linux_uid = simple_strtoul(value, &value, 0); 1124 vol->linux_uid = simple_strtoul(value, &value, 0);
1115 uid_specified = true; 1125 uid_specified = true;
1126 } else if (!strnicmp(data, "cruid", 5) && value && *value) {
1127 vol->cred_uid = simple_strtoul(value, &value, 0);
1116 } else if (!strnicmp(data, "forceuid", 8)) { 1128 } else if (!strnicmp(data, "forceuid", 8)) {
1117 override_uid = 1; 1129 override_uid = 1;
1118 } else if (!strnicmp(data, "noforceuid", 10)) { 1130 } else if (!strnicmp(data, "noforceuid", 10)) {
@@ -1353,6 +1365,8 @@ cifs_parse_mount_options(char *options, const char *devname,
1353 vol->direct_io = 1; 1365 vol->direct_io = 1;
1354 } else if (strnicmp(data, "forcedirectio", 13) == 0) { 1366 } else if (strnicmp(data, "forcedirectio", 13) == 0) {
1355 vol->direct_io = 1; 1367 vol->direct_io = 1;
1368 } else if (strnicmp(data, "strictcache", 11) == 0) {
1369 vol->strict_io = 1;
1356 } else if (strnicmp(data, "noac", 4) == 0) { 1370 } else if (strnicmp(data, "noac", 4) == 0) {
1357 printk(KERN_WARNING "CIFS: Mount option noac not " 1371 printk(KERN_WARNING "CIFS: Mount option noac not "
1358 "supported. Instead set " 1372 "supported. Instead set "
@@ -1458,7 +1472,7 @@ srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs)
1458static bool 1472static bool
1459match_port(struct TCP_Server_Info *server, struct sockaddr *addr) 1473match_port(struct TCP_Server_Info *server, struct sockaddr *addr)
1460{ 1474{
1461 unsigned short int port, *sport; 1475 __be16 port, *sport;
1462 1476
1463 switch (addr->sa_family) { 1477 switch (addr->sa_family) {
1464 case AF_INET: 1478 case AF_INET:
@@ -1558,7 +1572,7 @@ match_security(struct TCP_Server_Info *server, struct smb_vol *vol)
1558 return false; 1572 return false;
1559 } 1573 }
1560 1574
1561 /* now check if signing mode is acceptible */ 1575 /* now check if signing mode is acceptable */
1562 if ((secFlags & CIFSSEC_MAY_SIGN) == 0 && 1576 if ((secFlags & CIFSSEC_MAY_SIGN) == 0 &&
1563 (server->secMode & SECMODE_SIGN_REQUIRED)) 1577 (server->secMode & SECMODE_SIGN_REQUIRED))
1564 return false; 1578 return false;
@@ -1577,6 +1591,9 @@ cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol)
1577 1591
1578 spin_lock(&cifs_tcp_ses_lock); 1592 spin_lock(&cifs_tcp_ses_lock);
1579 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) { 1593 list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
1594 if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns))
1595 continue;
1596
1580 if (!match_address(server, addr, 1597 if (!match_address(server, addr,
1581 (struct sockaddr *)&vol->srcaddr)) 1598 (struct sockaddr *)&vol->srcaddr))
1582 continue; 1599 continue;
@@ -1607,9 +1624,13 @@ cifs_put_tcp_session(struct TCP_Server_Info *server)
1607 return; 1624 return;
1608 } 1625 }
1609 1626
1627 put_net(cifs_net_ns(server));
1628
1610 list_del_init(&server->tcp_ses_list); 1629 list_del_init(&server->tcp_ses_list);
1611 spin_unlock(&cifs_tcp_ses_lock); 1630 spin_unlock(&cifs_tcp_ses_lock);
1612 1631
1632 cancel_delayed_work_sync(&server->echo);
1633
1613 spin_lock(&GlobalMid_Lock); 1634 spin_lock(&GlobalMid_Lock);
1614 server->tcpStatus = CifsExiting; 1635 server->tcpStatus = CifsExiting;
1615 spin_unlock(&GlobalMid_Lock); 1636 spin_unlock(&GlobalMid_Lock);
@@ -1679,6 +1700,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
1679 goto out_err; 1700 goto out_err;
1680 } 1701 }
1681 1702
1703 cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns));
1682 tcp_ses->hostname = extract_hostname(volume_info->UNC); 1704 tcp_ses->hostname = extract_hostname(volume_info->UNC);
1683 if (IS_ERR(tcp_ses->hostname)) { 1705 if (IS_ERR(tcp_ses->hostname)) {
1684 rc = PTR_ERR(tcp_ses->hostname); 1706 rc = PTR_ERR(tcp_ses->hostname);
@@ -1699,8 +1721,10 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
1699 volume_info->target_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL); 1721 volume_info->target_rfc1001_name, RFC1001_NAME_LEN_WITH_NULL);
1700 tcp_ses->session_estab = false; 1722 tcp_ses->session_estab = false;
1701 tcp_ses->sequence_number = 0; 1723 tcp_ses->sequence_number = 0;
1724 tcp_ses->lstrp = jiffies;
1702 INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); 1725 INIT_LIST_HEAD(&tcp_ses->tcp_ses_list);
1703 INIT_LIST_HEAD(&tcp_ses->smb_ses_list); 1726 INIT_LIST_HEAD(&tcp_ses->smb_ses_list);
1727 INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request);
1704 1728
1705 /* 1729 /*
1706 * at this point we are the only ones with the pointer 1730 * at this point we are the only ones with the pointer
@@ -1741,6 +1765,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
1741 module_put(THIS_MODULE); 1765 module_put(THIS_MODULE);
1742 goto out_err_crypto_release; 1766 goto out_err_crypto_release;
1743 } 1767 }
1768 tcp_ses->tcpStatus = CifsNeedNegotiate;
1744 1769
1745 /* thread spawned, put it on the list */ 1770 /* thread spawned, put it on the list */
1746 spin_lock(&cifs_tcp_ses_lock); 1771 spin_lock(&cifs_tcp_ses_lock);
@@ -1749,11 +1774,16 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
1749 1774
1750 cifs_fscache_get_client_cookie(tcp_ses); 1775 cifs_fscache_get_client_cookie(tcp_ses);
1751 1776
1777 /* queue echo request delayed work */
1778 queue_delayed_work(system_nrt_wq, &tcp_ses->echo, SMB_ECHO_INTERVAL);
1779
1752 return tcp_ses; 1780 return tcp_ses;
1753 1781
1754out_err_crypto_release: 1782out_err_crypto_release:
1755 cifs_crypto_shash_release(tcp_ses); 1783 cifs_crypto_shash_release(tcp_ses);
1756 1784
1785 put_net(cifs_net_ns(tcp_ses));
1786
1757out_err: 1787out_err:
1758 if (tcp_ses) { 1788 if (tcp_ses) {
1759 if (!IS_ERR(tcp_ses->hostname)) 1789 if (!IS_ERR(tcp_ses->hostname))
@@ -1779,7 +1809,9 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
1779 break; 1809 break;
1780 default: 1810 default:
1781 /* anything else takes username/password */ 1811 /* anything else takes username/password */
1782 if (strncmp(ses->userName, vol->username, 1812 if (ses->user_name == NULL)
1813 continue;
1814 if (strncmp(ses->user_name, vol->username,
1783 MAX_USERNAME_SIZE)) 1815 MAX_USERNAME_SIZE))
1784 continue; 1816 continue;
1785 if (strlen(vol->username) != 0 && 1817 if (strlen(vol->username) != 0 &&
@@ -1822,6 +1854,8 @@ cifs_put_smb_ses(struct cifsSesInfo *ses)
1822 cifs_put_tcp_session(server); 1854 cifs_put_tcp_session(server);
1823} 1855}
1824 1856
1857static bool warned_on_ntlm; /* globals init to false automatically */
1858
1825static struct cifsSesInfo * 1859static struct cifsSesInfo *
1826cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info) 1860cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
1827{ 1861{
@@ -1877,9 +1911,11 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
1877 else 1911 else
1878 sprintf(ses->serverName, "%pI4", &addr->sin_addr); 1912 sprintf(ses->serverName, "%pI4", &addr->sin_addr);
1879 1913
1880 if (volume_info->username) 1914 if (volume_info->username) {
1881 strncpy(ses->userName, volume_info->username, 1915 ses->user_name = kstrdup(volume_info->username, GFP_KERNEL);
1882 MAX_USERNAME_SIZE); 1916 if (!ses->user_name)
1917 goto get_ses_fail;
1918 }
1883 1919
1884 /* volume_info->password freed at unmount */ 1920 /* volume_info->password freed at unmount */
1885 if (volume_info->password) { 1921 if (volume_info->password) {
@@ -1894,6 +1930,15 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
1894 } 1930 }
1895 ses->cred_uid = volume_info->cred_uid; 1931 ses->cred_uid = volume_info->cred_uid;
1896 ses->linux_uid = volume_info->linux_uid; 1932 ses->linux_uid = volume_info->linux_uid;
1933
1934 /* ntlmv2 is much stronger than ntlm security, and has been broadly
1935 supported for many years, time to update default security mechanism */
1936 if ((volume_info->secFlg == 0) && warned_on_ntlm == false) {
1937 warned_on_ntlm = true;
1938 cERROR(1, "default security mechanism requested. The default "
1939 "security mechanism will be upgraded from ntlm to "
1940 "ntlmv2 in kernel release 2.6.41");
1941 }
1897 ses->overrideSecFlg = volume_info->secFlg; 1942 ses->overrideSecFlg = volume_info->secFlg;
1898 1943
1899 mutex_lock(&ses->session_mutex); 1944 mutex_lock(&ses->session_mutex);
@@ -2247,7 +2292,7 @@ static int
2247generic_ip_connect(struct TCP_Server_Info *server) 2292generic_ip_connect(struct TCP_Server_Info *server)
2248{ 2293{
2249 int rc = 0; 2294 int rc = 0;
2250 unsigned short int sport; 2295 __be16 sport;
2251 int slen, sfamily; 2296 int slen, sfamily;
2252 struct socket *socket = server->ssocket; 2297 struct socket *socket = server->ssocket;
2253 struct sockaddr *saddr; 2298 struct sockaddr *saddr;
@@ -2265,8 +2310,8 @@ generic_ip_connect(struct TCP_Server_Info *server)
2265 } 2310 }
2266 2311
2267 if (socket == NULL) { 2312 if (socket == NULL) {
2268 rc = sock_create_kern(sfamily, SOCK_STREAM, 2313 rc = __sock_create(cifs_net_ns(server), sfamily, SOCK_STREAM,
2269 IPPROTO_TCP, &socket); 2314 IPPROTO_TCP, &socket, 1);
2270 if (rc < 0) { 2315 if (rc < 0) {
2271 cERROR(1, "Error %d creating socket", rc); 2316 cERROR(1, "Error %d creating socket", rc);
2272 server->ssocket = NULL; 2317 server->ssocket = NULL;
@@ -2332,7 +2377,7 @@ generic_ip_connect(struct TCP_Server_Info *server)
2332static int 2377static int
2333ip_connect(struct TCP_Server_Info *server) 2378ip_connect(struct TCP_Server_Info *server)
2334{ 2379{
2335 unsigned short int *sport; 2380 __be16 *sport;
2336 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; 2381 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr;
2337 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; 2382 struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr;
2338 2383
@@ -2578,6 +2623,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
2578 if (pvolume_info->multiuser) 2623 if (pvolume_info->multiuser)
2579 cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER | 2624 cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER |
2580 CIFS_MOUNT_NO_PERM); 2625 CIFS_MOUNT_NO_PERM);
2626 if (pvolume_info->strict_io)
2627 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_STRICT_IO;
2581 if (pvolume_info->direct_io) { 2628 if (pvolume_info->direct_io) {
2582 cFYI(1, "mounting share using direct i/o"); 2629 cFYI(1, "mounting share using direct i/o");
2583 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO; 2630 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
@@ -2795,7 +2842,7 @@ try_mount_again:
2795 2842
2796remote_path_check: 2843remote_path_check:
2797 /* check if a whole path (including prepath) is not remote */ 2844 /* check if a whole path (including prepath) is not remote */
2798 if (!rc && cifs_sb->prepathlen && tcon) { 2845 if (!rc && tcon) {
2799 /* build_path_to_root works only when we have a valid tcon */ 2846 /* build_path_to_root works only when we have a valid tcon */
2800 full_path = cifs_build_path_to_root(cifs_sb, tcon); 2847 full_path = cifs_build_path_to_root(cifs_sb, tcon);
2801 if (full_path == NULL) { 2848 if (full_path == NULL) {
@@ -2902,7 +2949,7 @@ mount_fail_check:
2902 if (mount_data != mount_data_global) 2949 if (mount_data != mount_data_global)
2903 kfree(mount_data); 2950 kfree(mount_data);
2904 /* If find_unc succeeded then rc == 0 so we can not end */ 2951 /* If find_unc succeeded then rc == 0 so we can not end */
2905 /* up accidently freeing someone elses tcon struct */ 2952 /* up accidentally freeing someone elses tcon struct */
2906 if (tcon) 2953 if (tcon)
2907 cifs_put_tcon(tcon); 2954 cifs_put_tcon(tcon);
2908 else if (pSesInfo) 2955 else if (pSesInfo)
@@ -2934,8 +2981,8 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
2934 TCONX_RSP *pSMBr; 2981 TCONX_RSP *pSMBr;
2935 unsigned char *bcc_ptr; 2982 unsigned char *bcc_ptr;
2936 int rc = 0; 2983 int rc = 0;
2937 int length, bytes_left; 2984 int length;
2938 __u16 count; 2985 __u16 bytes_left, count;
2939 2986
2940 if (ses == NULL) 2987 if (ses == NULL)
2941 return -EIO; 2988 return -EIO;
@@ -2963,7 +3010,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
2963 bcc_ptr++; /* skip password */ 3010 bcc_ptr++; /* skip password */
2964 /* already aligned so no need to do it below */ 3011 /* already aligned so no need to do it below */
2965 } else { 3012 } else {
2966 pSMB->PasswordLength = cpu_to_le16(CIFS_SESS_KEY_SIZE); 3013 pSMB->PasswordLength = cpu_to_le16(CIFS_AUTH_RESP_SIZE);
2967 /* BB FIXME add code to fail this if NTLMv2 or Kerberos 3014 /* BB FIXME add code to fail this if NTLMv2 or Kerberos
2968 specified as required (when that support is added to 3015 specified as required (when that support is added to
2969 the vfs in the future) as only NTLM or the much 3016 the vfs in the future) as only NTLM or the much
@@ -2979,9 +3026,10 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
2979 bcc_ptr); 3026 bcc_ptr);
2980 else 3027 else
2981#endif /* CIFS_WEAK_PW_HASH */ 3028#endif /* CIFS_WEAK_PW_HASH */
2982 SMBNTencrypt(tcon->password, ses->server->cryptkey, bcc_ptr); 3029 rc = SMBNTencrypt(tcon->password, ses->server->cryptkey,
3030 bcc_ptr);
2983 3031
2984 bcc_ptr += CIFS_SESS_KEY_SIZE; 3032 bcc_ptr += CIFS_AUTH_RESP_SIZE;
2985 if (ses->capabilities & CAP_UNICODE) { 3033 if (ses->capabilities & CAP_UNICODE) {
2986 /* must align unicode strings */ 3034 /* must align unicode strings */
2987 *bcc_ptr = 0; /* null byte password */ 3035 *bcc_ptr = 0; /* null byte password */
@@ -3019,7 +3067,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3019 pSMB->ByteCount = cpu_to_le16(count); 3067 pSMB->ByteCount = cpu_to_le16(count);
3020 3068
3021 rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length, 3069 rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length,
3022 CIFS_STD_OP); 3070 0);
3023 3071
3024 /* above now done in SendReceive */ 3072 /* above now done in SendReceive */
3025 if ((rc == 0) && (tcon != NULL)) { 3073 if ((rc == 0) && (tcon != NULL)) {
@@ -3029,7 +3077,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3029 tcon->need_reconnect = false; 3077 tcon->need_reconnect = false;
3030 tcon->tid = smb_buffer_response->Tid; 3078 tcon->tid = smb_buffer_response->Tid;
3031 bcc_ptr = pByteArea(smb_buffer_response); 3079 bcc_ptr = pByteArea(smb_buffer_response);
3032 bytes_left = BCC(smb_buffer_response); 3080 bytes_left = get_bcc(smb_buffer_response);
3033 length = strnlen(bcc_ptr, bytes_left - 2); 3081 length = strnlen(bcc_ptr, bytes_left - 2);
3034 if (smb_buffer->Flags2 & SMBFLG2_UNICODE) 3082 if (smb_buffer->Flags2 & SMBFLG2_UNICODE)
3035 is_unicode = true; 3083 is_unicode = true;
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index dd5f22918c33..9ea65cf36714 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -189,7 +189,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
189 inode->i_sb, mode, oflags, &oplock, &fileHandle, xid); 189 inode->i_sb, mode, oflags, &oplock, &fileHandle, xid);
190 /* EIO could indicate that (posix open) operation is not 190 /* EIO could indicate that (posix open) operation is not
191 supported, despite what server claimed in capability 191 supported, despite what server claimed in capability
192 negotation. EREMOTE indicates DFS junction, which is not 192 negotiation. EREMOTE indicates DFS junction, which is not
193 handled in posix open */ 193 handled in posix open */
194 194
195 if (rc == 0) { 195 if (rc == 0) {
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index d843631c028d..faf59529e847 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -287,6 +287,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
287 struct inode *inode = cifs_file->dentry->d_inode; 287 struct inode *inode = cifs_file->dentry->d_inode;
288 struct cifsTconInfo *tcon = tlink_tcon(cifs_file->tlink); 288 struct cifsTconInfo *tcon = tlink_tcon(cifs_file->tlink);
289 struct cifsInodeInfo *cifsi = CIFS_I(inode); 289 struct cifsInodeInfo *cifsi = CIFS_I(inode);
290 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
290 struct cifsLockInfo *li, *tmp; 291 struct cifsLockInfo *li, *tmp;
291 292
292 spin_lock(&cifs_file_list_lock); 293 spin_lock(&cifs_file_list_lock);
@@ -302,6 +303,13 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
302 if (list_empty(&cifsi->openFileList)) { 303 if (list_empty(&cifsi->openFileList)) {
303 cFYI(1, "closing last open instance for inode %p", 304 cFYI(1, "closing last open instance for inode %p",
304 cifs_file->dentry->d_inode); 305 cifs_file->dentry->d_inode);
306
307 /* in strict cache mode we need invalidate mapping on the last
308 close because it may cause a error when we open this file
309 again and get at least level II oplock */
310 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
311 CIFS_I(inode)->invalid_mapping = true;
312
305 cifs_set_oplock_level(cifsi, 0); 313 cifs_set_oplock_level(cifsi, 0);
306 } 314 }
307 spin_unlock(&cifs_file_list_lock); 315 spin_unlock(&cifs_file_list_lock);
@@ -338,7 +346,6 @@ int cifs_open(struct inode *inode, struct file *file)
338 struct cifsTconInfo *tcon; 346 struct cifsTconInfo *tcon;
339 struct tcon_link *tlink; 347 struct tcon_link *tlink;
340 struct cifsFileInfo *pCifsFile = NULL; 348 struct cifsFileInfo *pCifsFile = NULL;
341 struct cifsInodeInfo *pCifsInode;
342 char *full_path = NULL; 349 char *full_path = NULL;
343 bool posix_open_ok = false; 350 bool posix_open_ok = false;
344 __u16 netfid; 351 __u16 netfid;
@@ -353,8 +360,6 @@ int cifs_open(struct inode *inode, struct file *file)
353 } 360 }
354 tcon = tlink_tcon(tlink); 361 tcon = tlink_tcon(tlink);
355 362
356 pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
357
358 full_path = build_path_from_dentry(file->f_path.dentry); 363 full_path = build_path_from_dentry(file->f_path.dentry);
359 if (full_path == NULL) { 364 if (full_path == NULL) {
360 rc = -ENOMEM; 365 rc = -ENOMEM;
@@ -570,8 +575,10 @@ reopen_error_exit:
570 575
571int cifs_close(struct inode *inode, struct file *file) 576int cifs_close(struct inode *inode, struct file *file)
572{ 577{
573 cifsFileInfo_put(file->private_data); 578 if (file->private_data != NULL) {
574 file->private_data = NULL; 579 cifsFileInfo_put(file->private_data);
580 file->private_data = NULL;
581 }
575 582
576 /* return code from the ->release op is always ignored */ 583 /* return code from the ->release op is always ignored */
577 return 0; 584 return 0;
@@ -726,12 +733,12 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
726 733
727 /* BB we could chain these into one lock request BB */ 734 /* BB we could chain these into one lock request BB */
728 rc = CIFSSMBLock(xid, tcon, netfid, length, pfLock->fl_start, 735 rc = CIFSSMBLock(xid, tcon, netfid, length, pfLock->fl_start,
729 0, 1, lockType, 0 /* wait flag */ ); 736 0, 1, lockType, 0 /* wait flag */, 0);
730 if (rc == 0) { 737 if (rc == 0) {
731 rc = CIFSSMBLock(xid, tcon, netfid, length, 738 rc = CIFSSMBLock(xid, tcon, netfid, length,
732 pfLock->fl_start, 1 /* numUnlock */ , 739 pfLock->fl_start, 1 /* numUnlock */ ,
733 0 /* numLock */ , lockType, 740 0 /* numLock */ , lockType,
734 0 /* wait flag */ ); 741 0 /* wait flag */, 0);
735 pfLock->fl_type = F_UNLCK; 742 pfLock->fl_type = F_UNLCK;
736 if (rc != 0) 743 if (rc != 0)
737 cERROR(1, "Error unlocking previously locked " 744 cERROR(1, "Error unlocking previously locked "
@@ -748,13 +755,13 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
748 rc = CIFSSMBLock(xid, tcon, netfid, length, 755 rc = CIFSSMBLock(xid, tcon, netfid, length,
749 pfLock->fl_start, 0, 1, 756 pfLock->fl_start, 0, 1,
750 lockType | LOCKING_ANDX_SHARED_LOCK, 757 lockType | LOCKING_ANDX_SHARED_LOCK,
751 0 /* wait flag */); 758 0 /* wait flag */, 0);
752 if (rc == 0) { 759 if (rc == 0) {
753 rc = CIFSSMBLock(xid, tcon, netfid, 760 rc = CIFSSMBLock(xid, tcon, netfid,
754 length, pfLock->fl_start, 1, 0, 761 length, pfLock->fl_start, 1, 0,
755 lockType | 762 lockType |
756 LOCKING_ANDX_SHARED_LOCK, 763 LOCKING_ANDX_SHARED_LOCK,
757 0 /* wait flag */); 764 0 /* wait flag */, 0);
758 pfLock->fl_type = F_RDLCK; 765 pfLock->fl_type = F_RDLCK;
759 if (rc != 0) 766 if (rc != 0)
760 cERROR(1, "Error unlocking " 767 cERROR(1, "Error unlocking "
@@ -797,8 +804,8 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
797 804
798 if (numLock) { 805 if (numLock) {
799 rc = CIFSSMBLock(xid, tcon, netfid, length, 806 rc = CIFSSMBLock(xid, tcon, netfid, length,
800 pfLock->fl_start, 807 pfLock->fl_start, 0, numLock, lockType,
801 0, numLock, lockType, wait_flag); 808 wait_flag, 0);
802 809
803 if (rc == 0) { 810 if (rc == 0) {
804 /* For Windows locks we must store them. */ 811 /* For Windows locks we must store them. */
@@ -818,9 +825,9 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
818 (pfLock->fl_start + length) >= 825 (pfLock->fl_start + length) >=
819 (li->offset + li->length)) { 826 (li->offset + li->length)) {
820 stored_rc = CIFSSMBLock(xid, tcon, 827 stored_rc = CIFSSMBLock(xid, tcon,
821 netfid, 828 netfid, li->length,
822 li->length, li->offset, 829 li->offset, 1, 0,
823 1, 0, li->type, false); 830 li->type, false, 0);
824 if (stored_rc) 831 if (stored_rc)
825 rc = stored_rc; 832 rc = stored_rc;
826 else { 833 else {
@@ -839,31 +846,8 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
839 return rc; 846 return rc;
840} 847}
841 848
842/*
843 * Set the timeout on write requests past EOF. For some servers (Windows)
844 * these calls can be very long.
845 *
846 * If we're writing >10M past the EOF we give a 180s timeout. Anything less
847 * than that gets a 45s timeout. Writes not past EOF get 15s timeouts.
848 * The 10M cutoff is totally arbitrary. A better scheme for this would be
849 * welcome if someone wants to suggest one.
850 *
851 * We may be able to do a better job with this if there were some way to
852 * declare that a file should be sparse.
853 */
854static int
855cifs_write_timeout(struct cifsInodeInfo *cifsi, loff_t offset)
856{
857 if (offset <= cifsi->server_eof)
858 return CIFS_STD_OP;
859 else if (offset > (cifsi->server_eof + (10 * 1024 * 1024)))
860 return CIFS_VLONG_OP;
861 else
862 return CIFS_LONG_OP;
863}
864
865/* update the file size (if needed) after a write */ 849/* update the file size (if needed) after a write */
866static void 850void
867cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, 851cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
868 unsigned int bytes_written) 852 unsigned int bytes_written)
869{ 853{
@@ -882,7 +866,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
882 unsigned int total_written; 866 unsigned int total_written;
883 struct cifs_sb_info *cifs_sb; 867 struct cifs_sb_info *cifs_sb;
884 struct cifsTconInfo *pTcon; 868 struct cifsTconInfo *pTcon;
885 int xid, long_op; 869 int xid;
886 struct cifsFileInfo *open_file; 870 struct cifsFileInfo *open_file;
887 struct cifsInodeInfo *cifsi = CIFS_I(inode); 871 struct cifsInodeInfo *cifsi = CIFS_I(inode);
888 872
@@ -903,7 +887,6 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
903 887
904 xid = GetXid(); 888 xid = GetXid();
905 889
906 long_op = cifs_write_timeout(cifsi, *poffset);
907 for (total_written = 0; write_size > total_written; 890 for (total_written = 0; write_size > total_written;
908 total_written += bytes_written) { 891 total_written += bytes_written) {
909 rc = -EAGAIN; 892 rc = -EAGAIN;
@@ -931,7 +914,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
931 min_t(const int, cifs_sb->wsize, 914 min_t(const int, cifs_sb->wsize,
932 write_size - total_written), 915 write_size - total_written),
933 *poffset, &bytes_written, 916 *poffset, &bytes_written,
934 NULL, write_data + total_written, long_op); 917 NULL, write_data + total_written, 0);
935 } 918 }
936 if (rc || (bytes_written == 0)) { 919 if (rc || (bytes_written == 0)) {
937 if (total_written) 920 if (total_written)
@@ -944,8 +927,6 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
944 cifs_update_eof(cifsi, *poffset, bytes_written); 927 cifs_update_eof(cifsi, *poffset, bytes_written);
945 *poffset += bytes_written; 928 *poffset += bytes_written;
946 } 929 }
947 long_op = CIFS_STD_OP; /* subsequent writes fast -
948 15 seconds is plenty */
949 } 930 }
950 931
951 cifs_stats_bytes_written(pTcon, total_written); 932 cifs_stats_bytes_written(pTcon, total_written);
@@ -974,7 +955,7 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file,
974 unsigned int total_written; 955 unsigned int total_written;
975 struct cifs_sb_info *cifs_sb; 956 struct cifs_sb_info *cifs_sb;
976 struct cifsTconInfo *pTcon; 957 struct cifsTconInfo *pTcon;
977 int xid, long_op; 958 int xid;
978 struct dentry *dentry = open_file->dentry; 959 struct dentry *dentry = open_file->dentry;
979 struct cifsInodeInfo *cifsi = CIFS_I(dentry->d_inode); 960 struct cifsInodeInfo *cifsi = CIFS_I(dentry->d_inode);
980 961
@@ -987,11 +968,13 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file,
987 968
988 xid = GetXid(); 969 xid = GetXid();
989 970
990 long_op = cifs_write_timeout(cifsi, *poffset);
991 for (total_written = 0; write_size > total_written; 971 for (total_written = 0; write_size > total_written;
992 total_written += bytes_written) { 972 total_written += bytes_written) {
993 rc = -EAGAIN; 973 rc = -EAGAIN;
994 while (rc == -EAGAIN) { 974 while (rc == -EAGAIN) {
975 struct kvec iov[2];
976 unsigned int len;
977
995 if (open_file->invalidHandle) { 978 if (open_file->invalidHandle) {
996 /* we could deadlock if we called 979 /* we could deadlock if we called
997 filemap_fdatawait from here so tell 980 filemap_fdatawait from here so tell
@@ -1001,31 +984,14 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file,
1001 if (rc != 0) 984 if (rc != 0)
1002 break; 985 break;
1003 } 986 }
1004 if (experimEnabled || (pTcon->ses->server && 987
1005 ((pTcon->ses->server->secMode & 988 len = min((size_t)cifs_sb->wsize,
1006 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) 989 write_size - total_written);
1007 == 0))) { 990 /* iov[0] is reserved for smb header */
1008 struct kvec iov[2]; 991 iov[1].iov_base = (char *)write_data + total_written;
1009 unsigned int len; 992 iov[1].iov_len = len;
1010 993 rc = CIFSSMBWrite2(xid, pTcon, open_file->netfid, len,
1011 len = min((size_t)cifs_sb->wsize, 994 *poffset, &bytes_written, iov, 1, 0);
1012 write_size - total_written);
1013 /* iov[0] is reserved for smb header */
1014 iov[1].iov_base = (char *)write_data +
1015 total_written;
1016 iov[1].iov_len = len;
1017 rc = CIFSSMBWrite2(xid, pTcon,
1018 open_file->netfid, len,
1019 *poffset, &bytes_written,
1020 iov, 1, long_op);
1021 } else
1022 rc = CIFSSMBWrite(xid, pTcon,
1023 open_file->netfid,
1024 min_t(const int, cifs_sb->wsize,
1025 write_size - total_written),
1026 *poffset, &bytes_written,
1027 write_data + total_written,
1028 NULL, long_op);
1029 } 995 }
1030 if (rc || (bytes_written == 0)) { 996 if (rc || (bytes_written == 0)) {
1031 if (total_written) 997 if (total_written)
@@ -1038,8 +1004,6 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file,
1038 cifs_update_eof(cifsi, *poffset, bytes_written); 1004 cifs_update_eof(cifsi, *poffset, bytes_written);
1039 *poffset += bytes_written; 1005 *poffset += bytes_written;
1040 } 1006 }
1041 long_op = CIFS_STD_OP; /* subsequent writes fast -
1042 15 seconds is plenty */
1043 } 1007 }
1044 1008
1045 cifs_stats_bytes_written(pTcon, total_written); 1009 cifs_stats_bytes_written(pTcon, total_written);
@@ -1167,7 +1131,6 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
1167 char *write_data; 1131 char *write_data;
1168 int rc = -EFAULT; 1132 int rc = -EFAULT;
1169 int bytes_written = 0; 1133 int bytes_written = 0;
1170 struct cifs_sb_info *cifs_sb;
1171 struct inode *inode; 1134 struct inode *inode;
1172 struct cifsFileInfo *open_file; 1135 struct cifsFileInfo *open_file;
1173 1136
@@ -1175,7 +1138,6 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
1175 return -EFAULT; 1138 return -EFAULT;
1176 1139
1177 inode = page->mapping->host; 1140 inode = page->mapping->host;
1178 cifs_sb = CIFS_SB(inode->i_sb);
1179 1141
1180 offset += (loff_t)from; 1142 offset += (loff_t)from;
1181 write_data = kmap(page); 1143 write_data = kmap(page);
@@ -1239,7 +1201,7 @@ static int cifs_writepages(struct address_space *mapping,
1239 struct pagevec pvec; 1201 struct pagevec pvec;
1240 int rc = 0; 1202 int rc = 0;
1241 int scanned = 0; 1203 int scanned = 0;
1242 int xid, long_op; 1204 int xid;
1243 1205
1244 cifs_sb = CIFS_SB(mapping->host->i_sb); 1206 cifs_sb = CIFS_SB(mapping->host->i_sb);
1245 1207
@@ -1266,12 +1228,6 @@ static int cifs_writepages(struct address_space *mapping,
1266 } 1228 }
1267 1229
1268 tcon = tlink_tcon(open_file->tlink); 1230 tcon = tlink_tcon(open_file->tlink);
1269 if (!experimEnabled && tcon->ses->server->secMode &
1270 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) {
1271 cifsFileInfo_put(open_file);
1272 kfree(iov);
1273 return generic_writepages(mapping, wbc);
1274 }
1275 cifsFileInfo_put(open_file); 1231 cifsFileInfo_put(open_file);
1276 1232
1277 xid = GetXid(); 1233 xid = GetXid();
@@ -1377,43 +1333,67 @@ retry:
1377 break; 1333 break;
1378 } 1334 }
1379 if (n_iov) { 1335 if (n_iov) {
1336retry_write:
1380 open_file = find_writable_file(CIFS_I(mapping->host), 1337 open_file = find_writable_file(CIFS_I(mapping->host),
1381 false); 1338 false);
1382 if (!open_file) { 1339 if (!open_file) {
1383 cERROR(1, "No writable handles for inode"); 1340 cERROR(1, "No writable handles for inode");
1384 rc = -EBADF; 1341 rc = -EBADF;
1385 } else { 1342 } else {
1386 long_op = cifs_write_timeout(cifsi, offset);
1387 rc = CIFSSMBWrite2(xid, tcon, open_file->netfid, 1343 rc = CIFSSMBWrite2(xid, tcon, open_file->netfid,
1388 bytes_to_write, offset, 1344 bytes_to_write, offset,
1389 &bytes_written, iov, n_iov, 1345 &bytes_written, iov, n_iov,
1390 long_op); 1346 0);
1391 cifsFileInfo_put(open_file); 1347 cifsFileInfo_put(open_file);
1392 cifs_update_eof(cifsi, offset, bytes_written);
1393 } 1348 }
1394 1349
1395 if (rc || bytes_written < bytes_to_write) { 1350 cFYI(1, "Write2 rc=%d, wrote=%u", rc, bytes_written);
1396 cERROR(1, "Write2 ret %d, wrote %d", 1351
1397 rc, bytes_written); 1352 /*
1398 mapping_set_error(mapping, rc); 1353 * For now, treat a short write as if nothing got
1399 } else { 1354 * written. A zero length write however indicates
1355 * ENOSPC or EFBIG. We have no way to know which
1356 * though, so call it ENOSPC for now. EFBIG would
1357 * get translated to AS_EIO anyway.
1358 *
1359 * FIXME: make it take into account the data that did
1360 * get written
1361 */
1362 if (rc == 0) {
1363 if (bytes_written == 0)
1364 rc = -ENOSPC;
1365 else if (bytes_written < bytes_to_write)
1366 rc = -EAGAIN;
1367 }
1368
1369 /* retry on data-integrity flush */
1370 if (wbc->sync_mode == WB_SYNC_ALL && rc == -EAGAIN)
1371 goto retry_write;
1372
1373 /* fix the stats and EOF */
1374 if (bytes_written > 0) {
1400 cifs_stats_bytes_written(tcon, bytes_written); 1375 cifs_stats_bytes_written(tcon, bytes_written);
1376 cifs_update_eof(cifsi, offset, bytes_written);
1401 } 1377 }
1402 1378
1403 for (i = 0; i < n_iov; i++) { 1379 for (i = 0; i < n_iov; i++) {
1404 page = pvec.pages[first + i]; 1380 page = pvec.pages[first + i];
1405 /* Should we also set page error on 1381 /* on retryable write error, redirty page */
1406 success rc but too little data written? */ 1382 if (rc == -EAGAIN)
1407 /* BB investigate retry logic on temporary 1383 redirty_page_for_writepage(wbc, page);
1408 server crash cases and how recovery works 1384 else if (rc != 0)
1409 when page marked as error */
1410 if (rc)
1411 SetPageError(page); 1385 SetPageError(page);
1412 kunmap(page); 1386 kunmap(page);
1413 unlock_page(page); 1387 unlock_page(page);
1414 end_page_writeback(page); 1388 end_page_writeback(page);
1415 page_cache_release(page); 1389 page_cache_release(page);
1416 } 1390 }
1391
1392 if (rc != -EAGAIN)
1393 mapping_set_error(mapping, rc);
1394 else
1395 rc = 0;
1396
1417 if ((wbc->nr_to_write -= n_iov) <= 0) 1397 if ((wbc->nr_to_write -= n_iov) <= 0)
1418 done = 1; 1398 done = 1;
1419 index = next; 1399 index = next;
@@ -1525,59 +1505,51 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
1525 return rc; 1505 return rc;
1526} 1506}
1527 1507
1528int cifs_fsync(struct file *file, int datasync) 1508int cifs_strict_fsync(struct file *file, int datasync)
1529{ 1509{
1530 int xid; 1510 int xid;
1531 int rc = 0; 1511 int rc = 0;
1532 struct cifsTconInfo *tcon; 1512 struct cifsTconInfo *tcon;
1533 struct cifsFileInfo *smbfile = file->private_data; 1513 struct cifsFileInfo *smbfile = file->private_data;
1534 struct inode *inode = file->f_path.dentry->d_inode; 1514 struct inode *inode = file->f_path.dentry->d_inode;
1515 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1535 1516
1536 xid = GetXid(); 1517 xid = GetXid();
1537 1518
1538 cFYI(1, "Sync file - name: %s datasync: 0x%x", 1519 cFYI(1, "Sync file - name: %s datasync: 0x%x",
1539 file->f_path.dentry->d_name.name, datasync); 1520 file->f_path.dentry->d_name.name, datasync);
1540 1521
1541 rc = filemap_write_and_wait(inode->i_mapping); 1522 if (!CIFS_I(inode)->clientCanCacheRead)
1542 if (rc == 0) { 1523 cifs_invalidate_mapping(inode);
1543 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
1544 1524
1545 tcon = tlink_tcon(smbfile->tlink); 1525 tcon = tlink_tcon(smbfile->tlink);
1546 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) 1526 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
1547 rc = CIFSSMBFlush(xid, tcon, smbfile->netfid); 1527 rc = CIFSSMBFlush(xid, tcon, smbfile->netfid);
1548 }
1549 1528
1550 FreeXid(xid); 1529 FreeXid(xid);
1551 return rc; 1530 return rc;
1552} 1531}
1553 1532
1554/* static void cifs_sync_page(struct page *page) 1533int cifs_fsync(struct file *file, int datasync)
1555{ 1534{
1556 struct address_space *mapping; 1535 int xid;
1557 struct inode *inode;
1558 unsigned long index = page->index;
1559 unsigned int rpages = 0;
1560 int rc = 0; 1536 int rc = 0;
1537 struct cifsTconInfo *tcon;
1538 struct cifsFileInfo *smbfile = file->private_data;
1539 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
1561 1540
1562 cFYI(1, "sync page %p", page); 1541 xid = GetXid();
1563 mapping = page->mapping;
1564 if (!mapping)
1565 return 0;
1566 inode = mapping->host;
1567 if (!inode)
1568 return; */
1569 1542
1570/* fill in rpages then 1543 cFYI(1, "Sync file - name: %s datasync: 0x%x",
1571 result = cifs_pagein_inode(inode, index, rpages); */ /* BB finish */ 1544 file->f_path.dentry->d_name.name, datasync);
1572 1545
1573/* cFYI(1, "rpages is %d for sync page of Index %ld", rpages, index); 1546 tcon = tlink_tcon(smbfile->tlink);
1547 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
1548 rc = CIFSSMBFlush(xid, tcon, smbfile->netfid);
1574 1549
1575#if 0 1550 FreeXid(xid);
1576 if (rc < 0) 1551 return rc;
1577 return rc; 1552}
1578 return 0;
1579#endif
1580} */
1581 1553
1582/* 1554/*
1583 * As file closes, flush all cached write data for this inode checking 1555 * As file closes, flush all cached write data for this inode checking
@@ -1596,42 +1568,244 @@ int cifs_flush(struct file *file, fl_owner_t id)
1596 return rc; 1568 return rc;
1597} 1569}
1598 1570
1599ssize_t cifs_user_read(struct file *file, char __user *read_data, 1571static int
1600 size_t read_size, loff_t *poffset) 1572cifs_write_allocate_pages(struct page **pages, unsigned long num_pages)
1601{ 1573{
1602 int rc = -EACCES; 1574 int rc = 0;
1575 unsigned long i;
1576
1577 for (i = 0; i < num_pages; i++) {
1578 pages[i] = alloc_page(__GFP_HIGHMEM);
1579 if (!pages[i]) {
1580 /*
1581 * save number of pages we have already allocated and
1582 * return with ENOMEM error
1583 */
1584 num_pages = i;
1585 rc = -ENOMEM;
1586 goto error;
1587 }
1588 }
1589
1590 return rc;
1591
1592error:
1593 for (i = 0; i < num_pages; i++)
1594 put_page(pages[i]);
1595 return rc;
1596}
1597
1598static inline
1599size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len)
1600{
1601 size_t num_pages;
1602 size_t clen;
1603
1604 clen = min_t(const size_t, len, wsize);
1605 num_pages = clen / PAGE_CACHE_SIZE;
1606 if (clen % PAGE_CACHE_SIZE)
1607 num_pages++;
1608
1609 if (cur_len)
1610 *cur_len = clen;
1611
1612 return num_pages;
1613}
1614
1615static ssize_t
1616cifs_iovec_write(struct file *file, const struct iovec *iov,
1617 unsigned long nr_segs, loff_t *poffset)
1618{
1619 unsigned int written;
1620 unsigned long num_pages, npages, i;
1621 size_t copied, len, cur_len;
1622 ssize_t total_written = 0;
1623 struct kvec *to_send;
1624 struct page **pages;
1625 struct iov_iter it;
1626 struct inode *inode;
1627 struct cifsFileInfo *open_file;
1628 struct cifsTconInfo *pTcon;
1629 struct cifs_sb_info *cifs_sb;
1630 int xid, rc;
1631
1632 len = iov_length(iov, nr_segs);
1633 if (!len)
1634 return 0;
1635
1636 rc = generic_write_checks(file, poffset, &len, 0);
1637 if (rc)
1638 return rc;
1639
1640 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
1641 num_pages = get_numpages(cifs_sb->wsize, len, &cur_len);
1642
1643 pages = kmalloc(sizeof(struct pages *)*num_pages, GFP_KERNEL);
1644 if (!pages)
1645 return -ENOMEM;
1646
1647 to_send = kmalloc(sizeof(struct kvec)*(num_pages + 1), GFP_KERNEL);
1648 if (!to_send) {
1649 kfree(pages);
1650 return -ENOMEM;
1651 }
1652
1653 rc = cifs_write_allocate_pages(pages, num_pages);
1654 if (rc) {
1655 kfree(pages);
1656 kfree(to_send);
1657 return rc;
1658 }
1659
1660 xid = GetXid();
1661 open_file = file->private_data;
1662 pTcon = tlink_tcon(open_file->tlink);
1663 inode = file->f_path.dentry->d_inode;
1664
1665 iov_iter_init(&it, iov, nr_segs, len, 0);
1666 npages = num_pages;
1667
1668 do {
1669 size_t save_len = cur_len;
1670 for (i = 0; i < npages; i++) {
1671 copied = min_t(const size_t, cur_len, PAGE_CACHE_SIZE);
1672 copied = iov_iter_copy_from_user(pages[i], &it, 0,
1673 copied);
1674 cur_len -= copied;
1675 iov_iter_advance(&it, copied);
1676 to_send[i+1].iov_base = kmap(pages[i]);
1677 to_send[i+1].iov_len = copied;
1678 }
1679
1680 cur_len = save_len - cur_len;
1681
1682 do {
1683 if (open_file->invalidHandle) {
1684 rc = cifs_reopen_file(open_file, false);
1685 if (rc != 0)
1686 break;
1687 }
1688 rc = CIFSSMBWrite2(xid, pTcon, open_file->netfid,
1689 cur_len, *poffset, &written,
1690 to_send, npages, 0);
1691 } while (rc == -EAGAIN);
1692
1693 for (i = 0; i < npages; i++)
1694 kunmap(pages[i]);
1695
1696 if (written) {
1697 len -= written;
1698 total_written += written;
1699 cifs_update_eof(CIFS_I(inode), *poffset, written);
1700 *poffset += written;
1701 } else if (rc < 0) {
1702 if (!total_written)
1703 total_written = rc;
1704 break;
1705 }
1706
1707 /* get length and number of kvecs of the next write */
1708 npages = get_numpages(cifs_sb->wsize, len, &cur_len);
1709 } while (len > 0);
1710
1711 if (total_written > 0) {
1712 spin_lock(&inode->i_lock);
1713 if (*poffset > inode->i_size)
1714 i_size_write(inode, *poffset);
1715 spin_unlock(&inode->i_lock);
1716 }
1717
1718 cifs_stats_bytes_written(pTcon, total_written);
1719 mark_inode_dirty_sync(inode);
1720
1721 for (i = 0; i < num_pages; i++)
1722 put_page(pages[i]);
1723 kfree(to_send);
1724 kfree(pages);
1725 FreeXid(xid);
1726 return total_written;
1727}
1728
1729static ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov,
1730 unsigned long nr_segs, loff_t pos)
1731{
1732 ssize_t written;
1733 struct inode *inode;
1734
1735 inode = iocb->ki_filp->f_path.dentry->d_inode;
1736
1737 /*
1738 * BB - optimize the way when signing is disabled. We can drop this
1739 * extra memory-to-memory copying and use iovec buffers for constructing
1740 * write request.
1741 */
1742
1743 written = cifs_iovec_write(iocb->ki_filp, iov, nr_segs, &pos);
1744 if (written > 0) {
1745 CIFS_I(inode)->invalid_mapping = true;
1746 iocb->ki_pos = pos;
1747 }
1748
1749 return written;
1750}
1751
1752ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov,
1753 unsigned long nr_segs, loff_t pos)
1754{
1755 struct inode *inode;
1756
1757 inode = iocb->ki_filp->f_path.dentry->d_inode;
1758
1759 if (CIFS_I(inode)->clientCanCacheAll)
1760 return generic_file_aio_write(iocb, iov, nr_segs, pos);
1761
1762 /*
1763 * In strict cache mode we need to write the data to the server exactly
1764 * from the pos to pos+len-1 rather than flush all affected pages
1765 * because it may cause a error with mandatory locks on these pages but
1766 * not on the region from pos to ppos+len-1.
1767 */
1768
1769 return cifs_user_writev(iocb, iov, nr_segs, pos);
1770}
1771
1772static ssize_t
1773cifs_iovec_read(struct file *file, const struct iovec *iov,
1774 unsigned long nr_segs, loff_t *poffset)
1775{
1776 int rc;
1777 int xid;
1778 ssize_t total_read;
1603 unsigned int bytes_read = 0; 1779 unsigned int bytes_read = 0;
1604 unsigned int total_read = 0; 1780 size_t len, cur_len;
1605 unsigned int current_read_size; 1781 int iov_offset = 0;
1606 struct cifs_sb_info *cifs_sb; 1782 struct cifs_sb_info *cifs_sb;
1607 struct cifsTconInfo *pTcon; 1783 struct cifsTconInfo *pTcon;
1608 int xid;
1609 struct cifsFileInfo *open_file; 1784 struct cifsFileInfo *open_file;
1610 char *smb_read_data;
1611 char __user *current_offset;
1612 struct smb_com_read_rsp *pSMBr; 1785 struct smb_com_read_rsp *pSMBr;
1786 char *read_data;
1787
1788 if (!nr_segs)
1789 return 0;
1790
1791 len = iov_length(iov, nr_segs);
1792 if (!len)
1793 return 0;
1613 1794
1614 xid = GetXid(); 1795 xid = GetXid();
1615 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); 1796 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
1616 1797
1617 if (file->private_data == NULL) {
1618 rc = -EBADF;
1619 FreeXid(xid);
1620 return rc;
1621 }
1622 open_file = file->private_data; 1798 open_file = file->private_data;
1623 pTcon = tlink_tcon(open_file->tlink); 1799 pTcon = tlink_tcon(open_file->tlink);
1624 1800
1625 if ((file->f_flags & O_ACCMODE) == O_WRONLY) 1801 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
1626 cFYI(1, "attempting read on write only file instance"); 1802 cFYI(1, "attempting read on write only file instance");
1627 1803
1628 for (total_read = 0, current_offset = read_data; 1804 for (total_read = 0; total_read < len; total_read += bytes_read) {
1629 read_size > total_read; 1805 cur_len = min_t(const size_t, len - total_read, cifs_sb->rsize);
1630 total_read += bytes_read, current_offset += bytes_read) {
1631 current_read_size = min_t(const int, read_size - total_read,
1632 cifs_sb->rsize);
1633 rc = -EAGAIN; 1806 rc = -EAGAIN;
1634 smb_read_data = NULL; 1807 read_data = NULL;
1808
1635 while (rc == -EAGAIN) { 1809 while (rc == -EAGAIN) {
1636 int buf_type = CIFS_NO_BUFFER; 1810 int buf_type = CIFS_NO_BUFFER;
1637 if (open_file->invalidHandle) { 1811 if (open_file->invalidHandle) {
@@ -1639,27 +1813,25 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
1639 if (rc != 0) 1813 if (rc != 0)
1640 break; 1814 break;
1641 } 1815 }
1642 rc = CIFSSMBRead(xid, pTcon, 1816 rc = CIFSSMBRead(xid, pTcon, open_file->netfid,
1643 open_file->netfid, 1817 cur_len, *poffset, &bytes_read,
1644 current_read_size, *poffset, 1818 &read_data, &buf_type);
1645 &bytes_read, &smb_read_data, 1819 pSMBr = (struct smb_com_read_rsp *)read_data;
1646 &buf_type); 1820 if (read_data) {
1647 pSMBr = (struct smb_com_read_rsp *)smb_read_data; 1821 char *data_offset = read_data + 4 +
1648 if (smb_read_data) { 1822 le16_to_cpu(pSMBr->DataOffset);
1649 if (copy_to_user(current_offset, 1823 if (memcpy_toiovecend(iov, data_offset,
1650 smb_read_data + 1824 iov_offset, bytes_read))
1651 4 /* RFC1001 length field */ +
1652 le16_to_cpu(pSMBr->DataOffset),
1653 bytes_read))
1654 rc = -EFAULT; 1825 rc = -EFAULT;
1655
1656 if (buf_type == CIFS_SMALL_BUFFER) 1826 if (buf_type == CIFS_SMALL_BUFFER)
1657 cifs_small_buf_release(smb_read_data); 1827 cifs_small_buf_release(read_data);
1658 else if (buf_type == CIFS_LARGE_BUFFER) 1828 else if (buf_type == CIFS_LARGE_BUFFER)
1659 cifs_buf_release(smb_read_data); 1829 cifs_buf_release(read_data);
1660 smb_read_data = NULL; 1830 read_data = NULL;
1831 iov_offset += bytes_read;
1661 } 1832 }
1662 } 1833 }
1834
1663 if (rc || (bytes_read == 0)) { 1835 if (rc || (bytes_read == 0)) {
1664 if (total_read) { 1836 if (total_read) {
1665 break; 1837 break;
@@ -1672,13 +1844,57 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
1672 *poffset += bytes_read; 1844 *poffset += bytes_read;
1673 } 1845 }
1674 } 1846 }
1847
1675 FreeXid(xid); 1848 FreeXid(xid);
1676 return total_read; 1849 return total_read;
1677} 1850}
1678 1851
1852ssize_t cifs_user_read(struct file *file, char __user *read_data,
1853 size_t read_size, loff_t *poffset)
1854{
1855 struct iovec iov;
1856 iov.iov_base = read_data;
1857 iov.iov_len = read_size;
1858
1859 return cifs_iovec_read(file, &iov, 1, poffset);
1860}
1861
1862static ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov,
1863 unsigned long nr_segs, loff_t pos)
1864{
1865 ssize_t read;
1866
1867 read = cifs_iovec_read(iocb->ki_filp, iov, nr_segs, &pos);
1868 if (read > 0)
1869 iocb->ki_pos = pos;
1870
1871 return read;
1872}
1873
1874ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov,
1875 unsigned long nr_segs, loff_t pos)
1876{
1877 struct inode *inode;
1878
1879 inode = iocb->ki_filp->f_path.dentry->d_inode;
1880
1881 if (CIFS_I(inode)->clientCanCacheRead)
1882 return generic_file_aio_read(iocb, iov, nr_segs, pos);
1883
1884 /*
1885 * In strict cache mode we need to read from the server all the time
1886 * if we don't have level II oplock because the server can delay mtime
1887 * change - so we can't make a decision about inode invalidating.
1888 * And we can also fail with pagereading if there are mandatory locks
1889 * on pages affected by this read but not on the region from pos to
1890 * pos+len-1.
1891 */
1892
1893 return cifs_user_readv(iocb, iov, nr_segs, pos);
1894}
1679 1895
1680static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, 1896static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
1681 loff_t *poffset) 1897 loff_t *poffset)
1682{ 1898{
1683 int rc = -EACCES; 1899 int rc = -EACCES;
1684 unsigned int bytes_read = 0; 1900 unsigned int bytes_read = 0;
@@ -1746,6 +1962,41 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
1746 return total_read; 1962 return total_read;
1747} 1963}
1748 1964
1965/*
1966 * If the page is mmap'ed into a process' page tables, then we need to make
1967 * sure that it doesn't change while being written back.
1968 */
1969static int
1970cifs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
1971{
1972 struct page *page = vmf->page;
1973
1974 lock_page(page);
1975 return VM_FAULT_LOCKED;
1976}
1977
1978static struct vm_operations_struct cifs_file_vm_ops = {
1979 .fault = filemap_fault,
1980 .page_mkwrite = cifs_page_mkwrite,
1981};
1982
1983int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
1984{
1985 int rc, xid;
1986 struct inode *inode = file->f_path.dentry->d_inode;
1987
1988 xid = GetXid();
1989
1990 if (!CIFS_I(inode)->clientCanCacheRead)
1991 cifs_invalidate_mapping(inode);
1992
1993 rc = generic_file_mmap(file, vma);
1994 if (rc == 0)
1995 vma->vm_ops = &cifs_file_vm_ops;
1996 FreeXid(xid);
1997 return rc;
1998}
1999
1749int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) 2000int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
1750{ 2001{
1751 int rc, xid; 2002 int rc, xid;
@@ -1758,6 +2009,8 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
1758 return rc; 2009 return rc;
1759 } 2010 }
1760 rc = generic_file_mmap(file, vma); 2011 rc = generic_file_mmap(file, vma);
2012 if (rc == 0)
2013 vma->vm_ops = &cifs_file_vm_ops;
1761 FreeXid(xid); 2014 FreeXid(xid);
1762 return rc; 2015 return rc;
1763} 2016}
@@ -2192,7 +2445,8 @@ void cifs_oplock_break(struct work_struct *work)
2192 */ 2445 */
2193 if (!cfile->oplock_break_cancelled) { 2446 if (!cfile->oplock_break_cancelled) {
2194 rc = CIFSSMBLock(0, tlink_tcon(cfile->tlink), cfile->netfid, 0, 2447 rc = CIFSSMBLock(0, tlink_tcon(cfile->tlink), cfile->netfid, 0,
2195 0, 0, 0, LOCKING_ANDX_OPLOCK_RELEASE, false); 2448 0, 0, 0, LOCKING_ANDX_OPLOCK_RELEASE, false,
2449 cinode->clientCanCacheRead ? 1 : 0);
2196 cFYI(1, "Oplock release rc = %d", rc); 2450 cFYI(1, "Oplock release rc = %d", rc);
2197 } 2451 }
2198 2452
@@ -2232,7 +2486,6 @@ const struct address_space_operations cifs_addr_ops = {
2232 .set_page_dirty = __set_page_dirty_nobuffers, 2486 .set_page_dirty = __set_page_dirty_nobuffers,
2233 .releasepage = cifs_release_page, 2487 .releasepage = cifs_release_page,
2234 .invalidatepage = cifs_invalidate_page, 2488 .invalidatepage = cifs_invalidate_page,
2235 /* .sync_page = cifs_sync_page, */
2236 /* .direct_IO = */ 2489 /* .direct_IO = */
2237}; 2490};
2238 2491
@@ -2250,6 +2503,5 @@ const struct address_space_operations cifs_addr_ops_smallbuf = {
2250 .set_page_dirty = __set_page_dirty_nobuffers, 2503 .set_page_dirty = __set_page_dirty_nobuffers,
2251 .releasepage = cifs_release_page, 2504 .releasepage = cifs_release_page,
2252 .invalidatepage = cifs_invalidate_page, 2505 .invalidatepage = cifs_invalidate_page,
2253 /* .sync_page = cifs_sync_page, */
2254 /* .direct_IO = */ 2506 /* .direct_IO = */
2255}; 2507};
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 6c9ee8014ff0..8852470b4fbb 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -44,13 +44,17 @@ static void cifs_set_ops(struct inode *inode)
44 inode->i_fop = &cifs_file_direct_nobrl_ops; 44 inode->i_fop = &cifs_file_direct_nobrl_ops;
45 else 45 else
46 inode->i_fop = &cifs_file_direct_ops; 46 inode->i_fop = &cifs_file_direct_ops;
47 } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) {
48 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
49 inode->i_fop = &cifs_file_strict_nobrl_ops;
50 else
51 inode->i_fop = &cifs_file_strict_ops;
47 } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL) 52 } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
48 inode->i_fop = &cifs_file_nobrl_ops; 53 inode->i_fop = &cifs_file_nobrl_ops;
49 else { /* not direct, send byte range locks */ 54 else { /* not direct, send byte range locks */
50 inode->i_fop = &cifs_file_ops; 55 inode->i_fop = &cifs_file_ops;
51 } 56 }
52 57
53
54 /* check if server can support readpages */ 58 /* check if server can support readpages */
55 if (cifs_sb_master_tcon(cifs_sb)->ses->server->maxBuf < 59 if (cifs_sb_master_tcon(cifs_sb)->ses->server->maxBuf <
56 PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE) 60 PAGE_CACHE_SIZE + MAX_CIFS_HDR_SIZE)
@@ -1679,7 +1683,7 @@ cifs_inode_needs_reval(struct inode *inode)
1679/* 1683/*
1680 * Zap the cache. Called when invalid_mapping flag is set. 1684 * Zap the cache. Called when invalid_mapping flag is set.
1681 */ 1685 */
1682static void 1686void
1683cifs_invalidate_mapping(struct inode *inode) 1687cifs_invalidate_mapping(struct inode *inode)
1684{ 1688{
1685 int rc; 1689 int rc;
diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 306769de2fb5..ce417a9764a3 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -28,7 +28,6 @@
28#include "cifsproto.h" 28#include "cifsproto.h"
29#include "cifs_debug.h" 29#include "cifs_debug.h"
30#include "cifs_fs_sb.h" 30#include "cifs_fs_sb.h"
31#include "md5.h"
32 31
33#define CIFS_MF_SYMLINK_LEN_OFFSET (4+1) 32#define CIFS_MF_SYMLINK_LEN_OFFSET (4+1)
34#define CIFS_MF_SYMLINK_MD5_OFFSET (CIFS_MF_SYMLINK_LEN_OFFSET+(4+1)) 33#define CIFS_MF_SYMLINK_MD5_OFFSET (CIFS_MF_SYMLINK_LEN_OFFSET+(4+1))
@@ -47,6 +46,45 @@
47 md5_hash[12], md5_hash[13], md5_hash[14], md5_hash[15] 46 md5_hash[12], md5_hash[13], md5_hash[14], md5_hash[15]
48 47
49static int 48static int
49symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
50{
51 int rc;
52 unsigned int size;
53 struct crypto_shash *md5;
54 struct sdesc *sdescmd5;
55
56 md5 = crypto_alloc_shash("md5", 0, 0);
57 if (IS_ERR(md5)) {
58 rc = PTR_ERR(md5);
59 cERROR(1, "%s: Crypto md5 allocation error %d\n", __func__, rc);
60 return rc;
61 }
62 size = sizeof(struct shash_desc) + crypto_shash_descsize(md5);
63 sdescmd5 = kmalloc(size, GFP_KERNEL);
64 if (!sdescmd5) {
65 rc = -ENOMEM;
66 cERROR(1, "%s: Memory allocation failure\n", __func__);
67 goto symlink_hash_err;
68 }
69 sdescmd5->shash.tfm = md5;
70 sdescmd5->shash.flags = 0x0;
71
72 rc = crypto_shash_init(&sdescmd5->shash);
73 if (rc) {
74 cERROR(1, "%s: Could not init md5 shash\n", __func__);
75 goto symlink_hash_err;
76 }
77 crypto_shash_update(&sdescmd5->shash, link_str, link_len);
78 rc = crypto_shash_final(&sdescmd5->shash, md5_hash);
79
80symlink_hash_err:
81 crypto_free_shash(md5);
82 kfree(sdescmd5);
83
84 return rc;
85}
86
87static int
50CIFSParseMFSymlink(const u8 *buf, 88CIFSParseMFSymlink(const u8 *buf,
51 unsigned int buf_len, 89 unsigned int buf_len,
52 unsigned int *_link_len, 90 unsigned int *_link_len,
@@ -56,7 +94,6 @@ CIFSParseMFSymlink(const u8 *buf,
56 unsigned int link_len; 94 unsigned int link_len;
57 const char *md5_str1; 95 const char *md5_str1;
58 const char *link_str; 96 const char *link_str;
59 struct MD5Context md5_ctx;
60 u8 md5_hash[16]; 97 u8 md5_hash[16];
61 char md5_str2[34]; 98 char md5_str2[34];
62 99
@@ -70,9 +107,11 @@ CIFSParseMFSymlink(const u8 *buf,
70 if (rc != 1) 107 if (rc != 1)
71 return -EINVAL; 108 return -EINVAL;
72 109
73 cifs_MD5_init(&md5_ctx); 110 rc = symlink_hash(link_len, link_str, md5_hash);
74 cifs_MD5_update(&md5_ctx, (const u8 *)link_str, link_len); 111 if (rc) {
75 cifs_MD5_final(md5_hash, &md5_ctx); 112 cFYI(1, "%s: MD5 hash failure: %d\n", __func__, rc);
113 return rc;
114 }
76 115
77 snprintf(md5_str2, sizeof(md5_str2), 116 snprintf(md5_str2, sizeof(md5_str2),
78 CIFS_MF_SYMLINK_MD5_FORMAT, 117 CIFS_MF_SYMLINK_MD5_FORMAT,
@@ -94,9 +133,9 @@ CIFSParseMFSymlink(const u8 *buf,
94static int 133static int
95CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str) 134CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str)
96{ 135{
136 int rc;
97 unsigned int link_len; 137 unsigned int link_len;
98 unsigned int ofs; 138 unsigned int ofs;
99 struct MD5Context md5_ctx;
100 u8 md5_hash[16]; 139 u8 md5_hash[16];
101 140
102 if (buf_len != CIFS_MF_SYMLINK_FILE_SIZE) 141 if (buf_len != CIFS_MF_SYMLINK_FILE_SIZE)
@@ -107,9 +146,11 @@ CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str)
107 if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN) 146 if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN)
108 return -ENAMETOOLONG; 147 return -ENAMETOOLONG;
109 148
110 cifs_MD5_init(&md5_ctx); 149 rc = symlink_hash(link_len, link_str, md5_hash);
111 cifs_MD5_update(&md5_ctx, (const u8 *)link_str, link_len); 150 if (rc) {
112 cifs_MD5_final(md5_hash, &md5_ctx); 151 cFYI(1, "%s: MD5 hash failure: %d\n", __func__, rc);
152 return rc;
153 }
113 154
114 snprintf(buf, buf_len, 155 snprintf(buf, buf_len,
115 CIFS_MF_SYMLINK_LEN_FORMAT CIFS_MF_SYMLINK_MD5_FORMAT, 156 CIFS_MF_SYMLINK_LEN_FORMAT CIFS_MF_SYMLINK_MD5_FORMAT,
@@ -198,7 +239,7 @@ CIFSQueryMFSymLink(const int xid, struct cifsTconInfo *tcon,
198 if (rc != 0) 239 if (rc != 0)
199 return rc; 240 return rc;
200 241
201 if (file_info.EndOfFile != CIFS_MF_SYMLINK_FILE_SIZE) { 242 if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) {
202 CIFSSMBClose(xid, tcon, netfid); 243 CIFSSMBClose(xid, tcon, netfid);
203 /* it's not a symlink */ 244 /* it's not a symlink */
204 return -EINVAL; 245 return -EINVAL;
@@ -275,7 +316,7 @@ CIFSCheckMFSymlink(struct cifs_fattr *fattr,
275 if (rc != 0) 316 if (rc != 0)
276 goto out; 317 goto out;
277 318
278 if (file_info.EndOfFile != CIFS_MF_SYMLINK_FILE_SIZE) { 319 if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) {
279 CIFSSMBClose(xid, pTcon, netfid); 320 CIFSSMBClose(xid, pTcon, netfid);
280 /* it's not a symlink */ 321 /* it's not a symlink */
281 goto out; 322 goto out;
diff --git a/fs/cifs/md4.c b/fs/cifs/md4.c
deleted file mode 100644
index a725c2609d67..000000000000
--- a/fs/cifs/md4.c
+++ /dev/null
@@ -1,205 +0,0 @@
1/*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 a implementation of MD4 designed for use in the SMB authentication protocol
5 Copyright (C) Andrew Tridgell 1997-1998.
6 Modified by Steve French (sfrench@us.ibm.com) 2002-2003
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22#include <linux/module.h>
23#include <linux/fs.h>
24#include "cifsencrypt.h"
25
26/* NOTE: This code makes no attempt to be fast! */
27
28static __u32
29F(__u32 X, __u32 Y, __u32 Z)
30{
31 return (X & Y) | ((~X) & Z);
32}
33
34static __u32
35G(__u32 X, __u32 Y, __u32 Z)
36{
37 return (X & Y) | (X & Z) | (Y & Z);
38}
39
40static __u32
41H(__u32 X, __u32 Y, __u32 Z)
42{
43 return X ^ Y ^ Z;
44}
45
46static __u32
47lshift(__u32 x, int s)
48{
49 x &= 0xFFFFFFFF;
50 return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s));
51}
52
53#define ROUND1(a,b,c,d,k,s) (*a) = lshift((*a) + F(*b,*c,*d) + X[k], s)
54#define ROUND2(a,b,c,d,k,s) (*a) = lshift((*a) + G(*b,*c,*d) + X[k] + (__u32)0x5A827999,s)
55#define ROUND3(a,b,c,d,k,s) (*a) = lshift((*a) + H(*b,*c,*d) + X[k] + (__u32)0x6ED9EBA1,s)
56
57/* this applies md4 to 64 byte chunks */
58static void
59mdfour64(__u32 *M, __u32 *A, __u32 *B, __u32 *C, __u32 *D)
60{
61 int j;
62 __u32 AA, BB, CC, DD;
63 __u32 X[16];
64
65
66 for (j = 0; j < 16; j++)
67 X[j] = M[j];
68
69 AA = *A;
70 BB = *B;
71 CC = *C;
72 DD = *D;
73
74 ROUND1(A, B, C, D, 0, 3);
75 ROUND1(D, A, B, C, 1, 7);
76 ROUND1(C, D, A, B, 2, 11);
77 ROUND1(B, C, D, A, 3, 19);
78 ROUND1(A, B, C, D, 4, 3);
79 ROUND1(D, A, B, C, 5, 7);
80 ROUND1(C, D, A, B, 6, 11);
81 ROUND1(B, C, D, A, 7, 19);
82 ROUND1(A, B, C, D, 8, 3);
83 ROUND1(D, A, B, C, 9, 7);
84 ROUND1(C, D, A, B, 10, 11);
85 ROUND1(B, C, D, A, 11, 19);
86 ROUND1(A, B, C, D, 12, 3);
87 ROUND1(D, A, B, C, 13, 7);
88 ROUND1(C, D, A, B, 14, 11);
89 ROUND1(B, C, D, A, 15, 19);
90
91 ROUND2(A, B, C, D, 0, 3);
92 ROUND2(D, A, B, C, 4, 5);
93 ROUND2(C, D, A, B, 8, 9);
94 ROUND2(B, C, D, A, 12, 13);
95 ROUND2(A, B, C, D, 1, 3);
96 ROUND2(D, A, B, C, 5, 5);
97 ROUND2(C, D, A, B, 9, 9);
98 ROUND2(B, C, D, A, 13, 13);
99 ROUND2(A, B, C, D, 2, 3);
100 ROUND2(D, A, B, C, 6, 5);
101 ROUND2(C, D, A, B, 10, 9);
102 ROUND2(B, C, D, A, 14, 13);
103 ROUND2(A, B, C, D, 3, 3);
104 ROUND2(D, A, B, C, 7, 5);
105 ROUND2(C, D, A, B, 11, 9);
106 ROUND2(B, C, D, A, 15, 13);
107
108 ROUND3(A, B, C, D, 0, 3);
109 ROUND3(D, A, B, C, 8, 9);
110 ROUND3(C, D, A, B, 4, 11);
111 ROUND3(B, C, D, A, 12, 15);
112 ROUND3(A, B, C, D, 2, 3);
113 ROUND3(D, A, B, C, 10, 9);
114 ROUND3(C, D, A, B, 6, 11);
115 ROUND3(B, C, D, A, 14, 15);
116 ROUND3(A, B, C, D, 1, 3);
117 ROUND3(D, A, B, C, 9, 9);
118 ROUND3(C, D, A, B, 5, 11);
119 ROUND3(B, C, D, A, 13, 15);
120 ROUND3(A, B, C, D, 3, 3);
121 ROUND3(D, A, B, C, 11, 9);
122 ROUND3(C, D, A, B, 7, 11);
123 ROUND3(B, C, D, A, 15, 15);
124
125 *A += AA;
126 *B += BB;
127 *C += CC;
128 *D += DD;
129
130 *A &= 0xFFFFFFFF;
131 *B &= 0xFFFFFFFF;
132 *C &= 0xFFFFFFFF;
133 *D &= 0xFFFFFFFF;
134
135 for (j = 0; j < 16; j++)
136 X[j] = 0;
137}
138
139static void
140copy64(__u32 *M, unsigned char *in)
141{
142 int i;
143
144 for (i = 0; i < 16; i++)
145 M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) |
146 (in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0);
147}
148
149static void
150copy4(unsigned char *out, __u32 x)
151{
152 out[0] = x & 0xFF;
153 out[1] = (x >> 8) & 0xFF;
154 out[2] = (x >> 16) & 0xFF;
155 out[3] = (x >> 24) & 0xFF;
156}
157
158/* produce a md4 message digest from data of length n bytes */
159void
160mdfour(unsigned char *out, unsigned char *in, int n)
161{
162 unsigned char buf[128];
163 __u32 M[16];
164 __u32 b = n * 8;
165 int i;
166 __u32 A = 0x67452301;
167 __u32 B = 0xefcdab89;
168 __u32 C = 0x98badcfe;
169 __u32 D = 0x10325476;
170
171 while (n > 64) {
172 copy64(M, in);
173 mdfour64(M, &A, &B, &C, &D);
174 in += 64;
175 n -= 64;
176 }
177
178 for (i = 0; i < 128; i++)
179 buf[i] = 0;
180 memcpy(buf, in, n);
181 buf[n] = 0x80;
182
183 if (n <= 55) {
184 copy4(buf + 56, b);
185 copy64(M, buf);
186 mdfour64(M, &A, &B, &C, &D);
187 } else {
188 copy4(buf + 120, b);
189 copy64(M, buf);
190 mdfour64(M, &A, &B, &C, &D);
191 copy64(M, buf + 64);
192 mdfour64(M, &A, &B, &C, &D);
193 }
194
195 for (i = 0; i < 128; i++)
196 buf[i] = 0;
197 copy64(M, buf);
198
199 copy4(out, A);
200 copy4(out + 4, B);
201 copy4(out + 8, C);
202 copy4(out + 12, D);
203
204 A = B = C = D = 0;
205}
diff --git a/fs/cifs/md5.c b/fs/cifs/md5.c
deleted file mode 100644
index 98b66a54c319..000000000000
--- a/fs/cifs/md5.c
+++ /dev/null
@@ -1,366 +0,0 @@
1/*
2 * This code implements the MD5 message-digest algorithm.
3 * The algorithm is due to Ron Rivest. This code was
4 * written by Colin Plumb in 1993, no copyright is claimed.
5 * This code is in the public domain; do with it what you wish.
6 *
7 * Equivalent code is available from RSA Data Security, Inc.
8 * This code has been tested against that, and is equivalent,
9 * except that you don't need to include two pages of legalese
10 * with every copy.
11 *
12 * To compute the message digest of a chunk of bytes, declare an
13 * MD5Context structure, pass it to cifs_MD5_init, call cifs_MD5_update as
14 * needed on buffers full of bytes, and then call cifs_MD5_final, which
15 * will fill a supplied 16-byte array with the digest.
16 */
17
18/* This code slightly modified to fit into Samba by
19 abartlet@samba.org Jun 2001
20 and to fit the cifs vfs by
21 Steve French sfrench@us.ibm.com */
22
23#include <linux/string.h>
24#include "md5.h"
25
26static void MD5Transform(__u32 buf[4], __u32 const in[16]);
27
28/*
29 * Note: this code is harmless on little-endian machines.
30 */
31static void
32byteReverse(unsigned char *buf, unsigned longs)
33{
34 __u32 t;
35 do {
36 t = (__u32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
37 ((unsigned) buf[1] << 8 | buf[0]);
38 *(__u32 *) buf = t;
39 buf += 4;
40 } while (--longs);
41}
42
43/*
44 * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
45 * initialization constants.
46 */
47void
48cifs_MD5_init(struct MD5Context *ctx)
49{
50 ctx->buf[0] = 0x67452301;
51 ctx->buf[1] = 0xefcdab89;
52 ctx->buf[2] = 0x98badcfe;
53 ctx->buf[3] = 0x10325476;
54
55 ctx->bits[0] = 0;
56 ctx->bits[1] = 0;
57}
58
59/*
60 * Update context to reflect the concatenation of another buffer full
61 * of bytes.
62 */
63void
64cifs_MD5_update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
65{
66 register __u32 t;
67
68 /* Update bitcount */
69
70 t = ctx->bits[0];
71 if ((ctx->bits[0] = t + ((__u32) len << 3)) < t)
72 ctx->bits[1]++; /* Carry from low to high */
73 ctx->bits[1] += len >> 29;
74
75 t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
76
77 /* Handle any leading odd-sized chunks */
78
79 if (t) {
80 unsigned char *p = (unsigned char *) ctx->in + t;
81
82 t = 64 - t;
83 if (len < t) {
84 memmove(p, buf, len);
85 return;
86 }
87 memmove(p, buf, t);
88 byteReverse(ctx->in, 16);
89 MD5Transform(ctx->buf, (__u32 *) ctx->in);
90 buf += t;
91 len -= t;
92 }
93 /* Process data in 64-byte chunks */
94
95 while (len >= 64) {
96 memmove(ctx->in, buf, 64);
97 byteReverse(ctx->in, 16);
98 MD5Transform(ctx->buf, (__u32 *) ctx->in);
99 buf += 64;
100 len -= 64;
101 }
102
103 /* Handle any remaining bytes of data. */
104
105 memmove(ctx->in, buf, len);
106}
107
108/*
109 * Final wrapup - pad to 64-byte boundary with the bit pattern
110 * 1 0* (64-bit count of bits processed, MSB-first)
111 */
112void
113cifs_MD5_final(unsigned char digest[16], struct MD5Context *ctx)
114{
115 unsigned int count;
116 unsigned char *p;
117
118 /* Compute number of bytes mod 64 */
119 count = (ctx->bits[0] >> 3) & 0x3F;
120
121 /* Set the first char of padding to 0x80. This is safe since there is
122 always at least one byte free */
123 p = ctx->in + count;
124 *p++ = 0x80;
125
126 /* Bytes of padding needed to make 64 bytes */
127 count = 64 - 1 - count;
128
129 /* Pad out to 56 mod 64 */
130 if (count < 8) {
131 /* Two lots of padding: Pad the first block to 64 bytes */
132 memset(p, 0, count);
133 byteReverse(ctx->in, 16);
134 MD5Transform(ctx->buf, (__u32 *) ctx->in);
135
136 /* Now fill the next block with 56 bytes */
137 memset(ctx->in, 0, 56);
138 } else {
139 /* Pad block to 56 bytes */
140 memset(p, 0, count - 8);
141 }
142 byteReverse(ctx->in, 14);
143
144 /* Append length in bits and transform */
145 ((__u32 *) ctx->in)[14] = ctx->bits[0];
146 ((__u32 *) ctx->in)[15] = ctx->bits[1];
147
148 MD5Transform(ctx->buf, (__u32 *) ctx->in);
149 byteReverse((unsigned char *) ctx->buf, 4);
150 memmove(digest, ctx->buf, 16);
151 memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
152}
153
154/* The four core functions - F1 is optimized somewhat */
155
156/* #define F1(x, y, z) (x & y | ~x & z) */
157#define F1(x, y, z) (z ^ (x & (y ^ z)))
158#define F2(x, y, z) F1(z, x, y)
159#define F3(x, y, z) (x ^ y ^ z)
160#define F4(x, y, z) (y ^ (x | ~z))
161
162/* This is the central step in the MD5 algorithm. */
163#define MD5STEP(f, w, x, y, z, data, s) \
164 (w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x)
165
166/*
167 * The core of the MD5 algorithm, this alters an existing MD5 hash to
168 * reflect the addition of 16 longwords of new data. cifs_MD5_update blocks
169 * the data and converts bytes into longwords for this routine.
170 */
171static void
172MD5Transform(__u32 buf[4], __u32 const in[16])
173{
174 register __u32 a, b, c, d;
175
176 a = buf[0];
177 b = buf[1];
178 c = buf[2];
179 d = buf[3];
180
181 MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
182 MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
183 MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
184 MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
185 MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
186 MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
187 MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
188 MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
189 MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
190 MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
191 MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
192 MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
193 MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
194 MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
195 MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
196 MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
197
198 MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
199 MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
200 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
201 MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
202 MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
203 MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
204 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
205 MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
206 MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
207 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
208 MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
209 MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
210 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
211 MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
212 MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
213 MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
214
215 MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
216 MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
217 MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
218 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
219 MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
220 MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
221 MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
222 MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
223 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
224 MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
225 MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
226 MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
227 MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
228 MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
229 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
230 MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
231
232 MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
233 MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
234 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
235 MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
236 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
237 MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
238 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
239 MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
240 MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
241 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
242 MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
243 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
244 MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
245 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
246 MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
247 MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
248
249 buf[0] += a;
250 buf[1] += b;
251 buf[2] += c;
252 buf[3] += d;
253}
254
255#if 0 /* currently unused */
256/***********************************************************************
257 the rfc 2104 version of hmac_md5 initialisation.
258***********************************************************************/
259static void
260hmac_md5_init_rfc2104(unsigned char *key, int key_len,
261 struct HMACMD5Context *ctx)
262{
263 int i;
264
265 /* if key is longer than 64 bytes reset it to key=MD5(key) */
266 if (key_len > 64) {
267 unsigned char tk[16];
268 struct MD5Context tctx;
269
270 cifs_MD5_init(&tctx);
271 cifs_MD5_update(&tctx, key, key_len);
272 cifs_MD5_final(tk, &tctx);
273
274 key = tk;
275 key_len = 16;
276 }
277
278 /* start out by storing key in pads */
279 memset(ctx->k_ipad, 0, sizeof(ctx->k_ipad));
280 memset(ctx->k_opad, 0, sizeof(ctx->k_opad));
281 memcpy(ctx->k_ipad, key, key_len);
282 memcpy(ctx->k_opad, key, key_len);
283
284 /* XOR key with ipad and opad values */
285 for (i = 0; i < 64; i++) {
286 ctx->k_ipad[i] ^= 0x36;
287 ctx->k_opad[i] ^= 0x5c;
288 }
289
290 cifs_MD5_init(&ctx->ctx);
291 cifs_MD5_update(&ctx->ctx, ctx->k_ipad, 64);
292}
293#endif
294
295/***********************************************************************
296 the microsoft version of hmac_md5 initialisation.
297***********************************************************************/
298void
299hmac_md5_init_limK_to_64(const unsigned char *key, int key_len,
300 struct HMACMD5Context *ctx)
301{
302 int i;
303
304 /* if key is longer than 64 bytes truncate it */
305 if (key_len > 64)
306 key_len = 64;
307
308 /* start out by storing key in pads */
309 memset(ctx->k_ipad, 0, sizeof(ctx->k_ipad));
310 memset(ctx->k_opad, 0, sizeof(ctx->k_opad));
311 memcpy(ctx->k_ipad, key, key_len);
312 memcpy(ctx->k_opad, key, key_len);
313
314 /* XOR key with ipad and opad values */
315 for (i = 0; i < 64; i++) {
316 ctx->k_ipad[i] ^= 0x36;
317 ctx->k_opad[i] ^= 0x5c;
318 }
319
320 cifs_MD5_init(&ctx->ctx);
321 cifs_MD5_update(&ctx->ctx, ctx->k_ipad, 64);
322}
323
324/***********************************************************************
325 update hmac_md5 "inner" buffer
326***********************************************************************/
327void
328hmac_md5_update(const unsigned char *text, int text_len,
329 struct HMACMD5Context *ctx)
330{
331 cifs_MD5_update(&ctx->ctx, text, text_len); /* then text of datagram */
332}
333
334/***********************************************************************
335 finish off hmac_md5 "inner" buffer and generate outer one.
336***********************************************************************/
337void
338hmac_md5_final(unsigned char *digest, struct HMACMD5Context *ctx)
339{
340 struct MD5Context ctx_o;
341
342 cifs_MD5_final(digest, &ctx->ctx);
343
344 cifs_MD5_init(&ctx_o);
345 cifs_MD5_update(&ctx_o, ctx->k_opad, 64);
346 cifs_MD5_update(&ctx_o, digest, 16);
347 cifs_MD5_final(digest, &ctx_o);
348}
349
350/***********************************************************
351 single function to calculate an HMAC MD5 digest from data.
352 use the microsoft hmacmd5 init method because the key is 16 bytes.
353************************************************************/
354#if 0 /* currently unused */
355static void
356hmac_md5(unsigned char key[16], unsigned char *data, int data_len,
357 unsigned char *digest)
358{
359 struct HMACMD5Context ctx;
360 hmac_md5_init_limK_to_64(key, 16, &ctx);
361 if (data_len != 0)
362 hmac_md5_update(data, data_len, &ctx);
363
364 hmac_md5_final(digest, &ctx);
365}
366#endif
diff --git a/fs/cifs/md5.h b/fs/cifs/md5.h
deleted file mode 100644
index 6fba8cb402fd..000000000000
--- a/fs/cifs/md5.h
+++ /dev/null
@@ -1,38 +0,0 @@
1#ifndef MD5_H
2#define MD5_H
3#ifndef HEADER_MD5_H
4/* Try to avoid clashes with OpenSSL */
5#define HEADER_MD5_H
6#endif
7
8struct MD5Context {
9 __u32 buf[4];
10 __u32 bits[2];
11 unsigned char in[64];
12};
13#endif /* !MD5_H */
14
15#ifndef _HMAC_MD5_H
16struct HMACMD5Context {
17 struct MD5Context ctx;
18 unsigned char k_ipad[65];
19 unsigned char k_opad[65];
20};
21#endif /* _HMAC_MD5_H */
22
23void cifs_MD5_init(struct MD5Context *context);
24void cifs_MD5_update(struct MD5Context *context, unsigned char const *buf,
25 unsigned len);
26void cifs_MD5_final(unsigned char digest[16], struct MD5Context *context);
27
28/* The following definitions come from lib/hmacmd5.c */
29
30/* void hmac_md5_init_rfc2104(unsigned char *key, int key_len,
31 struct HMACMD5Context *ctx);*/
32void hmac_md5_init_limK_to_64(const unsigned char *key, int key_len,
33 struct HMACMD5Context *ctx);
34void hmac_md5_update(const unsigned char *text, int text_len,
35 struct HMACMD5Context *ctx);
36void hmac_md5_final(unsigned char *digest, struct HMACMD5Context *ctx);
37/* void hmac_md5(unsigned char key[16], unsigned char *data, int data_len,
38 unsigned char *digest);*/
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 43f10281bc19..0c684ae4c071 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -100,6 +100,7 @@ sesInfoFree(struct cifsSesInfo *buf_to_free)
100 memset(buf_to_free->password, 0, strlen(buf_to_free->password)); 100 memset(buf_to_free->password, 0, strlen(buf_to_free->password));
101 kfree(buf_to_free->password); 101 kfree(buf_to_free->password);
102 } 102 }
103 kfree(buf_to_free->user_name);
103 kfree(buf_to_free->domainName); 104 kfree(buf_to_free->domainName);
104 kfree(buf_to_free); 105 kfree(buf_to_free);
105} 106}
@@ -236,10 +237,7 @@ __u16 GetNextMid(struct TCP_Server_Info *server)
236{ 237{
237 __u16 mid = 0; 238 __u16 mid = 0;
238 __u16 last_mid; 239 __u16 last_mid;
239 int collision; 240 bool collision;
240
241 if (server == NULL)
242 return mid;
243 241
244 spin_lock(&GlobalMid_Lock); 242 spin_lock(&GlobalMid_Lock);
245 last_mid = server->CurrentMid; /* we do not want to loop forever */ 243 last_mid = server->CurrentMid; /* we do not want to loop forever */
@@ -252,24 +250,38 @@ __u16 GetNextMid(struct TCP_Server_Info *server)
252 (and it would also have to have been a request that 250 (and it would also have to have been a request that
253 did not time out) */ 251 did not time out) */
254 while (server->CurrentMid != last_mid) { 252 while (server->CurrentMid != last_mid) {
255 struct list_head *tmp;
256 struct mid_q_entry *mid_entry; 253 struct mid_q_entry *mid_entry;
254 unsigned int num_mids;
257 255
258 collision = 0; 256 collision = false;
259 if (server->CurrentMid == 0) 257 if (server->CurrentMid == 0)
260 server->CurrentMid++; 258 server->CurrentMid++;
261 259
262 list_for_each(tmp, &server->pending_mid_q) { 260 num_mids = 0;
263 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 261 list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
264 262 ++num_mids;
265 if ((mid_entry->mid == server->CurrentMid) && 263 if (mid_entry->mid == server->CurrentMid &&
266 (mid_entry->midState == MID_REQUEST_SUBMITTED)) { 264 mid_entry->midState == MID_REQUEST_SUBMITTED) {
267 /* This mid is in use, try a different one */ 265 /* This mid is in use, try a different one */
268 collision = 1; 266 collision = true;
269 break; 267 break;
270 } 268 }
271 } 269 }
272 if (collision == 0) { 270
271 /*
272 * if we have more than 32k mids in the list, then something
273 * is very wrong. Possibly a local user is trying to DoS the
274 * box by issuing long-running calls and SIGKILL'ing them. If
275 * we get to 2^16 mids then we're in big trouble as this
276 * function could loop forever.
277 *
278 * Go ahead and assign out the mid in this situation, but force
279 * an eventual reconnect to clean out the pending_mid_q.
280 */
281 if (num_mids > 32768)
282 server->tcpStatus = CifsNeedReconnect;
283
284 if (!collision) {
273 mid = server->CurrentMid; 285 mid = server->CurrentMid;
274 break; 286 break;
275 } 287 }
@@ -381,29 +393,31 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,
381} 393}
382 394
383static int 395static int
384checkSMBhdr(struct smb_hdr *smb, __u16 mid) 396check_smb_hdr(struct smb_hdr *smb, __u16 mid)
385{ 397{
386 /* Make sure that this really is an SMB, that it is a response, 398 /* does it have the right SMB "signature" ? */
387 and that the message ids match */ 399 if (*(__le32 *) smb->Protocol != cpu_to_le32(0x424d53ff)) {
388 if ((*(__le32 *) smb->Protocol == cpu_to_le32(0x424d53ff)) && 400 cERROR(1, "Bad protocol string signature header 0x%x",
389 (mid == smb->Mid)) { 401 *(unsigned int *)smb->Protocol);
390 if (smb->Flags & SMBFLG_RESPONSE) 402 return 1;
391 return 0;
392 else {
393 /* only one valid case where server sends us request */
394 if (smb->Command == SMB_COM_LOCKING_ANDX)
395 return 0;
396 else
397 cERROR(1, "Received Request not response");
398 }
399 } else { /* bad signature or mid */
400 if (*(__le32 *) smb->Protocol != cpu_to_le32(0x424d53ff))
401 cERROR(1, "Bad protocol string signature header %x",
402 *(unsigned int *) smb->Protocol);
403 if (mid != smb->Mid)
404 cERROR(1, "Mids do not match");
405 } 403 }
406 cERROR(1, "bad smb detected. The Mid=%d", smb->Mid); 404
405 /* Make sure that message ids match */
406 if (mid != smb->Mid) {
407 cERROR(1, "Mids do not match. received=%u expected=%u",
408 smb->Mid, mid);
409 return 1;
410 }
411
412 /* if it's a response then accept */
413 if (smb->Flags & SMBFLG_RESPONSE)
414 return 0;
415
416 /* only one valid case where server sends us request */
417 if (smb->Command == SMB_COM_LOCKING_ANDX)
418 return 0;
419
420 cERROR(1, "Server sent request, not response. mid=%u", smb->Mid);
407 return 1; 421 return 1;
408} 422}
409 423
@@ -448,7 +462,7 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
448 return 1; 462 return 1;
449 } 463 }
450 464
451 if (checkSMBhdr(smb, mid)) 465 if (check_smb_hdr(smb, mid))
452 return 1; 466 return 1;
453 clc_len = smbCalcSize_LE(smb); 467 clc_len = smbCalcSize_LE(smb);
454 468
@@ -465,25 +479,26 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
465 if (((4 + len) & 0xFFFF) == (clc_len & 0xFFFF)) 479 if (((4 + len) & 0xFFFF) == (clc_len & 0xFFFF))
466 return 0; /* bcc wrapped */ 480 return 0; /* bcc wrapped */
467 } 481 }
468 cFYI(1, "Calculated size %d vs length %d mismatch for mid %d", 482 cFYI(1, "Calculated size %u vs length %u mismatch for mid=%u",
469 clc_len, 4 + len, smb->Mid); 483 clc_len, 4 + len, smb->Mid);
470 /* Windows XP can return a few bytes too much, presumably 484
471 an illegal pad, at the end of byte range lock responses 485 if (4 + len < clc_len) {
472 so we allow for that three byte pad, as long as actual 486 cERROR(1, "RFC1001 size %u smaller than SMB for mid=%u",
473 received length is as long or longer than calculated length */
474 /* We have now had to extend this more, since there is a
475 case in which it needs to be bigger still to handle a
476 malformed response to transact2 findfirst from WinXP when
477 access denied is returned and thus bcc and wct are zero
478 but server says length is 0x21 bytes too long as if the server
479 forget to reset the smb rfc1001 length when it reset the
480 wct and bcc to minimum size and drop the t2 parms and data */
481 if ((4+len > clc_len) && (len <= clc_len + 512))
482 return 0;
483 else {
484 cERROR(1, "RFC1001 size %d bigger than SMB for Mid=%d",
485 len, smb->Mid); 487 len, smb->Mid);
486 return 1; 488 return 1;
489 } else if (len > clc_len + 512) {
490 /*
491 * Some servers (Windows XP in particular) send more
492 * data than the lengths in the SMB packet would
493 * indicate on certain calls (byte range locks and
494 * trans2 find first calls in particular). While the
495 * client can handle such a frame by ignoring the
496 * trailing data, we choose limit the amount of extra
497 * data to 512 bytes.
498 */
499 cERROR(1, "RFC1001 size %u more than 512 bytes larger "
500 "than SMB for mid=%u", len, smb->Mid);
501 return 1;
487 } 502 }
488 } 503 }
489 return 0; 504 return 0;
@@ -506,7 +521,7 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
506 (struct smb_com_transaction_change_notify_rsp *)buf; 521 (struct smb_com_transaction_change_notify_rsp *)buf;
507 struct file_notify_information *pnotify; 522 struct file_notify_information *pnotify;
508 __u32 data_offset = 0; 523 __u32 data_offset = 0;
509 if (pSMBr->ByteCount > sizeof(struct file_notify_information)) { 524 if (get_bcc_le(buf) > sizeof(struct file_notify_information)) {
510 data_offset = le32_to_cpu(pSMBr->DataOffset); 525 data_offset = le32_to_cpu(pSMBr->DataOffset);
511 526
512 pnotify = (struct file_notify_information *) 527 pnotify = (struct file_notify_information *)
@@ -571,7 +586,7 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
571 pCifsInode = CIFS_I(netfile->dentry->d_inode); 586 pCifsInode = CIFS_I(netfile->dentry->d_inode);
572 587
573 cifs_set_oplock_level(pCifsInode, 588 cifs_set_oplock_level(pCifsInode,
574 pSMB->OplockLevel); 589 pSMB->OplockLevel ? OPLOCK_READ : 0);
575 /* 590 /*
576 * cifs_oplock_break_put() can't be called 591 * cifs_oplock_break_put() can't be called
577 * from here. Get reference after queueing 592 * from here. Get reference after queueing
@@ -637,77 +652,6 @@ dump_smb(struct smb_hdr *smb_buf, int smb_buf_length)
637 return; 652 return;
638} 653}
639 654
640/* Convert 16 bit Unicode pathname to wire format from string in current code
641 page. Conversion may involve remapping up the seven characters that are
642 only legal in POSIX-like OS (if they are present in the string). Path
643 names are little endian 16 bit Unicode on the wire */
644int
645cifsConvertToUCS(__le16 *target, const char *source, int maxlen,
646 const struct nls_table *cp, int mapChars)
647{
648 int i, j, charlen;
649 int len_remaining = maxlen;
650 char src_char;
651 __u16 temp;
652
653 if (!mapChars)
654 return cifs_strtoUCS(target, source, PATH_MAX, cp);
655
656 for (i = 0, j = 0; i < maxlen; j++) {
657 src_char = source[i];
658 switch (src_char) {
659 case 0:
660 target[j] = 0;
661 goto ctoUCS_out;
662 case ':':
663 target[j] = cpu_to_le16(UNI_COLON);
664 break;
665 case '*':
666 target[j] = cpu_to_le16(UNI_ASTERIK);
667 break;
668 case '?':
669 target[j] = cpu_to_le16(UNI_QUESTION);
670 break;
671 case '<':
672 target[j] = cpu_to_le16(UNI_LESSTHAN);
673 break;
674 case '>':
675 target[j] = cpu_to_le16(UNI_GRTRTHAN);
676 break;
677 case '|':
678 target[j] = cpu_to_le16(UNI_PIPE);
679 break;
680 /* BB We can not handle remapping slash until
681 all the calls to build_path_from_dentry
682 are modified, as they use slash as separator BB */
683 /* case '\\':
684 target[j] = cpu_to_le16(UNI_SLASH);
685 break;*/
686 default:
687 charlen = cp->char2uni(source+i,
688 len_remaining, &temp);
689 /* if no match, use question mark, which
690 at least in some cases servers as wild card */
691 if (charlen < 1) {
692 target[j] = cpu_to_le16(0x003f);
693 charlen = 1;
694 } else
695 target[j] = cpu_to_le16(temp);
696 len_remaining -= charlen;
697 /* character may take more than one byte in the
698 the source string, but will take exactly two
699 bytes in the target string */
700 i += charlen;
701 continue;
702 }
703 i++; /* move to next char in source string */
704 len_remaining--;
705 }
706
707ctoUCS_out:
708 return i;
709}
710
711void 655void
712cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb) 656cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb)
713{ 657{
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index 9aad47a2d62f..79f641eeda30 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -170,7 +170,7 @@ cifs_convert_address(struct sockaddr *dst, const char *src, int len)
170{ 170{
171 int rc, alen, slen; 171 int rc, alen, slen;
172 const char *pct; 172 const char *pct;
173 char *endp, scope_id[13]; 173 char scope_id[13];
174 struct sockaddr_in *s4 = (struct sockaddr_in *) dst; 174 struct sockaddr_in *s4 = (struct sockaddr_in *) dst;
175 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) dst; 175 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) dst;
176 176
@@ -197,9 +197,9 @@ cifs_convert_address(struct sockaddr *dst, const char *src, int len)
197 memcpy(scope_id, pct + 1, slen); 197 memcpy(scope_id, pct + 1, slen);
198 scope_id[slen] = '\0'; 198 scope_id[slen] = '\0';
199 199
200 s6->sin6_scope_id = (u32) simple_strtoul(pct, &endp, 0); 200 rc = strict_strtoul(scope_id, 0,
201 if (endp != scope_id + slen) 201 (unsigned long *)&s6->sin6_scope_id);
202 return 0; 202 rc = (rc == 0) ? 1 : 0;
203 } 203 }
204 204
205 return rc; 205 return rc;
@@ -899,8 +899,8 @@ map_smb_to_linux_error(struct smb_hdr *smb, int logErr)
899 } 899 }
900 /* else ERRHRD class errors or junk - return EIO */ 900 /* else ERRHRD class errors or junk - return EIO */
901 901
902 cFYI(1, "Mapping smb error code %d to POSIX err %d", 902 cFYI(1, "Mapping smb error code 0x%x to POSIX err %d",
903 smberrcode, rc); 903 le32_to_cpu(smb->Status.CifsError), rc);
904 904
905 /* generic corrective action e.g. reconnect SMB session on 905 /* generic corrective action e.g. reconnect SMB session on
906 * ERRbaduid could be added */ 906 * ERRbaduid could be added */
@@ -916,14 +916,14 @@ unsigned int
916smbCalcSize(struct smb_hdr *ptr) 916smbCalcSize(struct smb_hdr *ptr)
917{ 917{
918 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) + 918 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
919 2 /* size of the bcc field */ + BCC(ptr)); 919 2 /* size of the bcc field */ + get_bcc(ptr));
920} 920}
921 921
922unsigned int 922unsigned int
923smbCalcSize_LE(struct smb_hdr *ptr) 923smbCalcSize_LE(struct smb_hdr *ptr)
924{ 924{
925 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) + 925 return (sizeof(struct smb_hdr) + (2 * ptr->WordCount) +
926 2 /* size of the bcc field */ + le16_to_cpu(BCC_LE(ptr))); 926 2 /* size of the bcc field */ + get_bcc_le(ptr));
927} 927}
928 928
929/* The following are taken from fs/ntfs/util.c */ 929/* The following are taken from fs/ntfs/util.c */
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index 7f25cc3d2256..f8e4cd2a7912 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -764,7 +764,6 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
764{ 764{
765 int rc = 0; 765 int rc = 0;
766 int xid, i; 766 int xid, i;
767 struct cifs_sb_info *cifs_sb;
768 struct cifsTconInfo *pTcon; 767 struct cifsTconInfo *pTcon;
769 struct cifsFileInfo *cifsFile = NULL; 768 struct cifsFileInfo *cifsFile = NULL;
770 char *current_entry; 769 char *current_entry;
@@ -775,8 +774,6 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
775 774
776 xid = GetXid(); 775 xid = GetXid();
777 776
778 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
779
780 /* 777 /*
781 * Ensure FindFirst doesn't fail before doing filldir() for '.' and 778 * Ensure FindFirst doesn't fail before doing filldir() for '.' and
782 * '..'. Otherwise we won't be able to notify VFS in case of failure. 779 * '..'. Otherwise we won't be able to notify VFS in case of failure.
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index eb746486e49e..f6728eb6f4b9 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -219,12 +219,12 @@ static void unicode_ssetup_strings(char **pbcc_area, struct cifsSesInfo *ses,
219 bcc_ptr++; 219 bcc_ptr++;
220 } */ 220 } */
221 /* copy user */ 221 /* copy user */
222 if (ses->userName == NULL) { 222 if (ses->user_name == NULL) {
223 /* null user mount */ 223 /* null user mount */
224 *bcc_ptr = 0; 224 *bcc_ptr = 0;
225 *(bcc_ptr+1) = 0; 225 *(bcc_ptr+1) = 0;
226 } else { 226 } else {
227 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, ses->userName, 227 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, ses->user_name,
228 MAX_USERNAME_SIZE, nls_cp); 228 MAX_USERNAME_SIZE, nls_cp);
229 } 229 }
230 bcc_ptr += 2 * bytes_ret; 230 bcc_ptr += 2 * bytes_ret;
@@ -244,12 +244,11 @@ static void ascii_ssetup_strings(char **pbcc_area, struct cifsSesInfo *ses,
244 /* copy user */ 244 /* copy user */
245 /* BB what about null user mounts - check that we do this BB */ 245 /* BB what about null user mounts - check that we do this BB */
246 /* copy user */ 246 /* copy user */
247 if (ses->userName == NULL) { 247 if (ses->user_name != NULL)
248 /* BB what about null user mounts - check that we do this BB */ 248 strncpy(bcc_ptr, ses->user_name, MAX_USERNAME_SIZE);
249 } else { 249 /* else null user mount */
250 strncpy(bcc_ptr, ses->userName, MAX_USERNAME_SIZE); 250
251 } 251 bcc_ptr += strnlen(ses->user_name, MAX_USERNAME_SIZE);
252 bcc_ptr += strnlen(ses->userName, MAX_USERNAME_SIZE);
253 *bcc_ptr = 0; 252 *bcc_ptr = 0;
254 bcc_ptr++; /* account for null termination */ 253 bcc_ptr++; /* account for null termination */
255 254
@@ -277,7 +276,7 @@ static void ascii_ssetup_strings(char **pbcc_area, struct cifsSesInfo *ses,
277} 276}
278 277
279static void 278static void
280decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses, 279decode_unicode_ssetup(char **pbcc_area, __u16 bleft, struct cifsSesInfo *ses,
281 const struct nls_table *nls_cp) 280 const struct nls_table *nls_cp)
282{ 281{
283 int len; 282 int len;
@@ -323,7 +322,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses,
323 return; 322 return;
324} 323}
325 324
326static int decode_ascii_ssetup(char **pbcc_area, int bleft, 325static int decode_ascii_ssetup(char **pbcc_area, __u16 bleft,
327 struct cifsSesInfo *ses, 326 struct cifsSesInfo *ses,
328 const struct nls_table *nls_cp) 327 const struct nls_table *nls_cp)
329{ 328{
@@ -405,8 +404,8 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
405 /* BB spec says that if AvId field of MsvAvTimestamp is populated then 404 /* BB spec says that if AvId field of MsvAvTimestamp is populated then
406 we must set the MIC field of the AUTHENTICATE_MESSAGE */ 405 we must set the MIC field of the AUTHENTICATE_MESSAGE */
407 ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags); 406 ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags);
408 tioffset = cpu_to_le16(pblob->TargetInfoArray.BufferOffset); 407 tioffset = le32_to_cpu(pblob->TargetInfoArray.BufferOffset);
409 tilen = cpu_to_le16(pblob->TargetInfoArray.Length); 408 tilen = le16_to_cpu(pblob->TargetInfoArray.Length);
410 if (tilen) { 409 if (tilen) {
411 ses->auth_key.response = kmalloc(tilen, GFP_KERNEL); 410 ses->auth_key.response = kmalloc(tilen, GFP_KERNEL);
412 if (!ses->auth_key.response) { 411 if (!ses->auth_key.response) {
@@ -523,14 +522,14 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
523 tmp += len; 522 tmp += len;
524 } 523 }
525 524
526 if (ses->userName == NULL) { 525 if (ses->user_name == NULL) {
527 sec_blob->UserName.BufferOffset = cpu_to_le32(tmp - pbuffer); 526 sec_blob->UserName.BufferOffset = cpu_to_le32(tmp - pbuffer);
528 sec_blob->UserName.Length = 0; 527 sec_blob->UserName.Length = 0;
529 sec_blob->UserName.MaximumLength = 0; 528 sec_blob->UserName.MaximumLength = 0;
530 tmp += 2; 529 tmp += 2;
531 } else { 530 } else {
532 int len; 531 int len;
533 len = cifs_strtoUCS((__le16 *)tmp, ses->userName, 532 len = cifs_strtoUCS((__le16 *)tmp, ses->user_name,
534 MAX_USERNAME_SIZE, nls_cp); 533 MAX_USERNAME_SIZE, nls_cp);
535 len *= 2; /* unicode is 2 bytes each */ 534 len *= 2; /* unicode is 2 bytes each */
536 sec_blob->UserName.BufferOffset = cpu_to_le32(tmp - pbuffer); 535 sec_blob->UserName.BufferOffset = cpu_to_le32(tmp - pbuffer);
@@ -575,12 +574,11 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
575 char *str_area; 574 char *str_area;
576 SESSION_SETUP_ANDX *pSMB; 575 SESSION_SETUP_ANDX *pSMB;
577 __u32 capabilities; 576 __u32 capabilities;
578 int count; 577 __u16 count;
579 int resp_buf_type; 578 int resp_buf_type;
580 struct kvec iov[3]; 579 struct kvec iov[3];
581 enum securityEnum type; 580 enum securityEnum type;
582 __u16 action; 581 __u16 action, bytes_remaining;
583 int bytes_remaining;
584 struct key *spnego_key = NULL; 582 struct key *spnego_key = NULL;
585 __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */ 583 __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */
586 u16 blob_len; 584 u16 blob_len;
@@ -657,13 +655,13 @@ ssetup_ntlmssp_authenticate:
657 655
658 if (type == LANMAN) { 656 if (type == LANMAN) {
659#ifdef CONFIG_CIFS_WEAK_PW_HASH 657#ifdef CONFIG_CIFS_WEAK_PW_HASH
660 char lnm_session_key[CIFS_SESS_KEY_SIZE]; 658 char lnm_session_key[CIFS_AUTH_RESP_SIZE];
661 659
662 pSMB->req.hdr.Flags2 &= ~SMBFLG2_UNICODE; 660 pSMB->req.hdr.Flags2 &= ~SMBFLG2_UNICODE;
663 661
664 /* no capabilities flags in old lanman negotiation */ 662 /* no capabilities flags in old lanman negotiation */
665 663
666 pSMB->old_req.PasswordLength = cpu_to_le16(CIFS_SESS_KEY_SIZE); 664 pSMB->old_req.PasswordLength = cpu_to_le16(CIFS_AUTH_RESP_SIZE);
667 665
668 /* Calculate hash with password and copy into bcc_ptr. 666 /* Calculate hash with password and copy into bcc_ptr.
669 * Encryption Key (stored as in cryptkey) gets used if the 667 * Encryption Key (stored as in cryptkey) gets used if the
@@ -676,8 +674,8 @@ ssetup_ntlmssp_authenticate:
676 true : false, lnm_session_key); 674 true : false, lnm_session_key);
677 675
678 ses->flags |= CIFS_SES_LANMAN; 676 ses->flags |= CIFS_SES_LANMAN;
679 memcpy(bcc_ptr, (char *)lnm_session_key, CIFS_SESS_KEY_SIZE); 677 memcpy(bcc_ptr, (char *)lnm_session_key, CIFS_AUTH_RESP_SIZE);
680 bcc_ptr += CIFS_SESS_KEY_SIZE; 678 bcc_ptr += CIFS_AUTH_RESP_SIZE;
681 679
682 /* can not sign if LANMAN negotiated so no need 680 /* can not sign if LANMAN negotiated so no need
683 to calculate signing key? but what if server 681 to calculate signing key? but what if server
@@ -876,10 +874,10 @@ ssetup_ntlmssp_authenticate:
876 count = iov[1].iov_len + iov[2].iov_len; 874 count = iov[1].iov_len + iov[2].iov_len;
877 smb_buf->smb_buf_length += count; 875 smb_buf->smb_buf_length += count;
878 876
879 BCC_LE(smb_buf) = cpu_to_le16(count); 877 put_bcc_le(count, smb_buf);
880 878
881 rc = SendReceive2(xid, ses, iov, 3 /* num_iovecs */, &resp_buf_type, 879 rc = SendReceive2(xid, ses, iov, 3 /* num_iovecs */, &resp_buf_type,
882 CIFS_STD_OP /* not long */ | CIFS_LOG_ERROR); 880 CIFS_LOG_ERROR);
883 /* SMB request buf freed in SendReceive2 */ 881 /* SMB request buf freed in SendReceive2 */
884 882
885 pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base; 883 pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base;
@@ -910,7 +908,7 @@ ssetup_ntlmssp_authenticate:
910 cFYI(1, "UID = %d ", ses->Suid); 908 cFYI(1, "UID = %d ", ses->Suid);
911 /* response can have either 3 or 4 word count - Samba sends 3 */ 909 /* response can have either 3 or 4 word count - Samba sends 3 */
912 /* and lanman response is 3 */ 910 /* and lanman response is 3 */
913 bytes_remaining = BCC(smb_buf); 911 bytes_remaining = get_bcc(smb_buf);
914 bcc_ptr = pByteArea(smb_buf); 912 bcc_ptr = pByteArea(smb_buf);
915 913
916 if (smb_buf->WordCount == 4) { 914 if (smb_buf->WordCount == 4) {
diff --git a/fs/cifs/smbdes.c b/fs/cifs/smbdes.c
index b6b6dcb500bf..04721485925d 100644
--- a/fs/cifs/smbdes.c
+++ b/fs/cifs/smbdes.c
@@ -45,7 +45,6 @@
45 up with a different answer to the one above) 45 up with a different answer to the one above)
46*/ 46*/
47#include <linux/slab.h> 47#include <linux/slab.h>
48#include "cifsencrypt.h"
49#define uchar unsigned char 48#define uchar unsigned char
50 49
51static uchar perm1[56] = { 57, 49, 41, 33, 25, 17, 9, 50static uchar perm1[56] = { 57, 49, 41, 33, 25, 17, 9,
diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
index 192ea51af20f..b5041c849981 100644
--- a/fs/cifs/smbencrypt.c
+++ b/fs/cifs/smbencrypt.c
@@ -32,9 +32,8 @@
32#include "cifs_unicode.h" 32#include "cifs_unicode.h"
33#include "cifspdu.h" 33#include "cifspdu.h"
34#include "cifsglob.h" 34#include "cifsglob.h"
35#include "md5.h"
36#include "cifs_debug.h" 35#include "cifs_debug.h"
37#include "cifsencrypt.h" 36#include "cifsproto.h"
38 37
39#ifndef false 38#ifndef false
40#define false 0 39#define false 0
@@ -48,14 +47,58 @@
48#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8) 47#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
49#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((__u16)(val))) 48#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((__u16)(val)))
50 49
51/*The following definitions come from libsmb/smbencrypt.c */ 50/* produce a md4 message digest from data of length n bytes */
51int
52mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len)
53{
54 int rc;
55 unsigned int size;
56 struct crypto_shash *md4;
57 struct sdesc *sdescmd4;
58
59 md4 = crypto_alloc_shash("md4", 0, 0);
60 if (IS_ERR(md4)) {
61 rc = PTR_ERR(md4);
62 cERROR(1, "%s: Crypto md4 allocation error %d\n", __func__, rc);
63 return rc;
64 }
65 size = sizeof(struct shash_desc) + crypto_shash_descsize(md4);
66 sdescmd4 = kmalloc(size, GFP_KERNEL);
67 if (!sdescmd4) {
68 rc = -ENOMEM;
69 cERROR(1, "%s: Memory allocation failure\n", __func__);
70 goto mdfour_err;
71 }
72 sdescmd4->shash.tfm = md4;
73 sdescmd4->shash.flags = 0x0;
74
75 rc = crypto_shash_init(&sdescmd4->shash);
76 if (rc) {
77 cERROR(1, "%s: Could not init md4 shash\n", __func__);
78 goto mdfour_err;
79 }
80 crypto_shash_update(&sdescmd4->shash, link_str, link_len);
81 rc = crypto_shash_final(&sdescmd4->shash, md4_hash);
52 82
53void SMBencrypt(unsigned char *passwd, const unsigned char *c8, 83mdfour_err:
54 unsigned char *p24); 84 crypto_free_shash(md4);
55void E_md4hash(const unsigned char *passwd, unsigned char *p16); 85 kfree(sdescmd4);
56static void SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8, 86
57 unsigned char p24[24]); 87 return rc;
58void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24); 88}
89
90/* Does the des encryption from the NT or LM MD4 hash. */
91static void
92SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8,
93 unsigned char p24[24])
94{
95 unsigned char p21[21];
96
97 memset(p21, '\0', 21);
98
99 memcpy(p21, passwd, 16);
100 E_P24(p21, c8, p24);
101}
59 102
60/* 103/*
61 This implements the X/Open SMB password encryption 104 This implements the X/Open SMB password encryption
@@ -118,9 +161,10 @@ _my_mbstowcs(__u16 *dst, const unsigned char *src, int len)
118 * Creates the MD4 Hash of the users password in NT UNICODE. 161 * Creates the MD4 Hash of the users password in NT UNICODE.
119 */ 162 */
120 163
121void 164int
122E_md4hash(const unsigned char *passwd, unsigned char *p16) 165E_md4hash(const unsigned char *passwd, unsigned char *p16)
123{ 166{
167 int rc;
124 int len; 168 int len;
125 __u16 wpwd[129]; 169 __u16 wpwd[129];
126 170
@@ -139,8 +183,10 @@ E_md4hash(const unsigned char *passwd, unsigned char *p16)
139 /* Calculate length in bytes */ 183 /* Calculate length in bytes */
140 len = _my_wcslen(wpwd) * sizeof(__u16); 184 len = _my_wcslen(wpwd) * sizeof(__u16);
141 185
142 mdfour(p16, (unsigned char *) wpwd, len); 186 rc = mdfour(p16, (unsigned char *) wpwd, len);
143 memset(wpwd, 0, 129 * 2); 187 memset(wpwd, 0, 129 * 2);
188
189 return rc;
144} 190}
145 191
146#if 0 /* currently unused */ 192#if 0 /* currently unused */
@@ -212,19 +258,6 @@ ntv2_owf_gen(const unsigned char owf[16], const char *user_n,
212} 258}
213#endif 259#endif
214 260
215/* Does the des encryption from the NT or LM MD4 hash. */
216static void
217SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8,
218 unsigned char p24[24])
219{
220 unsigned char p21[21];
221
222 memset(p21, '\0', 21);
223
224 memcpy(p21, passwd, 16);
225 E_P24(p21, c8, p24);
226}
227
228/* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */ 261/* Does the des encryption from the FIRST 8 BYTES of the NT or LM MD4 hash. */
229#if 0 /* currently unused */ 262#if 0 /* currently unused */
230static void 263static void
@@ -242,16 +275,21 @@ NTLMSSPOWFencrypt(unsigned char passwd[8],
242#endif 275#endif
243 276
244/* Does the NT MD4 hash then des encryption. */ 277/* Does the NT MD4 hash then des encryption. */
245 278int
246void
247SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24) 279SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24)
248{ 280{
281 int rc;
249 unsigned char p21[21]; 282 unsigned char p21[21];
250 283
251 memset(p21, '\0', 21); 284 memset(p21, '\0', 21);
252 285
253 E_md4hash(passwd, p21); 286 rc = E_md4hash(passwd, p21);
287 if (rc) {
288 cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc);
289 return rc;
290 }
254 SMBOWFencrypt(p21, c8, p24); 291 SMBOWFencrypt(p21, c8, p24);
292 return rc;
255} 293}
256 294
257 295
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index 59ca81b16919..46d8756f2b24 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -36,7 +36,13 @@
36 36
37extern mempool_t *cifs_mid_poolp; 37extern mempool_t *cifs_mid_poolp;
38 38
39static struct mid_q_entry * 39static void
40wake_up_task(struct mid_q_entry *mid)
41{
42 wake_up_process(mid->callback_data);
43}
44
45struct mid_q_entry *
40AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server) 46AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
41{ 47{
42 struct mid_q_entry *temp; 48 struct mid_q_entry *temp;
@@ -58,28 +64,28 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
58 /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */ 64 /* do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */
59 /* when mid allocated can be before when sent */ 65 /* when mid allocated can be before when sent */
60 temp->when_alloc = jiffies; 66 temp->when_alloc = jiffies;
61 temp->tsk = current; 67
68 /*
69 * The default is for the mid to be synchronous, so the
70 * default callback just wakes up the current task.
71 */
72 temp->callback = wake_up_task;
73 temp->callback_data = current;
62 } 74 }
63 75
64 spin_lock(&GlobalMid_Lock);
65 list_add_tail(&temp->qhead, &server->pending_mid_q);
66 atomic_inc(&midCount); 76 atomic_inc(&midCount);
67 temp->midState = MID_REQUEST_ALLOCATED; 77 temp->midState = MID_REQUEST_ALLOCATED;
68 spin_unlock(&GlobalMid_Lock);
69 return temp; 78 return temp;
70} 79}
71 80
72static void 81void
73DeleteMidQEntry(struct mid_q_entry *midEntry) 82DeleteMidQEntry(struct mid_q_entry *midEntry)
74{ 83{
75#ifdef CONFIG_CIFS_STATS2 84#ifdef CONFIG_CIFS_STATS2
76 unsigned long now; 85 unsigned long now;
77#endif 86#endif
78 spin_lock(&GlobalMid_Lock);
79 midEntry->midState = MID_FREE; 87 midEntry->midState = MID_FREE;
80 list_del(&midEntry->qhead);
81 atomic_dec(&midCount); 88 atomic_dec(&midCount);
82 spin_unlock(&GlobalMid_Lock);
83 if (midEntry->largeBuf) 89 if (midEntry->largeBuf)
84 cifs_buf_release(midEntry->resp_buf); 90 cifs_buf_release(midEntry->resp_buf);
85 else 91 else
@@ -103,6 +109,16 @@ DeleteMidQEntry(struct mid_q_entry *midEntry)
103 mempool_free(midEntry, cifs_mid_poolp); 109 mempool_free(midEntry, cifs_mid_poolp);
104} 110}
105 111
112static void
113delete_mid(struct mid_q_entry *mid)
114{
115 spin_lock(&GlobalMid_Lock);
116 list_del(&mid->qhead);
117 spin_unlock(&GlobalMid_Lock);
118
119 DeleteMidQEntry(mid);
120}
121
106static int 122static int
107smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) 123smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
108{ 124{
@@ -220,9 +236,9 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
220 server->tcpStatus = CifsNeedReconnect; 236 server->tcpStatus = CifsNeedReconnect;
221 } 237 }
222 238
223 if (rc < 0) { 239 if (rc < 0 && rc != -EINTR)
224 cERROR(1, "Error %d sending data on socket to server", rc); 240 cERROR(1, "Error %d sending data on socket to server", rc);
225 } else 241 else
226 rc = 0; 242 rc = 0;
227 243
228 /* Don't want to modify the buffer as a 244 /* Don't want to modify the buffer as a
@@ -244,31 +260,31 @@ smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer,
244 return smb_sendv(server, &iov, 1); 260 return smb_sendv(server, &iov, 1);
245} 261}
246 262
247static int wait_for_free_request(struct cifsSesInfo *ses, const int long_op) 263static int wait_for_free_request(struct TCP_Server_Info *server,
264 const int long_op)
248{ 265{
249 if (long_op == CIFS_ASYNC_OP) { 266 if (long_op == CIFS_ASYNC_OP) {
250 /* oplock breaks must not be held up */ 267 /* oplock breaks must not be held up */
251 atomic_inc(&ses->server->inFlight); 268 atomic_inc(&server->inFlight);
252 return 0; 269 return 0;
253 } 270 }
254 271
255 spin_lock(&GlobalMid_Lock); 272 spin_lock(&GlobalMid_Lock);
256 while (1) { 273 while (1) {
257 if (atomic_read(&ses->server->inFlight) >= 274 if (atomic_read(&server->inFlight) >= cifs_max_pending) {
258 cifs_max_pending){
259 spin_unlock(&GlobalMid_Lock); 275 spin_unlock(&GlobalMid_Lock);
260#ifdef CONFIG_CIFS_STATS2 276#ifdef CONFIG_CIFS_STATS2
261 atomic_inc(&ses->server->num_waiters); 277 atomic_inc(&server->num_waiters);
262#endif 278#endif
263 wait_event(ses->server->request_q, 279 wait_event(server->request_q,
264 atomic_read(&ses->server->inFlight) 280 atomic_read(&server->inFlight)
265 < cifs_max_pending); 281 < cifs_max_pending);
266#ifdef CONFIG_CIFS_STATS2 282#ifdef CONFIG_CIFS_STATS2
267 atomic_dec(&ses->server->num_waiters); 283 atomic_dec(&server->num_waiters);
268#endif 284#endif
269 spin_lock(&GlobalMid_Lock); 285 spin_lock(&GlobalMid_Lock);
270 } else { 286 } else {
271 if (ses->server->tcpStatus == CifsExiting) { 287 if (server->tcpStatus == CifsExiting) {
272 spin_unlock(&GlobalMid_Lock); 288 spin_unlock(&GlobalMid_Lock);
273 return -ENOENT; 289 return -ENOENT;
274 } 290 }
@@ -278,7 +294,7 @@ static int wait_for_free_request(struct cifsSesInfo *ses, const int long_op)
278 294
279 /* update # of requests on the wire to server */ 295 /* update # of requests on the wire to server */
280 if (long_op != CIFS_BLOCKING_OP) 296 if (long_op != CIFS_BLOCKING_OP)
281 atomic_inc(&ses->server->inFlight); 297 atomic_inc(&server->inFlight);
282 spin_unlock(&GlobalMid_Lock); 298 spin_unlock(&GlobalMid_Lock);
283 break; 299 break;
284 } 300 }
@@ -308,53 +324,85 @@ static int allocate_mid(struct cifsSesInfo *ses, struct smb_hdr *in_buf,
308 *ppmidQ = AllocMidQEntry(in_buf, ses->server); 324 *ppmidQ = AllocMidQEntry(in_buf, ses->server);
309 if (*ppmidQ == NULL) 325 if (*ppmidQ == NULL)
310 return -ENOMEM; 326 return -ENOMEM;
327 spin_lock(&GlobalMid_Lock);
328 list_add_tail(&(*ppmidQ)->qhead, &ses->server->pending_mid_q);
329 spin_unlock(&GlobalMid_Lock);
311 return 0; 330 return 0;
312} 331}
313 332
314static int wait_for_response(struct cifsSesInfo *ses, 333static int
315 struct mid_q_entry *midQ, 334wait_for_response(struct TCP_Server_Info *server, struct mid_q_entry *midQ)
316 unsigned long timeout,
317 unsigned long time_to_wait)
318{ 335{
319 unsigned long curr_timeout; 336 int error;
320 337
321 for (;;) { 338 error = wait_event_killable(server->response_q,
322 curr_timeout = timeout + jiffies; 339 midQ->midState != MID_REQUEST_SUBMITTED);
323 wait_event_timeout(ses->server->response_q, 340 if (error < 0)
324 midQ->midState != MID_REQUEST_SUBMITTED, timeout); 341 return -ERESTARTSYS;
325 342
326 if (time_after(jiffies, curr_timeout) && 343 return 0;
327 (midQ->midState == MID_REQUEST_SUBMITTED) && 344}
328 ((ses->server->tcpStatus == CifsGood) ||
329 (ses->server->tcpStatus == CifsNew))) {
330 345
331 unsigned long lrt;
332 346
333 /* We timed out. Is the server still 347/*
334 sending replies ? */ 348 * Send a SMB request and set the callback function in the mid to handle
335 spin_lock(&GlobalMid_Lock); 349 * the result. Caller is responsible for dealing with timeouts.
336 lrt = ses->server->lstrp; 350 */
337 spin_unlock(&GlobalMid_Lock); 351int
352cifs_call_async(struct TCP_Server_Info *server, struct smb_hdr *in_buf,
353 mid_callback_t *callback, void *cbdata)
354{
355 int rc;
356 struct mid_q_entry *mid;
338 357
339 /* Calculate time_to_wait past last receive time. 358 rc = wait_for_free_request(server, CIFS_ASYNC_OP);
340 Although we prefer not to time out if the 359 if (rc)
341 server is still responding - we will time 360 return rc;
342 out if the server takes more than 15 (or 45 361
343 or 180) seconds to respond to this request 362 /* enable signing if server requires it */
344 and has not responded to any request from 363 if (server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
345 other threads on the client within 10 seconds */ 364 in_buf->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
346 lrt += time_to_wait; 365
347 if (time_after(jiffies, lrt)) { 366 mutex_lock(&server->srv_mutex);
348 /* No replies for time_to_wait. */ 367 mid = AllocMidQEntry(in_buf, server);
349 cERROR(1, "server not responding"); 368 if (mid == NULL) {
350 return -1; 369 mutex_unlock(&server->srv_mutex);
351 } 370 return -ENOMEM;
352 } else {
353 return 0;
354 }
355 } 371 }
356}
357 372
373 /* put it on the pending_mid_q */
374 spin_lock(&GlobalMid_Lock);
375 list_add_tail(&mid->qhead, &server->pending_mid_q);
376 spin_unlock(&GlobalMid_Lock);
377
378 rc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
379 if (rc) {
380 mutex_unlock(&server->srv_mutex);
381 goto out_err;
382 }
383
384 mid->callback = callback;
385 mid->callback_data = cbdata;
386 mid->midState = MID_REQUEST_SUBMITTED;
387#ifdef CONFIG_CIFS_STATS2
388 atomic_inc(&server->inSend);
389#endif
390 rc = smb_send(server, in_buf, in_buf->smb_buf_length);
391#ifdef CONFIG_CIFS_STATS2
392 atomic_dec(&server->inSend);
393 mid->when_sent = jiffies;
394#endif
395 mutex_unlock(&server->srv_mutex);
396 if (rc)
397 goto out_err;
398
399 return rc;
400out_err:
401 delete_mid(mid);
402 atomic_dec(&server->inFlight);
403 wake_up(&server->request_q);
404 return rc;
405}
358 406
359/* 407/*
360 * 408 *
@@ -382,6 +430,84 @@ SendReceiveNoRsp(const unsigned int xid, struct cifsSesInfo *ses,
382 return rc; 430 return rc;
383} 431}
384 432
433static int
434sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)
435{
436 int rc = 0;
437
438 cFYI(1, "%s: cmd=%d mid=%d state=%d", __func__, mid->command,
439 mid->mid, mid->midState);
440
441 spin_lock(&GlobalMid_Lock);
442 /* ensure that it's no longer on the pending_mid_q */
443 list_del_init(&mid->qhead);
444
445 switch (mid->midState) {
446 case MID_RESPONSE_RECEIVED:
447 spin_unlock(&GlobalMid_Lock);
448 return rc;
449 case MID_REQUEST_SUBMITTED:
450 /* socket is going down, reject all calls */
451 if (server->tcpStatus == CifsExiting) {
452 cERROR(1, "%s: canceling mid=%d cmd=0x%x state=%d",
453 __func__, mid->mid, mid->command, mid->midState);
454 rc = -EHOSTDOWN;
455 break;
456 }
457 case MID_RETRY_NEEDED:
458 rc = -EAGAIN;
459 break;
460 case MID_RESPONSE_MALFORMED:
461 rc = -EIO;
462 break;
463 default:
464 cERROR(1, "%s: invalid mid state mid=%d state=%d", __func__,
465 mid->mid, mid->midState);
466 rc = -EIO;
467 }
468 spin_unlock(&GlobalMid_Lock);
469
470 DeleteMidQEntry(mid);
471 return rc;
472}
473
474/*
475 * An NT cancel request header looks just like the original request except:
476 *
477 * The Command is SMB_COM_NT_CANCEL
478 * The WordCount is zeroed out
479 * The ByteCount is zeroed out
480 *
481 * This function mangles an existing request buffer into a
482 * SMB_COM_NT_CANCEL request and then sends it.
483 */
484static int
485send_nt_cancel(struct TCP_Server_Info *server, struct smb_hdr *in_buf,
486 struct mid_q_entry *mid)
487{
488 int rc = 0;
489
490 /* -4 for RFC1001 length and +2 for BCC field */
491 in_buf->smb_buf_length = sizeof(struct smb_hdr) - 4 + 2;
492 in_buf->Command = SMB_COM_NT_CANCEL;
493 in_buf->WordCount = 0;
494 put_bcc_le(0, in_buf);
495
496 mutex_lock(&server->srv_mutex);
497 rc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
498 if (rc) {
499 mutex_unlock(&server->srv_mutex);
500 return rc;
501 }
502 rc = smb_send(server, in_buf, in_buf->smb_buf_length);
503 mutex_unlock(&server->srv_mutex);
504
505 cFYI(1, "issued NT_CANCEL for mid %u, rc = %d",
506 in_buf->Mid, rc);
507
508 return rc;
509}
510
385int 511int
386SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, 512SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
387 struct kvec *iov, int n_vec, int *pRespBufType /* ret */, 513 struct kvec *iov, int n_vec, int *pRespBufType /* ret */,
@@ -390,7 +516,6 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
390 int rc = 0; 516 int rc = 0;
391 int long_op; 517 int long_op;
392 unsigned int receive_len; 518 unsigned int receive_len;
393 unsigned long timeout;
394 struct mid_q_entry *midQ; 519 struct mid_q_entry *midQ;
395 struct smb_hdr *in_buf = iov[0].iov_base; 520 struct smb_hdr *in_buf = iov[0].iov_base;
396 521
@@ -413,7 +538,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
413 to the same server. We may make this configurable later or 538 to the same server. We may make this configurable later or
414 use ses->maxReq */ 539 use ses->maxReq */
415 540
416 rc = wait_for_free_request(ses, long_op); 541 rc = wait_for_free_request(ses->server, long_op);
417 if (rc) { 542 if (rc) {
418 cifs_small_buf_release(in_buf); 543 cifs_small_buf_release(in_buf);
419 return rc; 544 return rc;
@@ -452,70 +577,41 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
452#endif 577#endif
453 578
454 mutex_unlock(&ses->server->srv_mutex); 579 mutex_unlock(&ses->server->srv_mutex);
455 cifs_small_buf_release(in_buf);
456 580
457 if (rc < 0) 581 if (rc < 0) {
458 goto out; 582 cifs_small_buf_release(in_buf);
459
460 if (long_op == CIFS_STD_OP)
461 timeout = 15 * HZ;
462 else if (long_op == CIFS_VLONG_OP) /* e.g. slow writes past EOF */
463 timeout = 180 * HZ;
464 else if (long_op == CIFS_LONG_OP)
465 timeout = 45 * HZ; /* should be greater than
466 servers oplock break timeout (about 43 seconds) */
467 else if (long_op == CIFS_ASYNC_OP)
468 goto out;
469 else if (long_op == CIFS_BLOCKING_OP)
470 timeout = 0x7FFFFFFF; /* large, but not so large as to wrap */
471 else {
472 cERROR(1, "unknown timeout flag %d", long_op);
473 rc = -EIO;
474 goto out; 583 goto out;
475 } 584 }
476 585
477 /* wait for 15 seconds or until woken up due to response arriving or 586 if (long_op == CIFS_ASYNC_OP) {
478 due to last connection to this server being unmounted */ 587 cifs_small_buf_release(in_buf);
479 if (signal_pending(current)) { 588 goto out;
480 /* if signal pending do not hold up user for full smb timeout
481 but we still give response a chance to complete */
482 timeout = 2 * HZ;
483 } 589 }
484 590
485 /* No user interrupts in wait - wreaks havoc with performance */ 591 rc = wait_for_response(ses->server, midQ);
486 wait_for_response(ses, midQ, timeout, 10 * HZ); 592 if (rc != 0) {
487 593 send_nt_cancel(ses->server, in_buf, midQ);
488 spin_lock(&GlobalMid_Lock); 594 spin_lock(&GlobalMid_Lock);
489
490 if (midQ->resp_buf == NULL) {
491 cERROR(1, "No response to cmd %d mid %d",
492 midQ->command, midQ->mid);
493 if (midQ->midState == MID_REQUEST_SUBMITTED) { 595 if (midQ->midState == MID_REQUEST_SUBMITTED) {
494 if (ses->server->tcpStatus == CifsExiting) 596 midQ->callback = DeleteMidQEntry;
495 rc = -EHOSTDOWN; 597 spin_unlock(&GlobalMid_Lock);
496 else { 598 cifs_small_buf_release(in_buf);
497 ses->server->tcpStatus = CifsNeedReconnect; 599 atomic_dec(&ses->server->inFlight);
498 midQ->midState = MID_RETRY_NEEDED; 600 wake_up(&ses->server->request_q);
499 } 601 return rc;
500 }
501
502 if (rc != -EHOSTDOWN) {
503 if (midQ->midState == MID_RETRY_NEEDED) {
504 rc = -EAGAIN;
505 cFYI(1, "marking request for retry");
506 } else {
507 rc = -EIO;
508 }
509 } 602 }
510 spin_unlock(&GlobalMid_Lock); 603 spin_unlock(&GlobalMid_Lock);
511 DeleteMidQEntry(midQ); 604 }
512 /* Update # of requests on wire to server */ 605
606 cifs_small_buf_release(in_buf);
607
608 rc = sync_mid_result(midQ, ses->server);
609 if (rc != 0) {
513 atomic_dec(&ses->server->inFlight); 610 atomic_dec(&ses->server->inFlight);
514 wake_up(&ses->server->request_q); 611 wake_up(&ses->server->request_q);
515 return rc; 612 return rc;
516 } 613 }
517 614
518 spin_unlock(&GlobalMid_Lock);
519 receive_len = midQ->resp_buf->smb_buf_length; 615 receive_len = midQ->resp_buf->smb_buf_length;
520 616
521 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { 617 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
@@ -559,19 +655,18 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
559 if (receive_len >= sizeof(struct smb_hdr) - 4 655 if (receive_len >= sizeof(struct smb_hdr) - 4
560 /* do not count RFC1001 header */ + 656 /* do not count RFC1001 header */ +
561 (2 * midQ->resp_buf->WordCount) + 2 /* bcc */ ) 657 (2 * midQ->resp_buf->WordCount) + 2 /* bcc */ )
562 BCC(midQ->resp_buf) = 658 put_bcc(get_bcc_le(midQ->resp_buf), midQ->resp_buf);
563 le16_to_cpu(BCC_LE(midQ->resp_buf));
564 if ((flags & CIFS_NO_RESP) == 0) 659 if ((flags & CIFS_NO_RESP) == 0)
565 midQ->resp_buf = NULL; /* mark it so buf will 660 midQ->resp_buf = NULL; /* mark it so buf will
566 not be freed by 661 not be freed by
567 DeleteMidQEntry */ 662 delete_mid */
568 } else { 663 } else {
569 rc = -EIO; 664 rc = -EIO;
570 cFYI(1, "Bad MID state?"); 665 cFYI(1, "Bad MID state?");
571 } 666 }
572 667
573out: 668out:
574 DeleteMidQEntry(midQ); 669 delete_mid(midQ);
575 atomic_dec(&ses->server->inFlight); 670 atomic_dec(&ses->server->inFlight);
576 wake_up(&ses->server->request_q); 671 wake_up(&ses->server->request_q);
577 672
@@ -585,7 +680,6 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
585{ 680{
586 int rc = 0; 681 int rc = 0;
587 unsigned int receive_len; 682 unsigned int receive_len;
588 unsigned long timeout;
589 struct mid_q_entry *midQ; 683 struct mid_q_entry *midQ;
590 684
591 if (ses == NULL) { 685 if (ses == NULL) {
@@ -610,7 +704,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
610 return -EIO; 704 return -EIO;
611 } 705 }
612 706
613 rc = wait_for_free_request(ses, long_op); 707 rc = wait_for_free_request(ses->server, long_op);
614 if (rc) 708 if (rc)
615 return rc; 709 return rc;
616 710
@@ -649,64 +743,31 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
649 if (rc < 0) 743 if (rc < 0)
650 goto out; 744 goto out;
651 745
652 if (long_op == CIFS_STD_OP) 746 if (long_op == CIFS_ASYNC_OP)
653 timeout = 15 * HZ;
654 /* wait for 15 seconds or until woken up due to response arriving or
655 due to last connection to this server being unmounted */
656 else if (long_op == CIFS_ASYNC_OP)
657 goto out;
658 else if (long_op == CIFS_VLONG_OP) /* writes past EOF can be slow */
659 timeout = 180 * HZ;
660 else if (long_op == CIFS_LONG_OP)
661 timeout = 45 * HZ; /* should be greater than
662 servers oplock break timeout (about 43 seconds) */
663 else if (long_op == CIFS_BLOCKING_OP)
664 timeout = 0x7FFFFFFF; /* large but no so large as to wrap */
665 else {
666 cERROR(1, "unknown timeout flag %d", long_op);
667 rc = -EIO;
668 goto out; 747 goto out;
669 }
670
671 if (signal_pending(current)) {
672 /* if signal pending do not hold up user for full smb timeout
673 but we still give response a chance to complete */
674 timeout = 2 * HZ;
675 }
676
677 /* No user interrupts in wait - wreaks havoc with performance */
678 wait_for_response(ses, midQ, timeout, 10 * HZ);
679 748
680 spin_lock(&GlobalMid_Lock); 749 rc = wait_for_response(ses->server, midQ);
681 if (midQ->resp_buf == NULL) { 750 if (rc != 0) {
682 cERROR(1, "No response for cmd %d mid %d", 751 send_nt_cancel(ses->server, in_buf, midQ);
683 midQ->command, midQ->mid); 752 spin_lock(&GlobalMid_Lock);
684 if (midQ->midState == MID_REQUEST_SUBMITTED) { 753 if (midQ->midState == MID_REQUEST_SUBMITTED) {
685 if (ses->server->tcpStatus == CifsExiting) 754 /* no longer considered to be "in-flight" */
686 rc = -EHOSTDOWN; 755 midQ->callback = DeleteMidQEntry;
687 else { 756 spin_unlock(&GlobalMid_Lock);
688 ses->server->tcpStatus = CifsNeedReconnect; 757 atomic_dec(&ses->server->inFlight);
689 midQ->midState = MID_RETRY_NEEDED; 758 wake_up(&ses->server->request_q);
690 } 759 return rc;
691 }
692
693 if (rc != -EHOSTDOWN) {
694 if (midQ->midState == MID_RETRY_NEEDED) {
695 rc = -EAGAIN;
696 cFYI(1, "marking request for retry");
697 } else {
698 rc = -EIO;
699 }
700 } 760 }
701 spin_unlock(&GlobalMid_Lock); 761 spin_unlock(&GlobalMid_Lock);
702 DeleteMidQEntry(midQ); 762 }
703 /* Update # of requests on wire to server */ 763
764 rc = sync_mid_result(midQ, ses->server);
765 if (rc != 0) {
704 atomic_dec(&ses->server->inFlight); 766 atomic_dec(&ses->server->inFlight);
705 wake_up(&ses->server->request_q); 767 wake_up(&ses->server->request_q);
706 return rc; 768 return rc;
707 } 769 }
708 770
709 spin_unlock(&GlobalMid_Lock);
710 receive_len = midQ->resp_buf->smb_buf_length; 771 receive_len = midQ->resp_buf->smb_buf_length;
711 772
712 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { 773 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
@@ -748,43 +809,20 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
748 if (receive_len >= sizeof(struct smb_hdr) - 4 809 if (receive_len >= sizeof(struct smb_hdr) - 4
749 /* do not count RFC1001 header */ + 810 /* do not count RFC1001 header */ +
750 (2 * out_buf->WordCount) + 2 /* bcc */ ) 811 (2 * out_buf->WordCount) + 2 /* bcc */ )
751 BCC(out_buf) = le16_to_cpu(BCC_LE(out_buf)); 812 put_bcc(get_bcc_le(midQ->resp_buf), midQ->resp_buf);
752 } else { 813 } else {
753 rc = -EIO; 814 rc = -EIO;
754 cERROR(1, "Bad MID state?"); 815 cERROR(1, "Bad MID state?");
755 } 816 }
756 817
757out: 818out:
758 DeleteMidQEntry(midQ); 819 delete_mid(midQ);
759 atomic_dec(&ses->server->inFlight); 820 atomic_dec(&ses->server->inFlight);
760 wake_up(&ses->server->request_q); 821 wake_up(&ses->server->request_q);
761 822
762 return rc; 823 return rc;
763} 824}
764 825
765/* Send an NT_CANCEL SMB to cause the POSIX blocking lock to return. */
766
767static int
768send_nt_cancel(struct cifsTconInfo *tcon, struct smb_hdr *in_buf,
769 struct mid_q_entry *midQ)
770{
771 int rc = 0;
772 struct cifsSesInfo *ses = tcon->ses;
773 __u16 mid = in_buf->Mid;
774
775 header_assemble(in_buf, SMB_COM_NT_CANCEL, tcon, 0);
776 in_buf->Mid = mid;
777 mutex_lock(&ses->server->srv_mutex);
778 rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number);
779 if (rc) {
780 mutex_unlock(&ses->server->srv_mutex);
781 return rc;
782 }
783 rc = smb_send(ses->server, in_buf, in_buf->smb_buf_length);
784 mutex_unlock(&ses->server->srv_mutex);
785 return rc;
786}
787
788/* We send a LOCKINGX_CANCEL_LOCK to cause the Windows 826/* We send a LOCKINGX_CANCEL_LOCK to cause the Windows
789 blocking lock to return. */ 827 blocking lock to return. */
790 828
@@ -807,7 +845,7 @@ send_lock_cancel(const unsigned int xid, struct cifsTconInfo *tcon,
807 pSMB->hdr.Mid = GetNextMid(ses->server); 845 pSMB->hdr.Mid = GetNextMid(ses->server);
808 846
809 return SendReceive(xid, ses, in_buf, out_buf, 847 return SendReceive(xid, ses, in_buf, out_buf,
810 &bytes_returned, CIFS_STD_OP); 848 &bytes_returned, 0);
811} 849}
812 850
813int 851int
@@ -845,7 +883,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
845 return -EIO; 883 return -EIO;
846 } 884 }
847 885
848 rc = wait_for_free_request(ses, CIFS_BLOCKING_OP); 886 rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP);
849 if (rc) 887 if (rc)
850 return rc; 888 return rc;
851 889
@@ -863,7 +901,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
863 901
864 rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number); 902 rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number);
865 if (rc) { 903 if (rc) {
866 DeleteMidQEntry(midQ); 904 delete_mid(midQ);
867 mutex_unlock(&ses->server->srv_mutex); 905 mutex_unlock(&ses->server->srv_mutex);
868 return rc; 906 return rc;
869 } 907 }
@@ -880,7 +918,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
880 mutex_unlock(&ses->server->srv_mutex); 918 mutex_unlock(&ses->server->srv_mutex);
881 919
882 if (rc < 0) { 920 if (rc < 0) {
883 DeleteMidQEntry(midQ); 921 delete_mid(midQ);
884 return rc; 922 return rc;
885 } 923 }
886 924
@@ -899,10 +937,9 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
899 if (in_buf->Command == SMB_COM_TRANSACTION2) { 937 if (in_buf->Command == SMB_COM_TRANSACTION2) {
900 /* POSIX lock. We send a NT_CANCEL SMB to cause the 938 /* POSIX lock. We send a NT_CANCEL SMB to cause the
901 blocking lock to return. */ 939 blocking lock to return. */
902 940 rc = send_nt_cancel(ses->server, in_buf, midQ);
903 rc = send_nt_cancel(tcon, in_buf, midQ);
904 if (rc) { 941 if (rc) {
905 DeleteMidQEntry(midQ); 942 delete_mid(midQ);
906 return rc; 943 return rc;
907 } 944 }
908 } else { 945 } else {
@@ -914,47 +951,33 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
914 /* If we get -ENOLCK back the lock may have 951 /* If we get -ENOLCK back the lock may have
915 already been removed. Don't exit in this case. */ 952 already been removed. Don't exit in this case. */
916 if (rc && rc != -ENOLCK) { 953 if (rc && rc != -ENOLCK) {
917 DeleteMidQEntry(midQ); 954 delete_mid(midQ);
918 return rc; 955 return rc;
919 } 956 }
920 } 957 }
921 958
922 /* Wait 5 seconds for the response. */ 959 rc = wait_for_response(ses->server, midQ);
923 if (wait_for_response(ses, midQ, 5 * HZ, 5 * HZ) == 0) { 960 if (rc) {
924 /* We got the response - restart system call. */ 961 send_nt_cancel(ses->server, in_buf, midQ);
925 rstart = 1; 962 spin_lock(&GlobalMid_Lock);
926 } 963 if (midQ->midState == MID_REQUEST_SUBMITTED) {
927 } 964 /* no longer considered to be "in-flight" */
928 965 midQ->callback = DeleteMidQEntry;
929 spin_lock(&GlobalMid_Lock); 966 spin_unlock(&GlobalMid_Lock);
930 if (midQ->resp_buf) { 967 return rc;
931 spin_unlock(&GlobalMid_Lock);
932 receive_len = midQ->resp_buf->smb_buf_length;
933 } else {
934 cERROR(1, "No response for cmd %d mid %d",
935 midQ->command, midQ->mid);
936 if (midQ->midState == MID_REQUEST_SUBMITTED) {
937 if (ses->server->tcpStatus == CifsExiting)
938 rc = -EHOSTDOWN;
939 else {
940 ses->server->tcpStatus = CifsNeedReconnect;
941 midQ->midState = MID_RETRY_NEEDED;
942 } 968 }
969 spin_unlock(&GlobalMid_Lock);
943 } 970 }
944 971
945 if (rc != -EHOSTDOWN) { 972 /* We got the response - restart system call. */
946 if (midQ->midState == MID_RETRY_NEEDED) { 973 rstart = 1;
947 rc = -EAGAIN;
948 cFYI(1, "marking request for retry");
949 } else {
950 rc = -EIO;
951 }
952 }
953 spin_unlock(&GlobalMid_Lock);
954 DeleteMidQEntry(midQ);
955 return rc;
956 } 974 }
957 975
976 rc = sync_mid_result(midQ, ses->server);
977 if (rc != 0)
978 return rc;
979
980 receive_len = midQ->resp_buf->smb_buf_length;
958 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { 981 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
959 cERROR(1, "Frame too large received. Length: %d Xid: %d", 982 cERROR(1, "Frame too large received. Length: %d Xid: %d",
960 receive_len, xid); 983 receive_len, xid);
@@ -998,10 +1021,10 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
998 if (receive_len >= sizeof(struct smb_hdr) - 4 1021 if (receive_len >= sizeof(struct smb_hdr) - 4
999 /* do not count RFC1001 header */ + 1022 /* do not count RFC1001 header */ +
1000 (2 * out_buf->WordCount) + 2 /* bcc */ ) 1023 (2 * out_buf->WordCount) + 2 /* bcc */ )
1001 BCC(out_buf) = le16_to_cpu(BCC_LE(out_buf)); 1024 put_bcc(get_bcc_le(out_buf), out_buf);
1002 1025
1003out: 1026out:
1004 DeleteMidQEntry(midQ); 1027 delete_mid(midQ);
1005 if (rstart && rc == -EACCES) 1028 if (rstart && rc == -EACCES)
1006 return -ERESTARTSYS; 1029 return -ERESTARTSYS;
1007 return rc; 1030 return rc;