]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ocfs2: fix kernel BUG in ocfs2_find_victim_chain
authorPrithvi Tambewagh <activprithvi@gmail.com>
Mon, 1 Dec 2025 13:07:11 +0000 (18:37 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 Jan 2026 11:57:19 +0000 (12:57 +0100)
commit 039bef30e320827bac8990c9f29d2a68cd8adb5f upstream.

syzbot reported a kernel BUG in ocfs2_find_victim_chain() because the
`cl_next_free_rec` field of the allocation chain list (next free slot in
the chain list) is 0, triggring the BUG_ON(!cl->cl_next_free_rec)
condition in ocfs2_find_victim_chain() and panicking the kernel.

To fix this, an if condition is introduced in ocfs2_claim_suballoc_bits(),
just before calling ocfs2_find_victim_chain(), the code block in it being
executed when either of the following conditions is true:

1. `cl_next_free_rec` is equal to 0, indicating that there are no free
chains in the allocation chain list
2. `cl_next_free_rec` is greater than `cl_count` (the total number of
chains in the allocation chain list)

Either of them being true is indicative of the fact that there are no
chains left for usage.

This is addressed using ocfs2_error(), which prints
the error log for debugging purposes, rather than panicking the kernel.

Link: https://lkml.kernel.org/r/20251201130711.143900-1-activprithvi@gmail.com
Signed-off-by: Prithvi Tambewagh <activprithvi@gmail.com>
Reported-by: syzbot+96d38c6e1655c1420a72@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=96d38c6e1655c1420a72
Tested-by: syzbot+96d38c6e1655c1420a72@syzkaller.appspotmail.com
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Jun Piao <piaojun@huawei.com>
Cc: Heming Zhao <heming.zhao@suse.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ocfs2/suballoc.c

index 6ac4dcd54588cfdafb9d5c8b1504acbe38ecd73e..e93fc842bb203851d45aec8d169d4d78473abe32 100644 (file)
@@ -1992,6 +1992,16 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_alloc_context *ac,
        }
 
        cl = (struct ocfs2_chain_list *) &fe->id2.i_chain;
+       if (!le16_to_cpu(cl->cl_next_free_rec) ||
+           le16_to_cpu(cl->cl_next_free_rec) > le16_to_cpu(cl->cl_count)) {
+               status = ocfs2_error(ac->ac_inode->i_sb,
+                                    "Chain allocator dinode %llu has invalid next "
+                                    "free chain record %u, but only %u total\n",
+                                    (unsigned long long)le64_to_cpu(fe->i_blkno),
+                                    le16_to_cpu(cl->cl_next_free_rec),
+                                    le16_to_cpu(cl->cl_count));
+               goto bail;
+       }
 
        victim = ocfs2_find_victim_chain(cl);
        ac->ac_chain = victim;