History

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull vfs fixes from Al Viro. * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: do_last(): ELOOP failure exit should be done after leaving RCU mode should_follow_link(): validate ->d_seq after having decided to follow namei: ->d_inode of a pinned dentry is stable only for positives do_last(): don't let a bogus return value from ->open() et.al. to confuse us fs: return -EOPNOTSUPP if clone is not supported hpfs: don't truncate the file when delete fails

Linus Torvalds committed 10 years ago

Commit 12b9fa62 parents 340b3a5 5129fa43 files · +22 −37Browse files

Unified · Split

3 files
  1. fs/hpfs/namei.c +3 −28
  2. fs/namei.c +15 −7
  3. fs/read_write.c +4 −2
fs/hpfs/namei.c+3−28
@@ -376,12 +376,11 @@ static int hpfs_unlink(struct inode *dir, struct dentry *dentry) · 375 unmodified lines
376376 struct inode *inode = d_inode(dentry);
377377 dnode_secno dno;
378378 int r;
379− int rep = 0;
380379 int err;
381380
382381 hpfs_lock(dir->i_sb);
383382 hpfs_adjust_length(name, &len);
384−again:
383+
385384 err = -ENOENT;
386385 de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, &dno, &qbh);
387386 if (!de)
@@ -401,33 +400,9 @@ again: · 13 unmodified lines
401400 hpfs_error(dir->i_sb, "there was error when removing dirent");
402401 err = -EFSERROR;
403402 break;
404− case 2: /* no space for deleting, try to truncate file */
405−
403+ case 2: /* no space for deleting */
406404 err = -ENOSPC;
407− if (rep++)
408− break;
409−
410− dentry_unhash(dentry);
411− if (!d_unhashed(dentry)) {
412− hpfs_unlock(dir->i_sb);
413− return -ENOSPC;
414− }
415− if (generic_permission(inode, MAY_WRITE) ||
416− !S_ISREG(inode->i_mode) ||
417− get_write_access(inode)) {
418− d_rehash(dentry);
419− } else {
420− struct iattr newattrs;
421− /*pr_info("truncating file before delete.\n");*/
422− newattrs.ia_size = 0;
423− newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
424− err = notify_change(dentry, &newattrs, NULL);
425− put_write_access(inode);
426− if (!err)
427− goto again;
428− }
429− hpfs_unlock(dir->i_sb);
430− return -ENOSPC;
405+ break;
431406 default:
432407 drop_nlink(inode);
433408 err = 0;
fs/namei.c+15−7
@@ -1712,6 +1712,11 @@ static inline int should_follow_link(struct nameidata *nd, struct path *link, · 1711 unmodified lines
17121712 return 0;
17131713 if (!follow)
17141714 return 0;
1715+ /* make sure that d_is_symlink above matches inode */
1716+ if (nd->flags & LOOKUP_RCU) {
1717+ if (read_seqcount_retry(&link->dentry->d_seq, seq))
1718+ return -ECHILD;
1719+ }
17151720 return pick_link(nd, link, inode, seq);
17161721 }
17171722
@@ -1743,11 +1748,11 @@ static int walk_component(struct nameidata *nd, int flags) · 25 unmodified lines
17431748 if (err < 0)
17441749 return err;
17451750
1746− inode = d_backing_inode(path.dentry);
17471751 seq = 0; /* we are already out of RCU mode */
17481752 err = -ENOENT;
17491753 if (d_is_negative(path.dentry))
17501754 goto out_path_put;
1755+ inode = d_backing_inode(path.dentry);
17511756 }
17521757
17531758 if (flags & WALK_PUT)
@@ -3192,12 +3197,12 @@ retry_lookup: · 1438 unmodified lines
31923197 return error;
31933198
31943199 BUG_ON(nd->flags & LOOKUP_RCU);
3195− inode = d_backing_inode(path.dentry);
31963200 seq = 0; /* out of RCU mode, so the value doesn't matter */
31973201 if (unlikely(d_is_negative(path.dentry))) {
31983202 path_to_nameidata(&path, nd);
31993203 return -ENOENT;
32003204 }
3205+ inode = d_backing_inode(path.dentry);
32013206 finish_lookup:
32023207 if (nd->depth)
32033208 put_link(nd);
@@ -3206,11 +3211,6 @@ finish_lookup: · 2 unmodified lines
32063211 if (unlikely(error))
32073212 return error;
32083213
3209− if (unlikely(d_is_symlink(path.dentry)) && !(open_flag & O_PATH)) {
3210− path_to_nameidata(&path, nd);
3211− return -ELOOP;
3212− }
3213−
32143214 if ((nd->flags & LOOKUP_RCU) || nd->path.mnt != path.mnt) {
32153215 path_to_nameidata(&path, nd);
32163216 } else {
@@ -3229,6 +3229,10 @@ finish_open: · 12 unmodified lines
32293229 return error;
32303230 }
32313231 audit_inode(nd->name, nd->path.dentry, 0);
3232+ if (unlikely(d_is_symlink(nd->path.dentry)) && !(open_flag & O_PATH)) {
3233+ error = -ELOOP;
3234+ goto out;
3235+ }
32323236 error = -EISDIR;
32333237 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
32343238 goto out;
@@ -3273,6 +3277,10 @@ opened: · 38 unmodified lines
32733277 goto exit_fput;
32743278 }
32753279 out:
3280+ if (unlikely(error > 0)) {
3281+ WARN_ON(1);
3282+ error = -EINVAL;
3283+ }
32763284 if (got_write)
32773285 mnt_drop_write(nd->path.mnt);
32783286 path_put(&save_parent);
fs/read_write.c+4−2
@@ -1533,10 +1533,12 @@ int vfs_clone_file_range(struct file *file_in, loff_t pos_in, · 1532 unmodified lines
15331533
15341534 if (!(file_in->f_mode & FMODE_READ) ||
15351535 !(file_out->f_mode & FMODE_WRITE) ||
1536− (file_out->f_flags & O_APPEND) ||
1537− !file_in->f_op->clone_file_range)
1536+ (file_out->f_flags & O_APPEND))
15381537 return -EBADF;
15391538
1539+ if (!file_in->f_op->clone_file_range)
1540+ return -EOPNOTSUPP;
1541+
15401542 ret = clone_verify_area(file_in, pos_in, len, false);
15411543 if (ret)
15421544 return ret;

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