Skip to content

Commit 70b6728

Browse files
Gality369akpm00
authored andcommitted
ocfs2: validate group add input before caching
[BUG] OCFS2_IOC_GROUP_ADD can trigger a BUG_ON in ocfs2_set_new_buffer_uptodate(): kernel BUG at fs/ocfs2/uptodate.c:509! Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI RIP: 0010:ocfs2_set_new_buffer_uptodate+0x194/0x1e0 fs/ocfs2/uptodate.c:509 Code: ffffe88f 42b9fe4c 89e64889 dfe8b4df Call Trace: ocfs2_group_add+0x3f1/0x1510 fs/ocfs2/resize.c:507 ocfs2_ioctl+0x309/0x6e0 fs/ocfs2/ioctl.c:887 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl fs/ioctl.c:583 [inline] __x64_sys_ioctl+0x197/0x1e0 fs/ioctl.c:583 x64_sys_call+0x1144/0x26a0 arch/x86/include/generated/asm/syscalls_64.h:17 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x93/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7bbfb55a966d [CAUSE] ocfs2_group_add() calls ocfs2_set_new_buffer_uptodate() on a user-controlled group block before ocfs2_verify_group_and_input() validates that block number. That helper is only valid for newly allocated metadata and asserts that the block is not already present in the chosen metadata cache. The code also uses INODE_CACHE(inode) even though the group descriptor belongs to main_bm_inode and later journal accesses use that cache context instead. [FIX] Validate the on-disk group descriptor before caching it, then add it to the metadata cache tracked by INODE_CACHE(main_bm_inode). Keep the validation failure path separate from the later cleanup path so we only remove the buffer from that cache after it has actually been inserted. This keeps the group buffer lifetime consistent across validation, journaling, and cleanup. Link: https://lkml.kernel.org/r/20260410020209.3786348-1-gality369@gmail.com Fixes: 7909f2b ("[PATCH 2/2] ocfs2: Implement group add for online resize") Signed-off-by: ZhengYuan Huang <gality369@gmail.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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 8f687ee commit 70b6728

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

fs/ocfs2/resize.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,22 +508,22 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
508508
goto out_unlock;
509509
}
510510

511-
ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), group_bh);
512-
513511
ret = ocfs2_verify_group_and_input(main_bm_inode, fe, input, group_bh);
514512
if (ret) {
515513
mlog_errno(ret);
516514
goto out_free_group_bh;
517515
}
518516

517+
ocfs2_set_new_buffer_uptodate(INODE_CACHE(main_bm_inode), group_bh);
518+
519519
trace_ocfs2_group_add((unsigned long long)input->group,
520520
input->chain, input->clusters, input->frees);
521521

522522
handle = ocfs2_start_trans(osb, OCFS2_GROUP_ADD_CREDITS);
523523
if (IS_ERR(handle)) {
524524
mlog_errno(PTR_ERR(handle));
525525
ret = -EINVAL;
526-
goto out_free_group_bh;
526+
goto out_remove_cache;
527527
}
528528

529529
cl_bpc = le16_to_cpu(fe->id2.i_chain.cl_bpc);
@@ -577,9 +577,11 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
577577
out_commit:
578578
ocfs2_commit_trans(osb, handle);
579579

580-
out_free_group_bh:
580+
out_remove_cache:
581581
if (ret < 0)
582-
ocfs2_remove_from_cache(INODE_CACHE(inode), group_bh);
582+
ocfs2_remove_from_cache(INODE_CACHE(main_bm_inode), group_bh);
583+
584+
out_free_group_bh:
583585
brelse(group_bh);
584586

585587
out_unlock:

0 commit comments

Comments
 (0)