From: <cheng.lin130@zte.com.cn>
To: <viro@zeniv.linux.org.uk>, <brauner@kernel.org>, <djwong@kernel.org>
Cc: <linux-fsdevel@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<david@fromorbit.com>, <hch@infradead.org>,
<jiang.yong5@zte.com.cn>, <wang.liang82@zte.com.cn>,
<liu.dong3@zte.com.cn>
Subject: [RFC PATCH] fs: introduce check for drop/inc_nlink
Date: Fri, 13 Oct 2023 15:27:30 +0800 (CST) [thread overview]
Message-ID: <202310131527303451636@zte.com.cn> (raw)
[-- Attachment #1.1.1: Type: text/plain, Size: 847 bytes --]
From: Cheng Lin <cheng.lin130@zte.com.cn>
Avoid inode nlink overflow or underflow.
Signed-off-by: Cheng Lin <cheng.lin130@zte.com.cn>
---
fs/inode.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/inode.c b/fs/inode.c
index 67611a360..8e6d62dc4 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -328,6 +328,9 @@ static void destroy_inode(struct inode *inode)
void drop_nlink(struct inode *inode)
{
WARN_ON(inode->i_nlink == 0);
+ if (unlikely(inode->i_nlink == 0))
+ return;
+
inode->__i_nlink--;
if (!inode->i_nlink)
atomic_long_inc(&inode->i_sb->s_remove_count);
@@ -388,6 +391,9 @@ void inc_nlink(struct inode *inode)
atomic_long_dec(&inode->i_sb->s_remove_count);
}
+ if (unlikely(inode->i_nlink == ~0U))
+ return;
+
inode->__i_nlink++;
}
EXPORT_SYMBOL(inc_nlink);
--
2.18.1
[-- Attachment #1.1.2: Type: text/html , Size: 1907 bytes --]
next reply other threads:[~2023-10-13 7:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-13 7:27 cheng.lin130 [this message]
2023-10-13 8:02 ` [RFC PATCH] fs: introduce check for drop/inc_nlink Christian Brauner
2023-10-13 9:40 ` cheng.lin130
2023-10-17 0:57 ` Darrick J. Wong
2023-10-17 2:31 ` cheng.lin130
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202310131527303451636@zte.com.cn \
--to=cheng.lin130@zte.com.cn \
--cc=brauner@kernel.org \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=jiang.yong5@zte.com.cn \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liu.dong3@zte.com.cn \
--cc=viro@zeniv.linux.org.uk \
--cc=wang.liang82@zte.com.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.