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

Merge branches 'work.namei', 'work.dcache' and 'work.iov_iter' into for-linus

Al Viro c4364f83 1d0fd57a

+221 -316
+1 -1
drivers/bluetooth/hci_vhci.c
··· 181 181 if (!skb) 182 182 return -ENOMEM; 183 183 184 - if (copy_from_iter(skb_put(skb, len), len, from) != len) { 184 + if (!copy_from_iter_full(skb_put(skb, len), len, from)) { 185 185 kfree_skb(skb); 186 186 return -EFAULT; 187 187 }
+1 -3
drivers/net/macvtap.c
··· 673 673 int depth; 674 674 bool zerocopy = false; 675 675 size_t linear; 676 - ssize_t n; 677 676 678 677 if (q->flags & IFF_VNET_HDR) { 679 678 vnet_hdr_len = q->vnet_hdr_sz; ··· 683 684 len -= vnet_hdr_len; 684 685 685 686 err = -EFAULT; 686 - n = copy_from_iter(&vnet_hdr, sizeof(vnet_hdr), from); 687 - if (n != sizeof(vnet_hdr)) 687 + if (!copy_from_iter_full(&vnet_hdr, sizeof(vnet_hdr), from)) 688 688 goto err; 689 689 iov_iter_advance(from, vnet_hdr_len - sizeof(vnet_hdr)); 690 690 if ((vnet_hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
+2 -5
drivers/net/tun.c
··· 1171 1171 bool zerocopy = false; 1172 1172 int err; 1173 1173 u32 rxhash; 1174 - ssize_t n; 1175 1174 1176 1175 if (!(tun->dev->flags & IFF_UP)) 1177 1176 return -EIO; ··· 1180 1181 return -EINVAL; 1181 1182 len -= sizeof(pi); 1182 1183 1183 - n = copy_from_iter(&pi, sizeof(pi), from); 1184 - if (n != sizeof(pi)) 1184 + if (!copy_from_iter_full(&pi, sizeof(pi), from)) 1185 1185 return -EFAULT; 1186 1186 } 1187 1187 ··· 1189 1191 return -EINVAL; 1190 1192 len -= tun->vnet_hdr_sz; 1191 1193 1192 - n = copy_from_iter(&gso, sizeof(gso), from); 1193 - if (n != sizeof(gso)) 1194 + if (!copy_from_iter_full(&gso, sizeof(gso), from)) 1194 1195 return -EFAULT; 1195 1196 1196 1197 if ((gso.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
+7 -26
drivers/staging/lustre/lustre/llite/dcache.c
··· 57 57 58 58 LASSERT(de); 59 59 lld = ll_d2d(de); 60 - if (!lld) /* NFS copies the de->d_op methods (bug 4655) */ 61 - return; 62 - 63 60 if (lld->lld_it) { 64 61 ll_intent_release(lld->lld_it); 65 62 kfree(lld->lld_it); ··· 123 126 return 0; 124 127 } 125 128 126 - int ll_d_init(struct dentry *de) 129 + static int ll_d_init(struct dentry *de) 127 130 { 128 - CDEBUG(D_DENTRY, "ldd on dentry %pd (%p) parent %p inode %p refc %d\n", 129 - de, de, de->d_parent, d_inode(de), d_count(de)); 130 - 131 - if (!de->d_fsdata) { 132 - struct ll_dentry_data *lld; 133 - 134 - lld = kzalloc(sizeof(*lld), GFP_NOFS); 135 - if (likely(lld)) { 136 - spin_lock(&de->d_lock); 137 - if (likely(!de->d_fsdata)) { 138 - de->d_fsdata = lld; 139 - __d_lustre_invalidate(de); 140 - } else { 141 - kfree(lld); 142 - } 143 - spin_unlock(&de->d_lock); 144 - } else { 145 - return -ENOMEM; 146 - } 147 - } 148 - LASSERT(de->d_op == &ll_d_ops); 149 - 131 + struct ll_dentry_data *lld = kzalloc(sizeof(*lld), GFP_KERNEL); 132 + if (unlikely(!lld)) 133 + return -ENOMEM; 134 + lld->lld_invalid = 1; 135 + de->d_fsdata = lld; 150 136 return 0; 151 137 } 152 138 ··· 280 300 } 281 301 282 302 const struct dentry_operations ll_d_ops = { 303 + .d_init = ll_d_init, 283 304 .d_revalidate = ll_revalidate_nd, 284 305 .d_release = ll_release, 285 306 .d_delete = ll_ddelete,
+3 -14
drivers/staging/lustre/lustre/llite/llite_internal.h
··· 801 801 802 802 /* llite/dcache.c */ 803 803 804 - int ll_d_init(struct dentry *de); 805 804 extern const struct dentry_operations ll_d_ops; 806 805 void ll_intent_drop_lock(struct lookup_intent *); 807 806 void ll_intent_release(struct lookup_intent *); ··· 1188 1189 * 'lld_sa_generation == lli->lli_sa_generation'. 1189 1190 */ 1190 1191 ldd = ll_d2d(dentry); 1191 - if (ldd && ldd->lld_sa_generation == lli->lli_sa_generation) 1192 + if (ldd->lld_sa_generation == lli->lli_sa_generation) 1192 1193 return false; 1193 1194 1194 1195 return true; ··· 1316 1317 1317 1318 static inline int d_lustre_invalid(const struct dentry *dentry) 1318 1319 { 1319 - struct ll_dentry_data *lld = ll_d2d(dentry); 1320 - 1321 - return !lld || lld->lld_invalid; 1322 - } 1323 - 1324 - static inline void __d_lustre_invalidate(struct dentry *dentry) 1325 - { 1326 - struct ll_dentry_data *lld = ll_d2d(dentry); 1327 - 1328 - if (lld) 1329 - lld->lld_invalid = 1; 1320 + return ll_d2d(dentry)->lld_invalid; 1330 1321 } 1331 1322 1332 1323 /* ··· 1332 1343 1333 1344 spin_lock_nested(&dentry->d_lock, 1334 1345 nested ? DENTRY_D_LOCK_NESTED : DENTRY_D_LOCK_NORMAL); 1335 - __d_lustre_invalidate(dentry); 1346 + ll_d2d(dentry)->lld_invalid = 1; 1336 1347 /* 1337 1348 * We should be careful about dentries created by d_obtain_alias(). 1338 1349 * These dentries are not put in the dentry tree, instead they are
+6 -16
drivers/staging/lustre/lustre/llite/llite_nfs.c
··· 169 169 /* N.B. d_obtain_alias() drops inode ref on error */ 170 170 result = d_obtain_alias(inode); 171 171 if (!IS_ERR(result)) { 172 - int rc; 173 - 174 - rc = ll_d_init(result); 175 - if (rc < 0) { 176 - dput(result); 177 - result = ERR_PTR(rc); 178 - } else { 179 - struct ll_dentry_data *ldd = ll_d2d(result); 180 - 181 - /* 182 - * Need to signal to the ll_intent_file_open that 183 - * we came from NFS and so opencache needs to be 184 - * enabled for this one 185 - */ 186 - ldd->lld_nfs_dentry = 1; 187 - } 172 + /* 173 + * Need to signal to the ll_intent_file_open that 174 + * we came from NFS and so opencache needs to be 175 + * enabled for this one 176 + */ 177 + ll_d2d(result)->lld_nfs_dentry = 1; 188 178 } 189 179 190 180 return result;
+1 -12
drivers/staging/lustre/lustre/llite/namei.c
··· 395 395 */ 396 396 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de) 397 397 { 398 - struct dentry *new; 399 - int rc; 400 - 401 398 if (inode) { 402 - new = ll_find_alias(inode, de); 399 + struct dentry *new = ll_find_alias(inode, de); 403 400 if (new) { 404 - rc = ll_d_init(new); 405 - if (rc < 0) { 406 - dput(new); 407 - return ERR_PTR(rc); 408 - } 409 401 d_move(new, de); 410 402 iput(inode); 411 403 CDEBUG(D_DENTRY, ··· 406 414 return new; 407 415 } 408 416 } 409 - rc = ll_d_init(de); 410 - if (rc < 0) 411 - return ERR_PTR(rc); 412 417 d_add(de, inode); 413 418 CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n", 414 419 de, d_inode(de), d_count(de), de->d_flags);
+1 -3
drivers/staging/lustre/lustre/llite/statahead.c
··· 1513 1513 */ 1514 1514 ldd = ll_d2d(*dentryp); 1515 1515 lli = ll_i2info(dir); 1516 - /* ldd can be NULL if llite lookup failed. */ 1517 - if (ldd) 1518 - ldd->lld_sa_generation = lli->lli_sa_generation; 1516 + ldd->lld_sa_generation = lli->lli_sa_generation; 1519 1517 sa_put(sai, entry); 1520 1518 return rc; 1521 1519 }
+1 -1
drivers/usb/gadget/function/f_fs.c
··· 949 949 goto error_mutex; 950 950 } 951 951 if (!io_data->read && 952 - copy_from_iter(data, data_len, &io_data->data) != data_len) { 952 + !copy_from_iter_full(data, data_len, &io_data->data)) { 953 953 ret = -EFAULT; 954 954 goto error_mutex; 955 955 }
+1 -1
drivers/usb/gadget/legacy/inode.c
··· 667 667 return -ENOMEM; 668 668 } 669 669 670 - if (unlikely(copy_from_iter(buf, len, from) != len)) { 670 + if (unlikely(!copy_from_iter_full(buf, len, from))) { 671 671 value = -EFAULT; 672 672 goto out; 673 673 }
+1 -2
drivers/vhost/scsi.c
··· 922 922 */ 923 923 iov_iter_init(&out_iter, WRITE, vq->iov, out, out_size); 924 924 925 - ret = copy_from_iter(req, req_size, &out_iter); 926 - if (unlikely(ret != req_size)) { 925 + if (unlikely(!copy_from_iter_full(req, req_size, &out_iter))) { 927 926 vq_err(vq, "Faulted on copy_from_iter\n"); 928 927 vhost_scsi_send_bad_target(vs, vq, head, out); 929 928 continue;
+1 -2
drivers/vhost/vhost.c
··· 1862 1862 i, count); 1863 1863 return -EINVAL; 1864 1864 } 1865 - if (unlikely(copy_from_iter(&desc, sizeof(desc), &from) != 1866 - sizeof(desc))) { 1865 + if (unlikely(!copy_from_iter_full(&desc, sizeof(desc), &from))) { 1867 1866 vq_err(vq, "Failed indirect descriptor: idx %d, %zx\n", 1868 1867 i, (size_t)vhost64_to_cpu(vq, indirect->addr) + i * sizeof desc); 1869 1868 return -EINVAL;
+5 -46
fs/ceph/dir.c
··· 32 32 /* 33 33 * Initialize ceph dentry state. 34 34 */ 35 - int ceph_init_dentry(struct dentry *dentry) 35 + static int ceph_d_init(struct dentry *dentry) 36 36 { 37 37 struct ceph_dentry_info *di; 38 - 39 - if (dentry->d_fsdata) 40 - return 0; 41 38 42 39 di = kmem_cache_zalloc(ceph_dentry_cachep, GFP_KERNEL); 43 40 if (!di) 44 41 return -ENOMEM; /* oh well */ 45 42 46 - spin_lock(&dentry->d_lock); 47 - if (dentry->d_fsdata) { 48 - /* lost a race */ 49 - kmem_cache_free(ceph_dentry_cachep, di); 50 - goto out_unlock; 51 - } 52 - 53 - if (ceph_snap(d_inode(dentry->d_parent)) == CEPH_NOSNAP) 54 - d_set_d_op(dentry, &ceph_dentry_ops); 55 - else if (ceph_snap(d_inode(dentry->d_parent)) == CEPH_SNAPDIR) 56 - d_set_d_op(dentry, &ceph_snapdir_dentry_ops); 57 - else 58 - d_set_d_op(dentry, &ceph_snap_dentry_ops); 59 - 60 43 di->dentry = dentry; 61 44 di->lease_session = NULL; 62 45 di->time = jiffies; 63 - /* avoid reordering d_fsdata setup so that the check above is safe */ 64 - smp_mb(); 65 46 dentry->d_fsdata = di; 66 47 ceph_dentry_lru_add(dentry); 67 - out_unlock: 68 - spin_unlock(&dentry->d_lock); 69 48 return 0; 70 49 } 71 50 ··· 716 737 if (dentry->d_name.len > NAME_MAX) 717 738 return ERR_PTR(-ENAMETOOLONG); 718 739 719 - err = ceph_init_dentry(dentry); 720 - if (err < 0) 721 - return ERR_PTR(err); 722 - 723 740 /* can we conclude ENOENT locally? */ 724 741 if (d_really_is_negative(dentry)) { 725 742 struct ceph_inode_info *ci = ceph_inode(dir); ··· 1294 1319 kmem_cache_free(ceph_dentry_cachep, di); 1295 1320 } 1296 1321 1297 - static int ceph_snapdir_d_revalidate(struct dentry *dentry, 1298 - unsigned int flags) 1299 - { 1300 - /* 1301 - * Eventually, we'll want to revalidate snapped metadata 1302 - * too... probably... 1303 - */ 1304 - return 1; 1305 - } 1306 - 1307 1322 /* 1308 1323 * When the VFS prunes a dentry from the cache, we need to clear the 1309 1324 * complete flag on the parent directory. ··· 1310 1345 1311 1346 /* if we are not hashed, we don't affect dir's completeness */ 1312 1347 if (d_unhashed(dentry)) 1348 + return; 1349 + 1350 + if (ceph_snap(d_inode(dentry->d_parent)) == CEPH_SNAPDIR) 1313 1351 return; 1314 1352 1315 1353 /* ··· 1485 1517 .d_revalidate = ceph_d_revalidate, 1486 1518 .d_release = ceph_d_release, 1487 1519 .d_prune = ceph_d_prune, 1488 - }; 1489 - 1490 - const struct dentry_operations ceph_snapdir_dentry_ops = { 1491 - .d_revalidate = ceph_snapdir_d_revalidate, 1492 - .d_release = ceph_d_release, 1493 - }; 1494 - 1495 - const struct dentry_operations ceph_snap_dentry_ops = { 1496 - .d_release = ceph_d_release, 1497 - .d_prune = ceph_d_prune, 1520 + .d_init = ceph_d_init, 1498 1521 };
+2 -24
fs/ceph/export.c
··· 62 62 { 63 63 struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc; 64 64 struct inode *inode; 65 - struct dentry *dentry; 66 65 struct ceph_vino vino; 67 66 int err; 68 67 ··· 93 94 return ERR_PTR(-ESTALE); 94 95 } 95 96 96 - dentry = d_obtain_alias(inode); 97 - if (IS_ERR(dentry)) 98 - return dentry; 99 - err = ceph_init_dentry(dentry); 100 - if (err < 0) { 101 - dput(dentry); 102 - return ERR_PTR(err); 103 - } 104 - dout("__fh_to_dentry %llx %p dentry %p\n", ino, inode, dentry); 105 - return dentry; 97 + return d_obtain_alias(inode); 106 98 } 107 99 108 100 /* ··· 121 131 struct ceph_mds_client *mdsc = ceph_sb_to_client(sb)->mdsc; 122 132 struct ceph_mds_request *req; 123 133 struct inode *inode; 124 - struct dentry *dentry; 125 134 int mask; 126 135 int err; 127 136 ··· 153 164 if (!inode) 154 165 return ERR_PTR(-ENOENT); 155 166 156 - dentry = d_obtain_alias(inode); 157 - if (IS_ERR(dentry)) 158 - return dentry; 159 - err = ceph_init_dentry(dentry); 160 - if (err < 0) { 161 - dput(dentry); 162 - return ERR_PTR(err); 163 - } 164 - dout("__get_parent ino %llx parent %p ino %llx.%llx\n", 165 - child ? ceph_ino(d_inode(child)) : ino, 166 - dentry, ceph_vinop(inode)); 167 - return dentry; 167 + return d_obtain_alias(inode); 168 168 } 169 169 170 170 static struct dentry *ceph_get_parent(struct dentry *child)
-4
fs/ceph/file.c
··· 351 351 if (dentry->d_name.len > NAME_MAX) 352 352 return -ENAMETOOLONG; 353 353 354 - err = ceph_init_dentry(dentry); 355 - if (err < 0) 356 - return err; 357 - 358 354 if (flags & O_CREAT) { 359 355 err = ceph_pre_init_acls(dir, &mode, &acls); 360 356 if (err < 0)
+6 -16
fs/ceph/inode.c
··· 1023 1023 long unsigned half_ttl = from_time + (duration * HZ / 2) / 1000; 1024 1024 struct inode *dir; 1025 1025 1026 - /* only track leases on regular dentries */ 1027 - if (dentry->d_op != &ceph_dentry_ops) 1028 - return; 1029 - 1030 1026 spin_lock(&dentry->d_lock); 1031 1027 dout("update_dentry_lease %p duration %lu ms ttl %lu\n", 1032 1028 dentry, duration, ttl); 1033 1029 1034 1030 /* make lease_rdcache_gen match directory */ 1035 1031 dir = d_inode(dentry->d_parent); 1032 + 1033 + /* only track leases on regular dentries */ 1034 + if (ceph_snap(dir) != CEPH_NOSNAP) 1035 + goto out_unlock; 1036 + 1036 1037 di->lease_shared_gen = ceph_inode(dir)->i_shared_gen; 1037 1038 1038 1039 if (duration == 0) ··· 1203 1202 err = -ENOMEM; 1204 1203 goto done; 1205 1204 } 1206 - err = ceph_init_dentry(dn); 1207 - if (err < 0) { 1208 - dput(dn); 1209 - dput(parent); 1210 - goto done; 1211 - } 1205 + err = 0; 1212 1206 } else if (d_really_is_positive(dn) && 1213 1207 (ceph_ino(d_inode(dn)) != vino.ino || 1214 1208 ceph_snap(d_inode(dn)) != vino.snap)) { ··· 1555 1559 if (dn == NULL) { 1556 1560 dout("d_alloc badness\n"); 1557 1561 err = -ENOMEM; 1558 - goto out; 1559 - } 1560 - ret = ceph_init_dentry(dn); 1561 - if (ret < 0) { 1562 - dput(dn); 1563 - err = ret; 1564 1562 goto out; 1565 1563 } 1566 1564 } else if (d_really_is_positive(dn) &&
+1 -1
fs/ceph/super.c
··· 795 795 root = ERR_PTR(-ENOMEM); 796 796 goto out; 797 797 } 798 - ceph_init_dentry(root); 799 798 dout("open_root_inode success, root dentry is %p\n", root); 800 799 } else { 801 800 root = ERR_PTR(err); ··· 878 879 fsc->sb = s; 879 880 880 881 s->s_op = &ceph_super_ops; 882 + s->s_d_op = &ceph_dentry_ops; 881 883 s->s_export_op = &ceph_export_ops; 882 884 883 885 s->s_time_gran = 1000; /* 1000 ns == 1 us */
+1 -9
fs/ceph/super.h
··· 934 934 extern const struct file_operations ceph_snapdir_fops; 935 935 extern const struct inode_operations ceph_dir_iops; 936 936 extern const struct inode_operations ceph_snapdir_iops; 937 - extern const struct dentry_operations ceph_dentry_ops, ceph_snap_dentry_ops, 938 - ceph_snapdir_dentry_ops; 937 + extern const struct dentry_operations ceph_dentry_ops; 939 938 940 939 extern loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order); 941 940 extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry); ··· 949 950 extern void ceph_invalidate_dentry_lease(struct dentry *dentry); 950 951 extern unsigned ceph_dentry_hash(struct inode *dir, struct dentry *dn); 951 952 extern void ceph_readdir_cache_release(struct ceph_readdir_cache_control *ctl); 952 - 953 - /* 954 - * our d_ops vary depending on whether the inode is live, 955 - * snapshotted (read-only), or a virtual ".snap" directory. 956 - */ 957 - int ceph_init_dentry(struct dentry *dentry); 958 - 959 953 960 954 /* ioctl.c */ 961 955 extern long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
+54 -93
fs/namei.c
··· 1725 1725 return 1; 1726 1726 } 1727 1727 1728 + enum {WALK_FOLLOW = 1, WALK_MORE = 2}; 1729 + 1728 1730 /* 1729 1731 * Do we need to follow links? We _really_ want to be able 1730 1732 * to do this check without having to look at inode->i_op, 1731 1733 * so we keep a cache of "no, this doesn't need follow_link" 1732 1734 * for the common case. 1733 1735 */ 1734 - static inline int should_follow_link(struct nameidata *nd, struct path *link, 1735 - int follow, 1736 - struct inode *inode, unsigned seq) 1736 + static inline int step_into(struct nameidata *nd, struct path *path, 1737 + int flags, struct inode *inode, unsigned seq) 1737 1738 { 1738 - if (likely(!d_is_symlink(link->dentry))) 1739 + if (!(flags & WALK_MORE) && nd->depth) 1740 + put_link(nd); 1741 + if (likely(!d_is_symlink(path->dentry)) || 1742 + !(flags & WALK_FOLLOW || nd->flags & LOOKUP_FOLLOW)) { 1743 + /* not a symlink or should not follow */ 1744 + path_to_nameidata(path, nd); 1745 + nd->inode = inode; 1746 + nd->seq = seq; 1739 1747 return 0; 1740 - if (!follow) 1741 - return 0; 1748 + } 1742 1749 /* make sure that d_is_symlink above matches inode */ 1743 1750 if (nd->flags & LOOKUP_RCU) { 1744 - if (read_seqcount_retry(&link->dentry->d_seq, seq)) 1751 + if (read_seqcount_retry(&path->dentry->d_seq, seq)) 1745 1752 return -ECHILD; 1746 1753 } 1747 - return pick_link(nd, link, inode, seq); 1754 + return pick_link(nd, path, inode, seq); 1748 1755 } 1749 - 1750 - enum {WALK_GET = 1, WALK_PUT = 2}; 1751 1756 1752 1757 static int walk_component(struct nameidata *nd, int flags) 1753 1758 { ··· 1767 1762 */ 1768 1763 if (unlikely(nd->last_type != LAST_NORM)) { 1769 1764 err = handle_dots(nd, nd->last_type); 1770 - if (flags & WALK_PUT) 1765 + if (!(flags & WALK_MORE) && nd->depth) 1771 1766 put_link(nd); 1772 1767 return err; 1773 1768 } ··· 1794 1789 inode = d_backing_inode(path.dentry); 1795 1790 } 1796 1791 1797 - if (flags & WALK_PUT) 1798 - put_link(nd); 1799 - err = should_follow_link(nd, &path, flags & WALK_GET, inode, seq); 1800 - if (unlikely(err)) 1801 - return err; 1802 - path_to_nameidata(&path, nd); 1803 - nd->inode = inode; 1804 - nd->seq = seq; 1805 - return 0; 1792 + return step_into(nd, &path, flags, inode, seq); 1806 1793 } 1807 1794 1808 1795 /* ··· 2101 2104 if (!name) 2102 2105 return 0; 2103 2106 /* last component of nested symlink */ 2104 - err = walk_component(nd, WALK_GET | WALK_PUT); 2107 + err = walk_component(nd, WALK_FOLLOW); 2105 2108 } else { 2106 - err = walk_component(nd, WALK_GET); 2109 + /* not the last component */ 2110 + err = walk_component(nd, WALK_FOLLOW | WALK_MORE); 2107 2111 } 2108 2112 if (err < 0) 2109 2113 return err; ··· 2246 2248 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; 2247 2249 2248 2250 nd->flags &= ~LOOKUP_PARENT; 2249 - return walk_component(nd, 2250 - nd->flags & LOOKUP_FOLLOW 2251 - ? nd->depth 2252 - ? WALK_PUT | WALK_GET 2253 - : WALK_GET 2254 - : 0); 2251 + return walk_component(nd, 0); 2255 2252 } 2256 2253 2257 2254 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */ ··· 2551 2558 } 2552 2559 EXPORT_SYMBOL(user_path_at_empty); 2553 2560 2554 - /* 2555 - * NB: most callers don't do anything directly with the reference to the 2556 - * to struct filename, but the nd->last pointer points into the name string 2557 - * allocated by getname. So we must hold the reference to it until all 2558 - * path-walking is complete. 2559 - */ 2560 - static inline struct filename * 2561 - user_path_parent(int dfd, const char __user *path, 2562 - struct path *parent, 2563 - struct qstr *last, 2564 - int *type, 2565 - unsigned int flags) 2566 - { 2567 - /* only LOOKUP_REVAL is allowed in extra flags */ 2568 - return filename_parentat(dfd, getname(path), flags & LOOKUP_REVAL, 2569 - parent, last, type); 2570 - } 2571 - 2572 2561 /** 2573 2562 * mountpoint_last - look up last component for umount 2574 2563 * @nd: pathwalk nameidata - currently pointing at parent directory of "last" 2575 - * @path: pointer to container for result 2576 2564 * 2577 2565 * This is a special lookup_last function just for umount. In this case, we 2578 2566 * need to resolve the path without doing any revalidation. ··· 2566 2592 * 2567 2593 * Returns: 2568 2594 * -error: if there was an error during lookup. This includes -ENOENT if the 2569 - * lookup found a negative dentry. The nd->path reference will also be 2570 - * put in this case. 2595 + * lookup found a negative dentry. 2571 2596 * 2572 - * 0: if we successfully resolved nd->path and found it to not to be a 2573 - * symlink that needs to be followed. "path" will also be populated. 2574 - * The nd->path reference will also be put. 2597 + * 0: if we successfully resolved nd->last and found it to not to be a 2598 + * symlink that needs to be followed. 2575 2599 * 2576 2600 * 1: if we successfully resolved nd->last and found it to be a symlink 2577 - * that needs to be followed. "path" will be populated with the path 2578 - * to the link, and nd->path will *not* be put. 2601 + * that needs to be followed. 2579 2602 */ 2580 2603 static int 2581 - mountpoint_last(struct nameidata *nd, struct path *path) 2604 + mountpoint_last(struct nameidata *nd) 2582 2605 { 2583 2606 int error = 0; 2584 - struct dentry *dentry; 2585 2607 struct dentry *dir = nd->path.dentry; 2608 + struct path path; 2586 2609 2587 2610 /* If we're in rcuwalk, drop out of it to handle last component */ 2588 2611 if (nd->flags & LOOKUP_RCU) { ··· 2593 2622 error = handle_dots(nd, nd->last_type); 2594 2623 if (error) 2595 2624 return error; 2596 - dentry = dget(nd->path.dentry); 2625 + path.dentry = dget(nd->path.dentry); 2597 2626 } else { 2598 - dentry = d_lookup(dir, &nd->last); 2599 - if (!dentry) { 2627 + path.dentry = d_lookup(dir, &nd->last); 2628 + if (!path.dentry) { 2600 2629 /* 2601 2630 * No cached dentry. Mounted dentries are pinned in the 2602 2631 * cache, so that means that this dentry is probably 2603 2632 * a symlink or the path doesn't actually point 2604 2633 * to a mounted dentry. 2605 2634 */ 2606 - dentry = lookup_slow(&nd->last, dir, 2635 + path.dentry = lookup_slow(&nd->last, dir, 2607 2636 nd->flags | LOOKUP_NO_REVAL); 2608 - if (IS_ERR(dentry)) 2609 - return PTR_ERR(dentry); 2637 + if (IS_ERR(path.dentry)) 2638 + return PTR_ERR(path.dentry); 2610 2639 } 2611 2640 } 2612 - if (d_is_negative(dentry)) { 2613 - dput(dentry); 2641 + if (d_is_negative(path.dentry)) { 2642 + dput(path.dentry); 2614 2643 return -ENOENT; 2615 2644 } 2616 - if (nd->depth) 2617 - put_link(nd); 2618 - path->dentry = dentry; 2619 - path->mnt = nd->path.mnt; 2620 - error = should_follow_link(nd, path, nd->flags & LOOKUP_FOLLOW, 2621 - d_backing_inode(dentry), 0); 2622 - if (unlikely(error)) 2623 - return error; 2624 - mntget(path->mnt); 2625 - follow_mount(path); 2626 - return 0; 2645 + path.mnt = nd->path.mnt; 2646 + return step_into(nd, &path, 0, d_backing_inode(path.dentry), 0); 2627 2647 } 2628 2648 2629 2649 /** ··· 2634 2672 if (IS_ERR(s)) 2635 2673 return PTR_ERR(s); 2636 2674 while (!(err = link_path_walk(s, nd)) && 2637 - (err = mountpoint_last(nd, path)) > 0) { 2675 + (err = mountpoint_last(nd)) > 0) { 2638 2676 s = trailing_symlink(nd); 2639 2677 if (IS_ERR(s)) { 2640 2678 err = PTR_ERR(s); 2641 2679 break; 2642 2680 } 2681 + } 2682 + if (!err) { 2683 + *path = nd->path; 2684 + nd->path.mnt = NULL; 2685 + nd->path.dentry = NULL; 2686 + follow_mount(path); 2643 2687 } 2644 2688 terminate_walk(nd); 2645 2689 return err; ··· 3303 3335 seq = 0; /* out of RCU mode, so the value doesn't matter */ 3304 3336 inode = d_backing_inode(path.dentry); 3305 3337 finish_lookup: 3306 - if (nd->depth) 3307 - put_link(nd); 3308 - error = should_follow_link(nd, &path, nd->flags & LOOKUP_FOLLOW, 3309 - inode, seq); 3338 + error = step_into(nd, &path, 0, inode, seq); 3310 3339 if (unlikely(error)) 3311 3340 return error; 3312 - 3313 - path_to_nameidata(&path, nd); 3314 - nd->inode = inode; 3315 - nd->seq = seq; 3316 - /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */ 3317 3341 finish_open: 3342 + /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */ 3318 3343 error = complete_walk(nd); 3319 3344 if (error) 3320 3345 return error; ··· 3822 3861 int type; 3823 3862 unsigned int lookup_flags = 0; 3824 3863 retry: 3825 - name = user_path_parent(dfd, pathname, 3826 - &path, &last, &type, lookup_flags); 3864 + name = filename_parentat(dfd, getname(pathname), lookup_flags, 3865 + &path, &last, &type); 3827 3866 if (IS_ERR(name)) 3828 3867 return PTR_ERR(name); 3829 3868 ··· 3952 3991 struct inode *delegated_inode = NULL; 3953 3992 unsigned int lookup_flags = 0; 3954 3993 retry: 3955 - name = user_path_parent(dfd, pathname, 3956 - &path, &last, &type, lookup_flags); 3994 + name = filename_parentat(dfd, getname(pathname), lookup_flags, 3995 + &path, &last, &type); 3957 3996 if (IS_ERR(name)) 3958 3997 return PTR_ERR(name); 3959 3998 ··· 4452 4491 target_flags = 0; 4453 4492 4454 4493 retry: 4455 - from = user_path_parent(olddfd, oldname, 4456 - &old_path, &old_last, &old_type, lookup_flags); 4494 + from = filename_parentat(olddfd, getname(oldname), lookup_flags, 4495 + &old_path, &old_last, &old_type); 4457 4496 if (IS_ERR(from)) { 4458 4497 error = PTR_ERR(from); 4459 4498 goto exit; 4460 4499 } 4461 4500 4462 - to = user_path_parent(newdfd, newname, 4463 - &new_path, &new_last, &new_type, lookup_flags); 4501 + to = filename_parentat(newdfd, getname(newname), lookup_flags, 4502 + &new_path, &new_last, &new_type); 4464 4503 if (IS_ERR(to)) { 4465 4504 error = PTR_ERR(to); 4466 4505 goto exit1;
+1 -1
fs/ncpfs/file.c
··· 203 203 bufsize - (pos % bufsize), 204 204 iov_iter_count(from)); 205 205 206 - if (copy_from_iter(bouncebuffer, to_write, from) != to_write) { 206 + if (!copy_from_iter_full(bouncebuffer, to_write, from)) { 207 207 errno = -EFAULT; 208 208 break; 209 209 }
+4 -9
fs/orangefs/devorangefs-req.c
··· 355 355 __u64 tag; 356 356 } head; 357 357 int total = ret = iov_iter_count(iter); 358 - int n; 359 358 int downcall_size = sizeof(struct orangefs_downcall_s); 360 359 int head_size = sizeof(head); 361 360 ··· 371 372 return -EFAULT; 372 373 } 373 374 374 - n = copy_from_iter(&head, head_size, iter); 375 - if (n < head_size) { 375 + if (!copy_from_iter_full(&head, head_size, iter)) { 376 376 gossip_err("%s: failed to copy head.\n", __func__); 377 377 return -EFAULT; 378 378 } ··· 405 407 return ret; 406 408 } 407 409 408 - n = copy_from_iter(&op->downcall, downcall_size, iter); 409 - if (n != downcall_size) { 410 + if (!copy_from_iter_full(&op->downcall, downcall_size, iter)) { 410 411 gossip_err("%s: failed to copy downcall.\n", __func__); 411 412 goto Efault; 412 413 } ··· 459 462 goto Enomem; 460 463 } 461 464 memset(op->downcall.trailer_buf, 0, op->downcall.trailer_size); 462 - n = copy_from_iter(op->downcall.trailer_buf, 463 - op->downcall.trailer_size, 464 - iter); 465 - if (n != op->downcall.trailer_size) { 465 + if (!copy_from_iter_full(op->downcall.trailer_buf, 466 + op->downcall.trailer_size, iter)) { 466 467 gossip_err("%s: failed to copy trailer.\n", __func__); 467 468 vfree(op->downcall.trailer_buf); 468 469 goto Efault;
+3 -3
include/linux/skbuff.h
··· 2809 2809 2810 2810 if (skb->ip_summed == CHECKSUM_NONE) { 2811 2811 __wsum csum = 0; 2812 - if (csum_and_copy_from_iter(skb_put(skb, copy), copy, 2813 - &csum, from) == copy) { 2812 + if (csum_and_copy_from_iter_full(skb_put(skb, copy), copy, 2813 + &csum, from)) { 2814 2814 skb->csum = csum_block_add(skb->csum, csum, off); 2815 2815 return 0; 2816 2816 } 2817 - } else if (copy_from_iter(skb_put(skb, copy), copy, from) == copy) 2817 + } else if (copy_from_iter_full(skb_put(skb, copy), copy, from)) 2818 2818 return 0; 2819 2819 2820 2820 __skb_trim(skb, off);
+3
include/linux/uio.h
··· 89 89 struct iov_iter *i); 90 90 size_t copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i); 91 91 size_t copy_from_iter(void *addr, size_t bytes, struct iov_iter *i); 92 + bool copy_from_iter_full(void *addr, size_t bytes, struct iov_iter *i); 92 93 size_t copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i); 94 + bool copy_from_iter_full_nocache(void *addr, size_t bytes, struct iov_iter *i); 93 95 size_t iov_iter_zero(size_t bytes, struct iov_iter *); 94 96 unsigned long iov_iter_alignment(const struct iov_iter *i); 95 97 unsigned long iov_iter_gap_alignment(const struct iov_iter *i); ··· 157 155 } 158 156 size_t csum_and_copy_to_iter(const void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); 159 157 size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); 158 + bool csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); 160 159 161 160 int import_iovec(int type, const struct iovec __user * uvector, 162 161 unsigned nr_segs, unsigned fast_segs,
+3 -3
include/net/sock.h
··· 1783 1783 { 1784 1784 if (skb->ip_summed == CHECKSUM_NONE) { 1785 1785 __wsum csum = 0; 1786 - if (csum_and_copy_from_iter(to, copy, &csum, from) != copy) 1786 + if (!csum_and_copy_from_iter_full(to, copy, &csum, from)) 1787 1787 return -EFAULT; 1788 1788 skb->csum = csum_block_add(skb->csum, csum, offset); 1789 1789 } else if (sk->sk_route_caps & NETIF_F_NOCACHE_COPY) { 1790 - if (copy_from_iter_nocache(to, copy, from) != copy) 1790 + if (!copy_from_iter_full_nocache(to, copy, from)) 1791 1791 return -EFAULT; 1792 - } else if (copy_from_iter(to, copy, from) != copy) 1792 + } else if (!copy_from_iter_full(to, copy, from)) 1793 1793 return -EFAULT; 1794 1794 1795 1795 return 0;
+1 -1
include/net/udplite.h
··· 20 20 int len, int odd, struct sk_buff *skb) 21 21 { 22 22 struct msghdr *msg = from; 23 - return copy_from_iter(to, len, &msg->msg_iter) != len ? -EFAULT : 0; 23 + return copy_from_iter_full(to, len, &msg->msg_iter) ? 0 : -EFAULT; 24 24 } 25 25 26 26 /* Designate sk as UDP-Lite socket */
+1 -1
kernel/printk/printk.c
··· 748 748 return -ENOMEM; 749 749 750 750 buf[len] = '\0'; 751 - if (copy_from_iter(buf, len, from) != len) { 751 + if (!copy_from_iter_full(buf, len, from)) { 752 752 kfree(buf); 753 753 return -EFAULT; 754 754 }
+96 -2
lib/iov_iter.c
··· 568 568 } 569 569 EXPORT_SYMBOL(copy_from_iter); 570 570 571 + bool copy_from_iter_full(void *addr, size_t bytes, struct iov_iter *i) 572 + { 573 + char *to = addr; 574 + if (unlikely(i->type & ITER_PIPE)) { 575 + WARN_ON(1); 576 + return false; 577 + } 578 + if (unlikely(i->count < bytes)) \ 579 + return false; 580 + 581 + iterate_all_kinds(i, bytes, v, ({ 582 + if (__copy_from_user((to += v.iov_len) - v.iov_len, 583 + v.iov_base, v.iov_len)) 584 + return false; 585 + 0;}), 586 + memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, 587 + v.bv_offset, v.bv_len), 588 + memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) 589 + ) 590 + 591 + iov_iter_advance(i, bytes); 592 + return true; 593 + } 594 + EXPORT_SYMBOL(copy_from_iter_full); 595 + 571 596 size_t copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i) 572 597 { 573 598 char *to = addr; ··· 611 586 return bytes; 612 587 } 613 588 EXPORT_SYMBOL(copy_from_iter_nocache); 589 + 590 + bool copy_from_iter_full_nocache(void *addr, size_t bytes, struct iov_iter *i) 591 + { 592 + char *to = addr; 593 + if (unlikely(i->type & ITER_PIPE)) { 594 + WARN_ON(1); 595 + return false; 596 + } 597 + if (unlikely(i->count < bytes)) \ 598 + return false; 599 + iterate_all_kinds(i, bytes, v, ({ 600 + if (__copy_from_user_nocache((to += v.iov_len) - v.iov_len, 601 + v.iov_base, v.iov_len)) 602 + return false; 603 + 0;}), 604 + memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page, 605 + v.bv_offset, v.bv_len), 606 + memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len) 607 + ) 608 + 609 + iov_iter_advance(i, bytes); 610 + return true; 611 + } 612 + EXPORT_SYMBOL(copy_from_iter_full_nocache); 614 613 615 614 size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, 616 615 struct iov_iter *i) ··· 1057 1008 } 1058 1009 iterate_and_advance(i, bytes, v, ({ 1059 1010 int err = 0; 1060 - next = csum_and_copy_from_user(v.iov_base, 1011 + next = csum_and_copy_from_user(v.iov_base, 1061 1012 (to += v.iov_len) - v.iov_len, 1062 1013 v.iov_len, 0, &err); 1063 1014 if (!err) { ··· 1086 1037 } 1087 1038 EXPORT_SYMBOL(csum_and_copy_from_iter); 1088 1039 1040 + bool csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, 1041 + struct iov_iter *i) 1042 + { 1043 + char *to = addr; 1044 + __wsum sum, next; 1045 + size_t off = 0; 1046 + sum = *csum; 1047 + if (unlikely(i->type & ITER_PIPE)) { 1048 + WARN_ON(1); 1049 + return false; 1050 + } 1051 + if (unlikely(i->count < bytes)) 1052 + return false; 1053 + iterate_all_kinds(i, bytes, v, ({ 1054 + int err = 0; 1055 + next = csum_and_copy_from_user(v.iov_base, 1056 + (to += v.iov_len) - v.iov_len, 1057 + v.iov_len, 0, &err); 1058 + if (err) 1059 + return false; 1060 + sum = csum_block_add(sum, next, off); 1061 + off += v.iov_len; 1062 + 0; 1063 + }), ({ 1064 + char *p = kmap_atomic(v.bv_page); 1065 + next = csum_partial_copy_nocheck(p + v.bv_offset, 1066 + (to += v.bv_len) - v.bv_len, 1067 + v.bv_len, 0); 1068 + kunmap_atomic(p); 1069 + sum = csum_block_add(sum, next, off); 1070 + off += v.bv_len; 1071 + }),({ 1072 + next = csum_partial_copy_nocheck(v.iov_base, 1073 + (to += v.iov_len) - v.iov_len, 1074 + v.iov_len, 0); 1075 + sum = csum_block_add(sum, next, off); 1076 + off += v.iov_len; 1077 + }) 1078 + ) 1079 + *csum = sum; 1080 + iov_iter_advance(i, bytes); 1081 + return true; 1082 + } 1083 + EXPORT_SYMBOL(csum_and_copy_from_iter_full); 1084 + 1089 1085 size_t csum_and_copy_to_iter(const void *addr, size_t bytes, __wsum *csum, 1090 1086 struct iov_iter *i) 1091 1087 { ··· 1145 1051 iterate_and_advance(i, bytes, v, ({ 1146 1052 int err = 0; 1147 1053 next = csum_and_copy_to_user((from += v.iov_len) - v.iov_len, 1148 - v.iov_base, 1054 + v.iov_base, 1149 1055 v.iov_len, 0, &err); 1150 1056 if (!err) { 1151 1057 sum = csum_block_add(sum, next, off);
+1 -1
net/atm/common.c
··· 630 630 goto out; 631 631 skb->dev = NULL; /* for paths shared with net_device interfaces */ 632 632 ATM_SKB(skb)->atm_options = vcc->atm_options; 633 - if (copy_from_iter(skb_put(skb, size), size, &m->msg_iter) != size) { 633 + if (!copy_from_iter_full(skb_put(skb, size), size, &m->msg_iter)) { 634 634 kfree_skb(skb); 635 635 error = -EFAULT; 636 636 goto out;
+3 -3
net/bluetooth/l2cap_core.c
··· 2127 2127 struct sk_buff **frag; 2128 2128 int sent = 0; 2129 2129 2130 - if (copy_from_iter(skb_put(skb, count), count, &msg->msg_iter) != count) 2130 + if (!copy_from_iter_full(skb_put(skb, count), count, &msg->msg_iter)) 2131 2131 return -EFAULT; 2132 2132 2133 2133 sent += count; ··· 2147 2147 2148 2148 *frag = tmp; 2149 2149 2150 - if (copy_from_iter(skb_put(*frag, count), count, 2151 - &msg->msg_iter) != count) 2150 + if (!copy_from_iter_full(skb_put(*frag, count), count, 2151 + &msg->msg_iter)) 2152 2152 return -EFAULT; 2153 2153 2154 2154 sent += count;
+2 -2
net/ipv4/ip_output.c
··· 802 802 struct msghdr *msg = from; 803 803 804 804 if (skb->ip_summed == CHECKSUM_PARTIAL) { 805 - if (copy_from_iter(to, len, &msg->msg_iter) != len) 805 + if (!copy_from_iter_full(to, len, &msg->msg_iter)) 806 806 return -EFAULT; 807 807 } else { 808 808 __wsum csum = 0; 809 - if (csum_and_copy_from_iter(to, len, &csum, &msg->msg_iter) != len) 809 + if (!csum_and_copy_from_iter_full(to, len, &csum, &msg->msg_iter)) 810 810 return -EFAULT; 811 811 skb->csum = csum_block_add(skb->csum, csum, odd); 812 812 }
+4 -4
net/ipv4/ping.c
··· 609 609 fraglen -= sizeof(struct icmphdr); 610 610 if (fraglen < 0) 611 611 BUG(); 612 - if (csum_and_copy_from_iter(to + sizeof(struct icmphdr), 612 + if (!csum_and_copy_from_iter_full(to + sizeof(struct icmphdr), 613 613 fraglen, &pfh->wcheck, 614 - &pfh->msg->msg_iter) != fraglen) 614 + &pfh->msg->msg_iter)) 615 615 return -EFAULT; 616 616 } else if (offset < sizeof(struct icmphdr)) { 617 617 BUG(); 618 618 } else { 619 - if (csum_and_copy_from_iter(to, fraglen, &pfh->wcheck, 620 - &pfh->msg->msg_iter) != fraglen) 619 + if (!csum_and_copy_from_iter_full(to, fraglen, &pfh->wcheck, 620 + &pfh->msg->msg_iter)) 621 621 return -EFAULT; 622 622 } 623 623
+1 -4
net/packet/af_packet.c
··· 2432 2432 static int packet_snd_vnet_parse(struct msghdr *msg, size_t *len, 2433 2433 struct virtio_net_hdr *vnet_hdr) 2434 2434 { 2435 - int n; 2436 - 2437 2435 if (*len < sizeof(*vnet_hdr)) 2438 2436 return -EINVAL; 2439 2437 *len -= sizeof(*vnet_hdr); 2440 2438 2441 - n = copy_from_iter(vnet_hdr, sizeof(*vnet_hdr), &msg->msg_iter); 2442 - if (n != sizeof(*vnet_hdr)) 2439 + if (!copy_from_iter_full(vnet_hdr, sizeof(*vnet_hdr), &msg->msg_iter)) 2443 2440 return -EFAULT; 2444 2441 2445 2442 return __packet_snd_vnet_parse(vnet_hdr, *len);
+2 -2
net/tipc/msg.c
··· 268 268 __skb_queue_tail(list, skb); 269 269 skb_copy_to_linear_data(skb, mhdr, mhsz); 270 270 pktpos = skb->data + mhsz; 271 - if (copy_from_iter(pktpos, dsz, &m->msg_iter) == dsz) 271 + if (copy_from_iter_full(pktpos, dsz, &m->msg_iter)) 272 272 return dsz; 273 273 rc = -EFAULT; 274 274 goto error; ··· 299 299 if (drem < pktrem) 300 300 pktrem = drem; 301 301 302 - if (copy_from_iter(pktpos, pktrem, &m->msg_iter) != pktrem) { 302 + if (!copy_from_iter_full(pktpos, pktrem, &m->msg_iter)) { 303 303 rc = -EFAULT; 304 304 goto error; 305 305 }
+1 -1
security/keys/keyctl.c
··· 1074 1074 } 1075 1075 1076 1076 ret = -EFAULT; 1077 - if (copy_from_iter(payload, plen, from) != plen) 1077 + if (!copy_from_iter_full(payload, plen, from)) 1078 1078 goto error2; 1079 1079 } 1080 1080