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 ...
Unified · Split
| @@ -754,7 +754,7 @@ static ssize_t cifs_stats_proc_write(struct file *file, · 753 unmodified lines | ||
| 754 | 754 | atomic_set(&server->smb2slowcmd[i], 0); |
| 755 | 755 | server->time_per_cmd[i] = 0; |
| 756 | 756 | server->slowest_cmd[i] = 0; |
| 757 | − server->fastest_cmd[0] = 0; | |
| 757 | + server->fastest_cmd[i] = 0; | |
| 758 | 758 | } |
| 759 | 759 | #endif /* CONFIG_CIFS_STATS2 */ |
| 760 | 760 | list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { |
| @@ -249,12 +249,13 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash, · 248 unmodified lines | ||
| 249 | 249 | E_md4hash(ses->password, nt_hash, nls_cp); |
| 250 | 250 | |
| 251 | 251 | hmac_md5_init_usingrawkey(&hmac_ctx, nt_hash, CIFS_NTHASH_SIZE); |
| 252 | + memzero_explicit(nt_hash, sizeof(nt_hash)); | |
| 252 | 253 | |
| 253 | 254 | /* convert ses->user_name to unicode */ |
| 254 | 255 | len = ses->user_name ? strlen(ses->user_name) : 0; |
| 255 | 256 | user = kmalloc(2 + (len * 2), GFP_KERNEL); |
| 256 | 257 | if (user == NULL) |
| 257 | − return -ENOMEM; | |
| 258 | + goto out_nomem; | |
| 258 | 259 | |
| 259 | 260 | if (len) { |
| 260 | 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 | 274 | domain = kmalloc(2 + (len * 2), GFP_KERNEL); |
| 274 | 275 | if (domain == NULL) |
| 275 | − return -ENOMEM; | |
| 276 | + goto out_nomem; | |
| 276 | 277 | |
| 277 | 278 | len = cifs_strtoUTF16((__le16 *)domain, ses->domainName, len, |
| 278 | 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 | 286 | server = kmalloc(2 + (len * 2), GFP_KERNEL); |
| 286 | 287 | if (server == NULL) |
| 287 | − return -ENOMEM; | |
| 288 | + goto out_nomem; | |
| 288 | 289 | |
| 289 | 290 | len = cifs_strtoUTF16((__le16 *)server, ses->ip_addr, len, nls_cp); |
| 290 | 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 | 295 | hmac_md5_final(&hmac_ctx, ntlmv2_hash); |
| 295 | 296 | return 0; |
| 297 | + | |
| 298 | +out_nomem: | |
| 299 | + memzero_explicit(&hmac_ctx, sizeof(hmac_ctx)); | |
| 300 | + return -ENOMEM; | |
| 296 | 301 | } |
| 297 | 302 | |
| 298 | 303 | static 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 | 468 | rc = 0; |
| 464 | 469 | unlock: |
| 465 | 470 | cifs_server_unlock(ses->server); |
| 471 | + memzero_explicit(ntlmv2_hash, sizeof(ntlmv2_hash)); | |
| 466 | 472 | setup_ntlmv2_rsp_ret: |
| 467 | 473 | kfree_sensitive(tiblob); |
| 468 | 474 | |
| @@ -1413,8 +1413,19 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off, · 1412 unmodified lines | ||
| 1413 | 1413 | */ |
| 1414 | 1414 | lock_two_nondirectories(target_inode, src_inode); |
| 1415 | 1415 | |
| 1416 | − if (len == 0) | |
| 1417 | − len = src_inode->i_size - off; | |
| 1416 | + if (len == 0) { | |
| 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 | 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 | 1477 | if (target_tcon->ses->server->ops->duplicate_extents) { |
| 1467 | 1478 | rc = target_tcon->ses->server->ops->duplicate_extents(xid, |
| 1468 | 1479 | smb_file_src, smb_file_target, off, len, destoff); |
| 1469 | − if (rc == 0 && new_size > i_size) { | |
| 1470 | − truncate_setsize(target_inode, new_size); | |
| 1471 | − fscache_resize_cookie(cifs_inode_cookie(target_inode), | |
| 1472 | − new_size); | |
| 1473 | − } else if (rc == -EOPNOTSUPP) { | |
| 1480 | + if (rc == -EOPNOTSUPP) { | |
| 1474 | 1481 | /* |
| 1475 | 1482 | * copy_file_range syscall man page indicates EINVAL |
| 1476 | 1483 | * is returned e.g when "fd_in and fd_out refer to the |
| @@ -147,6 +147,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, struct file *src_file, · 146 unmodified lines | ||
| 147 | 147 | |
| 148 | 148 | long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg); |
| 149 | 149 | void cifs_setsize(struct inode *inode, loff_t offset); |
| 150 | +void cifs_resize_file_locked(struct inode *inode, loff_t offset); | |
| 150 | 151 | |
| 151 | 152 | struct fs_context; |
| 152 | 153 | struct smb3_fs_context; |
| @@ -615,6 +615,11 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses, · 614 unmodified lines | ||
| 615 | 615 | tcon->tid = smb_buffer_response->Tid; |
| 616 | 616 | bcc_ptr = pByteArea(smb_buffer_response); |
| 617 | 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 | 623 | length = strnlen(bcc_ptr, bytes_left - 2); |
| 619 | 624 | if (smb_buffer->Flags2 & SMBFLG2_UNICODE) |
| 620 | 625 | is_unicode = true; |
| @@ -670,6 +675,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses, · 49 unmodified lines | ||
| 670 | 675 | reset_cifs_unix_caps(xid, tcon, NULL, NULL); |
| 671 | 676 | } |
| 672 | 677 | } |
| 678 | +out: | |
| 673 | 679 | cifs_buf_release(smb_buffer); |
| 674 | 680 | return rc; |
| 675 | 681 | } |
| @@ -1143,7 +1143,7 @@ clean_demultiplex_info(struct TCP_Server_Info *server) · 1142 unmodified lines | ||
| 1143 | 1143 | put_net(cifs_net_ns(server)); |
| 1144 | 1144 | kfree(server->leaf_fullpath); |
| 1145 | 1145 | kfree(server->hostname); |
| 1146 | − kfree(server); | |
| 1146 | + kfree_sensitive(server); | |
| 1147 | 1147 | |
| 1148 | 1148 | length = atomic_dec_return(&tcpSesAllocCount); |
| 1149 | 1149 | if (length > 0) |
| @@ -4003,9 +4003,6 @@ cifs_umount(struct cifs_sb_info *cifs_sb) · 2853 unmodified lines | ||
| 4003 | 4003 | } |
| 4004 | 4004 | spin_unlock(&cifs_sb->tlink_tree_lock); |
| 4005 | 4005 | |
| 4006 | − flush_workqueue(serverclose_wq); | |
| 4007 | − flush_workqueue(fileinfo_put_wq); | |
| 4008 | − | |
| 4009 | 4006 | kfree(cifs_sb->prepath); |
| 4010 | 4007 | call_rcu(&cifs_sb->rcu, delayed_free); |
| 4011 | 4008 | } |
| @@ -122,6 +122,8 @@ static inline void free_tgts(struct cache_entry *ce) · 121 unmodified lines | ||
| 122 | 122 | kfree(t->name); |
| 123 | 123 | kfree(t); |
| 124 | 124 | } |
| 125 | + | |
| 126 | + WRITE_ONCE(ce->tgthint, NULL); | |
| 125 | 127 | } |
| 126 | 128 | |
| 127 | 129 | static 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 | 871 | goto out_free_path; |
| 870 | 872 | } |
| 871 | 873 | |
| 872 | − if (ref) | |
| 873 | − rc = setup_referral(path, ce, ref, get_tgt_name(ce)); | |
| 874 | − else | |
| 874 | + if (ref) { | |
| 875 | + char *target = get_tgt_name(ce); | |
| 876 | + | |
| 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 | 883 | rc = 0; |
| 884 | + } | |
| 885 | + | |
| 876 | 886 | if (!rc && tgt_list) |
| 877 | 887 | rc = get_targets(ce, tgt_list); |
| 878 | 888 | |
| 889 | +out_unlock: | |
| 879 | 890 | up_read(&htable_rw_lock); |
| 880 | 891 | |
| 881 | 892 | out_free_path: |
| @@ -915,10 +926,17 @@ int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref, · 33 unmodified lines | ||
| 915 | 926 | goto out_unlock; |
| 916 | 927 | } |
| 917 | 928 | |
| 918 | − if (ref) | |
| 919 | − rc = setup_referral(path, ce, ref, get_tgt_name(ce)); | |
| 920 | − else | |
| 929 | + if (ref) { | |
| 930 | + char *target = get_tgt_name(ce); | |
| 931 | + | |
| 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 | 938 | rc = 0; |
| 939 | + } | |
| 922 | 940 | if (!rc && tgt_list) |
| 923 | 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 | 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 | 982 | goto out_unlock; |
| 964 | 983 | |
| 965 | 984 | list_for_each_entry(t, &ce->tlist, list) { |
| @@ -115,11 +115,7 @@ char *__build_path_from_dentry_optional_prefix(struct dentry *direntry, void *pa · 114 unmodified lines | ||
| 115 | 115 | } |
| 116 | 116 | if (dirsep != '/') { |
| 117 | 117 | /* BB test paths to Windows with '/' in the midst of prepath */ |
| 118 | − char *p; | |
| 119 | − | |
| 120 | − for (p = s; *p; p++) | |
| 121 | − if (*p == '/') | |
| 122 | − *p = dirsep; | |
| 118 | + strreplace(s, '/', dirsep); | |
| 123 | 119 | } |
| 124 | 120 | if (dfsplen) { |
| 125 | 121 | s -= dfsplen; |
| @@ -1138,6 +1134,8 @@ int cifs_tmpfile(struct mnt_idmap *idmap, struct inode *dir, · 1012 unmodified lines | ||
| 1138 | 1134 | } while (unlikely(rc == -EEXIST) && ++retries < max_retries); |
| 1139 | 1135 | |
| 1140 | 1136 | if (rc) { |
| 1137 | + if (rc == -ENOENT) | |
| 1138 | + rc = -EOPNOTSUPP; | |
| 1141 | 1139 | cifs_del_pending_open(&open); |
| 1142 | 1140 | goto out; |
| 1143 | 1141 | } |
| @@ -1016,6 +1016,7 @@ static int cifs_do_truncate(const unsigned int xid, struct dentry *dentry) · 1015 unmodified lines | ||
| 1016 | 1016 | if (!rc) { |
| 1017 | 1017 | netfs_resize_file(&cinode->netfs, 0, true); |
| 1018 | 1018 | cifs_setsize(inode, 0); |
| 1019 | + cifs_invalidate_cache(inode, 0); | |
| 1019 | 1020 | } |
| 1020 | 1021 | } |
| 1021 | 1022 | if (cfile) |
| @@ -1215,7 +1215,7 @@ static int reparse_info_to_fattr(struct cifs_open_info_data *data, · 1214 unmodified lines | ||
| 1215 | 1215 | break; |
| 1216 | 1216 | case IO_REPARSE_TAG_INTERNAL: |
| 1217 | 1217 | rc = 0; |
| 1218 | − if (le32_to_cpu(data->fi.Attributes) & ATTR_DIRECTORY) { | |
| 1218 | + if (cifs_open_data_attrs(data) & ATTR_DIRECTORY) { | |
| 1219 | 1219 | cifs_create_junction_fattr(fattr, sb); |
| 1220 | 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 | 1240 | if (rc == -EOPNOTSUPP && |
| 1241 | 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 | 1243 | rc = 0; |
| 1244 | 1244 | cifs_create_junction_fattr(fattr, sb); |
| 1245 | 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 | 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 | 1262 | rc = smb2_fix_symlink_target_type(&data->symlink_target, directory, cifs_sb); |
| 1262 | 1263 | } |
| 1263 | 1264 | break; |
| 1264 | 1265 | } |
| 1265 | 1266 | |
| 1266 | − if (tcon->posix_extensions) | |
| 1267 | + if (data->contains_posix_file_info) | |
| 1267 | 1268 | smb311_posix_info_to_fattr(fattr, data, sb); |
| 1268 | 1269 | else |
| 1269 | 1270 | cifs_open_info_to_fattr(fattr, data, sb); |
| @@ -2655,11 +2656,8 @@ unlink_target: · 1385 unmodified lines | ||
| 2655 | 2656 | if (d_really_is_positive(target_dentry)) { |
| 2656 | 2657 | if (!rc) { |
| 2657 | 2658 | struct inode *inode = d_inode(target_dentry); |
| 2658 | − /* | |
| 2659 | − * Samba and ksmbd servers allow renaming a target | |
| 2660 | − * directory that is open, so make sure to update | |
| 2661 | − * ->i_nlink and then mark it as delete pending. | |
| 2662 | − */ | |
| 2659 | + | |
| 2660 | + /* Update the target link count after rename. */ | |
| 2663 | 2661 | if (S_ISDIR(inode->i_mode)) { |
| 2664 | 2662 | drop_cached_dir_by_name(xid, tcon, to_name, cifs_sb); |
| 2665 | 2663 | spin_lock(&inode->i_lock); |
| @@ -2670,6 +2668,10 @@ unlink_target: · 4 unmodified lines | ||
| 2670 | 2668 | CIFS_I(inode)->time = 0; /* force reval */ |
| 2671 | 2669 | inode_set_ctime_current(inode); |
| 2672 | 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 | 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 | 3066 | inode->i_blocks = blocks; |
| 3065 | 3067 | spin_unlock(&inode->i_lock); |
| 3066 | 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 | 3071 | truncate_pagecache(inode, offset); |
| 3068 | 3072 | netfs_wait_for_outstanding_io(inode); |
| 3069 | − fscache_resize_cookie(cifs_inode_cookie(inode), offset); | |
| 3073 | +} | |
| 3074 | + | |
| 3075 | +void 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 | |
| 3072 | 3092 | int 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 | 3127 | size, false); |
| 3108 | 3128 | cifs_dbg(FYI, "%s: set_file_size: rc = %d\n", __func__, rc); |
| 3109 | 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 | 3153 | cifs_put_tlink(tlink); |
| 3133 | 3154 | |
| 3134 | 3155 | set_size_out: |
| 3135 | − if (rc == 0) { | |
| 3136 | − netfs_resize_file(&cifsInode->netfs, size, true); | |
| 3137 | − cifs_setsize(inode, size); | |
| 3138 | − } | |
| 3156 | + if (rc == 0) | |
| 3157 | + cifs_resize_file_locked(inode, size); | |
| 3139 | 3158 | |
| 3140 | 3159 | return rc; |
| 3141 | 3160 | } |
| @@ -3221,9 +3240,13 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) · 79 unmodified lines | ||
| 3221 | 3240 | attrs->ia_valid &= ~(ATTR_CTIME | ATTR_MTIME); |
| 3222 | 3241 | } |
| 3223 | 3242 | |
| 3224 | − /* skip mode change if it's just for clearing setuid/setgid */ | |
| 3225 | − if (attrs->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID)) | |
| 3226 | − attrs->ia_valid &= ~ATTR_MODE; | |
| 3243 | + /* | |
| 3244 | + * This function is only called when Unix extensions are in effect, | |
| 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 | 3251 | args = kmalloc_obj(*args); |
| 3229 | 3252 | if (args == NULL) { |
| @@ -3296,13 +3319,6 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) · 66 unmodified lines | ||
| 3296 | 3319 | if (rc) |
| 3297 | 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 | 3322 | setattr_copy(&nop_mnt_idmap, inode, attrs); |
| 3307 | 3323 | mark_inode_dirty(inode); |
| 3308 | 3324 | |
| @@ -3432,8 +3448,23 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) · 123 unmodified lines | ||
| 3432 | 3448 | attrs->ia_valid &= ~(ATTR_UID | ATTR_GID); |
| 3433 | 3449 | } |
| 3434 | 3450 | |
| 3435 | − /* skip mode change if it's just for clearing setuid/setgid */ | |
| 3436 | − if (attrs->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID)) | |
| 3451 | + /* | |
| 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 | 3468 | attrs->ia_valid &= ~ATTR_MODE; |
| 3438 | 3469 | |
| 3439 | 3470 | if (attrs->ia_valid & ATTR_MODE) { |
| @@ -3508,13 +3539,6 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) · 68 unmodified lines | ||
| 3508 | 3539 | if (rc) |
| 3509 | 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 | 3542 | setattr_copy(&nop_mnt_idmap, inode, attrs); |
| 3519 | 3543 | mark_inode_dirty(inode); |
| 3520 | 3544 | |
| @@ -133,8 +133,7 @@ static int cifs_set_compression_by_path(unsigned int xid, struct file *filep, · 132 unmodified lines | ||
| 133 | 133 | |
| 134 | 134 | close: |
| 135 | 135 | server->ops->close(xid, tcon, &fid); |
| 136 | − if (tmp_cfile) | |
| 137 | − kfree(tmp_cfile); | |
| 136 | + kfree(tmp_cfile); | |
| 138 | 137 | cifs_free_open_info(&data); |
| 139 | 138 | out: |
| 140 | 139 | free_dentry_path(page); |
| @@ -98,15 +98,21 @@ static inline bool reparse_inode_match(struct inode *inode, · 97 unmodified lines | ||
| 98 | 98 | timespec64_equal(&ctime, &fattr->cf_ctime); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | +static 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 | + | |
| 101 | 109 | static inline bool cifs_open_data_reparse(struct cifs_open_info_data *data) |
| 102 | 110 | { |
| 103 | − u32 attrs; | |
| 104 | − bool ret; | |
| 111 | + u32 attrs = cifs_open_data_attrs(data); | |
| 105 | 112 | |
| 106 | 113 | if (data->contains_posix_file_info) { |
| 107 | 114 | struct smb311_posix_qinfo *fi = &data->posix_fi; |
| 108 | 115 | |
| 109 | − attrs = le32_to_cpu(fi->DosAttributes); | |
| 110 | 116 | if (data->reparse_point) { |
| 111 | 117 | attrs |= ATTR_REPARSE_POINT; |
| 112 | 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 | 121 | } else { |
| 116 | 122 | struct smb2_file_all_info *fi = &data->fi; |
| 117 | 123 | |
| 118 | − attrs = le32_to_cpu(fi->Attributes); | |
| 119 | 124 | if (data->reparse_point) { |
| 120 | 125 | attrs |= ATTR_REPARSE_POINT; |
| 121 | 126 | fi->Attributes = cpu_to_le32(attrs); |
| 122 | 127 | } |
| 123 | 128 | } |
| 124 | 129 | |
| 125 | − ret = attrs & ATTR_REPARSE_POINT; | |
| 126 | − | |
| 127 | − return ret; | |
| 130 | + return attrs & ATTR_REPARSE_POINT; | |
| 128 | 131 | } |
| 129 | 132 | |
| 130 | 133 | bool cifs_reparse_point_to_fattr(struct cifs_sb_info *cifs_sb, |
| @@ -81,6 +81,7 @@ int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server, · 80 unmodified lines | ||
| 81 | 81 | else |
| 82 | 82 | memcpy(cifs_pdu->Signature.SecuritySignature, smb_signature, 8); |
| 83 | 83 | |
| 84 | + memzero_explicit(smb_signature, sizeof(smb_signature)); | |
| 84 | 85 | return rc; |
| 85 | 86 | } |
| 86 | 87 | |
| @@ -126,15 +127,13 @@ int cifs_verify_signature(struct smb_rqst *rqst, · 39 unmodified lines | ||
| 126 | 127 | rc = cifs_calc_signature(rqst, server, what_we_think_sig_should_be); |
| 127 | 128 | cifs_server_unlock(server); |
| 128 | 129 | |
| 129 | − if (rc) | |
| 130 | − return rc; | |
| 131 | − | |
| 132 | −/* cifs_dump_mem("what we think it should be: ", | |
| 133 | − what_we_think_sig_should_be, 16); */ | |
| 134 | − | |
| 135 | − if (crypto_memneq(server_response_sig, what_we_think_sig_should_be, 8)) | |
| 136 | − return -EACCES; | |
| 137 | − else | |
| 138 | − return 0; | |
| 130 | + if (!rc) { | |
| 131 | + if (crypto_memneq(server_response_sig, | |
| 132 | + what_we_think_sig_should_be, 8)) | |
| 133 | + rc = -EACCES; | |
| 134 | + } | |
| 139 | 135 | |
| 136 | + memzero_explicit(what_we_think_sig_should_be, | |
| 137 | + sizeof(what_we_think_sig_should_be)); | |
| 138 | + return rc; | |
| 140 | 139 | } |
| @@ -80,7 +80,8 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv) · 79 unmodified lines | ||
| 80 | 80 | (struct smb_com_transaction_change_notify_rsp *)buf; |
| 81 | 81 | struct file_notify_information *pnotify; |
| 82 | 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 | 86 | if (get_bcc(buf) > sizeof(struct file_notify_information)) { |
| 86 | 87 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| @@ -542,6 +542,7 @@ static int cifs_query_path_info(const unsigned int xid, · 541 unmodified lines | ||
| 542 | 542 | |
| 543 | 543 | data->reparse_point = false; |
| 544 | 544 | data->adjust_tz = false; |
| 545 | + data->unknown_nlink = false; | |
| 545 | 546 | |
| 546 | 547 | /* |
| 547 | 548 | * 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 | 609 | fi.EASize = di->EaSize; |
| 609 | 610 | } |
| 610 | 611 | fi.NumberOfLinks = cpu_to_le32(1); |
| 612 | + data->unknown_nlink = true; | |
| 611 | 613 | fi.DeletePending = 0; |
| 612 | 614 | fi.Directory = !!(le32_to_cpu(fi.Attributes) & ATTR_DIRECTORY); |
| 613 | 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 | 632 | rc = SMBQueryInformation(xid, tcon, full_path, &fi, cifs_sb->local_nls, |
| 631 | 633 | cifs_remap(cifs_sb)); |
| 632 | 634 | data->adjust_tz = true; |
| 635 | + if (!rc) | |
| 636 | + data->unknown_nlink = true; | |
| 633 | 637 | } else if ((rc == -EOPNOTSUPP || rc == -EINVAL) && non_unicode_wildcard) { |
| 634 | 638 | /* Path with non-UNICODE wildcard character cannot exist. */ |
| 635 | 639 | rc = -ENOENT; |
| @@ -717,7 +721,7 @@ static int cifs_query_path_info(const unsigned int xid, · 81 unmodified lines | ||
| 717 | 721 | ea->ea_value_length = cpu_to_le16(SMB2_WSL_XATTR_DEV_SIZE); |
| 718 | 722 | memcpy(&ea->ea_data[0], SMB2_WSL_XATTR_DEV, SMB2_WSL_XATTR_NAME_LEN + 1); |
| 719 | 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 | 725 | rc = 0; |
| 722 | 726 | } else if (rc >= 0) { |
| 723 | 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 | 897 | else |
| 894 | 898 | rc = CIFS_open(xid, oparms, oplock, &fi); |
| 895 | 899 | |
| 896 | − if (!rc && data) | |
| 900 | + if (!rc && data) { | |
| 897 | 901 | move_cifs_info_to_smb2(&data->fi, &fi); |
| 902 | + data->unknown_nlink = true; | |
| 903 | + } | |
| 898 | 904 | |
| 899 | 905 | return rc; |
| 900 | 906 | } |
| @@ -375,12 +375,31 @@ coalesce_t2(char *second_buf, struct smb_hdr *target_hdr, unsigned int *pdu_len) · 374 unmodified lines | ||
| 375 | 375 | data_area_of_tgt = (char *)&pSMBt->hdr.Protocol + |
| 376 | 376 | get_unaligned_le16(&pSMBt->t2_rsp.DataOffset); |
| 377 | 377 | |
| 378 | − /* validate target area */ | |
| 379 | 378 | data_area_of_src = (char *)&pSMBs->hdr.Protocol + |
| 380 | 379 | get_unaligned_le16(&pSMBs->t2_rsp.DataOffset); |
| 381 | 380 | |
| 382 | 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 | 403 | total_in_tgt += total_in_src; |
| 385 | 404 | /* is the result too big for the field? */ |
| 386 | 405 | if (total_in_tgt > USHRT_MAX) { |
| @@ -430,10 +449,18 @@ bool · 43 unmodified lines | ||
| 430 | 449 | cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server, |
| 431 | 450 | char *buf, int malformed) |
| 432 | 451 | { |
| 433 | − if (malformed) | |
| 434 | − return false; | |
| 435 | − if (check2ndT2(buf) <= 0) | |
| 452 | + if (malformed || check2ndT2(buf) <= 0) { | |
| 453 | + /* mid->multiRsp blocks the server buf detach in handle_mid(); | |
| 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 | 462 | return false; |
| 463 | + } | |
| 437 | 464 | mid->multiRsp = true; |
| 438 | 465 | if (mid->resp_buf) { |
| 439 | 466 | /* merge response - fix up 1st*/ |
| @@ -61,7 +61,10 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov) · 60 unmodified lines | ||
| 61 | 61 | cifs_dbg(FYI, "%s: skipping unhandled error context: 0x%x\n", |
| 62 | 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 | 68 | if (len > end - ((u8 *)p + sizeof(*p))) |
| 66 | 69 | return ERR_PTR(-EINVAL); |
| 67 | 70 | |
| @@ -22,6 +22,7 @@ · 21 unmodified lines | ||
| 22 | 22 | #include "smb2glob.h" |
| 23 | 23 | #include "smb2proto.h" |
| 24 | 24 | #include "cached_dir.h" |
| 25 | +#include "reparse.h" | |
| 25 | 26 | #include "../common/smb2status.h" |
| 26 | 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 | 42 | buf = (struct reparse_data_buffer *)((u8 *)io + off); |
| 42 | 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 | 49 | return ERR_PTR(smb_EIO2(smb_eio_trace_reparse_rdlen, count, rdlen)); |
| 47 | 50 | return buf; |
| 48 | 51 | } |
| @@ -574,8 +577,10 @@ finished: · 525 unmodified lines | ||
| 574 | 577 | idata->fi.Attributes = create_rsp->FileAttributes; |
| 575 | 578 | idata->fi.AllocationSize = create_rsp->AllocationSize; |
| 576 | 579 | idata->fi.EndOfFile = create_rsp->EndofFile; |
| 580 | + idata->contains_posix_file_info = false; | |
| 577 | 581 | if (le32_to_cpu(idata->fi.NumberOfLinks) == 0) |
| 578 | 582 | idata->fi.NumberOfLinks = cpu_to_le32(1); /* dummy value */ |
| 583 | + idata->unknown_nlink = true; | |
| 579 | 584 | idata->fi.DeletePending = 0; /* successful open = not delete pending */ |
| 580 | 585 | idata->fi.Directory = !!(le32_to_cpu(create_rsp->FileAttributes) & ATTR_DIRECTORY); |
| 581 | 586 | |
| @@ -596,7 +601,6 @@ finished: · 14 unmodified lines | ||
| 596 | 601 | switch (cmds[i]) { |
| 597 | 602 | case SMB2_OP_QUERY_INFO: |
| 598 | 603 | idata = in_iov[i].iov_base; |
| 599 | − idata->contains_posix_file_info = false; | |
| 600 | 604 | if (rc == 0 && cfile && cfile->symlink_target) { |
| 601 | 605 | idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL); |
| 602 | 606 | if (!idata->symlink_target) |
| @@ -609,6 +613,8 @@ finished: · 6 unmodified lines | ||
| 609 | 613 | le16_to_cpu(qi_rsp->OutputBufferOffset), |
| 610 | 614 | le32_to_cpu(qi_rsp->OutputBufferLength), |
| 611 | 615 | &rsp_iov[i + 1], sizeof(idata->fi), (char *)&idata->fi); |
| 616 | + if (!rc) | |
| 617 | + idata->contains_posix_file_info = false; | |
| 612 | 618 | } |
| 613 | 619 | SMB2_query_info_free(&rqst[num_rqst++]); |
| 614 | 620 | if (rc) |
| @@ -620,7 +626,6 @@ finished: · 5 unmodified lines | ||
| 620 | 626 | break; |
| 621 | 627 | case SMB2_OP_POSIX_QUERY_INFO: |
| 622 | 628 | idata = in_iov[i].iov_base; |
| 623 | − idata->contains_posix_file_info = true; | |
| 624 | 629 | if (rc == 0 && cfile && cfile->symlink_target) { |
| 625 | 630 | idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL); |
| 626 | 631 | if (!idata->symlink_target) |
| @@ -634,6 +639,8 @@ finished: · 7 unmodified lines | ||
| 634 | 639 | le32_to_cpu(qi_rsp->OutputBufferLength), |
| 635 | 640 | &rsp_iov[i + 1], sizeof(idata->posix_fi) /* add SIDs */, |
| 636 | 641 | (char *)&idata->posix_fi); |
| 642 | + if (!rc) | |
| 643 | + idata->contains_posix_file_info = true; | |
| 637 | 644 | } |
| 638 | 645 | if (rc == 0) |
| 639 | 646 | rc = parse_posix_sids(idata, &rsp_iov[i + 1]); |
| @@ -705,7 +712,6 @@ finished: · 65 unmodified lines | ||
| 705 | 712 | idata = in_iov[i].iov_base; |
| 706 | 713 | idata->reparse.io.iov = *iov; |
| 707 | 714 | idata->reparse.io.buftype = resp_buftype[i + 1]; |
| 708 | − idata->contains_posix_file_info = false; /* BB VERIFY */ | |
| 709 | 715 | rbuf = reparse_buf_ptr(iov); |
| 710 | 716 | if (IS_ERR(rbuf)) { |
| 711 | 717 | rc = PTR_ERR(rbuf); |
| @@ -727,7 +733,6 @@ finished: · 15 unmodified lines | ||
| 727 | 733 | case SMB2_OP_QUERY_WSL_EA: |
| 728 | 734 | if (!rc) { |
| 729 | 735 | idata = in_iov[i].iov_base; |
| 730 | − idata->contains_posix_file_info = false; | |
| 731 | 736 | qi_rsp = rsp_iov[i + 1].iov_base; |
| 732 | 737 | data[0] = (u8 *)qi_rsp + le16_to_cpu(qi_rsp->OutputBufferOffset); |
| 733 | 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 | 1006 | * If the symlink was already parsed in create response then it is needed to fix |
| 1002 | 1007 | * 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 then | |
| 1008 | + * metadata attributes). If the symlink was not parsed in create response then | |
| 1004 | 1009 | * the data->symlink_target was not filled yet and then the type will be fixed |
| 1005 | 1010 | * later after data->symlink_target is filled. |
| 1006 | 1011 | */ |
| 1007 | 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 | 1015 | rc = smb2_fix_symlink_target_type(&data->symlink_target, directory, cifs_sb); |
| 1010 | 1016 | } |
| 1011 | 1017 | break; |
| @@ -1569,7 +1569,7 @@ SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon, · 1568 unmodified lines | ||
| 1569 | 1569 | memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE); |
| 1570 | 1570 | |
| 1571 | 1571 | req_res_key_exit: |
| 1572 | − kfree(res_key); | |
| 1572 | + kfree_sensitive(res_key); | |
| 1573 | 1573 | return rc; |
| 1574 | 1574 | } |
| 1575 | 1575 | |
| @@ -2222,8 +2222,7 @@ smb2_duplicate_extents(const unsigned int xid, · 646 unmodified lines | ||
| 2222 | 2222 | rc = smb2_set_file_size(xid, tcon, trgtfile, dest_off + len, false); |
| 2223 | 2223 | if (rc) |
| 2224 | 2224 | goto duplicate_extents_out; |
| 2225 | − netfs_resize_file(netfs_inode(inode), dest_off + len, true); | |
| 2226 | − cifs_setsize(inode, dest_off + len); | |
| 2225 | + cifs_resize_file_locked(inode, dest_off + len); | |
| 2227 | 2226 | } |
| 2228 | 2227 | rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid, |
| 2229 | 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 | 3777 | new_eof = off + len; |
| 3779 | − netfs_resize_file(&cifsi->netfs, new_eof, true); | |
| 3780 | − cifs_setsize(inode, new_eof); | |
| 3778 | + cifs_resize_file_locked(inode, new_eof); | |
| 3781 | 3779 | |
| 3782 | 3780 | qrc = SMB2_query_info(xid, tcon, |
| 3783 | 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 | 3823 | if (rc) |
| 3826 | 3824 | goto out; |
| 3827 | 3825 | |
| 3828 | − netfs_resize_file(&cifsi->netfs, new_eof, true); | |
| 3829 | − cifs_setsize(inode, new_eof); | |
| 3826 | + cifs_resize_file_locked(inode, new_eof); | |
| 3830 | 3827 | |
| 3831 | 3828 | qrc = SMB2_query_info(xid, tcon, |
| 3832 | 3829 | cfile->fid.persistent_fid, |
| @@ -4636,7 +4633,7 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst, · 803 unmodified lines | ||
| 4636 | 4633 | rc = crypto_aead_setkey(tfm, key, SMB3_GCM256_CRYPTKEY_SIZE); |
| 4637 | 4634 | else |
| 4638 | 4635 | rc = crypto_aead_setkey(tfm, key, SMB3_GCM128_CRYPTKEY_SIZE); |
| 4639 | − | |
| 4636 | + memzero_explicit(key, sizeof(key)); | |
| 4640 | 4637 | if (rc) { |
| 4641 | 4638 | cifs_server_dbg(VFS, "%s: Failed to set aead key %d\n", __func__, rc); |
| 4642 | 4639 | return rc; |
| @@ -3372,6 +3372,7 @@ replay_again: · 3371 unmodified lines | ||
| 3372 | 3372 | #endif /* CIFS_DEBUG2 */ |
| 3373 | 3373 | |
| 3374 | 3374 | if (file_info) { |
| 3375 | + buf->contains_posix_file_info = false; | |
| 3375 | 3376 | file_info->CreationTime = rsp->CreationTime; |
| 3376 | 3377 | file_info->LastAccessTime = rsp->LastAccessTime; |
| 3377 | 3378 | file_info->LastWriteTime = rsp->LastWriteTime; |
| @@ -4564,8 +4565,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len, · 1186 unmodified lines | ||
| 4564 | 4565 | if (rc) |
| 4565 | 4566 | return rc; |
| 4566 | 4567 | |
| 4567 | − if (server == NULL) | |
| 4568 | − return -ECONNABORTED; | |
| 4568 | + if (!server) { | |
| 4569 | + rc = -ECONNABORTED; | |
| 4570 | + goto free_req; | |
| 4571 | + } | |
| 4569 | 4572 | |
| 4570 | 4573 | shdr = &req->hdr; |
| 4571 | 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 | 4600 | rdata->mr = smbd_register_mr(server->smbd_conn, &rdata->subreq.io_iter, |
| 4598 | 4601 | true, need_invalidate); |
| 4599 | − if (!rdata->mr) | |
| 4600 | − return -EAGAIN; | |
| 4602 | + if (!rdata->mr) { | |
| 4603 | + rc = -EAGAIN; | |
| 4604 | + goto free_req; | |
| 4605 | + } | |
| 4601 | 4606 | |
| 4602 | 4607 | req->Channel = SMB2_CHANNEL_RDMA_V1_INVALIDATE; |
| 4603 | 4608 | if (need_invalidate) |
| @@ -4638,6 +4643,10 @@ smb2_new_read_req(void **buf, unsigned int *total_len, · 34 unmodified lines | ||
| 4638 | 4643 | |
| 4639 | 4644 | *buf = req; |
| 4640 | 4645 | return rc; |
| 4646 | + | |
| 4647 | +free_req: | |
| 4648 | + cifs_small_buf_release(req); | |
| 4649 | + return rc; | |
| 4641 | 4650 | } |
| 4642 | 4651 | |
| 4643 | 4652 | static void |
| @@ -4885,6 +4894,7 @@ out: · 241 unmodified lines | ||
| 4885 | 4894 | smb2_should_replay(tcon, |
| 4886 | 4895 | &rdata->retries, |
| 4887 | 4896 | &rdata->cur_sleep)) { |
| 4897 | + rdata->replay = true; | |
| 4888 | 4898 | trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed); |
| 4889 | 4899 | __set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags); |
| 4890 | 4900 | } |
| @@ -249,6 +249,8 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) · 248 unmodified lines | ||
| 249 | 249 | if (!rc) |
| 250 | 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 | 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 | 285 | hmac_sha256_final(&hmac_ctx, prfhash); |
| 284 | 286 | |
| 285 | 287 | memcpy(key, prfhash, key_size); |
| 288 | + memzero_explicit(prfhash, sizeof(prfhash)); | |
| 286 | 289 | } |
| 287 | 290 | |
| 288 | 291 | struct derivation { |
| @@ -482,6 +485,7 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) · 193 unmodified lines | ||
| 482 | 485 | memset(shdr->Signature, 0x0, SMB2_SIGNATURE_SIZE); |
| 483 | 486 | |
| 484 | 487 | rc = aes_cmac_preparekey(&cmac_key, key, SMB2_CMACAES_SIZE); |
| 488 | + memzero_explicit(key, sizeof(key)); | |
| 485 | 489 | if (rc) { |
| 486 | 490 | cifs_server_dbg(VFS, "%s: Could not set key for cmac aes\n", __func__); |
| 487 | 491 | return rc; |
| @@ -133,6 +133,7 @@ · 132 unmodified lines | ||
| 133 | 133 | EM(smb_eio_trace_sym_slash, "sym_slash") \ |
| 134 | 134 | EM(smb_eio_trace_sym_target_len, "sym_target_len") \ |
| 135 | 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 | 137 | EM(smb_eio_trace_tdis_in_reconnect, "tdis_in_reconnect") \ |
| 137 | 138 | EM(smb_eio_trace_tx_chained_async, "tx_chained_async") \ |
| 138 | 139 | EM(smb_eio_trace_tx_compress_failed, "tx_compress_failed") \ |
| @@ -213,7 +214,7 @@ · 74 unmodified lines | ||
| 213 | 214 | #define EM(a, b) a, |
| 214 | 215 | #define E_(a, b) a |
| 215 | 216 | |
| 216 | −enum smb_eio_trace { smb_eio_traces } __mode(byte); | |
| 217 | +enum smb_eio_trace { smb_eio_traces }; | |
| 217 | 218 | enum smb3_rw_credits_trace { smb3_rw_credits_traces } __mode(byte); |
| 218 | 219 | enum smb3_tcon_ref_trace { smb3_tcon_ref_traces } __mode(byte); |
| 219 | 220 | |