ocfs2: fix crash issue if access released lockres in debugfs
PATCH 1/1 ocfs2: fix crash issue if access released lockres in debugfs
Access locking_state of dlm debugfs may cause crash as scene below:
Proc A: Proc that access debuginfo:add_lockres_tracking(lockresA)
...
ocfs2_dlm_seq_next():
//priv->p_iter_res points to next
//lockres e.g. B. priv->p_tmp_res hold
//copy of lockres A before leave
ocfs2_dlm_seq_show()...remove_lockres_tracking(lockres B):
//free lockres B, l_debug_list in
//priv->p_ter_res is updated but not
//priv->p_tmp_res
...
ocfs2_dlm_seq_next():
//priv->p_tmp_res which holds a old copy of
//lockres A, the l_debug_list holds a
//out-of-date succeed pointer, which will
//cause crash as //access invalid memory
iter = v; //priv->p_tmp_res
iter = ocfs2_dlm_next_res(iter, priv)The root cause of this issue is that private->p_iter_res acts as the agent of accessing lockres and is protected by ocfs2_dlm_tracking_lock while p_tmp_res is only a copy of the lockres and will be out-of-dated after leave critial region of ocfs2_dlm_tracking_lock. We should use priv->p_ter_res as the forward iterater instead.
--- fs/ocfs2/dlmglue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/dlmglue.c +1 -1
@@ -3109,7 +3109,7 @@ static void *ocfs2_dlm_seq_next(struct seq_file *m, void *v, loff_t *pos)struct ocfs2_lock_res *dummy = &priv->p_iter_res;spin_lock (&ocfs2_dlm_tracking_lock); - iter =ocfs2_dlm_next_res (iter, priv); + iter =ocfs2_dlm_next_res (dummy, priv);list_del_init (&dummy->l_debug_list);if (iter) {list_add (&dummy->l_debug_list, &iter->l_debug_list);
Signature · 1 line
1.8.3.1
Joseph Qi
maintainerHi,
Sorry for the late reply.
It seems it is indeed an issue and I'll get into it more deeply. I'm curious about how you figure out this? Is it a real issue you've encountered?
Thanks,
Joseph
Quoted 48 lines · Rock Li
Access
locking_stateof dlm debugfs may cause crash as scene below:Proc A: Proc that access debuginfo:
add_lockres_tracking(lockresA)
...ocfs2_dlm_seq_next(): //priv->p_iter_res points to next //lockres e.g. B. priv->p_tmp_res hold //copy of lockres A before leave ocfs2_dlm_seq_show()...
remove_lockres_tracking(lockres B):
//free lockres B,l_debug_listin
//priv->p_ter_res is updated but not
//priv->p_tmp_res
...ocfs2_dlm_seq_next(): //priv->p_tmp_res which holds a old copy of //lockres A, the l_debug_list holds a //out-of-date succeed pointer, which will //cause crash as //access invalid memory iter = v; //priv->p_tmp_res iter = ocfs2_dlm_next_res(iter, priv)The root cause of this issue is that
private->p_iter_resacts as the agent of accessing lockres and is protected byocfs2_dlm_tracking_lockwhilep_tmp_resis only a copy of the lockres and will be out-of-dated after leave critial region ofocfs2_dlm_tracking_lock. We should usepriv->p_ter_resas the forward iterater instead.Signed-off-by Rock Li <[email protected]>--- fs/ocfs2/dlmglue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ocfs2/dlmglue.c +1
-1@@ -3109,7 +3109,7 @@ static void *ocfs2_dlm_seq_next(struct seq_file *m, void *v, loff_t *pos)struct ocfs2_lock_res *dummy = &priv->p_iter_res;spin_lock (&ocfs2_dlm_tracking_lock); - iter =ocfs2_dlm_next_res (iter, priv); + iter =ocfs2_dlm_next_res (dummy, priv);list_del_init (&dummy->l_debug_list);if (iter) {list_add (&dummy->l_debug_list, &iter->l_debug_list);