Commit e6bc45d65df8599fdbae73be9cec4ceed274db53

Authored by Theodore Ts'o
Committed by Al Viro
1 parent 9054760ff5

vfs: make unlink() and rmdir() return ENOENT in preference to EROFS

If user space attempts to remove a non-existent file or directory, and
the file system is mounted read-only, return ENOENT instead of EROFS.
Either error code is arguably valid/correct, but ENOENT is a more
specific error message.

Reported-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 1 changed file with 7 additions and 4 deletions Side-by-side Diff

... ... @@ -2624,6 +2624,10 @@
2624 2624 error = PTR_ERR(dentry);
2625 2625 if (IS_ERR(dentry))
2626 2626 goto exit2;
  2627 + if (!dentry->d_inode) {
  2628 + error = -ENOENT;
  2629 + goto exit3;
  2630 + }
2627 2631 error = mnt_want_write(nd.path.mnt);
2628 2632 if (error)
2629 2633 goto exit3;
2630 2634  
... ... @@ -2709,11 +2713,10 @@
2709 2713 error = PTR_ERR(dentry);
2710 2714 if (!IS_ERR(dentry)) {
2711 2715 /* Why not before? Because we want correct error value */
2712   - if (nd.last.name[nd.last.len])
2713   - goto slashes;
2714 2716 inode = dentry->d_inode;
2715   - if (inode)
2716   - ihold(inode);
  2717 + if (nd.last.name[nd.last.len] || !inode)
  2718 + goto slashes;
  2719 + ihold(inode);
2717 2720 error = mnt_want_write(nd.path.mnt);
2718 2721 if (error)
2719 2722 goto exit2;