* [PATCH] ocfs2: validate group add input before caching
@ 2026-04-09 9:02 ZhengYuan Huang
2026-04-09 13:05 ` Joseph Qi
0 siblings, 1 reply; 3+ messages in thread
From: ZhengYuan Huang @ 2026-04-09 9:02 UTC (permalink / raw)
To: mark, jlbec, joseph.qi
Cc: ocfs2-devel, linux-kernel, baijiaju1990, r33s3n6, zzzccc427,
ZhengYuan Huang
[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). Update the
error path to remove the buffer from the same cache context so the group
buffer lifetime stays consistent across validation, journaling, and
cleanup.
Signed-off-by: ZhengYuan Huang <gality369@gmail.com>
---
fs/ocfs2/resize.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/ocfs2/resize.c b/fs/ocfs2/resize.c
index b0733c08ed13..e45ab5592ee0 100644
--- a/fs/ocfs2/resize.c
+++ b/fs/ocfs2/resize.c
@@ -504,14 +504,14 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
goto out_unlock;
}
- ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), group_bh);
-
ret = ocfs2_verify_group_and_input(main_bm_inode, fe, input, group_bh);
if (ret) {
mlog_errno(ret);
goto out_free_group_bh;
}
+ ocfs2_set_new_buffer_uptodate(INODE_CACHE(main_bm_inode), group_bh);
+
trace_ocfs2_group_add((unsigned long long)input->group,
input->chain, input->clusters, input->frees);
@@ -575,7 +575,7 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
out_free_group_bh:
if (ret < 0)
- ocfs2_remove_from_cache(INODE_CACHE(inode), group_bh);
+ ocfs2_remove_from_cache(INODE_CACHE(main_bm_inode), group_bh);
brelse(group_bh);
out_unlock:
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ocfs2: validate group add input before caching
2026-04-09 9:02 [PATCH] ocfs2: validate group add input before caching ZhengYuan Huang
@ 2026-04-09 13:05 ` Joseph Qi
2026-04-09 15:40 ` ZhengYuan Huang
0 siblings, 1 reply; 3+ messages in thread
From: Joseph Qi @ 2026-04-09 13:05 UTC (permalink / raw)
To: ZhengYuan Huang, akpm, Heming Zhao
Cc: ocfs2-devel, linux-kernel, baijiaju1990, r33s3n6, zzzccc427,
Mark Fasheh, Joel Becker
On 4/9/26 5:02 PM, ZhengYuan Huang wrote:
> [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). Update the
> error path to remove the buffer from the same cache context so the group
> buffer lifetime stays consistent across validation, journaling, and
> cleanup.
>
> Signed-off-by: ZhengYuan Huang <gality369@gmail.com>
Missing Fixes tag:
Fixes: 7909f2bf8353 ("[PATCH 2/2] ocfs2: Implement group add for online resize")
> ---
> fs/ocfs2/resize.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ocfs2/resize.c b/fs/ocfs2/resize.c
> index b0733c08ed13..e45ab5592ee0 100644
> --- a/fs/ocfs2/resize.c
> +++ b/fs/ocfs2/resize.c
> @@ -504,14 +504,14 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
> goto out_unlock;
> }
>
> - ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), group_bh);
> -
> ret = ocfs2_verify_group_and_input(main_bm_inode, fe, input, group_bh);
> if (ret) {
> mlog_errno(ret);
> goto out_free_group_bh;
> }
Since ocfs2_set_new_buffer_uptodate is now moved down, the error goto
above should also be changed.
e.g. do the same ioctl twice, the second will remove the cache which
should be valid. This is not the expected behavior.
Thanks,
Joseph
>
> + ocfs2_set_new_buffer_uptodate(INODE_CACHE(main_bm_inode), group_bh);
> +
> trace_ocfs2_group_add((unsigned long long)input->group,
> input->chain, input->clusters, input->frees);
>
> @@ -575,7 +575,7 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
>
> out_free_group_bh:
> if (ret < 0)
> - ocfs2_remove_from_cache(INODE_CACHE(inode), group_bh);
> + ocfs2_remove_from_cache(INODE_CACHE(main_bm_inode), group_bh);
> brelse(group_bh);
>
> out_unlock:
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ocfs2: validate group add input before caching
2026-04-09 13:05 ` Joseph Qi
@ 2026-04-09 15:40 ` ZhengYuan Huang
0 siblings, 0 replies; 3+ messages in thread
From: ZhengYuan Huang @ 2026-04-09 15:40 UTC (permalink / raw)
To: Joseph Qi
Cc: akpm, Heming Zhao, ocfs2-devel, linux-kernel, baijiaju1990,
r33s3n6, zzzccc427, Mark Fasheh, Joel Becker
On Thu, Apr 9, 2026 at 9:05 PM Joseph Qi <joseph.qi@linux.alibaba.com> wrote:
> Missing Fixes tag:
> Fixes: 7909f2bf8353 ("[PATCH 2/2] ocfs2: Implement group add for online resize")
>
> > ---
> > fs/ocfs2/resize.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/fs/ocfs2/resize.c b/fs/ocfs2/resize.c
> > index b0733c08ed13..e45ab5592ee0 100644
> > --- a/fs/ocfs2/resize.c
> > +++ b/fs/ocfs2/resize.c
> > @@ -504,14 +504,14 @@ int ocfs2_group_add(struct inode *inode, struct ocfs2_new_group_input *input)
> > goto out_unlock;
> > }
> >
> > - ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), group_bh);
> > -
> > ret = ocfs2_verify_group_and_input(main_bm_inode, fe, input, group_bh);
> > if (ret) {
> > mlog_errno(ret);
> > goto out_free_group_bh;
> > }
>
> Since ocfs2_set_new_buffer_uptodate is now moved down, the error goto
> above should also be changed.
>
> e.g. do the same ioctl twice, the second will remove the cache which
> should be valid. This is not the expected behavior.
>
> Thanks,
> Joseph
Thanks for pointing this out.
The issue is valid, and I’ve addressed it in v2 by fixing the error
path accordingly.
v2 patch has been sent.
Thanks,
ZhengYuan Huang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-09 15:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09 9:02 [PATCH] ocfs2: validate group add input before caching ZhengYuan Huang
2026-04-09 13:05 ` Joseph Qi
2026-04-09 15:40 ` ZhengYuan Huang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox