diff options
Diffstat (limited to 'fs/cifs')
-rw-r--r-- | fs/cifs/Kconfig | 1 | ||||
-rw-r--r-- | fs/cifs/Makefile | 2 | ||||
-rw-r--r-- | fs/cifs/README | 5 | ||||
-rw-r--r-- | fs/cifs/cifs_dfs_ref.c | 10 | ||||
-rw-r--r-- | fs/cifs/cifsacl.c | 4 | ||||
-rw-r--r-- | fs/cifs/cifsencrypt.c | 38 | ||||
-rw-r--r-- | fs/cifs/cifsencrypt.h | 33 | ||||
-rw-r--r-- | fs/cifs/cifsfs.c | 15 | ||||
-rw-r--r-- | fs/cifs/cifsfs.h | 6 | ||||
-rw-r--r-- | fs/cifs/cifsglob.h | 37 | ||||
-rw-r--r-- | fs/cifs/cifsproto.h | 11 | ||||
-rw-r--r-- | fs/cifs/cifssmb.c | 8 | ||||
-rw-r--r-- | fs/cifs/connect.c | 70 | ||||
-rw-r--r-- | fs/cifs/file.c | 211 | ||||
-rw-r--r-- | fs/cifs/link.c | 59 | ||||
-rw-r--r-- | fs/cifs/md4.c | 205 | ||||
-rw-r--r-- | fs/cifs/md5.c | 366 | ||||
-rw-r--r-- | fs/cifs/md5.h | 38 | ||||
-rw-r--r-- | fs/cifs/misc.c | 116 | ||||
-rw-r--r-- | fs/cifs/readdir.c | 3 | ||||
-rw-r--r-- | fs/cifs/smbdes.c | 1 | ||||
-rw-r--r-- | fs/cifs/smbencrypt.c | 92 | ||||
-rw-r--r-- | fs/cifs/transport.c | 69 |
23 files changed, 593 insertions, 807 deletions
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 | ||
6 | cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \ | 6 | cifs-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 | ||
11 | cifs-$(CONFIG_CIFS_ACL) += cifsacl.o | 11 | cifs-$(CONFIG_CIFS_ACL) += cifsacl.o |
diff --git a/fs/cifs/README b/fs/cifs/README index 46af99ab3614..fe1683590828 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 |
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c index 7ed36536e754..0a265ad9e426 100644 --- a/fs/cifs/cifs_dfs_ref.c +++ b/fs/cifs/cifs_dfs_ref.c | |||
@@ -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); |
340 | free_full_path: | 339 | free_full_path: |
341 | kfree(full_path); | 340 | kfree(full_path); |
342 | free_xid: | 341 | cdda_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/cifsacl.c b/fs/cifs/cifsacl.c index 1e7636b145a8..beeebf194234 100644 --- a/fs/cifs/cifsacl.c +++ b/fs/cifs/cifsacl.c | |||
@@ -372,6 +372,10 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl, | |||
372 | 372 | ||
373 | ppace = kmalloc(num_aces * sizeof(struct cifs_ace *), | 373 | ppace = kmalloc(num_aces * sizeof(struct cifs_ace *), |
374 | GFP_KERNEL); | 374 | GFP_KERNEL); |
375 | if (!ppace) { | ||
376 | cERROR(1, "DACL memory allocation error"); | ||
377 | return; | ||
378 | } | ||
375 | 379 | ||
376 | for (i = 0; i < num_aces; ++i) { | 380 | for (i = 0; i < num_aces; ++i) { |
377 | ppace[i] = (struct cifs_ace *) (acl_base + acl_size); | 381 | ppace[i] = (struct cifs_ace *) (acl_base + acl_size); |
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index 66f3d50d0676..a51585f9852b 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c | |||
@@ -24,7 +24,6 @@ | |||
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" |
@@ -37,11 +36,6 @@ | |||
37 | /* Note that the smb header signature field on input contains the | 36 | /* Note that the smb header signature field on input contains the |
38 | sequence number before this function is called */ | 37 | sequence number before this function is called */ |
39 | 38 | ||
40 | extern void mdfour(unsigned char *out, unsigned char *in, int n); | ||
41 | extern void E_md4hash(const unsigned char *passwd, unsigned char *p16); | ||
42 | extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8, | ||
43 | unsigned char *p24); | ||
44 | |||
45 | static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu, | 39 | static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu, |
46 | struct TCP_Server_Info *server, char *signature) | 40 | struct TCP_Server_Info *server, char *signature) |
47 | { | 41 | { |
@@ -234,6 +228,7 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu, | |||
234 | /* first calculate 24 bytes ntlm response and then 16 byte session key */ | 228 | /* first calculate 24 bytes ntlm response and then 16 byte session key */ |
235 | int setup_ntlm_response(struct cifsSesInfo *ses) | 229 | int setup_ntlm_response(struct cifsSesInfo *ses) |
236 | { | 230 | { |
231 | int rc = 0; | ||
237 | unsigned int temp_len = CIFS_SESS_KEY_SIZE + CIFS_AUTH_RESP_SIZE; | 232 | unsigned int temp_len = CIFS_SESS_KEY_SIZE + CIFS_AUTH_RESP_SIZE; |
238 | char temp_key[CIFS_SESS_KEY_SIZE]; | 233 | char temp_key[CIFS_SESS_KEY_SIZE]; |
239 | 234 | ||
@@ -247,13 +242,26 @@ int setup_ntlm_response(struct cifsSesInfo *ses) | |||
247 | } | 242 | } |
248 | ses->auth_key.len = temp_len; | 243 | ses->auth_key.len = temp_len; |
249 | 244 | ||
250 | SMBNTencrypt(ses->password, ses->server->cryptkey, | 245 | rc = SMBNTencrypt(ses->password, ses->server->cryptkey, |
251 | ses->auth_key.response + CIFS_SESS_KEY_SIZE); | 246 | ses->auth_key.response + CIFS_SESS_KEY_SIZE); |
247 | if (rc) { | ||
248 | cFYI(1, "%s Can't generate NTLM response, error: %d", | ||
249 | __func__, rc); | ||
250 | return rc; | ||
251 | } | ||
252 | 252 | ||
253 | E_md4hash(ses->password, temp_key); | 253 | rc = E_md4hash(ses->password, temp_key); |
254 | mdfour(ses->auth_key.response, temp_key, CIFS_SESS_KEY_SIZE); | 254 | if (rc) { |
255 | cFYI(1, "%s Can't generate NT hash, error: %d", __func__, rc); | ||
256 | return rc; | ||
257 | } | ||
255 | 258 | ||
256 | return 0; | 259 | rc = mdfour(ses->auth_key.response, temp_key, CIFS_SESS_KEY_SIZE); |
260 | if (rc) | ||
261 | cFYI(1, "%s Can't generate NTLM session key, error: %d", | ||
262 | __func__, rc); | ||
263 | |||
264 | return rc; | ||
257 | } | 265 | } |
258 | 266 | ||
259 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | 267 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
@@ -649,9 +657,10 @@ calc_seckey(struct cifsSesInfo *ses) | |||
649 | get_random_bytes(sec_key, CIFS_SESS_KEY_SIZE); | 657 | get_random_bytes(sec_key, CIFS_SESS_KEY_SIZE); |
650 | 658 | ||
651 | tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); | 659 | tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC); |
652 | if (!tfm_arc4 || IS_ERR(tfm_arc4)) { | 660 | if (IS_ERR(tfm_arc4)) { |
661 | rc = PTR_ERR(tfm_arc4); | ||
653 | cERROR(1, "could not allocate crypto API arc4\n"); | 662 | cERROR(1, "could not allocate crypto API arc4\n"); |
654 | return PTR_ERR(tfm_arc4); | 663 | return rc; |
655 | } | 664 | } |
656 | 665 | ||
657 | desc.tfm = tfm_arc4; | 666 | desc.tfm = tfm_arc4; |
@@ -700,14 +709,13 @@ cifs_crypto_shash_allocate(struct TCP_Server_Info *server) | |||
700 | unsigned int size; | 709 | unsigned int size; |
701 | 710 | ||
702 | server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0); | 711 | server->secmech.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0); |
703 | if (!server->secmech.hmacmd5 || | 712 | if (IS_ERR(server->secmech.hmacmd5)) { |
704 | IS_ERR(server->secmech.hmacmd5)) { | ||
705 | cERROR(1, "could not allocate crypto hmacmd5\n"); | 713 | cERROR(1, "could not allocate crypto hmacmd5\n"); |
706 | return PTR_ERR(server->secmech.hmacmd5); | 714 | return PTR_ERR(server->secmech.hmacmd5); |
707 | } | 715 | } |
708 | 716 | ||
709 | server->secmech.md5 = crypto_alloc_shash("md5", 0, 0); | 717 | server->secmech.md5 = crypto_alloc_shash("md5", 0, 0); |
710 | if (!server->secmech.md5 || IS_ERR(server->secmech.md5)) { | 718 | if (IS_ERR(server->secmech.md5)) { |
711 | cERROR(1, "could not allocate crypto md5\n"); | 719 | cERROR(1, "could not allocate crypto md5\n"); |
712 | rc = PTR_ERR(server->secmech.md5); | 720 | rc = PTR_ERR(server->secmech.md5); |
713 | goto crypto_allocate_md5_fail; | 721 | 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 */ | ||
26 | extern void mdfour(unsigned char *out, unsigned char *in, int n); | ||
27 | /* smbdes.c */ | ||
28 | extern void E_P16(unsigned char *p14, unsigned char *p16); | ||
29 | extern 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 a8323f1dc1c4..f2970136d17d 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c | |||
@@ -600,10 +600,17 @@ static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
600 | { | 600 | { |
601 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; | 601 | struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; |
602 | ssize_t written; | 602 | ssize_t written; |
603 | int rc; | ||
603 | 604 | ||
604 | written = generic_file_aio_write(iocb, iov, nr_segs, pos); | 605 | written = generic_file_aio_write(iocb, iov, nr_segs, pos); |
605 | if (!CIFS_I(inode)->clientCanCacheAll) | 606 | |
606 | 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 | |||
607 | return written; | 614 | return written; |
608 | } | 615 | } |
609 | 616 | ||
@@ -737,7 +744,7 @@ const struct file_operations cifs_file_strict_ops = { | |||
737 | .read = do_sync_read, | 744 | .read = do_sync_read, |
738 | .write = do_sync_write, | 745 | .write = do_sync_write, |
739 | .aio_read = cifs_strict_readv, | 746 | .aio_read = cifs_strict_readv, |
740 | .aio_write = cifs_file_aio_write, | 747 | .aio_write = cifs_strict_writev, |
741 | .open = cifs_open, | 748 | .open = cifs_open, |
742 | .release = cifs_close, | 749 | .release = cifs_close, |
743 | .lock = cifs_lock, | 750 | .lock = cifs_lock, |
@@ -793,7 +800,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = { | |||
793 | .read = do_sync_read, | 800 | .read = do_sync_read, |
794 | .write = do_sync_write, | 801 | .write = do_sync_write, |
795 | .aio_read = cifs_strict_readv, | 802 | .aio_read = cifs_strict_readv, |
796 | .aio_write = cifs_file_aio_write, | 803 | .aio_write = cifs_strict_writev, |
797 | .open = cifs_open, | 804 | .open = cifs_open, |
798 | .release = cifs_close, | 805 | .release = cifs_close, |
799 | .fsync = cifs_strict_fsync, | 806 | .fsync = cifs_strict_fsync, |
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index f23206d46531..4a3330235d55 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h | |||
@@ -85,7 +85,9 @@ extern ssize_t cifs_user_read(struct file *file, char __user *read_data, | |||
85 | extern ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, | 85 | extern ssize_t cifs_strict_readv(struct kiocb *iocb, const struct iovec *iov, |
86 | unsigned long nr_segs, loff_t pos); | 86 | unsigned long nr_segs, loff_t pos); |
87 | extern ssize_t cifs_user_write(struct file *file, const char __user *write_data, | 87 | extern ssize_t cifs_user_write(struct file *file, const char __user *write_data, |
88 | size_t write_size, loff_t *poffset); | 88 | size_t write_size, loff_t *poffset); |
89 | extern ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, | ||
90 | unsigned long nr_segs, loff_t pos); | ||
89 | extern int cifs_lock(struct file *, int, struct file_lock *); | 91 | extern int cifs_lock(struct file *, int, struct file_lock *); |
90 | extern int cifs_fsync(struct file *, int); | 92 | extern int cifs_fsync(struct file *, int); |
91 | extern int cifs_strict_fsync(struct file *, int); | 93 | extern int cifs_strict_fsync(struct file *, int); |
@@ -125,5 +127,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); | |||
125 | extern const struct export_operations cifs_export_ops; | 127 | extern const struct export_operations cifs_export_ops; |
126 | #endif /* EXPERIMENTAL */ | 128 | #endif /* EXPERIMENTAL */ |
127 | 129 | ||
128 | #define CIFS_VERSION "1.69" | 130 | #define CIFS_VERSION "1.70" |
129 | #endif /* _CIFSFS_H */ | 131 | #endif /* _CIFSFS_H */ |
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 5bfb75346cb0..17afb0fbcaed 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
@@ -166,6 +166,9 @@ struct TCP_Server_Info { | |||
166 | struct socket *ssocket; | 166 | struct socket *ssocket; |
167 | struct sockaddr_storage dstaddr; | 167 | struct sockaddr_storage dstaddr; |
168 | 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 | ||
169 | wait_queue_head_t response_q; | 172 | wait_queue_head_t response_q; |
170 | 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*/ |
171 | struct list_head pending_mid_q; | 174 | struct list_head pending_mid_q; |
@@ -185,6 +188,8 @@ struct TCP_Server_Info { | |||
185 | /* multiplexed reads or writes */ | 188 | /* multiplexed reads or writes */ |
186 | unsigned int maxBuf; /* maxBuf specifies the maximum */ | 189 | unsigned int maxBuf; /* maxBuf specifies the maximum */ |
187 | /* 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 */ | ||
188 | unsigned int max_rw; /* maxRw specifies the maximum */ | 193 | unsigned int max_rw; /* maxRw specifies the maximum */ |
189 | /* message size the server can send or receive for */ | 194 | /* message size the server can send or receive for */ |
190 | /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */ | 195 | /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */ |
@@ -217,6 +222,36 @@ struct TCP_Server_Info { | |||
217 | }; | 222 | }; |
218 | 223 | ||
219 | /* | 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 | |||
231 | static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv) | ||
232 | { | ||
233 | return srv->net; | ||
234 | } | ||
235 | |||
236 | static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net) | ||
237 | { | ||
238 | srv->net = net; | ||
239 | } | ||
240 | |||
241 | #else | ||
242 | |||
243 | static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv) | ||
244 | { | ||
245 | return &init_net; | ||
246 | } | ||
247 | |||
248 | static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net) | ||
249 | { | ||
250 | } | ||
251 | |||
252 | #endif | ||
253 | |||
254 | /* | ||
220 | * 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 |
221 | */ | 256 | */ |
222 | struct cifsSesInfo { | 257 | struct cifsSesInfo { |
@@ -619,7 +654,7 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param, | |||
619 | #define MID_REQUEST_SUBMITTED 2 | 654 | #define MID_REQUEST_SUBMITTED 2 |
620 | #define MID_RESPONSE_RECEIVED 4 | 655 | #define MID_RESPONSE_RECEIVED 4 |
621 | #define MID_RETRY_NEEDED 8 /* session closed while this request out */ | 656 | #define MID_RETRY_NEEDED 8 /* session closed while this request out */ |
622 | #define MID_NO_RESP_NEEDED 0x10 | 657 | #define MID_RESPONSE_MALFORMED 0x10 |
623 | 658 | ||
624 | /* Types of response buffer returned from SendReceive2 */ | 659 | /* Types of response buffer returned from SendReceive2 */ |
625 | #define CIFS_NO_BUFFER 0 /* Response buffer not returned */ | 660 | #define CIFS_NO_BUFFER 0 /* Response buffer not returned */ |
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 982895fa7615..8096f27ad9a8 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h | |||
@@ -85,6 +85,8 @@ extern int checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length); | |||
85 | extern bool is_valid_oplock_break(struct smb_hdr *smb, | 85 | extern bool is_valid_oplock_break(struct smb_hdr *smb, |
86 | struct TCP_Server_Info *); | 86 | struct TCP_Server_Info *); |
87 | extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof); | 87 | extern bool is_size_safe_to_change(struct cifsInodeInfo *, __u64 eof); |
88 | extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, | ||
89 | unsigned int bytes_written); | ||
88 | extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); | 90 | extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool); |
89 | extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); | 91 | extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool); |
90 | extern unsigned int smbCalcSize(struct smb_hdr *ptr); | 92 | extern unsigned int smbCalcSize(struct smb_hdr *ptr); |
@@ -373,7 +375,7 @@ extern int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *, | |||
373 | extern int cifs_verify_signature(struct smb_hdr *, | 375 | extern int cifs_verify_signature(struct smb_hdr *, |
374 | struct TCP_Server_Info *server, | 376 | struct TCP_Server_Info *server, |
375 | __u32 expected_sequence_number); | 377 | __u32 expected_sequence_number); |
376 | extern void SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *); | 378 | extern int SMBNTencrypt(unsigned char *, unsigned char *, unsigned char *); |
377 | extern int setup_ntlm_response(struct cifsSesInfo *); | 379 | extern int setup_ntlm_response(struct cifsSesInfo *); |
378 | extern int setup_ntlmv2_rsp(struct cifsSesInfo *, const struct nls_table *); | 380 | extern int setup_ntlmv2_rsp(struct cifsSesInfo *, const struct nls_table *); |
379 | extern int cifs_crypto_shash_allocate(struct TCP_Server_Info *); | 381 | extern int cifs_crypto_shash_allocate(struct TCP_Server_Info *); |
@@ -423,4 +425,11 @@ extern bool CIFSCouldBeMFSymlink(const struct cifs_fattr *fattr); | |||
423 | extern int CIFSCheckMFSymlink(struct cifs_fattr *fattr, | 425 | extern int CIFSCheckMFSymlink(struct cifs_fattr *fattr, |
424 | const unsigned char *path, | 426 | const unsigned char *path, |
425 | struct cifs_sb_info *cifs_sb, int xid); | 427 | struct cifs_sb_info *cifs_sb, int xid); |
428 | extern int mdfour(unsigned char *, unsigned char *, int); | ||
429 | extern int E_md4hash(const unsigned char *passwd, unsigned char *p16); | ||
430 | extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8, | ||
431 | unsigned char *p24); | ||
432 | extern void E_P16(unsigned char *p14, unsigned char *p16); | ||
433 | extern void E_P24(unsigned char *p21, const unsigned char *c8, | ||
434 | unsigned char *p24); | ||
426 | #endif /* _CIFSPROTO_H */ | 435 | #endif /* _CIFSPROTO_H */ |
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 3106f5e5c633..904aa47e3515 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
@@ -136,9 +136,6 @@ 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 |
@@ -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 | } |
@@ -4914,7 +4911,6 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, | |||
4914 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) | 4911 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) |
4915 | { | 4912 | { |
4916 | struct smb_com_transaction2_sfi_req *pSMB = NULL; | 4913 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
4917 | char *data_offset; | ||
4918 | struct file_end_of_file_info *parm_data; | 4914 | struct file_end_of_file_info *parm_data; |
4919 | int rc = 0; | 4915 | int rc = 0; |
4920 | __u16 params, param_offset, offset, byte_count, count; | 4916 | __u16 params, param_offset, offset, byte_count, count; |
@@ -4938,8 +4934,6 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, | |||
4938 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; | 4934 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
4939 | offset = param_offset + params; | 4935 | offset = param_offset + params; |
4940 | 4936 | ||
4941 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; | ||
4942 | |||
4943 | count = sizeof(struct file_end_of_file_info); | 4937 | count = sizeof(struct file_end_of_file_info); |
4944 | pSMB->MaxParameterCount = cpu_to_le16(2); | 4938 | pSMB->MaxParameterCount = cpu_to_le16(2); |
4945 | /* BB find exact max SMB PDU from sess structure BB */ | 4939 | /* BB find exact max SMB PDU from sess structure BB */ |
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 18d3c7724d6e..8d6c17ab593d 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -55,9 +55,6 @@ | |||
55 | /* SMB echo "timeout" -- FIXME: tunable? */ | 55 | /* SMB echo "timeout" -- FIXME: tunable? */ |
56 | #define SMB_ECHO_INTERVAL (60 * HZ) | 56 | #define SMB_ECHO_INTERVAL (60 * HZ) |
57 | 57 | ||
58 | extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, | ||
59 | unsigned char *p24); | ||
60 | |||
61 | extern mempool_t *cifs_req_poolp; | 58 | extern mempool_t *cifs_req_poolp; |
62 | 59 | ||
63 | struct smb_vol { | 60 | struct smb_vol { |
@@ -87,6 +84,7 @@ struct smb_vol { | |||
87 | 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*/ |
88 | bool server_ino:1; /* use inode numbers from server ie UniqueId */ | 85 | bool server_ino:1; /* use inode numbers from server ie UniqueId */ |
89 | bool direct_io:1; | 86 | bool direct_io:1; |
87 | bool strict_io:1; /* strict cache behavior */ | ||
90 | bool remap:1; /* set to remap seven reserved chars in filenames */ | 88 | bool remap:1; /* set to remap seven reserved chars in filenames */ |
91 | bool posix_paths:1; /* unset to not ask for posix pathnames. */ | 89 | bool posix_paths:1; /* unset to not ask for posix pathnames. */ |
92 | bool no_linux_ext:1; | 90 | bool no_linux_ext:1; |
@@ -339,8 +337,13 @@ cifs_echo_request(struct work_struct *work) | |||
339 | struct TCP_Server_Info *server = container_of(work, | 337 | struct TCP_Server_Info *server = container_of(work, |
340 | struct TCP_Server_Info, echo.work); | 338 | struct TCP_Server_Info, echo.work); |
341 | 339 | ||
342 | /* no need to ping if we got a response recently */ | 340 | /* |
343 | if (time_before(jiffies, server->lstrp + SMB_ECHO_INTERVAL - HZ)) | 341 | * We cannot send an echo until the NEGOTIATE_PROTOCOL request is |
342 | * done, which is indicated by maxBuf != 0. Also, no need to ping if | ||
343 | * we got a response recently | ||
344 | */ | ||
345 | if (server->maxBuf == 0 || | ||
346 | time_before(jiffies, server->lstrp + SMB_ECHO_INTERVAL - HZ)) | ||
344 | goto requeue_echo; | 347 | goto requeue_echo; |
345 | 348 | ||
346 | rc = CIFSSMBEcho(server); | 349 | rc = CIFSSMBEcho(server); |
@@ -580,14 +583,23 @@ incomplete_rcv: | |||
580 | else if (reconnect == 1) | 583 | else if (reconnect == 1) |
581 | continue; | 584 | continue; |
582 | 585 | ||
583 | length += 4; /* account for rfc1002 hdr */ | 586 | total_read += 4; /* account for rfc1002 hdr */ |
584 | 587 | ||
588 | dump_smb(smb_buffer, total_read); | ||
585 | 589 | ||
586 | dump_smb(smb_buffer, length); | 590 | /* |
587 | if (checkSMB(smb_buffer, smb_buffer->Mid, total_read+4)) { | 591 | * We know that we received enough to get to the MID as we |
588 | cifs_dump_mem("Bad SMB: ", smb_buffer, 48); | 592 | * checked the pdu_length earlier. Now check to see |
589 | continue; | 593 | * if the rest of the header is OK. We borrow the length |
590 | } | 594 | * var for the rest of the loop to avoid a new stack var. |
595 | * | ||
596 | * 48 bytes is enough to display the header and a little bit | ||
597 | * into the payload for debugging purposes. | ||
598 | */ | ||
599 | length = checkSMB(smb_buffer, smb_buffer->Mid, total_read); | ||
600 | if (length != 0) | ||
601 | cifs_dump_mem("Bad SMB: ", smb_buffer, | ||
602 | min_t(unsigned int, total_read, 48)); | ||
591 | 603 | ||
592 | mid_entry = NULL; | 604 | mid_entry = NULL; |
593 | server->lstrp = jiffies; | 605 | server->lstrp = jiffies; |
@@ -599,7 +611,8 @@ incomplete_rcv: | |||
599 | if ((mid_entry->mid == smb_buffer->Mid) && | 611 | if ((mid_entry->mid == smb_buffer->Mid) && |
600 | (mid_entry->midState == MID_REQUEST_SUBMITTED) && | 612 | (mid_entry->midState == MID_REQUEST_SUBMITTED) && |
601 | (mid_entry->command == smb_buffer->Command)) { | 613 | (mid_entry->command == smb_buffer->Command)) { |
602 | if (check2ndT2(smb_buffer,server->maxBuf) > 0) { | 614 | if (length == 0 && |
615 | check2ndT2(smb_buffer, server->maxBuf) > 0) { | ||
603 | /* We have a multipart transact2 resp */ | 616 | /* We have a multipart transact2 resp */ |
604 | isMultiRsp = true; | 617 | isMultiRsp = true; |
605 | if (mid_entry->resp_buf) { | 618 | if (mid_entry->resp_buf) { |
@@ -634,12 +647,17 @@ incomplete_rcv: | |||
634 | mid_entry->resp_buf = smb_buffer; | 647 | mid_entry->resp_buf = smb_buffer; |
635 | mid_entry->largeBuf = isLargeBuf; | 648 | mid_entry->largeBuf = isLargeBuf; |
636 | multi_t2_fnd: | 649 | multi_t2_fnd: |
637 | mid_entry->midState = MID_RESPONSE_RECEIVED; | 650 | if (length == 0) |
638 | list_del_init(&mid_entry->qhead); | 651 | mid_entry->midState = |
639 | mid_entry->callback(mid_entry); | 652 | MID_RESPONSE_RECEIVED; |
653 | else | ||
654 | mid_entry->midState = | ||
655 | MID_RESPONSE_MALFORMED; | ||
640 | #ifdef CONFIG_CIFS_STATS2 | 656 | #ifdef CONFIG_CIFS_STATS2 |
641 | mid_entry->when_received = jiffies; | 657 | mid_entry->when_received = jiffies; |
642 | #endif | 658 | #endif |
659 | list_del_init(&mid_entry->qhead); | ||
660 | mid_entry->callback(mid_entry); | ||
643 | break; | 661 | break; |
644 | } | 662 | } |
645 | mid_entry = NULL; | 663 | mid_entry = NULL; |
@@ -655,6 +673,9 @@ multi_t2_fnd: | |||
655 | else | 673 | else |
656 | smallbuf = NULL; | 674 | smallbuf = NULL; |
657 | } | 675 | } |
676 | } else if (length != 0) { | ||
677 | /* response sanity checks failed */ | ||
678 | continue; | ||
658 | } else if (!is_valid_oplock_break(smb_buffer, server) && | 679 | } else if (!is_valid_oplock_break(smb_buffer, server) && |
659 | !isMultiRsp) { | 680 | !isMultiRsp) { |
660 | cERROR(1, "No task to wake, unknown frame received! " | 681 | cERROR(1, "No task to wake, unknown frame received! " |
@@ -1344,6 +1365,8 @@ cifs_parse_mount_options(char *options, const char *devname, | |||
1344 | vol->direct_io = 1; | 1365 | vol->direct_io = 1; |
1345 | } else if (strnicmp(data, "forcedirectio", 13) == 0) { | 1366 | } else if (strnicmp(data, "forcedirectio", 13) == 0) { |
1346 | vol->direct_io = 1; | 1367 | vol->direct_io = 1; |
1368 | } else if (strnicmp(data, "strictcache", 11) == 0) { | ||
1369 | vol->strict_io = 1; | ||
1347 | } else if (strnicmp(data, "noac", 4) == 0) { | 1370 | } else if (strnicmp(data, "noac", 4) == 0) { |
1348 | printk(KERN_WARNING "CIFS: Mount option noac not " | 1371 | printk(KERN_WARNING "CIFS: Mount option noac not " |
1349 | "supported. Instead set " | 1372 | "supported. Instead set " |
@@ -1568,6 +1591,9 @@ cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol) | |||
1568 | 1591 | ||
1569 | spin_lock(&cifs_tcp_ses_lock); | 1592 | spin_lock(&cifs_tcp_ses_lock); |
1570 | 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 | |||
1571 | if (!match_address(server, addr, | 1597 | if (!match_address(server, addr, |
1572 | (struct sockaddr *)&vol->srcaddr)) | 1598 | (struct sockaddr *)&vol->srcaddr)) |
1573 | continue; | 1599 | continue; |
@@ -1598,6 +1624,8 @@ cifs_put_tcp_session(struct TCP_Server_Info *server) | |||
1598 | return; | 1624 | return; |
1599 | } | 1625 | } |
1600 | 1626 | ||
1627 | put_net(cifs_net_ns(server)); | ||
1628 | |||
1601 | list_del_init(&server->tcp_ses_list); | 1629 | list_del_init(&server->tcp_ses_list); |
1602 | spin_unlock(&cifs_tcp_ses_lock); | 1630 | spin_unlock(&cifs_tcp_ses_lock); |
1603 | 1631 | ||
@@ -1672,6 +1700,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) | |||
1672 | goto out_err; | 1700 | goto out_err; |
1673 | } | 1701 | } |
1674 | 1702 | ||
1703 | cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns)); | ||
1675 | tcp_ses->hostname = extract_hostname(volume_info->UNC); | 1704 | tcp_ses->hostname = extract_hostname(volume_info->UNC); |
1676 | if (IS_ERR(tcp_ses->hostname)) { | 1705 | if (IS_ERR(tcp_ses->hostname)) { |
1677 | rc = PTR_ERR(tcp_ses->hostname); | 1706 | rc = PTR_ERR(tcp_ses->hostname); |
@@ -1752,6 +1781,8 @@ cifs_get_tcp_session(struct smb_vol *volume_info) | |||
1752 | out_err_crypto_release: | 1781 | out_err_crypto_release: |
1753 | cifs_crypto_shash_release(tcp_ses); | 1782 | cifs_crypto_shash_release(tcp_ses); |
1754 | 1783 | ||
1784 | put_net(cifs_net_ns(tcp_ses)); | ||
1785 | |||
1755 | out_err: | 1786 | out_err: |
1756 | if (tcp_ses) { | 1787 | if (tcp_ses) { |
1757 | if (!IS_ERR(tcp_ses->hostname)) | 1788 | if (!IS_ERR(tcp_ses->hostname)) |
@@ -2263,8 +2294,8 @@ generic_ip_connect(struct TCP_Server_Info *server) | |||
2263 | } | 2294 | } |
2264 | 2295 | ||
2265 | if (socket == NULL) { | 2296 | if (socket == NULL) { |
2266 | rc = sock_create_kern(sfamily, SOCK_STREAM, | 2297 | rc = __sock_create(cifs_net_ns(server), sfamily, SOCK_STREAM, |
2267 | IPPROTO_TCP, &socket); | 2298 | IPPROTO_TCP, &socket, 1); |
2268 | if (rc < 0) { | 2299 | if (rc < 0) { |
2269 | cERROR(1, "Error %d creating socket", rc); | 2300 | cERROR(1, "Error %d creating socket", rc); |
2270 | server->ssocket = NULL; | 2301 | server->ssocket = NULL; |
@@ -2576,6 +2607,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info, | |||
2576 | if (pvolume_info->multiuser) | 2607 | if (pvolume_info->multiuser) |
2577 | cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER | | 2608 | cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER | |
2578 | CIFS_MOUNT_NO_PERM); | 2609 | CIFS_MOUNT_NO_PERM); |
2610 | if (pvolume_info->strict_io) | ||
2611 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_STRICT_IO; | ||
2579 | if (pvolume_info->direct_io) { | 2612 | if (pvolume_info->direct_io) { |
2580 | cFYI(1, "mounting share using direct i/o"); | 2613 | cFYI(1, "mounting share using direct i/o"); |
2581 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO; | 2614 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO; |
@@ -2977,7 +3010,8 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses, | |||
2977 | bcc_ptr); | 3010 | bcc_ptr); |
2978 | else | 3011 | else |
2979 | #endif /* CIFS_WEAK_PW_HASH */ | 3012 | #endif /* CIFS_WEAK_PW_HASH */ |
2980 | SMBNTencrypt(tcon->password, ses->server->cryptkey, bcc_ptr); | 3013 | rc = SMBNTencrypt(tcon->password, ses->server->cryptkey, |
3014 | bcc_ptr); | ||
2981 | 3015 | ||
2982 | bcc_ptr += CIFS_AUTH_RESP_SIZE; | 3016 | bcc_ptr += CIFS_AUTH_RESP_SIZE; |
2983 | if (ses->capabilities & CAP_UNICODE) { | 3017 | if (ses->capabilities & CAP_UNICODE) { |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index d7d65a70678e..e964b1cd5dd0 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -346,7 +346,6 @@ int cifs_open(struct inode *inode, struct file *file) | |||
346 | struct cifsTconInfo *tcon; | 346 | struct cifsTconInfo *tcon; |
347 | struct tcon_link *tlink; | 347 | struct tcon_link *tlink; |
348 | struct cifsFileInfo *pCifsFile = NULL; | 348 | struct cifsFileInfo *pCifsFile = NULL; |
349 | struct cifsInodeInfo *pCifsInode; | ||
350 | char *full_path = NULL; | 349 | char *full_path = NULL; |
351 | bool posix_open_ok = false; | 350 | bool posix_open_ok = false; |
352 | __u16 netfid; | 351 | __u16 netfid; |
@@ -361,8 +360,6 @@ int cifs_open(struct inode *inode, struct file *file) | |||
361 | } | 360 | } |
362 | tcon = tlink_tcon(tlink); | 361 | tcon = tlink_tcon(tlink); |
363 | 362 | ||
364 | pCifsInode = CIFS_I(file->f_path.dentry->d_inode); | ||
365 | |||
366 | full_path = build_path_from_dentry(file->f_path.dentry); | 363 | full_path = build_path_from_dentry(file->f_path.dentry); |
367 | if (full_path == NULL) { | 364 | if (full_path == NULL) { |
368 | rc = -ENOMEM; | 365 | rc = -ENOMEM; |
@@ -848,7 +845,7 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock) | |||
848 | } | 845 | } |
849 | 846 | ||
850 | /* update the file size (if needed) after a write */ | 847 | /* update the file size (if needed) after a write */ |
851 | static void | 848 | void |
852 | cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, | 849 | cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, |
853 | unsigned int bytes_written) | 850 | unsigned int bytes_written) |
854 | { | 851 | { |
@@ -1146,7 +1143,6 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) | |||
1146 | char *write_data; | 1143 | char *write_data; |
1147 | int rc = -EFAULT; | 1144 | int rc = -EFAULT; |
1148 | int bytes_written = 0; | 1145 | int bytes_written = 0; |
1149 | struct cifs_sb_info *cifs_sb; | ||
1150 | struct inode *inode; | 1146 | struct inode *inode; |
1151 | struct cifsFileInfo *open_file; | 1147 | struct cifsFileInfo *open_file; |
1152 | 1148 | ||
@@ -1154,7 +1150,6 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to) | |||
1154 | return -EFAULT; | 1150 | return -EFAULT; |
1155 | 1151 | ||
1156 | inode = page->mapping->host; | 1152 | inode = page->mapping->host; |
1157 | cifs_sb = CIFS_SB(inode->i_sb); | ||
1158 | 1153 | ||
1159 | offset += (loff_t)from; | 1154 | offset += (loff_t)from; |
1160 | write_data = kmap(page); | 1155 | write_data = kmap(page); |
@@ -1619,13 +1614,215 @@ int cifs_flush(struct file *file, fl_owner_t id) | |||
1619 | return rc; | 1614 | return rc; |
1620 | } | 1615 | } |
1621 | 1616 | ||
1617 | static int | ||
1618 | cifs_write_allocate_pages(struct page **pages, unsigned long num_pages) | ||
1619 | { | ||
1620 | int rc = 0; | ||
1621 | unsigned long i; | ||
1622 | |||
1623 | for (i = 0; i < num_pages; i++) { | ||
1624 | pages[i] = alloc_page(__GFP_HIGHMEM); | ||
1625 | if (!pages[i]) { | ||
1626 | /* | ||
1627 | * save number of pages we have already allocated and | ||
1628 | * return with ENOMEM error | ||
1629 | */ | ||
1630 | num_pages = i; | ||
1631 | rc = -ENOMEM; | ||
1632 | goto error; | ||
1633 | } | ||
1634 | } | ||
1635 | |||
1636 | return rc; | ||
1637 | |||
1638 | error: | ||
1639 | for (i = 0; i < num_pages; i++) | ||
1640 | put_page(pages[i]); | ||
1641 | return rc; | ||
1642 | } | ||
1643 | |||
1644 | static inline | ||
1645 | size_t get_numpages(const size_t wsize, const size_t len, size_t *cur_len) | ||
1646 | { | ||
1647 | size_t num_pages; | ||
1648 | size_t clen; | ||
1649 | |||
1650 | clen = min_t(const size_t, len, wsize); | ||
1651 | num_pages = clen / PAGE_CACHE_SIZE; | ||
1652 | if (clen % PAGE_CACHE_SIZE) | ||
1653 | num_pages++; | ||
1654 | |||
1655 | if (cur_len) | ||
1656 | *cur_len = clen; | ||
1657 | |||
1658 | return num_pages; | ||
1659 | } | ||
1660 | |||
1661 | static ssize_t | ||
1662 | cifs_iovec_write(struct file *file, const struct iovec *iov, | ||
1663 | unsigned long nr_segs, loff_t *poffset) | ||
1664 | { | ||
1665 | unsigned int written; | ||
1666 | unsigned long num_pages, npages, i; | ||
1667 | size_t copied, len, cur_len; | ||
1668 | ssize_t total_written = 0; | ||
1669 | struct kvec *to_send; | ||
1670 | struct page **pages; | ||
1671 | struct iov_iter it; | ||
1672 | struct inode *inode; | ||
1673 | struct cifsFileInfo *open_file; | ||
1674 | struct cifsTconInfo *pTcon; | ||
1675 | struct cifs_sb_info *cifs_sb; | ||
1676 | int xid, rc; | ||
1677 | |||
1678 | len = iov_length(iov, nr_segs); | ||
1679 | if (!len) | ||
1680 | return 0; | ||
1681 | |||
1682 | rc = generic_write_checks(file, poffset, &len, 0); | ||
1683 | if (rc) | ||
1684 | return rc; | ||
1685 | |||
1686 | cifs_sb = CIFS_SB(file->f_path.dentry->d_sb); | ||
1687 | num_pages = get_numpages(cifs_sb->wsize, len, &cur_len); | ||
1688 | |||
1689 | pages = kmalloc(sizeof(struct pages *)*num_pages, GFP_KERNEL); | ||
1690 | if (!pages) | ||
1691 | return -ENOMEM; | ||
1692 | |||
1693 | to_send = kmalloc(sizeof(struct kvec)*(num_pages + 1), GFP_KERNEL); | ||
1694 | if (!to_send) { | ||
1695 | kfree(pages); | ||
1696 | return -ENOMEM; | ||
1697 | } | ||
1698 | |||
1699 | rc = cifs_write_allocate_pages(pages, num_pages); | ||
1700 | if (rc) { | ||
1701 | kfree(pages); | ||
1702 | kfree(to_send); | ||
1703 | return rc; | ||
1704 | } | ||
1705 | |||
1706 | xid = GetXid(); | ||
1707 | open_file = file->private_data; | ||
1708 | pTcon = tlink_tcon(open_file->tlink); | ||
1709 | inode = file->f_path.dentry->d_inode; | ||
1710 | |||
1711 | iov_iter_init(&it, iov, nr_segs, len, 0); | ||
1712 | npages = num_pages; | ||
1713 | |||
1714 | do { | ||
1715 | size_t save_len = cur_len; | ||
1716 | for (i = 0; i < npages; i++) { | ||
1717 | copied = min_t(const size_t, cur_len, PAGE_CACHE_SIZE); | ||
1718 | copied = iov_iter_copy_from_user(pages[i], &it, 0, | ||
1719 | copied); | ||
1720 | cur_len -= copied; | ||
1721 | iov_iter_advance(&it, copied); | ||
1722 | to_send[i+1].iov_base = kmap(pages[i]); | ||
1723 | to_send[i+1].iov_len = copied; | ||
1724 | } | ||
1725 | |||
1726 | cur_len = save_len - cur_len; | ||
1727 | |||
1728 | do { | ||
1729 | if (open_file->invalidHandle) { | ||
1730 | rc = cifs_reopen_file(open_file, false); | ||
1731 | if (rc != 0) | ||
1732 | break; | ||
1733 | } | ||
1734 | rc = CIFSSMBWrite2(xid, pTcon, open_file->netfid, | ||
1735 | cur_len, *poffset, &written, | ||
1736 | to_send, npages, 0); | ||
1737 | } while (rc == -EAGAIN); | ||
1738 | |||
1739 | for (i = 0; i < npages; i++) | ||
1740 | kunmap(pages[i]); | ||
1741 | |||
1742 | if (written) { | ||
1743 | len -= written; | ||
1744 | total_written += written; | ||
1745 | cifs_update_eof(CIFS_I(inode), *poffset, written); | ||
1746 | *poffset += written; | ||
1747 | } else if (rc < 0) { | ||
1748 | if (!total_written) | ||
1749 | total_written = rc; | ||
1750 | break; | ||
1751 | } | ||
1752 | |||
1753 | /* get length and number of kvecs of the next write */ | ||
1754 | npages = get_numpages(cifs_sb->wsize, len, &cur_len); | ||
1755 | } while (len > 0); | ||
1756 | |||
1757 | if (total_written > 0) { | ||
1758 | spin_lock(&inode->i_lock); | ||
1759 | if (*poffset > inode->i_size) | ||
1760 | i_size_write(inode, *poffset); | ||
1761 | spin_unlock(&inode->i_lock); | ||
1762 | } | ||
1763 | |||
1764 | cifs_stats_bytes_written(pTcon, total_written); | ||
1765 | mark_inode_dirty_sync(inode); | ||
1766 | |||
1767 | for (i = 0; i < num_pages; i++) | ||
1768 | put_page(pages[i]); | ||
1769 | kfree(to_send); | ||
1770 | kfree(pages); | ||
1771 | FreeXid(xid); | ||
1772 | return total_written; | ||
1773 | } | ||
1774 | |||
1775 | static ssize_t cifs_user_writev(struct kiocb *iocb, const struct iovec *iov, | ||
1776 | unsigned long nr_segs, loff_t pos) | ||
1777 | { | ||
1778 | ssize_t written; | ||
1779 | struct inode *inode; | ||
1780 | |||
1781 | inode = iocb->ki_filp->f_path.dentry->d_inode; | ||
1782 | |||
1783 | /* | ||
1784 | * BB - optimize the way when signing is disabled. We can drop this | ||
1785 | * extra memory-to-memory copying and use iovec buffers for constructing | ||
1786 | * write request. | ||
1787 | */ | ||
1788 | |||
1789 | written = cifs_iovec_write(iocb->ki_filp, iov, nr_segs, &pos); | ||
1790 | if (written > 0) { | ||
1791 | CIFS_I(inode)->invalid_mapping = true; | ||
1792 | iocb->ki_pos = pos; | ||
1793 | } | ||
1794 | |||
1795 | return written; | ||
1796 | } | ||
1797 | |||
1798 | ssize_t cifs_strict_writev(struct kiocb *iocb, const struct iovec *iov, | ||
1799 | unsigned long nr_segs, loff_t pos) | ||
1800 | { | ||
1801 | struct inode *inode; | ||
1802 | |||
1803 | inode = iocb->ki_filp->f_path.dentry->d_inode; | ||
1804 | |||
1805 | if (CIFS_I(inode)->clientCanCacheAll) | ||
1806 | return generic_file_aio_write(iocb, iov, nr_segs, pos); | ||
1807 | |||
1808 | /* | ||
1809 | * In strict cache mode we need to write the data to the server exactly | ||
1810 | * from the pos to pos+len-1 rather than flush all affected pages | ||
1811 | * because it may cause a error with mandatory locks on these pages but | ||
1812 | * not on the region from pos to ppos+len-1. | ||
1813 | */ | ||
1814 | |||
1815 | return cifs_user_writev(iocb, iov, nr_segs, pos); | ||
1816 | } | ||
1817 | |||
1622 | static ssize_t | 1818 | static ssize_t |
1623 | cifs_iovec_read(struct file *file, const struct iovec *iov, | 1819 | cifs_iovec_read(struct file *file, const struct iovec *iov, |
1624 | unsigned long nr_segs, loff_t *poffset) | 1820 | unsigned long nr_segs, loff_t *poffset) |
1625 | { | 1821 | { |
1626 | int rc; | 1822 | int rc; |
1627 | int xid; | 1823 | int xid; |
1628 | unsigned int total_read, bytes_read = 0; | 1824 | ssize_t total_read; |
1825 | unsigned int bytes_read = 0; | ||
1629 | size_t len, cur_len; | 1826 | size_t len, cur_len; |
1630 | int iov_offset = 0; | 1827 | int iov_offset = 0; |
1631 | struct cifs_sb_info *cifs_sb; | 1828 | struct cifs_sb_info *cifs_sb; |
diff --git a/fs/cifs/link.c b/fs/cifs/link.c index 306769de2fb5..e8804d373404 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 | ||
49 | static int | 48 | static int |
49 | symlink_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 | |||
80 | symlink_hash_err: | ||
81 | crypto_free_shash(md5); | ||
82 | kfree(sdescmd5); | ||
83 | |||
84 | return rc; | ||
85 | } | ||
86 | |||
87 | static int | ||
50 | CIFSParseMFSymlink(const u8 *buf, | 88 | CIFSParseMFSymlink(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, | |||
94 | static int | 133 | static int |
95 | CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str) | 134 | CIFSFormatMFSymlink(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, |
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 | |||
28 | static __u32 | ||
29 | F(__u32 X, __u32 Y, __u32 Z) | ||
30 | { | ||
31 | return (X & Y) | ((~X) & Z); | ||
32 | } | ||
33 | |||
34 | static __u32 | ||
35 | G(__u32 X, __u32 Y, __u32 Z) | ||
36 | { | ||
37 | return (X & Y) | (X & Z) | (Y & Z); | ||
38 | } | ||
39 | |||
40 | static __u32 | ||
41 | H(__u32 X, __u32 Y, __u32 Z) | ||
42 | { | ||
43 | return X ^ Y ^ Z; | ||
44 | } | ||
45 | |||
46 | static __u32 | ||
47 | lshift(__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 */ | ||
58 | static void | ||
59 | mdfour64(__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 | |||
139 | static void | ||
140 | copy64(__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 | |||
149 | static void | ||
150 | copy4(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 */ | ||
159 | void | ||
160 | mdfour(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 | |||
26 | static void MD5Transform(__u32 buf[4], __u32 const in[16]); | ||
27 | |||
28 | /* | ||
29 | * Note: this code is harmless on little-endian machines. | ||
30 | */ | ||
31 | static void | ||
32 | byteReverse(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 | */ | ||
47 | void | ||
48 | cifs_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 | */ | ||
63 | void | ||
64 | cifs_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 | */ | ||
112 | void | ||
113 | cifs_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 | */ | ||
171 | static void | ||
172 | MD5Transform(__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 | ***********************************************************************/ | ||
259 | static void | ||
260 | hmac_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 | ***********************************************************************/ | ||
298 | void | ||
299 | hmac_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 | ***********************************************************************/ | ||
327 | void | ||
328 | hmac_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 | ***********************************************************************/ | ||
337 | void | ||
338 | hmac_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 */ | ||
355 | static void | ||
356 | hmac_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 | |||
8 | struct 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 | ||
16 | struct HMACMD5Context { | ||
17 | struct MD5Context ctx; | ||
18 | unsigned char k_ipad[65]; | ||
19 | unsigned char k_opad[65]; | ||
20 | }; | ||
21 | #endif /* _HMAC_MD5_H */ | ||
22 | |||
23 | void cifs_MD5_init(struct MD5Context *context); | ||
24 | void cifs_MD5_update(struct MD5Context *context, unsigned char const *buf, | ||
25 | unsigned len); | ||
26 | void 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);*/ | ||
32 | void hmac_md5_init_limK_to_64(const unsigned char *key, int key_len, | ||
33 | struct HMACMD5Context *ctx); | ||
34 | void hmac_md5_update(const unsigned char *text, int text_len, | ||
35 | struct HMACMD5Context *ctx); | ||
36 | void 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 a09e077ba925..2a930a752a78 100644 --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c | |||
@@ -236,10 +236,7 @@ __u16 GetNextMid(struct TCP_Server_Info *server) | |||
236 | { | 236 | { |
237 | __u16 mid = 0; | 237 | __u16 mid = 0; |
238 | __u16 last_mid; | 238 | __u16 last_mid; |
239 | int collision; | 239 | bool collision; |
240 | |||
241 | if (server == NULL) | ||
242 | return mid; | ||
243 | 240 | ||
244 | spin_lock(&GlobalMid_Lock); | 241 | spin_lock(&GlobalMid_Lock); |
245 | last_mid = server->CurrentMid; /* we do not want to loop forever */ | 242 | last_mid = server->CurrentMid; /* we do not want to loop forever */ |
@@ -252,24 +249,38 @@ __u16 GetNextMid(struct TCP_Server_Info *server) | |||
252 | (and it would also have to have been a request that | 249 | (and it would also have to have been a request that |
253 | did not time out) */ | 250 | did not time out) */ |
254 | while (server->CurrentMid != last_mid) { | 251 | while (server->CurrentMid != last_mid) { |
255 | struct list_head *tmp; | ||
256 | struct mid_q_entry *mid_entry; | 252 | struct mid_q_entry *mid_entry; |
253 | unsigned int num_mids; | ||
257 | 254 | ||
258 | collision = 0; | 255 | collision = false; |
259 | if (server->CurrentMid == 0) | 256 | if (server->CurrentMid == 0) |
260 | server->CurrentMid++; | 257 | server->CurrentMid++; |
261 | 258 | ||
262 | list_for_each(tmp, &server->pending_mid_q) { | 259 | num_mids = 0; |
263 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); | 260 | list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) { |
264 | 261 | ++num_mids; | |
265 | if ((mid_entry->mid == server->CurrentMid) && | 262 | if (mid_entry->mid == server->CurrentMid && |
266 | (mid_entry->midState == MID_REQUEST_SUBMITTED)) { | 263 | mid_entry->midState == MID_REQUEST_SUBMITTED) { |
267 | /* This mid is in use, try a different one */ | 264 | /* This mid is in use, try a different one */ |
268 | collision = 1; | 265 | collision = true; |
269 | break; | 266 | break; |
270 | } | 267 | } |
271 | } | 268 | } |
272 | if (collision == 0) { | 269 | |
270 | /* | ||
271 | * if we have more than 32k mids in the list, then something | ||
272 | * is very wrong. Possibly a local user is trying to DoS the | ||
273 | * box by issuing long-running calls and SIGKILL'ing them. If | ||
274 | * we get to 2^16 mids then we're in big trouble as this | ||
275 | * function could loop forever. | ||
276 | * | ||
277 | * Go ahead and assign out the mid in this situation, but force | ||
278 | * an eventual reconnect to clean out the pending_mid_q. | ||
279 | */ | ||
280 | if (num_mids > 32768) | ||
281 | server->tcpStatus = CifsNeedReconnect; | ||
282 | |||
283 | if (!collision) { | ||
273 | mid = server->CurrentMid; | 284 | mid = server->CurrentMid; |
274 | break; | 285 | break; |
275 | } | 286 | } |
@@ -381,29 +392,31 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ , | |||
381 | } | 392 | } |
382 | 393 | ||
383 | static int | 394 | static int |
384 | checkSMBhdr(struct smb_hdr *smb, __u16 mid) | 395 | check_smb_hdr(struct smb_hdr *smb, __u16 mid) |
385 | { | 396 | { |
386 | /* Make sure that this really is an SMB, that it is a response, | 397 | /* does it have the right SMB "signature" ? */ |
387 | and that the message ids match */ | 398 | if (*(__le32 *) smb->Protocol != cpu_to_le32(0x424d53ff)) { |
388 | if ((*(__le32 *) smb->Protocol == cpu_to_le32(0x424d53ff)) && | 399 | cERROR(1, "Bad protocol string signature header 0x%x", |
389 | (mid == smb->Mid)) { | 400 | *(unsigned int *)smb->Protocol); |
390 | if (smb->Flags & SMBFLG_RESPONSE) | 401 | return 1; |
391 | return 0; | 402 | } |
392 | else { | 403 | |
393 | /* only one valid case where server sends us request */ | 404 | /* Make sure that message ids match */ |
394 | if (smb->Command == SMB_COM_LOCKING_ANDX) | 405 | if (mid != smb->Mid) { |
395 | return 0; | 406 | cERROR(1, "Mids do not match. received=%u expected=%u", |
396 | else | 407 | smb->Mid, mid); |
397 | cERROR(1, "Received Request not response"); | 408 | return 1; |
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 | } | 409 | } |
406 | cERROR(1, "bad smb detected. The Mid=%d", smb->Mid); | 410 | |
411 | /* if it's a response then accept */ | ||
412 | if (smb->Flags & SMBFLG_RESPONSE) | ||
413 | return 0; | ||
414 | |||
415 | /* only one valid case where server sends us request */ | ||
416 | if (smb->Command == SMB_COM_LOCKING_ANDX) | ||
417 | return 0; | ||
418 | |||
419 | cERROR(1, "Server sent request, not response. mid=%u", smb->Mid); | ||
407 | return 1; | 420 | return 1; |
408 | } | 421 | } |
409 | 422 | ||
@@ -448,7 +461,7 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
448 | return 1; | 461 | return 1; |
449 | } | 462 | } |
450 | 463 | ||
451 | if (checkSMBhdr(smb, mid)) | 464 | if (check_smb_hdr(smb, mid)) |
452 | return 1; | 465 | return 1; |
453 | clc_len = smbCalcSize_LE(smb); | 466 | clc_len = smbCalcSize_LE(smb); |
454 | 467 | ||
@@ -465,25 +478,26 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length) | |||
465 | if (((4 + len) & 0xFFFF) == (clc_len & 0xFFFF)) | 478 | if (((4 + len) & 0xFFFF) == (clc_len & 0xFFFF)) |
466 | return 0; /* bcc wrapped */ | 479 | return 0; /* bcc wrapped */ |
467 | } | 480 | } |
468 | cFYI(1, "Calculated size %d vs length %d mismatch for mid %d", | 481 | cFYI(1, "Calculated size %u vs length %u mismatch for mid=%u", |
469 | clc_len, 4 + len, smb->Mid); | 482 | clc_len, 4 + len, smb->Mid); |
470 | /* Windows XP can return a few bytes too much, presumably | 483 | |
471 | an illegal pad, at the end of byte range lock responses | 484 | if (4 + len < clc_len) { |
472 | so we allow for that three byte pad, as long as actual | 485 | 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); | 486 | len, smb->Mid); |
486 | return 1; | 487 | return 1; |
488 | } else if (len > clc_len + 512) { | ||
489 | /* | ||
490 | * Some servers (Windows XP in particular) send more | ||
491 | * data than the lengths in the SMB packet would | ||
492 | * indicate on certain calls (byte range locks and | ||
493 | * trans2 find first calls in particular). While the | ||
494 | * client can handle such a frame by ignoring the | ||
495 | * trailing data, we choose limit the amount of extra | ||
496 | * data to 512 bytes. | ||
497 | */ | ||
498 | cERROR(1, "RFC1001 size %u more than 512 bytes larger " | ||
499 | "than SMB for mid=%u", len, smb->Mid); | ||
500 | return 1; | ||
487 | } | 501 | } |
488 | } | 502 | } |
489 | return 0; | 503 | return 0; |
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/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 | ||
51 | static uchar perm1[56] = { 57, 49, 41, 33, 25, 17, 9, | 50 | static 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 */ |
51 | int | ||
52 | mdfour(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 | ||
53 | void SMBencrypt(unsigned char *passwd, const unsigned char *c8, | 83 | mdfour_err: |
54 | unsigned char *p24); | 84 | crypto_free_shash(md4); |
55 | void E_md4hash(const unsigned char *passwd, unsigned char *p16); | 85 | kfree(sdescmd4); |
56 | static void SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8, | 86 | |
57 | unsigned char p24[24]); | 87 | return rc; |
58 | void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24); | 88 | } |
89 | |||
90 | /* Does the des encryption from the NT or LM MD4 hash. */ | ||
91 | static void | ||
92 | SMBOWFencrypt(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 | ||
121 | void | 164 | int |
122 | E_md4hash(const unsigned char *passwd, unsigned char *p16) | 165 | E_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. */ | ||
216 | static void | ||
217 | SMBOWFencrypt(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 */ |
230 | static void | 263 | static 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 | 278 | int | |
246 | void | ||
247 | SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24) | 279 | SMBNTencrypt(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 c1ccca1a933f..46d8756f2b24 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c | |||
@@ -236,9 +236,9 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) | |||
236 | server->tcpStatus = CifsNeedReconnect; | 236 | server->tcpStatus = CifsNeedReconnect; |
237 | } | 237 | } |
238 | 238 | ||
239 | if (rc < 0) { | 239 | if (rc < 0 && rc != -EINTR) |
240 | cERROR(1, "Error %d sending data on socket to server", rc); | 240 | cERROR(1, "Error %d sending data on socket to server", rc); |
241 | } else | 241 | else |
242 | rc = 0; | 242 | rc = 0; |
243 | 243 | ||
244 | /* Don't want to modify the buffer as a | 244 | /* Don't want to modify the buffer as a |
@@ -359,6 +359,10 @@ cifs_call_async(struct TCP_Server_Info *server, struct smb_hdr *in_buf, | |||
359 | if (rc) | 359 | if (rc) |
360 | return rc; | 360 | return rc; |
361 | 361 | ||
362 | /* enable signing if server requires it */ | ||
363 | if (server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) | ||
364 | in_buf->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; | ||
365 | |||
362 | mutex_lock(&server->srv_mutex); | 366 | mutex_lock(&server->srv_mutex); |
363 | mid = AllocMidQEntry(in_buf, server); | 367 | mid = AllocMidQEntry(in_buf, server); |
364 | if (mid == NULL) { | 368 | if (mid == NULL) { |
@@ -453,6 +457,9 @@ sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server) | |||
453 | case MID_RETRY_NEEDED: | 457 | case MID_RETRY_NEEDED: |
454 | rc = -EAGAIN; | 458 | rc = -EAGAIN; |
455 | break; | 459 | break; |
460 | case MID_RESPONSE_MALFORMED: | ||
461 | rc = -EIO; | ||
462 | break; | ||
456 | default: | 463 | default: |
457 | cERROR(1, "%s: invalid mid state mid=%d state=%d", __func__, | 464 | cERROR(1, "%s: invalid mid state mid=%d state=%d", __func__, |
458 | mid->mid, mid->midState); | 465 | mid->mid, mid->midState); |
@@ -570,17 +577,33 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
570 | #endif | 577 | #endif |
571 | 578 | ||
572 | mutex_unlock(&ses->server->srv_mutex); | 579 | mutex_unlock(&ses->server->srv_mutex); |
573 | cifs_small_buf_release(in_buf); | ||
574 | 580 | ||
575 | if (rc < 0) | 581 | if (rc < 0) { |
582 | cifs_small_buf_release(in_buf); | ||
576 | goto out; | 583 | goto out; |
584 | } | ||
577 | 585 | ||
578 | if (long_op == CIFS_ASYNC_OP) | 586 | if (long_op == CIFS_ASYNC_OP) { |
587 | cifs_small_buf_release(in_buf); | ||
579 | goto out; | 588 | goto out; |
589 | } | ||
580 | 590 | ||
581 | rc = wait_for_response(ses->server, midQ); | 591 | rc = wait_for_response(ses->server, midQ); |
582 | if (rc != 0) | 592 | if (rc != 0) { |
583 | goto out; | 593 | send_nt_cancel(ses->server, in_buf, midQ); |
594 | spin_lock(&GlobalMid_Lock); | ||
595 | if (midQ->midState == MID_REQUEST_SUBMITTED) { | ||
596 | midQ->callback = DeleteMidQEntry; | ||
597 | spin_unlock(&GlobalMid_Lock); | ||
598 | cifs_small_buf_release(in_buf); | ||
599 | atomic_dec(&ses->server->inFlight); | ||
600 | wake_up(&ses->server->request_q); | ||
601 | return rc; | ||
602 | } | ||
603 | spin_unlock(&GlobalMid_Lock); | ||
604 | } | ||
605 | |||
606 | cifs_small_buf_release(in_buf); | ||
584 | 607 | ||
585 | rc = sync_mid_result(midQ, ses->server); | 608 | rc = sync_mid_result(midQ, ses->server); |
586 | if (rc != 0) { | 609 | if (rc != 0) { |
@@ -724,8 +747,19 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
724 | goto out; | 747 | goto out; |
725 | 748 | ||
726 | rc = wait_for_response(ses->server, midQ); | 749 | rc = wait_for_response(ses->server, midQ); |
727 | if (rc != 0) | 750 | if (rc != 0) { |
728 | goto out; | 751 | send_nt_cancel(ses->server, in_buf, midQ); |
752 | spin_lock(&GlobalMid_Lock); | ||
753 | if (midQ->midState == MID_REQUEST_SUBMITTED) { | ||
754 | /* no longer considered to be "in-flight" */ | ||
755 | midQ->callback = DeleteMidQEntry; | ||
756 | spin_unlock(&GlobalMid_Lock); | ||
757 | atomic_dec(&ses->server->inFlight); | ||
758 | wake_up(&ses->server->request_q); | ||
759 | return rc; | ||
760 | } | ||
761 | spin_unlock(&GlobalMid_Lock); | ||
762 | } | ||
729 | 763 | ||
730 | rc = sync_mid_result(midQ, ses->server); | 764 | rc = sync_mid_result(midQ, ses->server); |
731 | if (rc != 0) { | 765 | if (rc != 0) { |
@@ -922,10 +956,21 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
922 | } | 956 | } |
923 | } | 957 | } |
924 | 958 | ||
925 | if (wait_for_response(ses->server, midQ) == 0) { | 959 | rc = wait_for_response(ses->server, midQ); |
926 | /* We got the response - restart system call. */ | 960 | if (rc) { |
927 | rstart = 1; | 961 | send_nt_cancel(ses->server, in_buf, midQ); |
962 | spin_lock(&GlobalMid_Lock); | ||
963 | if (midQ->midState == MID_REQUEST_SUBMITTED) { | ||
964 | /* no longer considered to be "in-flight" */ | ||
965 | midQ->callback = DeleteMidQEntry; | ||
966 | spin_unlock(&GlobalMid_Lock); | ||
967 | return rc; | ||
968 | } | ||
969 | spin_unlock(&GlobalMid_Lock); | ||
928 | } | 970 | } |
971 | |||
972 | /* We got the response - restart system call. */ | ||
973 | rstart = 1; | ||
929 | } | 974 | } |
930 | 975 | ||
931 | rc = sync_mid_result(midQ, ses->server); | 976 | rc = sync_mid_result(midQ, ses->server); |