From nobody Sun Feb 8 20:28:29 2026 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF1C03A1C9 for ; Thu, 1 Jan 2026 11:12:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767265935; cv=none; b=Fvn4Cy84bYpHWTGj34wIpFy7CEvyIJBQUHp5QDb+qaFq1/V5H345M1f3Lsz3S4AMk4WUaq+dg2E5Fn1JT27Wjt5XBGx1+9JPX2thZhneWQ+eK1PdXWZru1MQRSYkhW6Jk8N72DSWvZxpfYghoJVuQqomtvKa5tm7T1XbKlpohY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767265935; c=relaxed/simple; bh=R1MOVECXK3sqsMn+Mx9E14uA8RiLKnycrhsD20xCPTU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=J59AEoUI4ufBi9a91KRyXe2l0pzUcSduOg49yldfLU5dE5ojWhCb7WmWCyejGUudt0FVBTcIoq1OshnNFDrYstH3mBe43d3aeZFDzb3DOKM9ffC8/qcuN2u4QLdtiHBYWHh7tiS4f2f0Y7CruuEIA2KJxxxRsl56g4uZOqIVC8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=E2VK2Bnh; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E2VK2Bnh" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-34c24f4dfb7so8921890a91.0 for ; Thu, 01 Jan 2026 03:12:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767265933; x=1767870733; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Uj1TWbqZEVpCJMC53klX2kUfu7ywMyphYkzhWZw10pc=; b=E2VK2BnhLTby6QB3Je2S5rKvOAd9QEopqBNdrtHT5jsTtbfxGE4CvGtbI+TwoebySx S7AxFASGh2yBdRAKJP+oLU5zw/LxM9tstzbBfoeCIt6nUZoPI5f/V3/U/3GHpSyawxEv BpVBwpfWU63hZEPzuM37u3YY2anHBk3lpoDJmHEPzzD/w4Z9mz+aFrBbtDuLdpRU2GQc +o4DAhKLXTf3R2jMJQgcCu0DnX9F+RNnFTuGZzYnTcAa6yHvifh3annN+ZwrgFreOG0V Go2Upc8O5H83ni2wKHxQOkyRWb1ZlwvIlflHoaoCbDRbwMkQnAA9hmEzVB+Ic3mAJ8W8 wKcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767265933; x=1767870733; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Uj1TWbqZEVpCJMC53klX2kUfu7ywMyphYkzhWZw10pc=; b=JCuZrgJ2SXpy8KRMj9gz0nOJtHfn+S4DbyXbcbLfd/Gg58Vygqzyof4v2M9Bobao6O H3kOt4c45kogkw71Z6bqekpUsX2Or6EZZ+GDH6Sgiuhv3a+dNSr3q+OQBIZcSKm1hRdB zDJdVWhqt4pzsVASg/TN9xh+87UD3J9tqGWv88zJqseU2izA2m1b6nKlNxjqtRiLeyvG t41aQK+L4/pRU8TyD0PfpaWVf7VqN4QQw9/SACtR1zUSeG/zaI+cOPlWNWevZ5pUuExn 9Zi3Egci1p+K9fm4aH/WMTS96uHSSosuBjD2euddV71DqqtYfXCnL6E2UB7iwpfg8lzY a5zw== X-Forwarded-Encrypted: i=1; AJvYcCVfkwm4M+Jv5sh5k8Ki8uGR2e8EqoHH0eQRlOOWuL+WZgDxeM4QPujEyLQjtGRW0yN6eQb+huYWGxmqEcA=@vger.kernel.org X-Gm-Message-State: AOJu0YwdT20YU6sfdNciI7duByhtdPpy07Vyq0U/toqNqmt+2ugG753b EpLlRkIudBxaaRU3UOZ1hY+c1dIyWfPNXeR91M890xBHxC+tWWpwTd2f X-Gm-Gg: AY/fxX68G8/KI7dDtGNEuMhWagNmKJKLj5NrcEEJwuH9Zl6KLEx5g5suuqi/LQCT7TF 1BoRvAabBCo0j5PGa4fXfZpq81/spJmHzd/8kUEWDlMqGF9A0dyhkdlhbE4L0gZ8dW1+ElroSs0 ZtNqJi/ty5nN4GNjQU7Cq423ykssCzMl7pC2s0aSIJVoCChOQbbTxI7IzHNfrVkSzNfPxyLWumY N3Wqahh6DCp4ThlN56gka4saFmYW1ZgZqnoCnaEWJOxIIJoMHl5lAnzH+o0CB+/S3a0mKczRaK9 vdCKiTqLQ1jQFqP2tu0xTBdtqPUocHOo20UQ1EiROns0ze0Ax53SLiO7ZwiIZ78ZIEK+zlIuS5W ijuHRWjDrijWrUzY0vCFqzL0T6C2QoHT9q1FQx3OoaquRlCqHfs8wj2qng6jDeE1A03KKVpElUJ OJECIkNkMTNuijXqRw1HDfETHYKraZs6Qnl1VqK0SrPNZB8LT7PeBZGq+Y4oZximDqSQ== X-Google-Smtp-Source: AGHT+IF0O7FTZv5t+moL2f3nVBNSmH+XjOdX+4LYTLzJeCO7v9W9CgwezVB8jY//JEZqeqOo/1kYpQ== X-Received: by 2002:a17:90b:4b43:b0:340:e8e9:cc76 with SMTP id 98e67ed59e1d1-34e92144873mr33965006a91.11.1767265932428; Thu, 01 Jan 2026 03:12:12 -0800 (PST) Received: from localhost.localdomain ([159.226.94.129]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-34e76de1c3csm19632961a91.2.2026.01.01.03.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jan 2026 03:12:12 -0800 (PST) From: Zhiyu Zhang To: hirofumi@mail.parknet.co.jp, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Zhiyu Zhang Subject: [PATCH] fat: avoid parent link count underflow in rmdir Date: Thu, 1 Jan 2026 19:11:48 +0800 Message-Id: <20260101111148.1437-1-zhiyuzhang999@gmail.com> X-Mailer: git-send-email 2.39.1.windows.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Corrupted FAT images can leave a directory inode with an incorrect i_nlink (e.g. 2 even though subdirectories exist). rmdir then unconditionally calls drop_nlink(dir) and can drive i_nlink to 0, triggering the WARN_ON in drop_nlink(). Add a sanity check in vfat_rmdir() and msdos_rmdir(): only drop the parent link count when it is at least 3, otherwise report a filesystem error. Fixes: 9a53c3a783c2 ("[PATCH] r/o bind mounts: unlink: monitor i_nlink") Reported-by: Zhiyu Zhang Closes: https://lore.kernel.org/linux-fsdevel/aVN06OKsKxZe6-Kv@casper.infra= dead.org/T/#t Tested-by: Zhiyu Zhang Signed-off-by: Zhiyu Zhang Acked-by: OGAWA Hirofumi --- fs/fat/namei_msdos.c | 7 ++++++- fs/fat/namei_vfat.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c index 0b920ee40a7f..262ec1b790b5 100644 --- a/fs/fat/namei_msdos.c +++ b/fs/fat/namei_msdos.c @@ -325,7 +325,12 @@ static int msdos_rmdir(struct inode *dir, struct dentr= y *dentry) err =3D fat_remove_entries(dir, &sinfo); /* and releases bh */ if (err) goto out; - drop_nlink(dir); + if (dir->i_nlink >=3D 3) + drop_nlink(dir); + else { + fat_fs_error(sb, "parent dir link count too low (%u)", + dir->i_nlink); + } =20 clear_nlink(inode); fat_truncate_time(inode, NULL, S_CTIME); diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index 5dbc4cbb8fce..47ff083cfc7e 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -803,7 +803,12 @@ static int vfat_rmdir(struct inode *dir, struct dentry= *dentry) err =3D fat_remove_entries(dir, &sinfo); /* and releases bh */ if (err) goto out; - drop_nlink(dir); + if (dir->i_nlink >=3D 3) + drop_nlink(dir); + else { + fat_fs_error(sb, "parent dir link count too low (%u)", + dir->i_nlink); + } =20 clear_nlink(inode); fat_truncate_time(inode, NULL, S_ATIME|S_MTIME); --=20 2.34.1