lkml.org 
[lkml]   [2023]   [Oct]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[RFC PATCH v2] fs: introduce check for inode nlink when delete
From: Cheng Lin <cheng.lin130@zte.com.cn>

Do not delete inode which nlink already zero to avoid
inode nlink underflow.

Signed-off-by: Cheng Lin <cheng.lin130@zte.com.cn>
---
fs/namei.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/fs/namei.c b/fs/namei.c
index e56ff39a7..30bc0d0a6 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4197,6 +4197,11 @@ int vfs_rmdir(struct mnt_idmap *idmap, struct inode *dir,
if (error)
goto out;

+ if (unlikely(dir->i_nlink == 0) ||
+ unlikely(dentry->d_inode->i_nlink == 0)) {
+ error = -EUCLEAN;
+ goto out;
+ }
error = dir->i_op->rmdir(dir, dentry);
if (error)
goto out;
@@ -4326,6 +4331,10 @@ int vfs_unlink(struct mnt_idmap *idmap, struct inode *dir,
error = try_break_deleg(target, delegated_inode);
if (error)
goto out;
+ if (unlikely(target->i_nlink == 0)) {
+ error = -EUCLEAN;
+ goto out;
+ }
error = dir->i_op->unlink(dir, dentry);
if (!error) {
dont_mount(dentry);
--
2.18.1
\
 
 \ /
  Last update: 2023-10-18 12:09    [W:0.025 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site