* [PATCH] vfs: Do not allow underflowing of i_nlink
@ 2018-10-22 11:48 Jan Kara
0 siblings, 0 replies; only message in thread
From: Jan Kara @ 2018-10-22 11:48 UTC (permalink / raw)
To: Al Viro; +Cc: linux-fsdevel, Jan Kara, Theodore Ts'o, Miklos Szeredi
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(-)
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-10-22 20:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-22 11:48 [PATCH] vfs: Do not allow underflowing of i_nlink Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).