minix: reject rmdir of a directory with a corrupted link count
PATCH 1/1 minix: reject rmdir of a directory with a corrupted link count
minix_rmdir() calls minix_unlink(), which drops the victim's link count once, and then drops it a second time for the "." entry. An image where an empty directory has i_nlink < 2 makes the second drop hit drop_nlink() with i_nlink == 0:
WARNING: fs/inode.c:408 at drop_nlink minix_rmdir+0xe9/0x150 vfs_rmdir filename_rmdir __do_sys_unlinkat
The parent's link count is already validated; do the same for the directory being removed and fail with -EFSCORRUPTED.
--- fs/minix/namei.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/minix/namei.c +4 -0
@@ -172,6 +172,10 @@ static int minix_rmdir(struct inode * dir, struct dentry *dentry)minix_error_inode (dir,"inode has corrupted nlink" ); goto out; } +if (inode->i_nlink <2 ) { +minix_error_inode (inode,"inode has corrupted nlink" ); + goto out; + } err = -ENOTEMPTY ;if (!minix_empty_dir (inode))
Signature · 1 line
2.43.0
Quoted 5 lines · Nguyen Ngoc Thang
minix_rmdir()callsminix_unlink(), which drops the victim's link count once, and then drops it a second time for the "." entry. An image where an empty directory hasi_nlink< 2 makes the second drop hitdrop_nlink()withi_nlink== 0:
Quoted 7 lines
WARNING: fs/inode.c:408 at drop_nlink minix_rmdir+0xe9/0x150 vfs_rmdir filename_rmdir __do_sys_unlinkat[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] minix: reject rmdir of a directory with a corrupted link count
https://git.kernel.org/vfs/vfs/c/fc9577079df8