* [Ocfs2-devel] [PATCH v2] ocfs2: Fix freeing uninitialized resource on ocfs2_dlm_shutdown
@ 2022-08-15 8:57 Heming Zhao via Ocfs2-devel
2022-08-15 9:29 ` Joseph Qi via Ocfs2-devel
0 siblings, 1 reply; 2+ messages in thread
From: Heming Zhao via Ocfs2-devel @ 2022-08-15 8:57 UTC (permalink / raw)
To: joseph.qi, junxiao.bi; +Cc: ocfs2-devel
After commit 0737e01de9c4 ("ocfs2: ocfs2_mount_volume does cleanup job
before return error"), any procedure after ocfs2_dlm_init() fails will
trigger crash when calling ocfs2_dlm_shutdown().
ie: On local mount mode, no dlm resource is initialized. If
ocfs2_mount_volume() fails in ocfs2_find_slot(), error handling
will call ocfs2_dlm_shutdown(), then does dlm resource cleanup
job, which will trigger kernel crash.
This solution should bypass uninitialized resources in
ocfs2_dlm_shutdown().
Fixes: 0737e01de9c4 ("ocfs2: ocfs2_mount_volume does cleanup job before return error")
Signed-off-by: Heming Zhao <heming.zhao@suse.com>
---
v1 -> v2:
- by review comments:
- revise commit log
- remove improperly checking osb->cconn in ocfs2_dismount_volume()
draft -> v1:
- separate to a single patch
- by review comment:
- do free lockres in shutdown path
- put 'Fixes' string in one line
- revise misspelled & grammar mistake in commit log
---
fs/ocfs2/dlmglue.c | 8 +++++---
fs/ocfs2/super.c | 3 +--
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c
index 801e60bab955..c28bc983a7b1 100644
--- a/fs/ocfs2/dlmglue.c
+++ b/fs/ocfs2/dlmglue.c
@@ -3403,10 +3403,12 @@ void ocfs2_dlm_shutdown(struct ocfs2_super *osb,
ocfs2_lock_res_free(&osb->osb_nfs_sync_lockres);
ocfs2_lock_res_free(&osb->osb_orphan_scan.os_lockres);
- ocfs2_cluster_disconnect(osb->cconn, hangup_pending);
- osb->cconn = NULL;
+ if (osb->cconn) {
+ ocfs2_cluster_disconnect(osb->cconn, hangup_pending);
+ osb->cconn = NULL;
- ocfs2_dlm_shutdown_debug(osb);
+ ocfs2_dlm_shutdown_debug(osb);
+ }
}
static int ocfs2_drop_lock(struct ocfs2_super *osb,
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 438be028935d..bc18c27e9683 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -1914,8 +1914,7 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
!ocfs2_is_hard_readonly(osb))
hangup_needed = 1;
- if (osb->cconn)
- ocfs2_dlm_shutdown(osb, hangup_needed);
+ ocfs2_dlm_shutdown(osb, hangup_needed);
ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
debugfs_remove_recursive(osb->osb_debug_root);
--
2.37.1
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Ocfs2-devel] [PATCH v2] ocfs2: Fix freeing uninitialized resource on ocfs2_dlm_shutdown
2022-08-15 8:57 [Ocfs2-devel] [PATCH v2] ocfs2: Fix freeing uninitialized resource on ocfs2_dlm_shutdown Heming Zhao via Ocfs2-devel
@ 2022-08-15 9:29 ` Joseph Qi via Ocfs2-devel
0 siblings, 0 replies; 2+ messages in thread
From: Joseph Qi via Ocfs2-devel @ 2022-08-15 9:29 UTC (permalink / raw)
To: Heming Zhao, junxiao.bi, akpm; +Cc: ocfs2-devel
On 8/15/22 4:57 PM, Heming Zhao wrote:
> After commit 0737e01de9c4 ("ocfs2: ocfs2_mount_volume does cleanup job
> before return error"), any procedure after ocfs2_dlm_init() fails will
> trigger crash when calling ocfs2_dlm_shutdown().
>
> ie: On local mount mode, no dlm resource is initialized. If
> ocfs2_mount_volume() fails in ocfs2_find_slot(), error handling
> will call ocfs2_dlm_shutdown(), then does dlm resource cleanup
> job, which will trigger kernel crash.
>
> This solution should bypass uninitialized resources in
> ocfs2_dlm_shutdown().
>
> Fixes: 0737e01de9c4 ("ocfs2: ocfs2_mount_volume does cleanup job before return error")
> Signed-off-by: Heming Zhao <heming.zhao@suse.com>
Looks good.
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
> v1 -> v2:
> - by review comments:
> - revise commit log
> - remove improperly checking osb->cconn in ocfs2_dismount_volume()
>
> draft -> v1:
> - separate to a single patch
> - by review comment:
> - do free lockres in shutdown path
> - put 'Fixes' string in one line
> - revise misspelled & grammar mistake in commit log
> ---
> fs/ocfs2/dlmglue.c | 8 +++++---
> fs/ocfs2/super.c | 3 +--
> 2 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c
> index 801e60bab955..c28bc983a7b1 100644
> --- a/fs/ocfs2/dlmglue.c
> +++ b/fs/ocfs2/dlmglue.c
> @@ -3403,10 +3403,12 @@ void ocfs2_dlm_shutdown(struct ocfs2_super *osb,
> ocfs2_lock_res_free(&osb->osb_nfs_sync_lockres);
> ocfs2_lock_res_free(&osb->osb_orphan_scan.os_lockres);
>
> - ocfs2_cluster_disconnect(osb->cconn, hangup_pending);
> - osb->cconn = NULL;
> + if (osb->cconn) {
> + ocfs2_cluster_disconnect(osb->cconn, hangup_pending);
> + osb->cconn = NULL;
>
> - ocfs2_dlm_shutdown_debug(osb);
> + ocfs2_dlm_shutdown_debug(osb);
> + }
> }
>
> static int ocfs2_drop_lock(struct ocfs2_super *osb,
> diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
> index 438be028935d..bc18c27e9683 100644
> --- a/fs/ocfs2/super.c
> +++ b/fs/ocfs2/super.c
> @@ -1914,8 +1914,7 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
> !ocfs2_is_hard_readonly(osb))
> hangup_needed = 1;
>
> - if (osb->cconn)
> - ocfs2_dlm_shutdown(osb, hangup_needed);
> + ocfs2_dlm_shutdown(osb, hangup_needed);
>
> ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
> debugfs_remove_recursive(osb->osb_debug_root);
_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-08-15 9:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15 8:57 [Ocfs2-devel] [PATCH v2] ocfs2: Fix freeing uninitialized resource on ocfs2_dlm_shutdown Heming Zhao via Ocfs2-devel
2022-08-15 9:29 ` Joseph Qi via Ocfs2-devel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).