* [PATCH v3] ocfs2: drain fs_state readers before journal teardown
@ 2026-11-21 7:51 Cen Zhang
2026-11-22 15:17 ` Joseph Qi
2026-11-22 17:40 ` + ocfs2-drain-fs_state-readers-before-journal-teardown.patch added to mm-nonmm-unstable branch Andrew Morton
0 siblings, 2 replies; 3+ messages in thread
From: Cen Zhang @ 2026-11-21 7:51 UTC (permalink / raw)
To: mark, jlbec, joseph.qi
Cc: heming.zhao, ocfs2-devel, linux-kernel, stable, baijiaju1990,
jjzuming, zzzccc427
The fs_state debugfs open callback builds a snapshot from mount state,
including the journal and cluster connection. The file is published
before ocfs2_mount_volume() and removed after journal and DLM shutdown,
so an open can overlap teardown on unmount or mount failure.
Publish fs_state at the successful end of ocfs2_fill_super(), after the
last fallible mount step. Remove it in ocfs2_put_super() before calling
ocfs2_dismount_volume(). Debugfs removal excludes new opens and drains
active callbacks. The release callback only frees the per-open snapshot.
KASAN reported:
BUG: KASAN: slab-use-after-free in ocfs2_osb_debug_open+0x967/0x15e0
Read of size 4 at addr ffff888116a56028 by task cat/502
...
Freed by task 504:
kfree+0x308/0x580
ocfs2_journal_shutdown+0x10a/0xc20
ocfs2_dismount_volume+0x315/0x940
Fixes: da5e7c87827e ("ocfs2: cleanup journal init and shutdown")
Cc: stable@vger.kernel.org
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
Changes in v3:
- Create fs_state at the successful end of ocfs2_fill_super() so failed
mounts never publish it.
- Remove fs_state in ocfs2_put_super() before volume teardown so creation
and removal are paired at the superblock level (Joseph Qi).
Changes in v2:
- Address the osb dereference before BUG_ON(!osb) raised by Sashiko:
https://sashiko.dev/#/patchset/98583
- Remove fs_state after BUG_ON(!osb) in ocfs2_dismount_volume().
- Trim the KASAN report.
Link to v1: https://lore.kernel.org/r/pm-ocfs2-objects-candidate-0003-v6-2f69dbb7417fcd537be6@gmail.com
Link to v2: https://lore.kernel.org/r/pm-ocfs2-objects-candidate-0003-v7-1522d068e5b943786c3e@gmail.com
This patch was written with assistance from Codex (OpenAI).
fs/ocfs2/super.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 0af2245ae303..2a58d3cd9690 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -1072,9 +1072,6 @@ static int ocfs2_fill_super(struct super_block *sb, struct fs_context *fc)
osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
ocfs2_debugfs_root);
- debugfs_create_file("fs_state", S_IFREG|S_IRUSR, osb->osb_debug_root,
- osb, &ocfs2_osb_debug_fops);
-
if (ocfs2_meta_ecc(osb)) {
ocfs2_initialize_journal_triggers(sb, osb->s_journal_triggers);
ocfs2_blockcheck_stats_debugfs_install( &osb->osb_ecc_stats,
@@ -1158,6 +1155,10 @@ static int ocfs2_fill_super(struct super_block *sb, struct fs_context *fc)
/* Start this when the mount is almost sure of being successful */
ocfs2_orphan_scan_start(osb);
+ /* Publish fs_state only after all fallible mount steps. */
+ debugfs_create_file("fs_state", 0400, osb->osb_debug_root,
+ osb, &ocfs2_osb_debug_fops);
+
return status;
out_dismount:
@@ -1555,8 +1556,13 @@ static void __exit ocfs2_exit(void)
static void ocfs2_put_super(struct super_block *sb)
{
+ struct ocfs2_super *osb = OCFS2_SB(sb);
+
trace_ocfs2_put_super(sb);
+ /* Drain fs_state opens before releasing their backing state. */
+ debugfs_lookup_and_remove("fs_state", osb->osb_debug_root);
+
ocfs2_sync_blockdev(sb);
ocfs2_dismount_volume(sb, 0);
}
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v3] ocfs2: drain fs_state readers before journal teardown
2026-11-21 7:51 [PATCH v3] ocfs2: drain fs_state readers before journal teardown Cen Zhang
@ 2026-11-22 15:17 ` Joseph Qi
2026-11-22 17:40 ` + ocfs2-drain-fs_state-readers-before-journal-teardown.patch added to mm-nonmm-unstable branch Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Joseph Qi @ 2026-11-22 15:17 UTC (permalink / raw)
To: Cen Zhang, Andrew Morton
Cc: mark, jlbec, heming.zhao, ocfs2-devel, linux-kernel, stable,
baijiaju1990, jjzuming
On 11/21/26 3:51 PM, Cen Zhang wrote:
> The fs_state debugfs open callback builds a snapshot from mount state,
> including the journal and cluster connection. The file is published
> before ocfs2_mount_volume() and removed after journal and DLM shutdown,
> so an open can overlap teardown on unmount or mount failure.
>
> Publish fs_state at the successful end of ocfs2_fill_super(), after the
> last fallible mount step. Remove it in ocfs2_put_super() before calling
> ocfs2_dismount_volume(). Debugfs removal excludes new opens and drains
> active callbacks. The release callback only frees the per-open snapshot.
>
> KASAN reported:
>
> BUG: KASAN: slab-use-after-free in ocfs2_osb_debug_open+0x967/0x15e0
> Read of size 4 at addr ffff888116a56028 by task cat/502
> ...
> Freed by task 504:
> kfree+0x308/0x580
> ocfs2_journal_shutdown+0x10a/0xc20
> ocfs2_dismount_volume+0x315/0x940
>
> Fixes: da5e7c87827e ("ocfs2: cleanup journal init and shutdown")
> Cc: stable@vger.kernel.org
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
Looks fine.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
> Changes in v3:
> - Create fs_state at the successful end of ocfs2_fill_super() so failed
> mounts never publish it.
> - Remove fs_state in ocfs2_put_super() before volume teardown so creation
> and removal are paired at the superblock level (Joseph Qi).
>
> Changes in v2:
> - Address the osb dereference before BUG_ON(!osb) raised by Sashiko:
> https://sashiko.dev/#/patchset/98583
> - Remove fs_state after BUG_ON(!osb) in ocfs2_dismount_volume().
> - Trim the KASAN report.
>
> Link to v1: https://lore.kernel.org/r/pm-ocfs2-objects-candidate-0003-v6-2f69dbb7417fcd537be6@gmail.com
> Link to v2: https://lore.kernel.org/r/pm-ocfs2-objects-candidate-0003-v7-1522d068e5b943786c3e@gmail.com
>
> This patch was written with assistance from Codex (OpenAI).
>
> fs/ocfs2/super.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
> index 0af2245ae303..2a58d3cd9690 100644
> --- a/fs/ocfs2/super.c
> +++ b/fs/ocfs2/super.c
> @@ -1072,9 +1072,6 @@ static int ocfs2_fill_super(struct super_block *sb, struct fs_context *fc)
> osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
> ocfs2_debugfs_root);
>
> - debugfs_create_file("fs_state", S_IFREG|S_IRUSR, osb->osb_debug_root,
> - osb, &ocfs2_osb_debug_fops);
> -
> if (ocfs2_meta_ecc(osb)) {
> ocfs2_initialize_journal_triggers(sb, osb->s_journal_triggers);
> ocfs2_blockcheck_stats_debugfs_install( &osb->osb_ecc_stats,
> @@ -1158,6 +1155,10 @@ static int ocfs2_fill_super(struct super_block *sb, struct fs_context *fc)
> /* Start this when the mount is almost sure of being successful */
> ocfs2_orphan_scan_start(osb);
>
> + /* Publish fs_state only after all fallible mount steps. */
> + debugfs_create_file("fs_state", 0400, osb->osb_debug_root,
> + osb, &ocfs2_osb_debug_fops);
> +
> return status;
>
> out_dismount:
> @@ -1555,8 +1556,13 @@ static void __exit ocfs2_exit(void)
>
> static void ocfs2_put_super(struct super_block *sb)
> {
> + struct ocfs2_super *osb = OCFS2_SB(sb);
> +
> trace_ocfs2_put_super(sb);
>
> + /* Drain fs_state opens before releasing their backing state. */
> + debugfs_lookup_and_remove("fs_state", osb->osb_debug_root);
> +
> ocfs2_sync_blockdev(sb);
> ocfs2_dismount_volume(sb, 0);
> }
^ permalink raw reply [flat|nested] 3+ messages in thread* + ocfs2-drain-fs_state-readers-before-journal-teardown.patch added to mm-nonmm-unstable branch
2026-11-21 7:51 [PATCH v3] ocfs2: drain fs_state readers before journal teardown Cen Zhang
2026-11-22 15:17 ` Joseph Qi
@ 2026-11-22 17:40 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2026-11-22 17:40 UTC (permalink / raw)
To: mm-commits, stable, mark, joseph.qi, jlbec, jjzuming, heming.zhao,
baijiaju1990, zzzccc427, akpm
The patch titled
Subject: ocfs2: drain fs_state readers before journal teardown
has been added to the -mm mm-nonmm-unstable branch. Its filename is
ocfs2-drain-fs_state-readers-before-journal-teardown.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/ocfs2-drain-fs_state-readers-before-journal-teardown.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Cen Zhang <zzzccc427@gmail.com>
Subject: ocfs2: drain fs_state readers before journal teardown
Date: Sat, 21 Nov 2026 15:51:57 +0800
The fs_state debugfs open callback builds a snapshot from mount state,
including the journal and cluster connection. The file is published
before ocfs2_mount_volume() and removed after journal and DLM shutdown, so
an open can overlap teardown on unmount or mount failure.
Publish fs_state at the successful end of ocfs2_fill_super(), after the
last fallible mount step. Remove it in ocfs2_put_super() before calling
ocfs2_dismount_volume(). Debugfs removal excludes new opens and drains
active callbacks. The release callback only frees the per-open snapshot.
KASAN reported:
BUG: KASAN: slab-use-after-free in ocfs2_osb_debug_open+0x967/0x15e0
Read of size 4 at addr ffff888116a56028 by task cat/502
...
Freed by task 504:
kfree+0x308/0x580
ocfs2_journal_shutdown+0x10a/0xc20
ocfs2_dismount_volume+0x315/0x940
Link: https://patch.msgid.link/pm-ocfs2-objects-candidate-0003-v8-8fb510a5c52b337960c9@gmail.com
Fixes: da5e7c87827e ("ocfs2: cleanup journal init and shutdown")
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Heming Zhao <heming.zhao@suse.com>
Cc: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: <jjzuming@gmail.com>
Cc: <stable@vger.kernel.org>
fs/ocfs2/super.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
--- a/fs/ocfs2/super.c~ocfs2-drain-fs_state-readers-before-journal-teardown
+++ a/fs/ocfs2/super.c
@@ -1072,9 +1072,6 @@ static int ocfs2_fill_super(struct super
osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
ocfs2_debugfs_root);
- debugfs_create_file("fs_state", S_IFREG|S_IRUSR, osb->osb_debug_root,
- osb, &ocfs2_osb_debug_fops);
-
if (ocfs2_meta_ecc(osb)) {
ocfs2_initialize_journal_triggers(sb, osb->s_journal_triggers);
ocfs2_blockcheck_stats_debugfs_install( &osb->osb_ecc_stats,
@@ -1158,6 +1155,10 @@ static int ocfs2_fill_super(struct super
/* Start this when the mount is almost sure of being successful */
ocfs2_orphan_scan_start(osb);
+ /* Publish fs_state only after all fallible mount steps. */
+ debugfs_create_file("fs_state", 0400, osb->osb_debug_root,
+ osb, &ocfs2_osb_debug_fops);
+
return status;
out_dismount:
@@ -1555,8 +1556,13 @@ static void __exit ocfs2_exit(void)
static void ocfs2_put_super(struct super_block *sb)
{
+ struct ocfs2_super *osb = OCFS2_SB(sb);
+
trace_ocfs2_put_super(sb);
+ /* Drain fs_state opens before releasing their backing state. */
+ debugfs_lookup_and_remove("fs_state", osb->osb_debug_root);
+
ocfs2_sync_blockdev(sb);
ocfs2_dismount_volume(sb, 0);
}
_
Patches currently in -mm which might be from zzzccc427@gmail.com are
ocfs2-drain-domain-handlers-before-destroying-the-dlm-worker.patch
ocfs2-drain-fs_state-readers-before-journal-teardown.patch
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-22 17:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 7:51 [PATCH v3] ocfs2: drain fs_state readers before journal teardown Cen Zhang
2026-11-22 15:17 ` Joseph Qi
2026-11-22 17:40 ` + ocfs2-drain-fs_state-readers-before-journal-teardown.patch added to mm-nonmm-unstable branch Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox