All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2] fs: introduce check for inode nlink when delete
@ 2023-10-18 10:08 cheng.lin130
  0 siblings, 0 replies; only message in thread
From: cheng.lin130 @ 2023-10-18 10:08 UTC (permalink / raw)
  To: brauner, viro, djwong
  Cc: linux-fsdevel, linux-kernel, david, hch, jiang.yong5,
	wang.liang82, liu.dong3

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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-18 10:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-18 10:08 [RFC PATCH v2] fs: introduce check for inode nlink when delete cheng.lin130

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.