Return-Path: Received: from mx2.suse.de ([195.135.220.15]:60820 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728250AbeJVUHS (ORCPT ); Mon, 22 Oct 2018 16:07:18 -0400 From: Jan Kara To: Al Viro Cc: , Jan Kara , Theodore Ts'o , Miklos Szeredi Subject: [PATCH] vfs: Do not allow underflowing of i_nlink Date: Mon, 22 Oct 2018 13:48:50 +0200 Message-Id: <20181022114850.1912-1-jack@suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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 CC: Miklos Szeredi Signed-off-by: Jan Kara --- fs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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); -- 2.16.4