From: Ryusuke Konishi <konishi.ryusuke@gmail.com>
To: Viacheslav Dubeyko <slava@dubeyko.com>
Cc: linux-nilfs <linux-nilfs@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
syzbot+79b815da3aec0a6a4d02@syzkaller.appspotmail.com,
syzkaller-bugs@googlegroups.com,
Igor Putko <igorpetindev@gmail.com>
Subject: [PATCH] nilfs2: handle corrupted checkpoint count gracefully during deletion
Date: Tue, 7 Jul 2026 16:59:41 +0900 [thread overview]
Message-ID: <20260707080019.21550-1-konishi.ryusuke@gmail.com> (raw)
From: Igor Putko <igorpetindev@gmail.com>
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 <igorpetindev@gmail.com>
Fixes: 1f5abe7e7dbc ("nilfs2: replace BUG_ON and BUG calls triggerable from ioctl")
Cc: <stable+noautosel@kernel.org> # Warning suppression primarily; will request backport individually if needed
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
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
next reply other threads:[~2026-07-07 8:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 7:59 Ryusuke Konishi [this message]
2026-07-07 18:16 ` [PATCH] nilfs2: handle corrupted checkpoint count gracefully during deletion Viacheslav Dubeyko
-- strict thread matches above, loose matches on Subject: below --
2026-07-06 11:08 Igor Putko
2026-07-06 16:39 ` Ryusuke Konishi
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=20260707080019.21550-1-konishi.ryusuke@gmail.com \
--to=konishi.ryusuke@gmail.com \
--cc=igorpetindev@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nilfs@vger.kernel.org \
--cc=slava@dubeyko.com \
--cc=syzbot+79b815da3aec0a6a4d02@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/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.