Skip to content

Commit e6bc45d

Browse files
tytsoAl Viro
authored andcommitted
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>
1 parent 9054760 commit e6bc45d

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎fs/namei.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,10 @@ static long do_rmdir(int dfd, const char __user *pathname)
26242624
error = PTR_ERR(dentry);
26252625
if (IS_ERR(dentry))
26262626
goto exit2;
2627+
if (!dentry->d_inode) {
2628+
error = -ENOENT;
2629+
goto exit3;
2630+
}
26272631
error = mnt_want_write(nd.path.mnt);
26282632
if (error)
26292633
goto exit3;
@@ -2709,11 +2713,10 @@ static long do_unlinkat(int dfd, const char __user *pathname)
27092713
error = PTR_ERR(dentry);
27102714
if (!IS_ERR(dentry)) {
27112715
/* Why not before? Because we want correct error value */
2712-
if (nd.last.name[nd.last.len])
2713-
goto slashes;
27142716
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);
27172720
error = mnt_want_write(nd.path.mnt);
27182721
if (error)
27192722
goto exit2;

0 commit comments

Comments
 (0)