Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6:
cifs: make sure we allocate enough storage for socket address
[CIFS] Make socket retry timeouts consistent between blocking and nonblocking cases
[CIFS] some cleanup to dir.c prior to addition of posix_open
[CIFS] revalidate parent inode when rmdir done within that directory
[CIFS] Rename md5 functions to avoid collision with new rt modules
cifs: turn smb_send into a wrapper around smb_sendv

+121 -161
+3 -1
fs/cifs/CHANGES
··· 5 support posix byte range locks. Fix query of root inode when prefixpath 6 specified and user does not have access to query information about the 7 top of the share. Fix problem in 2.6.28 resolving DFS paths to 8 - Samba servers (worked to Windows). 9 10 Version 1.55 11 ------------
··· 5 support posix byte range locks. Fix query of root inode when prefixpath 6 specified and user does not have access to query information about the 7 top of the share. Fix problem in 2.6.28 resolving DFS paths to 8 + Samba servers (worked to Windows). Fix rmdir so that pending search 9 + (readdir) requests do not get invalid results which include the now 10 + removed directory. 11 12 Version 1.55 13 ------------
+9 -9
fs/cifs/cifsencrypt.c
··· 48 if ((cifs_pdu == NULL) || (signature == NULL) || (key == NULL)) 49 return -EINVAL; 50 51 - MD5Init(&context); 52 - MD5Update(&context, (char *)&key->data, key->len); 53 - MD5Update(&context, cifs_pdu->Protocol, cifs_pdu->smb_buf_length); 54 55 - MD5Final(signature, &context); 56 return 0; 57 } 58 ··· 96 if ((iov == NULL) || (signature == NULL) || (key == NULL)) 97 return -EINVAL; 98 99 - MD5Init(&context); 100 - MD5Update(&context, (char *)&key->data, key->len); 101 for (i = 0; i < n_vec; i++) { 102 if (iov[i].iov_len == 0) 103 continue; ··· 110 if (i == 0) { 111 if (iov[0].iov_len <= 8) /* cmd field at offset 9 */ 112 break; /* nothing to sign or corrupt header */ 113 - MD5Update(&context, iov[0].iov_base+4, 114 iov[0].iov_len-4); 115 } else 116 - MD5Update(&context, iov[i].iov_base, iov[i].iov_len); 117 } 118 119 - MD5Final(signature, &context); 120 121 return 0; 122 }
··· 48 if ((cifs_pdu == NULL) || (signature == NULL) || (key == NULL)) 49 return -EINVAL; 50 51 + cifs_MD5_init(&context); 52 + cifs_MD5_update(&context, (char *)&key->data, key->len); 53 + cifs_MD5_update(&context, cifs_pdu->Protocol, cifs_pdu->smb_buf_length); 54 55 + cifs_MD5_final(signature, &context); 56 return 0; 57 } 58 ··· 96 if ((iov == NULL) || (signature == NULL) || (key == NULL)) 97 return -EINVAL; 98 99 + cifs_MD5_init(&context); 100 + cifs_MD5_update(&context, (char *)&key->data, key->len); 101 for (i = 0; i < n_vec; i++) { 102 if (iov[i].iov_len == 0) 103 continue; ··· 110 if (i == 0) { 111 if (iov[0].iov_len <= 8) /* cmd field at offset 9 */ 112 break; /* nothing to sign or corrupt header */ 113 + cifs_MD5_update(&context, iov[0].iov_base+4, 114 iov[0].iov_len-4); 115 } else 116 + cifs_MD5_update(&context, iov[i].iov_base, iov[i].iov_len); 117 } 118 119 + cifs_MD5_final(signature, &context); 120 121 return 0; 122 }
+2 -2
fs/cifs/cifsproto.h
··· 35 extern void cifs_buf_release(void *); 36 extern struct smb_hdr *cifs_small_buf_get(void); 37 extern void cifs_small_buf_release(void *); 38 - extern int smb_send(struct socket *, struct smb_hdr *, 39 - unsigned int /* length */ , struct sockaddr *, bool); 40 extern unsigned int _GetXid(void); 41 extern void _FreeXid(unsigned int); 42 #define GetXid() (int)_GetXid(); cFYI(1,("CIFS VFS: in %s as Xid: %d with uid: %d",__func__, xid,current_fsuid()));
··· 35 extern void cifs_buf_release(void *); 36 extern struct smb_hdr *cifs_small_buf_get(void); 37 extern void cifs_small_buf_release(void *); 38 + extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *, 39 + unsigned int /* length */); 40 extern unsigned int _GetXid(void); 41 extern void _FreeXid(unsigned int); 42 #define GetXid() (int)_GetXid(); cFYI(1,("CIFS VFS: in %s as Xid: %d with uid: %d",__func__, xid,current_fsuid()));
+11 -13
fs/cifs/connect.c
··· 1354 } 1355 1356 static struct TCP_Server_Info * 1357 - cifs_find_tcp_session(struct sockaddr *addr) 1358 { 1359 struct list_head *tmp; 1360 struct TCP_Server_Info *server; ··· 1374 if (server->tcpStatus == CifsNew) 1375 continue; 1376 1377 - if (addr->sa_family == AF_INET && 1378 (addr4->sin_addr.s_addr != 1379 server->addr.sockAddr.sin_addr.s_addr)) 1380 continue; 1381 - else if (addr->sa_family == AF_INET6 && 1382 memcmp(&server->addr.sockAddr6.sin6_addr, 1383 &addr6->sin6_addr, sizeof(addr6->sin6_addr))) 1384 continue; ··· 1419 cifs_get_tcp_session(struct smb_vol *volume_info) 1420 { 1421 struct TCP_Server_Info *tcp_ses = NULL; 1422 - struct sockaddr addr; 1423 struct sockaddr_in *sin_server = (struct sockaddr_in *) &addr; 1424 struct sockaddr_in6 *sin_server6 = (struct sockaddr_in6 *) &addr; 1425 int rc; 1426 1427 - memset(&addr, 0, sizeof(struct sockaddr)); 1428 1429 if (volume_info->UNCip && volume_info->UNC) { 1430 rc = cifs_inet_pton(AF_INET, volume_info->UNCip, ··· 1435 rc = cifs_inet_pton(AF_INET6, volume_info->UNCip, 1436 &sin_server6->sin6_addr.in6_u); 1437 if (rc > 0) 1438 - addr.sa_family = AF_INET6; 1439 } else { 1440 - addr.sa_family = AF_INET; 1441 } 1442 1443 if (rc <= 0) { ··· 1502 tcp_ses->tcpStatus = CifsNew; 1503 ++tcp_ses->srv_count; 1504 1505 - if (addr.sa_family == AF_INET6) { 1506 cFYI(1, ("attempting ipv6 connect")); 1507 /* BB should we allow ipv6 on port 139? */ 1508 /* other OS never observed in Wild doing 139 with v6 */ ··· 1802 * user space buffer 1803 */ 1804 socket->sk->sk_rcvtimeo = 7 * HZ; 1805 - socket->sk->sk_sndtimeo = 3 * HZ; 1806 1807 /* make the bufsizes depend on wsize/rsize and max requests */ 1808 if (server->noautotune) { ··· 1860 smb_buf = (struct smb_hdr *)ses_init_buf; 1861 /* sizeof RFC1002_SESSION_REQUEST with no scope */ 1862 smb_buf->smb_buf_length = 0x81000044; 1863 - rc = smb_send(socket, smb_buf, 0x44, 1864 - (struct sockaddr *) &server->addr.sockAddr, 1865 - server->noblocksnd); 1866 kfree(ses_init_buf); 1867 msleep(1); /* RFC1001 layer in at least one server 1868 requires very short break before negprot ··· 1953 * user space buffer 1954 */ 1955 socket->sk->sk_rcvtimeo = 7 * HZ; 1956 - socket->sk->sk_sndtimeo = 3 * HZ; 1957 server->ssocket = socket; 1958 1959 return rc;
··· 1354 } 1355 1356 static struct TCP_Server_Info * 1357 + cifs_find_tcp_session(struct sockaddr_storage *addr) 1358 { 1359 struct list_head *tmp; 1360 struct TCP_Server_Info *server; ··· 1374 if (server->tcpStatus == CifsNew) 1375 continue; 1376 1377 + if (addr->ss_family == AF_INET && 1378 (addr4->sin_addr.s_addr != 1379 server->addr.sockAddr.sin_addr.s_addr)) 1380 continue; 1381 + else if (addr->ss_family == AF_INET6 && 1382 memcmp(&server->addr.sockAddr6.sin6_addr, 1383 &addr6->sin6_addr, sizeof(addr6->sin6_addr))) 1384 continue; ··· 1419 cifs_get_tcp_session(struct smb_vol *volume_info) 1420 { 1421 struct TCP_Server_Info *tcp_ses = NULL; 1422 + struct sockaddr_storage addr; 1423 struct sockaddr_in *sin_server = (struct sockaddr_in *) &addr; 1424 struct sockaddr_in6 *sin_server6 = (struct sockaddr_in6 *) &addr; 1425 int rc; 1426 1427 + memset(&addr, 0, sizeof(struct sockaddr_storage)); 1428 1429 if (volume_info->UNCip && volume_info->UNC) { 1430 rc = cifs_inet_pton(AF_INET, volume_info->UNCip, ··· 1435 rc = cifs_inet_pton(AF_INET6, volume_info->UNCip, 1436 &sin_server6->sin6_addr.in6_u); 1437 if (rc > 0) 1438 + addr.ss_family = AF_INET6; 1439 } else { 1440 + addr.ss_family = AF_INET; 1441 } 1442 1443 if (rc <= 0) { ··· 1502 tcp_ses->tcpStatus = CifsNew; 1503 ++tcp_ses->srv_count; 1504 1505 + if (addr.ss_family == AF_INET6) { 1506 cFYI(1, ("attempting ipv6 connect")); 1507 /* BB should we allow ipv6 on port 139? */ 1508 /* other OS never observed in Wild doing 139 with v6 */ ··· 1802 * user space buffer 1803 */ 1804 socket->sk->sk_rcvtimeo = 7 * HZ; 1805 + socket->sk->sk_sndtimeo = 5 * HZ; 1806 1807 /* make the bufsizes depend on wsize/rsize and max requests */ 1808 if (server->noautotune) { ··· 1860 smb_buf = (struct smb_hdr *)ses_init_buf; 1861 /* sizeof RFC1002_SESSION_REQUEST with no scope */ 1862 smb_buf->smb_buf_length = 0x81000044; 1863 + rc = smb_send(server, smb_buf, 0x44); 1864 kfree(ses_init_buf); 1865 msleep(1); /* RFC1001 layer in at least one server 1866 requires very short break before negprot ··· 1955 * user space buffer 1956 */ 1957 socket->sk->sk_rcvtimeo = 7 * HZ; 1958 + socket->sk->sk_sndtimeo = 5 * HZ; 1959 server->ssocket = socket; 1960 1961 return rc;
+31 -25
fs/cifs/dir.c
··· 129 return full_path; 130 } 131 132 /* Inode operations in similar order to how they appear in Linux file fs.h */ 133 134 int ··· 150 int xid; 151 int create_options = CREATE_NOT_DIR; 152 int oplock = 0; 153 int desiredAccess = GENERIC_READ | GENERIC_WRITE; 154 __u16 fileHandle; 155 struct cifs_sb_info *cifs_sb; 156 - struct cifsTconInfo *pTcon; 157 char *full_path = NULL; 158 FILE_ALL_INFO *buf = NULL; 159 struct inode *newinode = NULL; 160 - struct cifsFileInfo *pCifsFile = NULL; 161 struct cifsInodeInfo *pCifsInode; 162 int disposition = FILE_OVERWRITE_IF; 163 bool write_only = false; ··· 165 xid = GetXid(); 166 167 cifs_sb = CIFS_SB(inode->i_sb); 168 - pTcon = cifs_sb->tcon; 169 170 full_path = build_path_from_dentry(direntry); 171 if (full_path == NULL) { 172 FreeXid(xid); 173 return -ENOMEM; 174 } 175 176 if (nd && (nd->flags & LOOKUP_OPEN)) { 177 int oflags = nd->intent.open.flags; ··· 209 return -ENOMEM; 210 } 211 212 - mode &= ~current->fs->umask; 213 - 214 /* 215 * if we're not using unix extensions, see if we need to set 216 * ATTR_READONLY on the create call 217 */ 218 - if (!pTcon->unix_ext && (mode & S_IWUGO) == 0) 219 create_options |= CREATE_OPTION_READONLY; 220 221 if (cifs_sb->tcon->ses->capabilities & CAP_NT_SMBS) 222 - rc = CIFSSMBOpen(xid, pTcon, full_path, disposition, 223 desiredAccess, create_options, 224 &fileHandle, &oplock, buf, cifs_sb->local_nls, 225 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); ··· 226 227 if (rc == -EIO) { 228 /* old server, retry the open legacy style */ 229 - rc = SMBLegacyOpen(xid, pTcon, full_path, disposition, 230 desiredAccess, create_options, 231 &fileHandle, &oplock, buf, cifs_sb->local_nls, 232 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); ··· 236 } else { 237 /* If Open reported that we actually created a file 238 then we now have to set the mode if possible */ 239 - if ((pTcon->unix_ext) && (oplock & CIFS_CREATE_ACTION)) { 240 struct cifs_unix_set_info_args args = { 241 .mode = mode, 242 .ctime = NO_CHANGE_64, ··· 255 args.uid = NO_CHANGE_64; 256 args.gid = NO_CHANGE_64; 257 } 258 - CIFSSMBUnixSetInfo(xid, pTcon, full_path, &args, 259 cifs_sb->local_nls, 260 cifs_sb->mnt_cifs_flags & 261 CIFS_MOUNT_MAP_SPECIAL_CHR); 262 } else { 263 /* BB implement mode setting via Windows security 264 descriptors e.g. */ 265 - /* CIFSSMBWinSetPerms(xid,pTcon,path,mode,-1,-1,nls);*/ 266 267 /* Could set r/o dos attribute if mode & 0222 == 0 */ 268 } 269 270 /* server might mask mode so we have to query for it */ 271 - if (pTcon->unix_ext) 272 rc = cifs_get_inode_info_unix(&newinode, full_path, 273 inode->i_sb, xid); 274 else { ··· 294 } 295 296 if (rc != 0) { 297 - cFYI(1, 298 - ("Create worked but get_inode_info failed rc = %d", 299 - rc)); 300 - } else { 301 - if (pTcon->nocase) 302 - direntry->d_op = &cifs_ci_dentry_ops; 303 - else 304 - direntry->d_op = &cifs_dentry_ops; 305 - d_instantiate(direntry, newinode); 306 - } 307 if ((nd == NULL /* nfsd case - nfs srv does not set nd */) || 308 (!(nd->flags & LOOKUP_OPEN))) { 309 /* mknod case - do not leave file open */ 310 - CIFSSMBClose(xid, pTcon, fileHandle); 311 } else if (newinode) { 312 - pCifsFile = 313 kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); 314 315 if (pCifsFile == NULL) ··· 322 /* set the following in open now 323 pCifsFile->pfile = file; */ 324 write_lock(&GlobalSMBSeslock); 325 - list_add(&pCifsFile->tlist, &pTcon->openFileList); 326 pCifsInode = CIFS_I(newinode); 327 if (pCifsInode) { 328 /* if readable file instance put first in list*/
··· 129 return full_path; 130 } 131 132 + static void setup_cifs_dentry(struct cifsTconInfo *tcon, 133 + struct dentry *direntry, 134 + struct inode *newinode) 135 + { 136 + if (tcon->nocase) 137 + direntry->d_op = &cifs_ci_dentry_ops; 138 + else 139 + direntry->d_op = &cifs_dentry_ops; 140 + d_instantiate(direntry, newinode); 141 + } 142 + 143 /* Inode operations in similar order to how they appear in Linux file fs.h */ 144 145 int ··· 139 int xid; 140 int create_options = CREATE_NOT_DIR; 141 int oplock = 0; 142 + /* BB below access is too much for the mknod to request */ 143 int desiredAccess = GENERIC_READ | GENERIC_WRITE; 144 __u16 fileHandle; 145 struct cifs_sb_info *cifs_sb; 146 + struct cifsTconInfo *tcon; 147 char *full_path = NULL; 148 FILE_ALL_INFO *buf = NULL; 149 struct inode *newinode = NULL; 150 struct cifsInodeInfo *pCifsInode; 151 int disposition = FILE_OVERWRITE_IF; 152 bool write_only = false; ··· 154 xid = GetXid(); 155 156 cifs_sb = CIFS_SB(inode->i_sb); 157 + tcon = cifs_sb->tcon; 158 159 full_path = build_path_from_dentry(direntry); 160 if (full_path == NULL) { 161 FreeXid(xid); 162 return -ENOMEM; 163 } 164 + 165 + mode &= ~current->fs->umask; 166 167 if (nd && (nd->flags & LOOKUP_OPEN)) { 168 int oflags = nd->intent.open.flags; ··· 196 return -ENOMEM; 197 } 198 199 /* 200 * if we're not using unix extensions, see if we need to set 201 * ATTR_READONLY on the create call 202 */ 203 + if (!tcon->unix_ext && (mode & S_IWUGO) == 0) 204 create_options |= CREATE_OPTION_READONLY; 205 206 if (cifs_sb->tcon->ses->capabilities & CAP_NT_SMBS) 207 + rc = CIFSSMBOpen(xid, tcon, full_path, disposition, 208 desiredAccess, create_options, 209 &fileHandle, &oplock, buf, cifs_sb->local_nls, 210 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); ··· 215 216 if (rc == -EIO) { 217 /* old server, retry the open legacy style */ 218 + rc = SMBLegacyOpen(xid, tcon, full_path, disposition, 219 desiredAccess, create_options, 220 &fileHandle, &oplock, buf, cifs_sb->local_nls, 221 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); ··· 225 } else { 226 /* If Open reported that we actually created a file 227 then we now have to set the mode if possible */ 228 + if ((tcon->unix_ext) && (oplock & CIFS_CREATE_ACTION)) { 229 struct cifs_unix_set_info_args args = { 230 .mode = mode, 231 .ctime = NO_CHANGE_64, ··· 244 args.uid = NO_CHANGE_64; 245 args.gid = NO_CHANGE_64; 246 } 247 + CIFSSMBUnixSetInfo(xid, tcon, full_path, &args, 248 cifs_sb->local_nls, 249 cifs_sb->mnt_cifs_flags & 250 CIFS_MOUNT_MAP_SPECIAL_CHR); 251 } else { 252 /* BB implement mode setting via Windows security 253 descriptors e.g. */ 254 + /* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/ 255 256 /* Could set r/o dos attribute if mode & 0222 == 0 */ 257 } 258 259 /* server might mask mode so we have to query for it */ 260 + if (tcon->unix_ext) 261 rc = cifs_get_inode_info_unix(&newinode, full_path, 262 inode->i_sb, xid); 263 else { ··· 283 } 284 285 if (rc != 0) { 286 + cFYI(1, ("Create worked, get_inode_info failed rc = %d", 287 + rc)); 288 + } else 289 + setup_cifs_dentry(tcon, direntry, newinode); 290 + 291 if ((nd == NULL /* nfsd case - nfs srv does not set nd */) || 292 (!(nd->flags & LOOKUP_OPEN))) { 293 /* mknod case - do not leave file open */ 294 + CIFSSMBClose(xid, tcon, fileHandle); 295 } else if (newinode) { 296 + struct cifsFileInfo *pCifsFile = 297 kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); 298 299 if (pCifsFile == NULL) ··· 316 /* set the following in open now 317 pCifsFile->pfile = file; */ 318 write_lock(&GlobalSMBSeslock); 319 + list_add(&pCifsFile->tlist, &tcon->openFileList); 320 pCifsInode = CIFS_I(newinode); 321 if (pCifsInode) { 322 /* if readable file instance put first in list*/
+5
fs/cifs/inode.c
··· 1285 cifsInode = CIFS_I(direntry->d_inode); 1286 cifsInode->time = 0; /* force revalidate to go get info when 1287 needed */ 1288 direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime = 1289 current_fs_time(inode->i_sb); 1290
··· 1285 cifsInode = CIFS_I(direntry->d_inode); 1286 cifsInode->time = 0; /* force revalidate to go get info when 1287 needed */ 1288 + 1289 + cifsInode = CIFS_I(inode); 1290 + cifsInode->time = 0; /* force revalidate to get parent dir info 1291 + since cached search results now invalid */ 1292 + 1293 direntry->d_inode->i_ctime = inode->i_ctime = inode->i_mtime = 1294 current_fs_time(inode->i_sb); 1295
+19 -19
fs/cifs/md5.c
··· 10 * with every copy. 11 * 12 * To compute the message digest of a chunk of bytes, declare an 13 - * MD5Context structure, pass it to MD5Init, call MD5Update as 14 - * needed on buffers full of bytes, and then call MD5Final, which 15 * will fill a supplied 16-byte array with the digest. 16 */ 17 ··· 45 * initialization constants. 46 */ 47 void 48 - MD5Init(struct MD5Context *ctx) 49 { 50 ctx->buf[0] = 0x67452301; 51 ctx->buf[1] = 0xefcdab89; ··· 61 * of bytes. 62 */ 63 void 64 - MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) 65 { 66 register __u32 t; 67 ··· 110 * 1 0* (64-bit count of bits processed, MSB-first) 111 */ 112 void 113 - MD5Final(unsigned char digest[16], struct MD5Context *ctx) 114 { 115 unsigned int count; 116 unsigned char *p; ··· 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. MD5Update blocks 169 * the data and converts bytes into longwords for this routine. 170 */ 171 static void ··· 267 unsigned char tk[16]; 268 struct MD5Context tctx; 269 270 - MD5Init(&tctx); 271 - MD5Update(&tctx, key, key_len); 272 - MD5Final(tk, &tctx); 273 274 key = tk; 275 key_len = 16; ··· 287 ctx->k_opad[i] ^= 0x5c; 288 } 289 290 - MD5Init(&ctx->ctx); 291 - MD5Update(&ctx->ctx, ctx->k_ipad, 64); 292 } 293 #endif 294 ··· 317 ctx->k_opad[i] ^= 0x5c; 318 } 319 320 - MD5Init(&ctx->ctx); 321 - MD5Update(&ctx->ctx, ctx->k_ipad, 64); 322 } 323 324 /*********************************************************************** ··· 328 hmac_md5_update(const unsigned char *text, int text_len, 329 struct HMACMD5Context *ctx) 330 { 331 - MD5Update(&ctx->ctx, text, text_len); /* then text of datagram */ 332 } 333 334 /*********************************************************************** ··· 339 { 340 struct MD5Context ctx_o; 341 342 - MD5Final(digest, &ctx->ctx); 343 344 - MD5Init(&ctx_o); 345 - MD5Update(&ctx_o, ctx->k_opad, 64); 346 - MD5Update(&ctx_o, digest, 16); 347 - MD5Final(digest, &ctx_o); 348 } 349 350 /***********************************************************
··· 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 ··· 45 * initialization constants. 46 */ 47 void 48 + cifs_MD5_init(struct MD5Context *ctx) 49 { 50 ctx->buf[0] = 0x67452301; 51 ctx->buf[1] = 0xefcdab89; ··· 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 ··· 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; ··· 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 ··· 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; ··· 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 ··· 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 /*********************************************************************** ··· 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 /*********************************************************************** ··· 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 /***********************************************************
+3 -3
fs/cifs/md5.h
··· 20 }; 21 #endif /* _HMAC_MD5_H */ 22 23 - void MD5Init(struct MD5Context *context); 24 - void MD5Update(struct MD5Context *context, unsigned char const *buf, 25 unsigned len); 26 - void MD5Final(unsigned char digest[16], struct MD5Context *context); 27 28 /* The following definitions come from lib/hmacmd5.c */ 29
··· 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
+38 -89
fs/cifs/transport.c
··· 154 spin_unlock(&GlobalMid_Lock); 155 } 156 157 - int 158 - smb_send(struct socket *ssocket, struct smb_hdr *smb_buffer, 159 - unsigned int smb_buf_length, struct sockaddr *sin, bool noblocksnd) 160 - { 161 - int rc = 0; 162 - int i = 0; 163 - struct msghdr smb_msg; 164 - struct kvec iov; 165 - unsigned len = smb_buf_length + 4; 166 - 167 - if (ssocket == NULL) 168 - return -ENOTSOCK; /* BB eventually add reconnect code here */ 169 - iov.iov_base = smb_buffer; 170 - iov.iov_len = len; 171 - 172 - smb_msg.msg_name = sin; 173 - smb_msg.msg_namelen = sizeof(struct sockaddr); 174 - smb_msg.msg_control = NULL; 175 - smb_msg.msg_controllen = 0; 176 - if (noblocksnd) 177 - smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; 178 - else 179 - smb_msg.msg_flags = MSG_NOSIGNAL; 180 - 181 - /* smb header is converted in header_assemble. bcc and rest of SMB word 182 - area, and byte area if necessary, is converted to littleendian in 183 - cifssmb.c and RFC1001 len is converted to bigendian in smb_send 184 - Flags2 is converted in SendReceive */ 185 - 186 - smb_buffer->smb_buf_length = cpu_to_be32(smb_buffer->smb_buf_length); 187 - cFYI(1, ("Sending smb of length %d", smb_buf_length)); 188 - dump_smb(smb_buffer, len); 189 - 190 - while (len > 0) { 191 - rc = kernel_sendmsg(ssocket, &smb_msg, &iov, 1, len); 192 - if ((rc == -ENOSPC) || (rc == -EAGAIN)) { 193 - i++; 194 - /* smaller timeout here than send2 since smaller size */ 195 - /* Although it may not be required, this also is smaller 196 - oplock break time */ 197 - if (i > 12) { 198 - cERROR(1, 199 - ("sends on sock %p stuck for 7 seconds", 200 - ssocket)); 201 - rc = -EAGAIN; 202 - break; 203 - } 204 - msleep(1 << i); 205 - continue; 206 - } 207 - if (rc < 0) 208 - break; 209 - else 210 - i = 0; /* reset i after each successful send */ 211 - iov.iov_base += rc; 212 - iov.iov_len -= rc; 213 - len -= rc; 214 - } 215 - 216 - if (rc < 0) { 217 - cERROR(1, ("Error %d sending data on socket to server", rc)); 218 - } else { 219 - rc = 0; 220 - } 221 - 222 - /* Don't want to modify the buffer as a 223 - side effect of this call. */ 224 - smb_buffer->smb_buf_length = smb_buf_length; 225 - 226 - return rc; 227 - } 228 - 229 static int 230 - smb_send2(struct TCP_Server_Info *server, struct kvec *iov, int n_vec, 231 - struct sockaddr *sin, bool noblocksnd) 232 { 233 int rc = 0; 234 int i = 0; ··· 170 if (ssocket == NULL) 171 return -ENOTSOCK; /* BB eventually add reconnect code here */ 172 173 - smb_msg.msg_name = sin; 174 smb_msg.msg_namelen = sizeof(struct sockaddr); 175 smb_msg.msg_control = NULL; 176 smb_msg.msg_controllen = 0; 177 - if (noblocksnd) 178 smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; 179 else 180 smb_msg.msg_flags = MSG_NOSIGNAL; ··· 199 n_vec - first_vec, total_len); 200 if ((rc == -ENOSPC) || (rc == -EAGAIN)) { 201 i++; 202 - if (i >= 14) { 203 cERROR(1, 204 ("sends on sock %p stuck for 15 seconds", 205 ssocket)); ··· 282 smb_buffer->smb_buf_length = smb_buf_length; 283 284 return rc; 285 } 286 287 static int wait_for_free_request(struct cifsSesInfo *ses, const int long_op) ··· 497 #ifdef CONFIG_CIFS_STATS2 498 atomic_inc(&ses->server->inSend); 499 #endif 500 - rc = smb_send2(ses->server, iov, n_vec, 501 - (struct sockaddr *) &(ses->server->addr.sockAddr), 502 - ses->server->noblocksnd); 503 #ifdef CONFIG_CIFS_STATS2 504 atomic_dec(&ses->server->inSend); 505 midQ->when_sent = jiffies; ··· 691 #ifdef CONFIG_CIFS_STATS2 692 atomic_inc(&ses->server->inSend); 693 #endif 694 - rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length, 695 - (struct sockaddr *) &(ses->server->addr.sockAddr), 696 - ses->server->noblocksnd); 697 #ifdef CONFIG_CIFS_STATS2 698 atomic_dec(&ses->server->inSend); 699 midQ->when_sent = jiffies; ··· 832 mutex_unlock(&ses->server->srv_mutex); 833 return rc; 834 } 835 - rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length, 836 - (struct sockaddr *) &(ses->server->addr.sockAddr), 837 - ses->server->noblocksnd); 838 mutex_unlock(&ses->server->srv_mutex); 839 return rc; 840 } ··· 924 #ifdef CONFIG_CIFS_STATS2 925 atomic_inc(&ses->server->inSend); 926 #endif 927 - rc = smb_send(ses->server->ssocket, in_buf, in_buf->smb_buf_length, 928 - (struct sockaddr *) &(ses->server->addr.sockAddr), 929 - ses->server->noblocksnd); 930 #ifdef CONFIG_CIFS_STATS2 931 atomic_dec(&ses->server->inSend); 932 midQ->when_sent = jiffies;
··· 154 spin_unlock(&GlobalMid_Lock); 155 } 156 157 static int 158 + smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec) 159 { 160 int rc = 0; 161 int i = 0; ··· 243 if (ssocket == NULL) 244 return -ENOTSOCK; /* BB eventually add reconnect code here */ 245 246 + smb_msg.msg_name = (struct sockaddr *) &server->addr.sockAddr; 247 smb_msg.msg_namelen = sizeof(struct sockaddr); 248 smb_msg.msg_control = NULL; 249 smb_msg.msg_controllen = 0; 250 + if (server->noblocksnd) 251 smb_msg.msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL; 252 else 253 smb_msg.msg_flags = MSG_NOSIGNAL; ··· 272 n_vec - first_vec, total_len); 273 if ((rc == -ENOSPC) || (rc == -EAGAIN)) { 274 i++; 275 + /* if blocking send we try 3 times, since each can block 276 + for 5 seconds. For nonblocking we have to try more 277 + but wait increasing amounts of time allowing time for 278 + socket to clear. The overall time we wait in either 279 + case to send on the socket is about 15 seconds. 280 + Similarly we wait for 15 seconds for 281 + a response from the server in SendReceive[2] 282 + for the server to send a response back for 283 + most types of requests (except SMB Write 284 + past end of file which can be slow, and 285 + blocking lock operations). NFS waits slightly longer 286 + than CIFS, but this can make it take longer for 287 + nonresponsive servers to be detected and 15 seconds 288 + is more than enough time for modern networks to 289 + send a packet. In most cases if we fail to send 290 + after the retries we will kill the socket and 291 + reconnect which may clear the network problem. 292 + */ 293 + if ((i >= 14) || (!server->noblocksnd && (i > 2))) { 294 cERROR(1, 295 ("sends on sock %p stuck for 15 seconds", 296 ssocket)); ··· 337 smb_buffer->smb_buf_length = smb_buf_length; 338 339 return rc; 340 + } 341 + 342 + int 343 + smb_send(struct TCP_Server_Info *server, struct smb_hdr *smb_buffer, 344 + unsigned int smb_buf_length) 345 + { 346 + struct kvec iov; 347 + 348 + iov.iov_base = smb_buffer; 349 + iov.iov_len = smb_buf_length + 4; 350 + 351 + return smb_sendv(server, &iov, 1); 352 } 353 354 static int wait_for_free_request(struct cifsSesInfo *ses, const int long_op) ··· 540 #ifdef CONFIG_CIFS_STATS2 541 atomic_inc(&ses->server->inSend); 542 #endif 543 + rc = smb_sendv(ses->server, iov, n_vec); 544 #ifdef CONFIG_CIFS_STATS2 545 atomic_dec(&ses->server->inSend); 546 midQ->when_sent = jiffies; ··· 736 #ifdef CONFIG_CIFS_STATS2 737 atomic_inc(&ses->server->inSend); 738 #endif 739 + rc = smb_send(ses->server, in_buf, in_buf->smb_buf_length); 740 #ifdef CONFIG_CIFS_STATS2 741 atomic_dec(&ses->server->inSend); 742 midQ->when_sent = jiffies; ··· 879 mutex_unlock(&ses->server->srv_mutex); 880 return rc; 881 } 882 + rc = smb_send(ses->server, in_buf, in_buf->smb_buf_length); 883 mutex_unlock(&ses->server->srv_mutex); 884 return rc; 885 } ··· 973 #ifdef CONFIG_CIFS_STATS2 974 atomic_inc(&ses->server->inSend); 975 #endif 976 + rc = smb_send(ses->server, in_buf, in_buf->smb_buf_length); 977 #ifdef CONFIG_CIFS_STATS2 978 atomic_dec(&ses->server->inSend); 979 midQ->when_sent = jiffies;