From nobody Thu Dec 18 15:31:39 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BA6FCDB47E for ; Wed, 18 Oct 2023 10:08:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230404AbjJRKI5 (ORCPT ); Wed, 18 Oct 2023 06:08:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbjJRKI4 (ORCPT ); Wed, 18 Oct 2023 06:08:56 -0400 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6539410A; Wed, 18 Oct 2023 03:08:53 -0700 (PDT) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4S9RQ70LnDz8XrRC; Wed, 18 Oct 2023 18:08:47 +0800 (CST) Received: from szxlzmapp05.zte.com.cn ([10.5.230.85]) by mse-fl2.zte.com.cn with SMTP id 39IA8ghC093171; Wed, 18 Oct 2023 18:08:42 +0800 (+08) (envelope-from cheng.lin130@zte.com.cn) Received: from mapi (szxlzmapp04[null]) by mapi (Zmail) with MAPI id mid14; Wed, 18 Oct 2023 18:08:45 +0800 (CST) Date: Wed, 18 Oct 2023 18:08:45 +0800 (CST) X-Zmail-TransId: 2b06652faeadffffffffbf8-6e3ce X-Mailer: Zmail v1.0 Message-ID: <202310181808454230330@zte.com.cn> Mime-Version: 1.0 From: To: , , Cc: , , , , , , Subject: =?UTF-8?B?W1JGQyBQQVRDSCB2Ml0gZnM6IGludHJvZHVjZSBjaGVjayBmb3IgaW5vZGUgbmxpbmsgd2hlbiBkZWxldGU=?= X-MAIL: mse-fl2.zte.com.cn 39IA8ghC093171 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 652FAEAF.000/4S9RQ70LnDz8XrRC Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Cheng Lin Do not delete inode which nlink already zero to avoid inode nlink underflow. Signed-off-by: Cheng Lin --- 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 =3D=3D 0) || + unlikely(dentry->d_inode->i_nlink =3D=3D 0)) { + error =3D -EUCLEAN; + goto out; + } error =3D 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 =3D try_break_deleg(target, delegated_inode); if (error) goto out; + if (unlikely(target->i_nlink =3D=3D 0)) { + error =3D -EUCLEAN; + goto out; + } error =3D dir->i_op->unlink(dir, dentry); if (!error) { dont_mount(dentry); --=20 2.18.1