Message ID | 20181022114850.1912-1-jack@suse.cz (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | vfs: Do not allow underflowing of i_nlink | expand |
diff --git a/fs/inode.c b/fs/inode.c index 42f6d25f32a5..d449824a90de 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -282,7 +282,8 @@ static void destroy_inode(struct inode *inode) */ void drop_nlink(struct inode *inode) { - WARN_ON(inode->i_nlink == 0); + if (WARN_ON(inode->i_nlink == 0)) + return; inode->__i_nlink--; if (!inode->i_nlink) atomic_long_inc(&inode->i_sb->s_remove_count);
Currently, drop_nlink() warns when i_nlink underflows but it still lets the value underflow. Granted such underflow means filesystem corruption so we are screwed but still it limits the damage more if we leave i_nlink at 0 to keep inode in "unlinked" state instead of letting it magically appear linked again which confuses filesystems even more. For example this would make b50282f3241a "ext4: check to make sure the rename(2)'s destination is not freed" just a cosmetic fix instead of a memory-corruption fix. CC: Theodore Ts'o <tytso@mit.edu> CC: Miklos Szeredi <mszeredi@redhat.com> Signed-off-by: Jan Kara <jack@suse.cz> --- fs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)