ocfs2: fix shift-out-of-bounds UBSAN bug in ocfs2_verify_volume()
authorqasdev <qasdev00@gmail.com>
Tue, 20 Aug 2024 01:22:09 +0000 (02:22 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 2 Sep 2024 03:43:38 +0000 (20:43 -0700)
This patch addresses a shift-out-of-bounds error in the
ocfs2_verify_volume() function, identified by UBSAN.  The bug was
triggered by an invalid s_clustersize_bits value (e.g., 1548), which
caused the expression "1 <<
le32_to_cpu(di->id2.i_super.s_clustersize_bits)" to exceed the limits of a
32-bit integer, leading to an out-of-bounds shift.

Link: https://lkml.kernel.org/r/ZsPvwQAXd5R/jNY+@hostname
Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
Reported-by: syzbot <syzbot+f3fff775402751ebb471@syzkaller.appspotmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=f3fff775402751ebb471
Tested-by: syzbot <syzbot+f3fff775402751ebb471@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: Gang He <ghe@suse.com>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/ocfs2/super.c

index afee70125ae3bf0e7e64189dd594e541a7c6ba89..b704983b2112078e847fc6fb27ac31b4ac9edcac 100644 (file)
@@ -2357,8 +2357,8 @@ static int ocfs2_verify_volume(struct ocfs2_dinode *di,
                             (unsigned long long)bh->b_blocknr);
                } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
                            le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
-                       mlog(ML_ERROR, "bad cluster size found: %u\n",
-                            1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
+                       mlog(ML_ERROR, "bad cluster size bit found: %u\n",
+                            le32_to_cpu(di->id2.i_super.s_clustersize_bits));
                } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
                        mlog(ML_ERROR, "bad root_blkno: 0\n");
                } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {