History

Merge tag 'cifs-fixes-7.3-rc1' of https://git.manguebit.org/linux

Pull smb client updates from Paulo Alcantara: - clear sensitive data after use (stack and heap cryptographic keys/hashes) - file size and cache synchronization fixes (fscache cookie serialization and truncation handling) - protocol validation and buffer safety fixes (prevent OOB access and loff_t underflow) - metadata and POSIX attribute fixes (proper hard-link counts and setuid/setgid stripping) - DFS cache and unmount fixes (prevent target-hint UAF and unmount hangs) - general client improvements (fix read request leaks, stats loops, handle servers that don't support O_TMPFILE) * tag 'cifs-fixes-7.3-rc1' of https://git.manguebit.org/linux: (33 commits) cifs: fix loff_t underflow in cifs_remap_file_range() when len == 0 smb: client: reject a tree connect response whose byte count is too small cifs: call pagecache_isize_extended() in cifs_setsize() when extending smb: client: fix copy-paste error in WSL EA length accounting for $LXDEV smb: client: remove redundant NULL check before kfree() smb: client: restore the data_offset bound in is_valid_oplock_break() cifs: clear tcon after cifsFileInfo_put() in cifs_file_set_size() smb: client: Avoid leaking sensitive data to the heap in connect.c smb: client: Clear sensitive stack data in smb1encrypt.c smb: client: Clear sensitive stack data in cifsencrypt.c smb: client: Clear sensitive stack and heap data in smb2ops.c smb: client: Clear sensitive stack data in smb2transport.c Revert "cifs: remove all cifs files before kill super" smb: client: fix use-before-check of ReparseDataLength in reparse_buf_ptr() smb: client: fix ALIGN() overflow in symlink_data() error context loop smb: client: simplify __build_path_from_dentry_optional_prefix() smb: client: fix UAF and buffer leak in cifs_check_trans2() for malformed secondary T2 smb: client: fix OOB read/write from unvalidated DataOffset in coalesce_t2() smb/client: decode reparse metadata using its payload type smb/client: preserve open info type across compound queries ...

Linus Torvalds committed 2 months ago

Commit ce14fe42 parents 66498c7 6c322f522 files · +223 −108Browse files

Unified · Split

22 files
  1. fs/smb/client/cifs_debug.c +1 −1
  2. fs/smb/client/cifsencrypt.c +9 −3
  3. fs/smb/client/cifsfs.c +14 −7
  4. fs/smb/client/cifsfs.h +1 −0
  5. fs/smb/client/cifssmb.c +6 −0
  6. fs/smb/client/connect.c +1 −4
  7. fs/smb/client/dfs_cache.c +26 −7
  8. fs/smb/client/dir.c +3 −5
  9. fs/smb/client/file.c +1 −0
  10. fs/smb/client/inode.c +57 −33
  11. fs/smb/client/ioctl.c +1 −2
  12. fs/smb/client/reparse.h +10 −7
  13. fs/smb/client/smb1encrypt.c +9 −10
  14. fs/smb/client/smb1misc.c +2 −1
  15. fs/smb/client/smb1ops.c +8 −2
  16. fs/smb/client/smb1transport.c +31 −4
  17. fs/smb/client/smb2file.c +4 −1
  18. fs/smb/client/smb2inode.c +14 −8
  19. fs/smb/client/smb2ops.c +5 −8
  20. fs/smb/client/smb2pdu.c +14 −4
  21. fs/smb/client/smb2transport.c +4 −0
  22. fs/smb/client/trace.h +2 −1
fs/smb/client/cifs_debug.c+1−1
@@ -754,7 +754,7 @@ static ssize_t cifs_stats_proc_write(struct file *file, · 753 unmodified lines
754 atomic_set(&server->smb2slowcmd[i], 0);754 atomic_set(&server->smb2slowcmd[i], 0);
755 server->time_per_cmd[i] = 0;755 server->time_per_cmd[i] = 0;
756 server->slowest_cmd[i] = 0;756 server->slowest_cmd[i] = 0;
757 server->fastest_cmd[0] = 0;757 server->fastest_cmd[i] = 0;
758 }758 }
759#endif /* CONFIG_CIFS_STATS2 */759#endif /* CONFIG_CIFS_STATS2 */
760 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {760 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
fs/smb/client/cifsencrypt.c+9−3
@@ -249,12 +249,13 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash, · 248 unmodified lines
249 E_md4hash(ses->password, nt_hash, nls_cp);249 E_md4hash(ses->password, nt_hash, nls_cp);
250 250
251 hmac_md5_init_usingrawkey(&hmac_ctx, nt_hash, CIFS_NTHASH_SIZE);251 hmac_md5_init_usingrawkey(&hmac_ctx, nt_hash, CIFS_NTHASH_SIZE);
252 memzero_explicit(nt_hash, sizeof(nt_hash));
252 253
253 /* convert ses->user_name to unicode */254 /* convert ses->user_name to unicode */
254 len = ses->user_name ? strlen(ses->user_name) : 0;255 len = ses->user_name ? strlen(ses->user_name) : 0;
255 user = kmalloc(2 + (len * 2), GFP_KERNEL);256 user = kmalloc(2 + (len * 2), GFP_KERNEL);
256 if (user == NULL)257 if (user == NULL)
257 return -ENOMEM;258 goto out_nomem;
258 259
259 if (len) {260 if (len) {
260 len = cifs_strtoUTF16(user, ses->user_name, len, nls_cp);261 len = cifs_strtoUTF16(user, ses->user_name, len, nls_cp);
@@ -272,7 +273,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash, · 11 unmodified lines
272 273
273 domain = kmalloc(2 + (len * 2), GFP_KERNEL);274 domain = kmalloc(2 + (len * 2), GFP_KERNEL);
274 if (domain == NULL)275 if (domain == NULL)
275 return -ENOMEM;276 goto out_nomem;
276 277
277 len = cifs_strtoUTF16((__le16 *)domain, ses->domainName, len,278 len = cifs_strtoUTF16((__le16 *)domain, ses->domainName, len,
278 nls_cp);279 nls_cp);
@@ -284,7 +285,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash, · 5 unmodified lines
284 285
285 server = kmalloc(2 + (len * 2), GFP_KERNEL);286 server = kmalloc(2 + (len * 2), GFP_KERNEL);
286 if (server == NULL)287 if (server == NULL)
287 return -ENOMEM;288 goto out_nomem;
288 289
289 len = cifs_strtoUTF16((__le16 *)server, ses->ip_addr, len, nls_cp);290 len = cifs_strtoUTF16((__le16 *)server, ses->ip_addr, len, nls_cp);
290 hmac_md5_update(&hmac_ctx, (const u8 *)server, 2 * len);291 hmac_md5_update(&hmac_ctx, (const u8 *)server, 2 * len);
@@ -293,6 +294,10 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash, · 2 unmodified lines
293 294
294 hmac_md5_final(&hmac_ctx, ntlmv2_hash);295 hmac_md5_final(&hmac_ctx, ntlmv2_hash);
295 return 0;296 return 0;
297
298out_nomem:
299 memzero_explicit(&hmac_ctx, sizeof(hmac_ctx));
300 return -ENOMEM;
296}301}
297 302
298static void CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)303static void CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
@@ -463,6 +468,7 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp) · 164 unmodified lines
463 rc = 0;468 rc = 0;
464unlock:469unlock:
465 cifs_server_unlock(ses->server);470 cifs_server_unlock(ses->server);
471 memzero_explicit(ntlmv2_hash, sizeof(ntlmv2_hash));
466setup_ntlmv2_rsp_ret:472setup_ntlmv2_rsp_ret:
467 kfree_sensitive(tiblob);473 kfree_sensitive(tiblob);
468 474
fs/smb/client/cifsfs.c+14−7
@@ -1413,8 +1413,19 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off, · 1412 unmodified lines
1413 */1413 */
1414 lock_two_nondirectories(target_inode, src_inode);1414 lock_two_nondirectories(target_inode, src_inode);
1415 1415
1416 if (len == 0)1416 if (len == 0) {
1417 len = src_inode->i_size - off;1417 loff_t src_size = i_size_read(src_inode);
1418
1419 if (off > src_size) {
1420 rc = -EINVAL;
1421 goto unlock;
1422 }
1423 len = src_size - off;
1424 if (!len) {
1425 rc = 0;
1426 goto unlock;
1427 }
1428 }
1418 1429
1419 cifs_dbg(FYI, "clone range\n");1430 cifs_dbg(FYI, "clone range\n");
1420 1431
@@ -1466,11 +1477,7 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off, · 45 unmodified lines
1466 if (target_tcon->ses->server->ops->duplicate_extents) {1477 if (target_tcon->ses->server->ops->duplicate_extents) {
1467 rc = target_tcon->ses->server->ops->duplicate_extents(xid,1478 rc = target_tcon->ses->server->ops->duplicate_extents(xid,
1468 smb_file_src, smb_file_target, off, len, destoff);1479 smb_file_src, smb_file_target, off, len, destoff);
1469 if (rc == 0 && new_size > i_size) {1480 if (rc == -EOPNOTSUPP) {
1470 truncate_setsize(target_inode, new_size);
1471 fscache_resize_cookie(cifs_inode_cookie(target_inode),
1472 new_size);
1473 } else if (rc == -EOPNOTSUPP) {
1474 /*1481 /*
1475 * copy_file_range syscall man page indicates EINVAL1482 * copy_file_range syscall man page indicates EINVAL
1476 * is returned e.g when "fd_in and fd_out refer to the1483 * is returned e.g when "fd_in and fd_out refer to the
fs/smb/client/cifsfs.h+1−0
@@ -147,6 +147,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, struct file *src_file, · 146 unmodified lines
147 147
148long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg);148long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg);
149void cifs_setsize(struct inode *inode, loff_t offset);149void cifs_setsize(struct inode *inode, loff_t offset);
150void cifs_resize_file_locked(struct inode *inode, loff_t offset);
150 151
151struct fs_context;152struct fs_context;
152struct smb3_fs_context;153struct smb3_fs_context;
fs/smb/client/cifssmb.c+6−0
@@ -615,6 +615,11 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses, · 614 unmodified lines
615 tcon->tid = smb_buffer_response->Tid;615 tcon->tid = smb_buffer_response->Tid;
616 bcc_ptr = pByteArea(smb_buffer_response);616 bcc_ptr = pByteArea(smb_buffer_response);
617 bytes_left = get_bcc(smb_buffer_response);617 bytes_left = get_bcc(smb_buffer_response);
618 if (bytes_left < 2) {
619 rc = smb_EIO2(smb_eio_trace_tcon_bcc_too_small,
620 bytes_left, 2);
621 goto out;
622 }
618 length = strnlen(bcc_ptr, bytes_left - 2);623 length = strnlen(bcc_ptr, bytes_left - 2);
619 if (smb_buffer->Flags2 & SMBFLG2_UNICODE)624 if (smb_buffer->Flags2 & SMBFLG2_UNICODE)
620 is_unicode = true;625 is_unicode = true;
@@ -670,6 +675,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses, · 49 unmodified lines
670 reset_cifs_unix_caps(xid, tcon, NULL, NULL);675 reset_cifs_unix_caps(xid, tcon, NULL, NULL);
671 }676 }
672 }677 }
678out:
673 cifs_buf_release(smb_buffer);679 cifs_buf_release(smb_buffer);
674 return rc;680 return rc;
675}681}
fs/smb/client/connect.c+1−4
@@ -1143,7 +1143,7 @@ clean_demultiplex_info(struct TCP_Server_Info *server) · 1142 unmodified lines
1143 put_net(cifs_net_ns(server));1143 put_net(cifs_net_ns(server));
1144 kfree(server->leaf_fullpath);1144 kfree(server->leaf_fullpath);
1145 kfree(server->hostname);1145 kfree(server->hostname);
1146 kfree(server);1146 kfree_sensitive(server);
1147 1147
1148 length = atomic_dec_return(&tcpSesAllocCount);1148 length = atomic_dec_return(&tcpSesAllocCount);
1149 if (length > 0)1149 if (length > 0)
@@ -4003,9 +4003,6 @@ cifs_umount(struct cifs_sb_info *cifs_sb) · 2853 unmodified lines
4003 }4003 }
4004 spin_unlock(&cifs_sb->tlink_tree_lock);4004 spin_unlock(&cifs_sb->tlink_tree_lock);
4005 4005
4006 flush_workqueue(serverclose_wq);
4007 flush_workqueue(fileinfo_put_wq);
4008
4009 kfree(cifs_sb->prepath);4006 kfree(cifs_sb->prepath);
4010 call_rcu(&cifs_sb->rcu, delayed_free);4007 call_rcu(&cifs_sb->rcu, delayed_free);
4011}4008}
fs/smb/client/dfs_cache.c+26−7
@@ -122,6 +122,8 @@ static inline void free_tgts(struct cache_entry *ce) · 121 unmodified lines
122 kfree(t->name);122 kfree(t->name);
123 kfree(t);123 kfree(t);
124 }124 }
125
126 WRITE_ONCE(ce->tgthint, NULL);
125}127}
126 128
127static inline void flush_cache_ent(struct cache_entry *ce)129static inline void flush_cache_ent(struct cache_entry *ce)
@@ -869,13 +871,22 @@ int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses, const struct nl · 741 unmodified lines
869 goto out_free_path;871 goto out_free_path;
870 }872 }
871 873
872 if (ref)874 if (ref) {
873 rc = setup_referral(path, ce, ref, get_tgt_name(ce));875 char *target = get_tgt_name(ce);
874 else876
877 if (IS_ERR(target)) {
878 rc = PTR_ERR(target);
879 goto out_unlock;
880 }
881 rc = setup_referral(path, ce, ref, target);
882 } else {
875 rc = 0;883 rc = 0;
884 }
885
876 if (!rc && tgt_list)886 if (!rc && tgt_list)
877 rc = get_targets(ce, tgt_list);887 rc = get_targets(ce, tgt_list);
878 888
889out_unlock:
879 up_read(&htable_rw_lock);890 up_read(&htable_rw_lock);
880 891
881out_free_path:892out_free_path:
@@ -915,10 +926,17 @@ int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref, · 33 unmodified lines
915 goto out_unlock;926 goto out_unlock;
916 }927 }
917 928
918 if (ref)929 if (ref) {
919 rc = setup_referral(path, ce, ref, get_tgt_name(ce));930 char *target = get_tgt_name(ce);
920 else931
932 if (IS_ERR(target)) {
933 rc = PTR_ERR(target);
934 goto out_unlock;
935 }
936 rc = setup_referral(path, ce, ref, target);
937 } else {
921 rc = 0;938 rc = 0;
939 }
922 if (!rc && tgt_list)940 if (!rc && tgt_list)
923 rc = get_targets(ce, tgt_list);941 rc = get_targets(ce, tgt_list);
924 942
@@ -959,7 +977,8 @@ void dfs_cache_noreq_update_tgthint(const char *path, const struct dfs_cache_tgt · 34 unmodified lines
959 977
960 t = READ_ONCE(ce->tgthint);978 t = READ_ONCE(ce->tgthint);
961 979
962 if (unlikely(!strcasecmp(it->it_name, t->name)))980 /* Check 't' in case ce->tgthint was cleared by free_tgts() */
981 if (t && unlikely(!strcasecmp(it->it_name, t->name)))
963 goto out_unlock;982 goto out_unlock;
964 983
965 list_for_each_entry(t, &ce->tlist, list) {984 list_for_each_entry(t, &ce->tlist, list) {
fs/smb/client/dir.c+3−5
@@ -115,11 +115,7 @@ char *__build_path_from_dentry_optional_prefix(struct dentry *direntry, void *pa · 114 unmodified lines
115 }115 }
116 if (dirsep != '/') {116 if (dirsep != '/') {
117 /* BB test paths to Windows with '/' in the midst of prepath */117 /* BB test paths to Windows with '/' in the midst of prepath */
118 char *p;118 strreplace(s, '/', dirsep);
119
120 for (p = s; *p; p++)
121 if (*p == '/')
122 *p = dirsep;
123 }119 }
124 if (dfsplen) {120 if (dfsplen) {
125 s -= dfsplen;121 s -= dfsplen;
@@ -1138,6 +1134,8 @@ int cifs_tmpfile(struct mnt_idmap *idmap, struct inode *dir, · 1012 unmodified lines
1138 } while (unlikely(rc == -EEXIST) && ++retries < max_retries);1134 } while (unlikely(rc == -EEXIST) && ++retries < max_retries);
1139 1135
1140 if (rc) {1136 if (rc) {
1137 if (rc == -ENOENT)
1138 rc = -EOPNOTSUPP;
1141 cifs_del_pending_open(&open);1139 cifs_del_pending_open(&open);
1142 goto out;1140 goto out;
1143 }1141 }
fs/smb/client/file.c+1−0
@@ -1016,6 +1016,7 @@ static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry) · 1015 unmodified lines
1016 if (!rc) {1016 if (!rc) {
1017 netfs_resize_file(&cinode->netfs, 0, true);1017 netfs_resize_file(&cinode->netfs, 0, true);
1018 cifs_setsize(inode, 0);1018 cifs_setsize(inode, 0);
1019 cifs_invalidate_cache(inode, 0);
1019 }1020 }
1020 }1021 }
1021 if (cfile)1022 if (cfile)
fs/smb/client/inode.c+57−33
@@ -1215,7 +1215,7 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data, · 1214 unmodified lines
1215 break;1215 break;
1216 case IO_REPARSE_TAG_INTERNAL:1216 case IO_REPARSE_TAG_INTERNAL:
1217 rc = 0;1217 rc = 0;
1218 if (le32_to_cpu(data->fi.Attributes) & ATTR_DIRECTORY) {1218 if (cifs_open_data_attrs(data) & ATTR_DIRECTORY) {
1219 cifs_create_junction_fattr(fattr, sb);1219 cifs_create_junction_fattr(fattr, sb);
1220 goto out;1220 goto out;
1221 }1221 }
@@ -1239,7 +1239,7 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data, · 17 unmodified lines
1239 */1239 */
1240 if (rc == -EOPNOTSUPP &&1240 if (rc == -EOPNOTSUPP &&
1241 IS_REPARSE_TAG_NAME_SURROGATE(data->reparse.tag) &&1241 IS_REPARSE_TAG_NAME_SURROGATE(data->reparse.tag) &&
1242 (le32_to_cpu(data->fi.Attributes) & ATTR_DIRECTORY)) {1242 (cifs_open_data_attrs(data) & ATTR_DIRECTORY)) {
1243 rc = 0;1243 rc = 0;
1244 cifs_create_junction_fattr(fattr, sb);1244 cifs_create_junction_fattr(fattr, sb);
1245 goto out;1245 goto out;
@@ -1257,13 +1257,14 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data, · 11 unmodified lines
1257 }1257 }
1258 1258
1259 if (data->reparse.tag == IO_REPARSE_TAG_SYMLINK && !rc) {1259 if (data->reparse.tag == IO_REPARSE_TAG_SYMLINK && !rc) {
1260 bool directory = le32_to_cpu(data->fi.Attributes) & ATTR_DIRECTORY;1260 bool directory = cifs_open_data_attrs(data) & ATTR_DIRECTORY;
1261
1261 rc = smb2_fix_symlink_target_type(&data->symlink_target, directory, cifs_sb);1262 rc = smb2_fix_symlink_target_type(&data->symlink_target, directory, cifs_sb);
1262 }1263 }
1263 break;1264 break;
1264 }1265 }
1265 1266
1266 if (tcon->posix_extensions)1267 if (data->contains_posix_file_info)
1267 smb311_posix_info_to_fattr(fattr, data, sb);1268 smb311_posix_info_to_fattr(fattr, data, sb);
1268 else1269 else
1269 cifs_open_info_to_fattr(fattr, data, sb);1270 cifs_open_info_to_fattr(fattr, data, sb);
@@ -2655,11 +2656,8 @@ unlink_target: · 1385 unmodified lines
2655 if (d_really_is_positive(target_dentry)) {2656 if (d_really_is_positive(target_dentry)) {
2656 if (!rc) {2657 if (!rc) {
2657 struct inode *inode = d_inode(target_dentry);2658 struct inode *inode = d_inode(target_dentry);
2658 /*2659
2659 * Samba and ksmbd servers allow renaming a target2660 /* Update the target link count after rename. */
2660 * directory that is open, so make sure to update
2661 * ->i_nlink and then mark it as delete pending.
2662 */
2663 if (S_ISDIR(inode->i_mode)) {2661 if (S_ISDIR(inode->i_mode)) {
2664 drop_cached_dir_by_name(xid, tcon, to_name, cifs_sb);2662 drop_cached_dir_by_name(xid, tcon, to_name, cifs_sb);
2665 spin_lock(&inode->i_lock);2663 spin_lock(&inode->i_lock);
@@ -2670,6 +2668,10 @@ unlink_target: · 4 unmodified lines
2670 CIFS_I(inode)->time = 0; /* force reval */2668 CIFS_I(inode)->time = 0; /* force reval */
2671 inode_set_ctime_current(inode);2669 inode_set_ctime_current(inode);
2672 inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));2670 inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
2671 } else {
2672 cifs_mark_open_handles_for_deleted_file(inode, to_name);
2673 cifs_drop_nlink(inode);
2674 inode_set_ctime_current(inode);
2673 }2675 }
2674 } else if (rc == -EACCES || rc == -EEXIST) {2676 } else if (rc == -EACCES || rc == -EEXIST) {
2675 /*2677 /*
@@ -3064,9 +3066,27 @@ void cifs_setsize(struct inode *inode, loff_t offset) · 388 unmodified lines
3064 inode->i_blocks = blocks;3066 inode->i_blocks = blocks;
3065 spin_unlock(&inode->i_lock);3067 spin_unlock(&inode->i_lock);
3066 inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));3068 inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
3069 if (offset > old_size)
3070 pagecache_isize_extended(inode, old_size, offset);
3067 truncate_pagecache(inode, offset);3071 truncate_pagecache(inode, offset);
3068 netfs_wait_for_outstanding_io(inode);3072 netfs_wait_for_outstanding_io(inode);
3069 fscache_resize_cookie(cifs_inode_cookie(inode), offset);3073}
3074
3075void cifs_resize_file_locked(struct inode *inode, loff_t offset)
3076{
3077 struct fscache_cookie *cookie = cifs_inode_cookie(inode);
3078
3079 lockdep_assert_held_write(&inode->i_rwsem);
3080
3081 netfs_resize_file(netfs_inode(inode), offset, true);
3082 cifs_setsize(inode, offset);
3083
3084 if (!cookie)
3085 return;
3086
3087 fscache_use_cookie(cookie, true);
3088 fscache_resize_cookie(cookie, offset);
3089 cifs_fscache_unuse_inode_cookie(inode, true);
3070}3090}
3071 3091
3072int cifs_file_set_size(const unsigned int xid, struct dentry *dentry,3092int cifs_file_set_size(const unsigned int xid, struct dentry *dentry,
@@ -3107,6 +3127,7 @@ int cifs_file_set_size(const unsigned int xid, struct dentry *dentry, · 34 unmodified lines
3107 size, false);3127 size, false);
3108 cifs_dbg(FYI, "%s: set_file_size: rc = %d\n", __func__, rc);3128 cifs_dbg(FYI, "%s: set_file_size: rc = %d\n", __func__, rc);
3109 cifsFileInfo_put(open_file);3129 cifsFileInfo_put(open_file);
3130 tcon = NULL;
3110 }3131 }
3111 }3132 }
3112 3133
@@ -3132,10 +3153,8 @@ int cifs_file_set_size(const unsigned int xid, struct dentry *dentry, · 19 unmodified lines
3132 cifs_put_tlink(tlink);3153 cifs_put_tlink(tlink);
3133 3154
3134set_size_out:3155set_size_out:
3135 if (rc == 0) {3156 if (rc == 0)
3136 netfs_resize_file(&cifsInode->netfs, size, true);3157 cifs_resize_file_locked(inode, size);
3137 cifs_setsize(inode, size);
3138 }
3139 3158
3140 return rc;3159 return rc;
3141}3160}
@@ -3221,9 +3240,13 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) · 79 unmodified lines
3221 attrs->ia_valid &= ~(ATTR_CTIME | ATTR_MTIME);3240 attrs->ia_valid &= ~(ATTR_CTIME | ATTR_MTIME);
3222 }3241 }
3223 3242
3224 /* skip mode change if it's just for clearing setuid/setgid */3243 /*
3225 if (attrs->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))3244 * This function is only called when Unix extensions are in effect,
3226 attrs->ia_valid &= ~ATTR_MODE;3245 * so the mode is always sent to and stored on the server. Do not
3246 * skip the mode change when clearing setuid/setgid bits: dropping
3247 * ATTR_MODE here would leave those bits set on the server after a
3248 * write, which is a security issue.
3249 */
3227 3250
3228 args = kmalloc_obj(*args);3251 args = kmalloc_obj(*args);
3229 if (args == NULL) {3252 if (args == NULL) {
@@ -3296,13 +3319,6 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) · 66 unmodified lines
3296 if (rc)3319 if (rc)
3297 goto out;3320 goto out;
3298 3321
3299 if ((attrs->ia_valid & ATTR_SIZE) &&
3300 attrs->ia_size != i_size_read(inode)) {
3301 truncate_setsize(inode, attrs->ia_size);
3302 netfs_resize_file(&cifsInode->netfs, attrs->ia_size, true);
3303 fscache_resize_cookie(cifs_inode_cookie(inode), attrs->ia_size);
3304 }
3305
3306 setattr_copy(&nop_mnt_idmap, inode, attrs);3322 setattr_copy(&nop_mnt_idmap, inode, attrs);
3307 mark_inode_dirty(inode);3323 mark_inode_dirty(inode);
3308 3324
@@ -3432,8 +3448,23 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) · 123 unmodified lines
3432 attrs->ia_valid &= ~(ATTR_UID | ATTR_GID);3448 attrs->ia_valid &= ~(ATTR_UID | ATTR_GID);
3433 }3449 }
3434 3450
3435 /* skip mode change if it's just for clearing setuid/setgid */3451 /*
3436 if (attrs->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))3452 * Skip the mode change if it is only being done to clear the
3453 * setuid/setgid bits *and* the mode is emulated via the DOS
3454 * read-only attribute (the default, non-ACL case), which cannot
3455 * represent the setuid/setgid bits anyway.
3456 *
3457 * When the mode is instead stored on the server - i.e. with the
3458 * cifsacl or modefromsid mount options (via an ACL) or with the
3459 * SMB3.1.1 POSIX extensions - the cleared mode must be pushed to
3460 * the server. Dropping ATTR_MODE here would leave the setuid/
3461 * setgid bit set on the server after a write, which is a security
3462 * issue (the bits are not stripped as they are on local
3463 * filesystems).
3464 */
3465 if ((attrs->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID)) &&
3466 !((sbflags & (CIFS_MOUNT_CIFS_ACL | CIFS_MOUNT_MODE_FROM_SID)) ||
3467 cifs_sb_master_tcon(cifs_sb)->posix_extensions))
3437 attrs->ia_valid &= ~ATTR_MODE;3468 attrs->ia_valid &= ~ATTR_MODE;
3438 3469
3439 if (attrs->ia_valid & ATTR_MODE) {3470 if (attrs->ia_valid & ATTR_MODE) {
@@ -3508,13 +3539,6 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) · 68 unmodified lines
3508 if (rc)3539 if (rc)
3509 goto cifs_setattr_exit;3540 goto cifs_setattr_exit;
3510 3541
3511 if ((attrs->ia_valid & ATTR_SIZE) &&
3512 attrs->ia_size != i_size_read(inode)) {
3513 truncate_setsize(inode, attrs->ia_size);
3514 netfs_resize_file(&cifsInode->netfs, attrs->ia_size, true);
3515 fscache_resize_cookie(cifs_inode_cookie(inode), attrs->ia_size);
3516 }
3517
3518 setattr_copy(&nop_mnt_idmap, inode, attrs);3542 setattr_copy(&nop_mnt_idmap, inode, attrs);
3519 mark_inode_dirty(inode);3543 mark_inode_dirty(inode);
3520 3544
fs/smb/client/ioctl.c+1−2
@@ -133,8 +133,7 @@ static int cifs_set_compression_by_path(unsigned int xid, struct file *filep, · 132 unmodified lines
133 133
134close:134close:
135 server->ops->close(xid, tcon, &fid);135 server->ops->close(xid, tcon, &fid);
136 if (tmp_cfile)136 kfree(tmp_cfile);
137 kfree(tmp_cfile);
138 cifs_free_open_info(&data);137 cifs_free_open_info(&data);
139out:138out:
140 free_dentry_path(page);139 free_dentry_path(page);
fs/smb/client/reparse.h+10−7
@@ -98,15 +98,21 @@ static inline bool reparse_inode_match(struct inode *inode, · 97 unmodified lines
98 timespec64_equal(&ctime, &fattr->cf_ctime);98 timespec64_equal(&ctime, &fattr->cf_ctime);
99}99}
100 100
101static inline u32 cifs_open_data_attrs(const struct cifs_open_info_data *data)
102{
103 if (data->contains_posix_file_info)
104 return le32_to_cpu(data->posix_fi.DosAttributes);
105
106 return le32_to_cpu(data->fi.Attributes);
107}
108
101static inline bool cifs_open_data_reparse(struct cifs_open_info_data *data)109static inline bool cifs_open_data_reparse(struct cifs_open_info_data *data)
102{110{
103 u32 attrs;111 u32 attrs = cifs_open_data_attrs(data);
104 bool ret;
105 112
106 if (data->contains_posix_file_info) {113 if (data->contains_posix_file_info) {
107 struct smb311_posix_qinfo *fi = &data->posix_fi;114 struct smb311_posix_qinfo *fi = &data->posix_fi;
108 115
109 attrs = le32_to_cpu(fi->DosAttributes);
110 if (data->reparse_point) {116 if (data->reparse_point) {
111 attrs |= ATTR_REPARSE_POINT;117 attrs |= ATTR_REPARSE_POINT;
112 fi->DosAttributes = cpu_to_le32(attrs);118 fi->DosAttributes = cpu_to_le32(attrs);
@@ -115,16 +121,13 @@ static inline bool cifs_open_data_reparse(struct cifs_open_info_data *data) · 2 unmodified lines
115 } else {121 } else {
116 struct smb2_file_all_info *fi = &data->fi;122 struct smb2_file_all_info *fi = &data->fi;
117 123
118 attrs = le32_to_cpu(fi->Attributes);
119 if (data->reparse_point) {124 if (data->reparse_point) {
120 attrs |= ATTR_REPARSE_POINT;125 attrs |= ATTR_REPARSE_POINT;
121 fi->Attributes = cpu_to_le32(attrs);126 fi->Attributes = cpu_to_le32(attrs);
122 }127 }
123 }128 }
124 129
125 ret = attrs & ATTR_REPARSE_POINT;130 return attrs & ATTR_REPARSE_POINT;
126
127 return ret;
128}131}
129 132
130bool cifs_reparse_point_to_fattr(struct cifs_sb_info *cifs_sb,133bool cifs_reparse_point_to_fattr(struct cifs_sb_info *cifs_sb,
fs/smb/client/smb1encrypt.c+9−10
@@ -81,6 +81,7 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, · 80 unmodified lines
81 else81 else
82 memcpy(cifs_pdu->Signature.SecuritySignature, smb_signature, 8);82 memcpy(cifs_pdu->Signature.SecuritySignature, smb_signature, 8);
83 83
84 memzero_explicit(smb_signature, sizeof(smb_signature));
84 return rc;85 return rc;
85}86}
86 87
@@ -126,15 +127,13 @@ int cifs_verify_signature(struct smb_rqst *rqst, · 39 unmodified lines
126 rc = cifs_calc_signature(rqst, server, what_we_think_sig_should_be);127 rc = cifs_calc_signature(rqst, server, what_we_think_sig_should_be);
127 cifs_server_unlock(server);128 cifs_server_unlock(server);
128 129
129 if (rc)130 if (!rc) {
130 return rc;131 if (crypto_memneq(server_response_sig,
131 132 what_we_think_sig_should_be, 8))
132/* cifs_dump_mem("what we think it should be: ",133 rc = -EACCES;
133 what_we_think_sig_should_be, 16); */134 }
134
135 if (crypto_memneq(server_response_sig, what_we_think_sig_should_be, 8))
136 return -EACCES;
137 else
138 return 0;
139 135
136 memzero_explicit(what_we_think_sig_should_be,
137 sizeof(what_we_think_sig_should_be));
138 return rc;
140}139}
fs/smb/client/smb1misc.c+2−1
@@ -80,7 +80,8 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv) · 79 unmodified lines
80 (struct smb_com_transaction_change_notify_rsp *)buf;80 (struct smb_com_transaction_change_notify_rsp *)buf;
81 struct file_notify_information *pnotify;81 struct file_notify_information *pnotify;
82 __u32 data_offset = 0;82 __u32 data_offset = 0;
83 size_t len = srv->total_read - srv->pdu_size;83 /* total_read excludes the RFC1002 preamble */
84 size_t len = srv->total_read;
84 85
85 if (get_bcc(buf) > sizeof(struct file_notify_information)) {86 if (get_bcc(buf) > sizeof(struct file_notify_information)) {
86 data_offset = le32_to_cpu(pSMBr->DataOffset);87 data_offset = le32_to_cpu(pSMBr->DataOffset);
fs/smb/client/smb1ops.c+8−2
@@ -542,6 +542,7 @@ static int cifs_query_path_info(const unsigned int xid, · 541 unmodified lines
542 542
543 data->reparse_point = false;543 data->reparse_point = false;
544 data->adjust_tz = false;544 data->adjust_tz = false;
545 data->unknown_nlink = false;
545 546
546 /*547 /*
547 * First try CIFSSMBQPathInfo() function which returns more info548 * First try CIFSSMBQPathInfo() function which returns more info
@@ -608,6 +609,7 @@ static int cifs_query_path_info(const unsigned int xid, · 60 unmodified lines
608 fi.EASize = di->EaSize;609 fi.EASize = di->EaSize;
609 }610 }
610 fi.NumberOfLinks = cpu_to_le32(1);611 fi.NumberOfLinks = cpu_to_le32(1);
612 data->unknown_nlink = true;
611 fi.DeletePending = 0;613 fi.DeletePending = 0;
612 fi.Directory = !!(le32_to_cpu(fi.Attributes) & ATTR_DIRECTORY);614 fi.Directory = !!(le32_to_cpu(fi.Attributes) & ATTR_DIRECTORY);
613 cifs_buf_release(search_info.ntwrk_buf_start);615 cifs_buf_release(search_info.ntwrk_buf_start);
@@ -630,6 +632,8 @@ static int cifs_query_path_info(const unsigned int xid, · 16 unmodified lines
630 rc = SMBQueryInformation(xid, tcon, full_path, &fi, cifs_sb->local_nls,632 rc = SMBQueryInformation(xid, tcon, full_path, &fi, cifs_sb->local_nls,
631 cifs_remap(cifs_sb));633 cifs_remap(cifs_sb));
632 data->adjust_tz = true;634 data->adjust_tz = true;
635 if (!rc)
636 data->unknown_nlink = true;
633 } else if ((rc == -EOPNOTSUPP || rc == -EINVAL) && non_unicode_wildcard) {637 } else if ((rc == -EOPNOTSUPP || rc == -EINVAL) && non_unicode_wildcard) {
634 /* Path with non-UNICODE wildcard character cannot exist. */638 /* Path with non-UNICODE wildcard character cannot exist. */
635 rc = -ENOENT;639 rc = -ENOENT;
@@ -717,7 +721,7 @@ static int cifs_query_path_info(const unsigned int xid, · 81 unmodified lines
717 ea->ea_value_length = cpu_to_le16(SMB2_WSL_XATTR_DEV_SIZE);721 ea->ea_value_length = cpu_to_le16(SMB2_WSL_XATTR_DEV_SIZE);
718 memcpy(&ea->ea_data[0], SMB2_WSL_XATTR_DEV, SMB2_WSL_XATTR_NAME_LEN + 1);722 memcpy(&ea->ea_data[0], SMB2_WSL_XATTR_DEV, SMB2_WSL_XATTR_NAME_LEN + 1);
719 data->wsl.eas_len += ALIGN(sizeof(*ea) + SMB2_WSL_XATTR_NAME_LEN + 1 +723 data->wsl.eas_len += ALIGN(sizeof(*ea) + SMB2_WSL_XATTR_NAME_LEN + 1 +
720 SMB2_WSL_XATTR_MODE_SIZE, 4);724 SMB2_WSL_XATTR_DEV_SIZE, 4);
721 rc = 0;725 rc = 0;
722 } else if (rc >= 0) {726 } else if (rc >= 0) {
723 /* It is an error if EA $LXDEV has wrong size. */727 /* It is an error if EA $LXDEV has wrong size. */
@@ -893,8 +897,10 @@ static int cifs_open_file(const unsigned int xid, struct cifs_open_parms *oparms · 169 unmodified lines
893 else897 else
894 rc = CIFS_open(xid, oparms, oplock, &fi);898 rc = CIFS_open(xid, oparms, oplock, &fi);
895 899
896 if (!rc && data)900 if (!rc && data) {
897 move_cifs_info_to_smb2(&data->fi, &fi);901 move_cifs_info_to_smb2(&data->fi, &fi);
902 data->unknown_nlink = true;
903 }
898 904
899 return rc;905 return rc;
900}906}
fs/smb/client/smb1transport.c+31−4
@@ -375,12 +375,31 @@ coalesce_t2(char *second_buf, struct smb_hdr *target_hdr, unsigned int *pdu_len) · 374 unmodified lines
375 data_area_of_tgt = (char *)&pSMBt->hdr.Protocol +375 data_area_of_tgt = (char *)&pSMBt->hdr.Protocol +
376 get_unaligned_le16(&pSMBt->t2_rsp.DataOffset);376 get_unaligned_le16(&pSMBt->t2_rsp.DataOffset);
377 377
378 /* validate target area */
379 data_area_of_src = (char *)&pSMBs->hdr.Protocol +378 data_area_of_src = (char *)&pSMBs->hdr.Protocol +
380 get_unaligned_le16(&pSMBs->t2_rsp.DataOffset);379 get_unaligned_le16(&pSMBs->t2_rsp.DataOffset);
381 380
382 data_area_of_tgt += total_in_tgt;381 data_area_of_tgt += total_in_tgt;
383 382
383 /*
384 * DataOffset fields are server-supplied and not validated against
385 * buffer bounds; check both data pointers before mutating the
386 * target header.
387 */
388 if (data_area_of_tgt < (char *)target_hdr +
389 sizeof(struct smb_t2_rsp) + sizeof(__le16) ||
390 data_area_of_tgt + total_in_src >
391 (char *)target_hdr + CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
392 cifs_dbg(VFS, "%s: target data area out of bounds\n", __func__);
393 return -EPROTO;
394 }
395 if (data_area_of_src < second_buf +
396 sizeof(struct smb_t2_rsp) + sizeof(__le16) ||
397 data_area_of_src + total_in_src >
398 second_buf + smbCalcSize((struct smb_hdr *)second_buf)) {
399 cifs_dbg(VFS, "%s: secondary data area out of bounds\n", __func__);
400 return -EPROTO;
401 }
402
384 total_in_tgt += total_in_src;403 total_in_tgt += total_in_src;
385 /* is the result too big for the field? */404 /* is the result too big for the field? */
386 if (total_in_tgt > USHRT_MAX) {405 if (total_in_tgt > USHRT_MAX) {
@@ -430,10 +449,18 @@ bool · 43 unmodified lines
430cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server,449cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server,
431 char *buf, int malformed)450 char *buf, int malformed)
432{451{
433 if (malformed)452 if (malformed || check2ndT2(buf) <= 0) {
434 return false;453 /* mid->multiRsp blocks the server buf detach in handle_mid();
435 if (check2ndT2(buf) <= 0)454 * returning false here would leak resp_buf and leave a dangling
455 * server->smallbuf/bigbuf after the user thread frees resp_buf.
456 */
457 if (mid->multiRsp) {
458 mid->multiEnd = true;
459 dequeue_mid(server, mid, true);
460 return true;
461 }
436 return false;462 return false;
463 }
437 mid->multiRsp = true;464 mid->multiRsp = true;
438 if (mid->resp_buf) {465 if (mid->resp_buf) {
439 /* merge response - fix up 1st*/466 /* merge response - fix up 1st*/
fs/smb/client/smb2file.c+4−1
@@ -61,7 +61,10 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov) · 60 unmodified lines
61 cifs_dbg(FYI, "%s: skipping unhandled error context: 0x%x\n",61 cifs_dbg(FYI, "%s: skipping unhandled error context: 0x%x\n",
62 __func__, le32_to_cpu(p->ErrorId));62 __func__, le32_to_cpu(p->ErrorId));
63 63
64 len = ALIGN(le32_to_cpu(p->ErrorDataLength), 8);64 len = le32_to_cpu(p->ErrorDataLength);
65 if (len > end - ((u8 *)p + sizeof(*p)))
66 return ERR_PTR(-EINVAL);
67 len = ALIGN(len, 8);
65 if (len > end - ((u8 *)p + sizeof(*p)))68 if (len > end - ((u8 *)p + sizeof(*p)))
66 return ERR_PTR(-EINVAL);69 return ERR_PTR(-EINVAL);
67 70
fs/smb/client/smb2inode.c+14−8
@@ -22,6 +22,7 @@ · 21 unmodified lines
22#include "smb2glob.h"22#include "smb2glob.h"
23#include "smb2proto.h"23#include "smb2proto.h"
24#include "cached_dir.h"24#include "cached_dir.h"
25#include "reparse.h"
25#include "../common/smb2status.h"26#include "../common/smb2status.h"
26#include "../common/smbfsctl.h"27#include "../common/smbfsctl.h"
27 28
@@ -40,9 +41,11 @@ static struct reparse_data_buffer *reparse_buf_ptr(struct kvec *iov) · 12 unmodified lines
40 41
41 buf = (struct reparse_data_buffer *)((u8 *)io + off);42 buf = (struct reparse_data_buffer *)((u8 *)io + off);
42 len = sizeof(*buf);43 len = sizeof(*buf);
43 rdlen = le16_to_cpu(buf->ReparseDataLength);44 if (count < len)
45 return ERR_PTR(smb_EIO2(smb_eio_trace_reparse_rdlen, count, 0));
44 46
45 if (count < len || count < rdlen + len)47 rdlen = le16_to_cpu(buf->ReparseDataLength);
48 if (count < rdlen + len)
46 return ERR_PTR(smb_EIO2(smb_eio_trace_reparse_rdlen, count, rdlen));49 return ERR_PTR(smb_EIO2(smb_eio_trace_reparse_rdlen, count, rdlen));
47 return buf;50 return buf;
48}51}
@@ -574,8 +577,10 @@ finished: · 525 unmodified lines
574 idata->fi.Attributes = create_rsp->FileAttributes;577 idata->fi.Attributes = create_rsp->FileAttributes;
575 idata->fi.AllocationSize = create_rsp->AllocationSize;578 idata->fi.AllocationSize = create_rsp->AllocationSize;
576 idata->fi.EndOfFile = create_rsp->EndofFile;579 idata->fi.EndOfFile = create_rsp->EndofFile;
580 idata->contains_posix_file_info = false;
577 if (le32_to_cpu(idata->fi.NumberOfLinks) == 0)581 if (le32_to_cpu(idata->fi.NumberOfLinks) == 0)
578 idata->fi.NumberOfLinks = cpu_to_le32(1); /* dummy value */582 idata->fi.NumberOfLinks = cpu_to_le32(1); /* dummy value */
583 idata->unknown_nlink = true;
579 idata->fi.DeletePending = 0; /* successful open = not delete pending */584 idata->fi.DeletePending = 0; /* successful open = not delete pending */
580 idata->fi.Directory = !!(le32_to_cpu(create_rsp->FileAttributes) & ATTR_DIRECTORY);585 idata->fi.Directory = !!(le32_to_cpu(create_rsp->FileAttributes) & ATTR_DIRECTORY);
581 586
@@ -596,7 +601,6 @@ finished: · 14 unmodified lines
596 switch (cmds[i]) {601 switch (cmds[i]) {
597 case SMB2_OP_QUERY_INFO:602 case SMB2_OP_QUERY_INFO:
598 idata = in_iov[i].iov_base;603 idata = in_iov[i].iov_base;
599 idata->contains_posix_file_info = false;
600 if (rc == 0 && cfile && cfile->symlink_target) {604 if (rc == 0 && cfile && cfile->symlink_target) {
601 idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);605 idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
602 if (!idata->symlink_target)606 if (!idata->symlink_target)
@@ -609,6 +613,8 @@ finished: · 6 unmodified lines
609 le16_to_cpu(qi_rsp->OutputBufferOffset),613 le16_to_cpu(qi_rsp->OutputBufferOffset),
610 le32_to_cpu(qi_rsp->OutputBufferLength),614 le32_to_cpu(qi_rsp->OutputBufferLength),
611 &rsp_iov[i + 1], sizeof(idata->fi), (char *)&idata->fi);615 &rsp_iov[i + 1], sizeof(idata->fi), (char *)&idata->fi);
616 if (!rc)
617 idata->contains_posix_file_info = false;
612 }618 }
613 SMB2_query_info_free(&rqst[num_rqst++]);619 SMB2_query_info_free(&rqst[num_rqst++]);
614 if (rc)620 if (rc)
@@ -620,7 +626,6 @@ finished: · 5 unmodified lines
620 break;626 break;
621 case SMB2_OP_POSIX_QUERY_INFO:627 case SMB2_OP_POSIX_QUERY_INFO:
622 idata = in_iov[i].iov_base;628 idata = in_iov[i].iov_base;
623 idata->contains_posix_file_info = true;
624 if (rc == 0 && cfile && cfile->symlink_target) {629 if (rc == 0 && cfile && cfile->symlink_target) {
625 idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);630 idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
626 if (!idata->symlink_target)631 if (!idata->symlink_target)
@@ -634,6 +639,8 @@ finished: · 7 unmodified lines
634 le32_to_cpu(qi_rsp->OutputBufferLength),639 le32_to_cpu(qi_rsp->OutputBufferLength),
635 &rsp_iov[i + 1], sizeof(idata->posix_fi) /* add SIDs */,640 &rsp_iov[i + 1], sizeof(idata->posix_fi) /* add SIDs */,
636 (char *)&idata->posix_fi);641 (char *)&idata->posix_fi);
642 if (!rc)
643 idata->contains_posix_file_info = true;
637 }644 }
638 if (rc == 0)645 if (rc == 0)
639 rc = parse_posix_sids(idata, &rsp_iov[i + 1]);646 rc = parse_posix_sids(idata, &rsp_iov[i + 1]);
@@ -705,7 +712,6 @@ finished: · 65 unmodified lines
705 idata = in_iov[i].iov_base;712 idata = in_iov[i].iov_base;
706 idata->reparse.io.iov = *iov;713 idata->reparse.io.iov = *iov;
707 idata->reparse.io.buftype = resp_buftype[i + 1];714 idata->reparse.io.buftype = resp_buftype[i + 1];
708 idata->contains_posix_file_info = false; /* BB VERIFY */
709 rbuf = reparse_buf_ptr(iov);715 rbuf = reparse_buf_ptr(iov);
710 if (IS_ERR(rbuf)) {716 if (IS_ERR(rbuf)) {
711 rc = PTR_ERR(rbuf);717 rc = PTR_ERR(rbuf);
@@ -727,7 +733,6 @@ finished: · 15 unmodified lines
727 case SMB2_OP_QUERY_WSL_EA:733 case SMB2_OP_QUERY_WSL_EA:
728 if (!rc) {734 if (!rc) {
729 idata = in_iov[i].iov_base;735 idata = in_iov[i].iov_base;
730 idata->contains_posix_file_info = false;
731 qi_rsp = rsp_iov[i + 1].iov_base;736 qi_rsp = rsp_iov[i + 1].iov_base;
732 data[0] = (u8 *)qi_rsp + le16_to_cpu(qi_rsp->OutputBufferOffset);737 data[0] = (u8 *)qi_rsp + le16_to_cpu(qi_rsp->OutputBufferOffset);
733 size[0] = le32_to_cpu(qi_rsp->OutputBufferLength);738 size[0] = le32_to_cpu(qi_rsp->OutputBufferLength);
@@ -1000,12 +1005,13 @@ int smb2_query_path_info(const unsigned int xid, · 266 unmodified lines
1000 /*1005 /*
1001 * If the symlink was already parsed in create response then it is needed to fix1006 * If the symlink was already parsed in create response then it is needed to fix
1002 * its type now (after the second call with OPEN_REPARSE_POINT which filled the1007 * its type now (after the second call with OPEN_REPARSE_POINT which filled the
1003 * data->fi.Attributes). If the symlink was not parsed in create response then1008 * metadata attributes). If the symlink was not parsed in create response then
1004 * the data->symlink_target was not filled yet and then the type will be fixed1009 * the data->symlink_target was not filled yet and then the type will be fixed
1005 * later after data->symlink_target is filled.1010 * later after data->symlink_target is filled.
1006 */1011 */
1007 if (data->reparse.tag == IO_REPARSE_TAG_SYMLINK && !rc && data->symlink_target) {1012 if (data->reparse.tag == IO_REPARSE_TAG_SYMLINK && !rc && data->symlink_target) {
1008 bool directory = le32_to_cpu(data->fi.Attributes) & ATTR_DIRECTORY;1013 bool directory = cifs_open_data_attrs(data) & ATTR_DIRECTORY;
1014
1009 rc = smb2_fix_symlink_target_type(&data->symlink_target, directory, cifs_sb);1015 rc = smb2_fix_symlink_target_type(&data->symlink_target, directory, cifs_sb);
1010 }1016 }
1011 break;1017 break;
fs/smb/client/smb2ops.c+5−8
@@ -1569,7 +1569,7 @@ SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, · 1568 unmodified lines
1569 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);1569 memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
1570 1570
1571req_res_key_exit:1571req_res_key_exit:
1572 kfree(res_key);1572 kfree_sensitive(res_key);
1573 return rc;1573 return rc;
1574}1574}
1575 1575
@@ -2222,8 +2222,7 @@ smb2_duplicate_extents(const unsigned int xid, · 646 unmodified lines
2222 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);2222 rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false);
2223 if (rc)2223 if (rc)
2224 goto duplicate_extents_out;2224 goto duplicate_extents_out;
2225 netfs_resize_file(netfs_inode(inode), dest_off + len, true);2225 cifs_resize_file_locked(inode, dest_off + len);
2226 cifs_setsize(inode, dest_off + len);
2227 }2226 }
2228 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,2227 rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
2229 trgtfile->fid.volatile_fid,2228 trgtfile->fid.volatile_fid,
@@ -3776,8 +3775,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, · 1546 unmodified lines
3776 }3775 }
3777 3776
3778 new_eof = off + len;3777 new_eof = off + len;
3779 netfs_resize_file(&cifsi->netfs, new_eof, true);3778 cifs_resize_file_locked(inode, new_eof);
3780 cifs_setsize(inode, new_eof);
3781 3779
3782 qrc = SMB2_query_info(xid, tcon,3780 qrc = SMB2_query_info(xid, tcon,
3783 cfile->fid.persistent_fid,3781 cfile->fid.persistent_fid,
@@ -3825,8 +3823,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, · 41 unmodified lines
3825 if (rc)3823 if (rc)
3826 goto out;3824 goto out;
3827 3825
3828 netfs_resize_file(&cifsi->netfs, new_eof, true);3826 cifs_resize_file_locked(inode, new_eof);
3829 cifs_setsize(inode, new_eof);
3830 3827
3831 qrc = SMB2_query_info(xid, tcon,3828 qrc = SMB2_query_info(xid, tcon,
3832 cfile->fid.persistent_fid,3829 cfile->fid.persistent_fid,
@@ -4636,7 +4633,7 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst, · 803 unmodified lines
4636 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);4633 rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE);
4637 else4634 else
4638 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);4635 rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE);
4639 4636 memzero_explicit(key, sizeof(key));
4640 if (rc) {4637 if (rc) {
4641 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);4638 cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc);
4642 return rc;4639 return rc;
fs/smb/client/smb2pdu.c+14−4
@@ -3372,6 +3372,7 @@ replay_again: · 3371 unmodified lines
3372#endif /* CIFS_DEBUG2 */3372#endif /* CIFS_DEBUG2 */
3373 3373
3374 if (file_info) {3374 if (file_info) {
3375 buf->contains_posix_file_info = false;
3375 file_info->CreationTime = rsp->CreationTime;3376 file_info->CreationTime = rsp->CreationTime;
3376 file_info->LastAccessTime = rsp->LastAccessTime;3377 file_info->LastAccessTime = rsp->LastAccessTime;
3377 file_info->LastWriteTime = rsp->LastWriteTime;3378 file_info->LastWriteTime = rsp->LastWriteTime;
@@ -4564,8 +4565,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len, · 1186 unmodified lines
4564 if (rc)4565 if (rc)
4565 return rc;4566 return rc;
4566 4567
4567 if (server == NULL)4568 if (!server) {
4568 return -ECONNABORTED;4569 rc = -ECONNABORTED;
4570 goto free_req;
4571 }
4569 4572
4570 shdr = &req->hdr;4573 shdr = &req->hdr;
4571 shdr->Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid);4574 shdr->Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid);
@@ -4596,8 +4599,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len, · 24 unmodified lines
4596 4599
4597 rdata->mr = smbd_register_mr(server->smbd_conn, &rdata->subreq.io_iter,4600 rdata->mr = smbd_register_mr(server->smbd_conn, &rdata->subreq.io_iter,
4598 true, need_invalidate);4601 true, need_invalidate);
4599 if (!rdata->mr)4602 if (!rdata->mr) {
4600 return -EAGAIN;4603 rc = -EAGAIN;
4604 goto free_req;
4605 }
4601 4606
4602 req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE;4607 req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE;
4603 if (need_invalidate)4608 if (need_invalidate)
@@ -4638,6 +4643,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len, · 34 unmodified lines
4638 4643
4639 *buf = req;4644 *buf = req;
4640 return rc;4645 return rc;
4646
4647free_req:
4648 cifs_small_buf_release(req);
4649 return rc;
4641}4650}
4642 4651
4643static void4652static void
@@ -4885,6 +4894,7 @@ out: · 241 unmodified lines
4885 smb2_should_replay(tcon,4894 smb2_should_replay(tcon,
4886 &rdata->retries,4895 &rdata->retries,
4887 &rdata->cur_sleep)) {4896 &rdata->cur_sleep)) {
4897 rdata->replay = true;
4888 trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed);4898 trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed);
4889 __set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags);4899 __set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags);
4890 }4900 }
fs/smb/client/smb2transport.c+4−0
@@ -249,6 +249,8 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) · 248 unmodified lines
249 if (!rc)249 if (!rc)
250 memcpy(shdr->Signature, smb2_signature, SMB2_SIGNATURE_SIZE);250 memcpy(shdr->Signature, smb2_signature, SMB2_SIGNATURE_SIZE);
251 251
252 memzero_explicit(key, sizeof(key));
253 memzero_explicit(&hmac_ctx, sizeof(hmac_ctx));
252 return rc;254 return rc;
253}255}
254 256
@@ -283,6 +285,7 @@ static void generate_key(struct cifs_ses *ses, struct kvec label, · 28 unmodified lines
283 hmac_sha256_final(&hmac_ctx, prfhash);285 hmac_sha256_final(&hmac_ctx, prfhash);
284 286
285 memcpy(key, prfhash, key_size);287 memcpy(key, prfhash, key_size);
288 memzero_explicit(prfhash, sizeof(prfhash));
286}289}
287 290
288struct derivation {291struct derivation {
@@ -482,6 +485,7 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) · 193 unmodified lines
482 memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE);485 memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE);
483 486
484 rc = aes_cmac_preparekey(&cmac_key, key, SMB2_CMACAES_SIZE);487 rc = aes_cmac_preparekey(&cmac_key, key, SMB2_CMACAES_SIZE);
488 memzero_explicit(key, sizeof(key));
485 if (rc) {489 if (rc) {
486 cifs_server_dbg(VFS, "%s: Could not set key for cmac aes\n", __func__);490 cifs_server_dbg(VFS, "%s: Could not set key for cmac aes\n", __func__);
487 return rc;491 return rc;
fs/smb/client/trace.h+2−1
@@ -133,6 +133,7 @@ · 132 unmodified lines
133 EM(smb_eio_trace_sym_slash, "sym_slash") \133 EM(smb_eio_trace_sym_slash, "sym_slash") \
134 EM(smb_eio_trace_sym_target_len, "sym_target_len") \134 EM(smb_eio_trace_sym_target_len, "sym_target_len") \
135 EM(smb_eio_trace_symlink_file_size, "symlink_file_size") \135 EM(smb_eio_trace_symlink_file_size, "symlink_file_size") \
136 EM(smb_eio_trace_tcon_bcc_too_small, "tcon_bcc_too_small") \
136 EM(smb_eio_trace_tdis_in_reconnect, "tdis_in_reconnect") \137 EM(smb_eio_trace_tdis_in_reconnect, "tdis_in_reconnect") \
137 EM(smb_eio_trace_tx_chained_async, "tx_chained_async") \138 EM(smb_eio_trace_tx_chained_async, "tx_chained_async") \
138 EM(smb_eio_trace_tx_compress_failed, "tx_compress_failed") \139 EM(smb_eio_trace_tx_compress_failed, "tx_compress_failed") \
@@ -213,7 +214,7 @@ · 74 unmodified lines
213#define EM(a, b) a,214#define EM(a, b) a,
214#define E_(a, b) a215#define E_(a, b) a
215 216
216enum smb_eio_trace { smb_eio_traces } __mode(byte);217enum smb_eio_trace { smb_eio_traces };
217enum smb3_rw_credits_trace { smb3_rw_credits_traces } __mode(byte);218enum smb3_rw_credits_trace { smb3_rw_credits_traces } __mode(byte);
218enum smb3_tcon_ref_trace { smb3_tcon_ref_traces } __mode(byte);219enum smb3_tcon_ref_trace { smb3_tcon_ref_traces } __mode(byte);
219 220

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t