From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 8AD562C181 for ; Tue, 7 Jul 2026 08:00:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783411225; cv=none; b=dF4H3uZTDbnPv1JzeEDle8TGa12jrBjTc28pmfz6YjxW6ARSYY9AEWwHiLGmpoX7AAEWOYxgBSvlaHXwlkcHS7qPx0NKEGWThsaMNXr7Sj93/9VlR7CL3vVwE3MVd9q8uefCrxeTGkcdHo3a6VJjd7jzVH7ujCoNPNQLoAH89oM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783411225; c=relaxed/simple; bh=ryDOfNlRaRGYN/Wt1BnJsasdKDRXWgRly1+2in/xZ+Y=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=qdcCO/HjcrT7svX/Q2IArnMQpSJAjVCusClWLFHpkJwB9L2zSGYQoSL/fpRciyLCzPN14bigXBux0ZRsqwRE8CPlS7Ixw7CsE1/s28pGcHRi0hZqwrtkfl8ARdFPev2Dgt8yyidusfZZO7k07jP7JRQK67tq60Hpn03AYo4tNTM= 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=C4y1fx7e; arc=none smtp.client-ip=209.85.216.42 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="C4y1fx7e" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-37ff8e0ad0fso4007830a91.2 for ; Tue, 07 Jul 2026 01:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783411223; x=1784016023; 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=/ensxtyL2InlA/bA/hJQoV9ROy5P1Zvl3hy+zcR+oqY=; b=C4y1fx7eoBJwOCi1XdKRzV5rJSsFXg7kP/Ey7tDnGX+05f2B587XcOfvjyi+6qMaI1 gPVmkpYB7jxhDrtIokDaGGNMDmjg6uA71DMjB39aEEnDBFK6Eeu4bZpIt75m5gKpeGAq iOTrhL386sKt7YDAp6AdOGAMo6loHSOOnsN/RfP7Vv75uaS/USGTueTzhUpdkd03EESL 0yIssmy+LkiRbPied+fCitmnHLoHf/aqFHF+sgjarbqCv0kxN49Bc2ni+PrTo+++fkxv Vwet/I13a/XpiTKVPQNHiABnIq0XO0+0t1R4Sz9bp5weXfFJKLrnqPhYqcaz5Maeuvbs 2i0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783411223; x=1784016023; 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=/ensxtyL2InlA/bA/hJQoV9ROy5P1Zvl3hy+zcR+oqY=; b=MVmABeqsDfXSZaSoFpGoPXLmNmPaaKRxjxOWdLw4W34PlBcSzCtY8cMVKF/EmfannS SPfJBVf9sbgxFQ2TSuVDmtB3ih3owkaOYN2fBrJ3+xkWzf/RhIRHRMeA8x2RgznjxXOF +iMejz0cXBc+56wiL8s2mA/0S5+cPhCztVL/kzPWmEIUAfSJ1wHjHLQpomnq5Sb6cS0y XShlHtNbCbvc2zp5qXJwRqqWJhhC1aNBIHDd3QGzInCbJ6H20npuVuXpcu7alsg8xtBf hc/rWpADa6HwIszEAoGz9WyJBge0ZSyg7yIvpWbiAZmPNz7/0pvTlRjHzswQ1OdTIEhu 6ZsA== X-Forwarded-Encrypted: i=1; AHgh+RrhIdQLLfT+srm3oRyfSi8xj2EN9K9NZ/6QR1XVtHe+NNk5hqGH9IoqnsFeZVPvo8QhwLXKFr4l5Lq43KE=@vger.kernel.org X-Gm-Message-State: AOJu0YyWgCTCWFTQm5G7GBTRv/+TQDYGYIisFsymAZwOzFZqRkMDM8Fs B/gc4Iexp+V5RKUzc6TD9FPTeLiRY1LwITEpmfpHJZV96VIeiyOvOIGm X-Gm-Gg: AfdE7cnsVGprz8/v+RqGzCcnzLIXJKyxuKJL8DTj+06+NCy6T3fX6AJGrHQHtAPDgq3 Lqsndf30hVLKLlRsjfZ86FgqIJ83L1B77eRNZgMFY3BlkWhAvJxQY6M9U0FazvEabVO4mW7xD+h r1NcZJCANPP829jeZF8tnQ1JitMtabM4STiqHaAJAxZTpWqR3emq766IaPp7MaGw+zXWsn5mY/K Kz7IdmKauyMQP8LVYHva2r6bSh909VTNA1fBl/w5A6jgzb6ZHfE7RLdQlvQACI2WMFfq/BhwuHu pmpdLrahzu4hPd/SBm0g+QVELgyfbIQKwyimF0OZPeT7eWw6sZm8R6C5bjt/jkEcRy/FV1QarES fyTD/Z/yEdWbMwUkiOhAJLv9obyBgYSkcts+/nijZdcsD2+ohWlm8buXyclvyPWPTem9OGsp3T3 Nx8s3kOwUG4mW4m7EKKTQ4U5yReLUpkVa6efgnbSwL3dqvLiNoNtga5r8B X-Received: by 2002:a17:90b:5292:b0:381:23d5:693f with SMTP id 98e67ed59e1d1-3875806236fmr4349519a91.28.1783411222720; Tue, 07 Jul 2026 01:00:22 -0700 (PDT) Received: from carrot.taila25129.ts.net (madb688455.ap.nuro.jp. [219.104.132.85]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-387d36676desm643964a91.10.2026.07.07.01.00.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 01:00:22 -0700 (PDT) From: Ryusuke Konishi To: Viacheslav Dubeyko Cc: linux-nilfs , LKML , syzbot+79b815da3aec0a6a4d02@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com, Igor Putko Subject: [PATCH] nilfs2: handle corrupted checkpoint count gracefully during deletion Date: Tue, 7 Jul 2026 16:59:41 +0900 Message-ID: <20260707080019.21550-1-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Igor Putko Syzkaller reported a kernel warning in nilfs_cpfile_delete_checkpoints() due to a corrupted checkpoint count on the storage medium where le32_to_cpu(cp->cp_checkpoints_count) is less than the number of checkpoints being deleted. Triggering a WARN_ON() for disk image corruption is suboptimal. Fix this by returning -EIO and reporting a filesystem error via nilfs_error() instead of interrupting execution with a kernel warning. Reported-by: syzbot+79b815da3aec0a6a4d02@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=79b815da3aec0a6a4d02 Signed-off-by: Igor Putko Fixes: 1f5abe7e7dbc ("nilfs2: replace BUG_ON and BUG calls triggerable from ioctl") Cc: # Warning suppression primarily; will request backport individually if needed Signed-off-by: Ryusuke Konishi --- Hi Viacheslav, Please apply this for the next cycle. This fixes a kernel warning and a missed inconsistency check that could occur with file system images containing corrupted checkpoint metadata. Thanks, Ryusuke Konishi fs/nilfs2/cpfile.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/fs/nilfs2/cpfile.c b/fs/nilfs2/cpfile.c index 4bbdc832d7f2..d3349fa58abe 100644 --- a/fs/nilfs2/cpfile.c +++ b/fs/nilfs2/cpfile.c @@ -81,18 +81,26 @@ nilfs_cpfile_block_add_valid_checkpoints(const struct inode *cpfile, return count; } -static unsigned int +static int nilfs_cpfile_block_sub_valid_checkpoints(const struct inode *cpfile, struct buffer_head *bh, unsigned int n) { struct nilfs_checkpoint *cp; - unsigned int count; + unsigned int checkpoints_count; + int count; cp = kmap_local_folio(bh->b_folio, offset_in_folio(bh->b_folio, bh->b_data)); - WARN_ON(le32_to_cpu(cp->cp_checkpoints_count) < n); - count = le32_to_cpu(cp->cp_checkpoints_count) - n; + checkpoints_count = le32_to_cpu(cp->cp_checkpoints_count); + if (unlikely(checkpoints_count < n)) { + nilfs_error(cpfile->i_sb, + "deleted checkpoints count %u exceeds block count %u", + n, checkpoints_count); + kunmap_local(cp); + return -EIO; + } + count = checkpoints_count - n; cp->cp_checkpoints_count = cpu_to_le32(count); kunmap_local(cp); return count; @@ -522,6 +530,10 @@ int nilfs_cpfile_delete_checkpoints(struct inode *cpfile, count = nilfs_cpfile_block_sub_valid_checkpoints(cpfile, cp_bh, nicps); brelse(cp_bh); + if (unlikely(count < 0)) { + ret = count; + break; + } if (count) continue; -- 2.43.0