[PATCH] vfs: Do not allow underflowing of i_nlink

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
CC: Miklos Szeredi <mszeredi@xxxxxxxxxx>
Signed-off-by: Jan Kara <jack@xxxxxxx>
---
 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




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux