All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ocfs2: fix race between ocfs2_control_install_private() and ocfs2_control_release()
@ 2026-06-01 12:16 Joseph Qi
  2026-06-02  4:18 ` Heming Zhao
  0 siblings, 1 reply; 4+ messages in thread
From: Joseph Qi @ 2026-06-01 12:16 UTC (permalink / raw)
  To: Andrew Morton, Heming Zhao, Ginger; +Cc: ocfs2-devel, linux-kernel

Move atomic_inc(&ocfs2_control_opened) and the handshake state update
inside ocfs2_control_lock to close a race window where
ocfs2_control_release() can observe ocfs2_control_opened dropping to
zero (resetting ocfs2_control_this_node and running_proto) while
ocfs2_control_install_private() is about to bump the counter and mark
the connection valid.

Fixes: 3cfd4ab6b6b4 ("ocfs2: Add the local node id to the handshake.")
Reported-by: Ginger <ginger@gmail.com>
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
---
 fs/ocfs2/stack_user.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/fs/ocfs2/stack_user.c b/fs/ocfs2/stack_user.c
index 5803f1dee679..91e19d33847c 100644
--- a/fs/ocfs2/stack_user.c
+++ b/fs/ocfs2/stack_user.c
@@ -327,18 +327,14 @@ static int ocfs2_control_install_private(struct file *file)
 		ocfs2_control_this_node = p->op_this_node;
 		running_proto.pv_major = p->op_proto.pv_major;
 		running_proto.pv_minor = p->op_proto.pv_minor;
-	}
-
-out_unlock:
-	mutex_unlock(&ocfs2_control_lock);
-
-	if (!rc && set_p) {
-		/* We set the global values successfully */
 		atomic_inc(&ocfs2_control_opened);
 		ocfs2_control_set_handshake_state(file,
 					OCFS2_CONTROL_HANDSHAKE_VALID);
 	}
 
+out_unlock:
+	mutex_unlock(&ocfs2_control_lock);
+
 	return rc;
 }
 
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ocfs2: fix race between ocfs2_control_install_private() and ocfs2_control_release()
  2026-06-01 12:16 [PATCH] ocfs2: fix race between ocfs2_control_install_private() and ocfs2_control_release() Joseph Qi
@ 2026-06-02  4:18 ` Heming Zhao
  2026-06-02  4:40   ` Andrew Morton
  2026-06-02  5:37   ` Joseph Qi
  0 siblings, 2 replies; 4+ messages in thread
From: Heming Zhao @ 2026-06-02  4:18 UTC (permalink / raw)
  To: Joseph Qi; +Cc: Andrew Morton, Ginger, ocfs2-devel, linux-kernel

On Mon, Jun 01, 2026 at 08:16:18PM +0800, Joseph Qi wrote:
> Move atomic_inc(&ocfs2_control_opened) and the handshake state update
> inside ocfs2_control_lock to close a race window where
> ocfs2_control_release() can observe ocfs2_control_opened dropping to
> zero (resetting ocfs2_control_this_node and running_proto) while
> ocfs2_control_install_private() is about to bump the counter and mark
> the connection valid.
> 
> Fixes: 3cfd4ab6b6b4 ("ocfs2: Add the local node id to the handshake.")
> Reported-by: Ginger <ginger@gmail.com>

The code looks good to me, but above email address is not valid.
The correct should be: <ginger.jzllee@gmail.com>

- Heming

> Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
>  fs/ocfs2/stack_user.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/ocfs2/stack_user.c b/fs/ocfs2/stack_user.c
> index 5803f1dee679..91e19d33847c 100644
> --- a/fs/ocfs2/stack_user.c
> +++ b/fs/ocfs2/stack_user.c
> @@ -327,18 +327,14 @@ static int ocfs2_control_install_private(struct file *file)
>  		ocfs2_control_this_node = p->op_this_node;
>  		running_proto.pv_major = p->op_proto.pv_major;
>  		running_proto.pv_minor = p->op_proto.pv_minor;
> -	}
> -
> -out_unlock:
> -	mutex_unlock(&ocfs2_control_lock);
> -
> -	if (!rc && set_p) {
> -		/* We set the global values successfully */
>  		atomic_inc(&ocfs2_control_opened);
>  		ocfs2_control_set_handshake_state(file,
>  					OCFS2_CONTROL_HANDSHAKE_VALID);
>  	}
>  
> +out_unlock:
> +	mutex_unlock(&ocfs2_control_lock);
> +
>  	return rc;
>  }
>  
> -- 
> 2.39.3
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ocfs2: fix race between ocfs2_control_install_private() and ocfs2_control_release()
  2026-06-02  4:18 ` Heming Zhao
@ 2026-06-02  4:40   ` Andrew Morton
  2026-06-02  5:37   ` Joseph Qi
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2026-06-02  4:40 UTC (permalink / raw)
  To: Heming Zhao; +Cc: Joseph Qi, Ginger, ocfs2-devel, linux-kernel

On Tue, 2 Jun 2026 12:18:59 +0800 Heming Zhao <heming.zhao@suse.com> wrote:

> On Mon, Jun 01, 2026 at 08:16:18PM +0800, Joseph Qi wrote:
> > Move atomic_inc(&ocfs2_control_opened) and the handshake state update
> > inside ocfs2_control_lock to close a race window where
> > ocfs2_control_release() can observe ocfs2_control_opened dropping to
> > zero (resetting ocfs2_control_this_node and running_proto) while
> > ocfs2_control_install_private() is about to bump the counter and mark
> > the connection valid.
> > 
> > Fixes: 3cfd4ab6b6b4 ("ocfs2: Add the local node id to the handshake.")
> > Reported-by: Ginger <ginger@gmail.com>
> 
> The code looks good to me, but above email address is not valid.
> The correct should be: <ginger.jzllee@gmail.com>

Updated, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ocfs2: fix race between ocfs2_control_install_private() and ocfs2_control_release()
  2026-06-02  4:18 ` Heming Zhao
  2026-06-02  4:40   ` Andrew Morton
@ 2026-06-02  5:37   ` Joseph Qi
  1 sibling, 0 replies; 4+ messages in thread
From: Joseph Qi @ 2026-06-02  5:37 UTC (permalink / raw)
  To: Heming Zhao; +Cc: Andrew Morton, Ginger, ocfs2-devel, linux-kernel



On 6/2/26 12:18 PM, Heming Zhao wrote:
> On Mon, Jun 01, 2026 at 08:16:18PM +0800, Joseph Qi wrote:
>> Move atomic_inc(&ocfs2_control_opened) and the handshake state update
>> inside ocfs2_control_lock to close a race window where
>> ocfs2_control_release() can observe ocfs2_control_opened dropping to
>> zero (resetting ocfs2_control_this_node and running_proto) while
>> ocfs2_control_install_private() is about to bump the counter and mark
>> the connection valid.
>>
>> Fixes: 3cfd4ab6b6b4 ("ocfs2: Add the local node id to the handshake.")
>> Reported-by: Ginger <ginger@gmail.com>
> 
> The code looks good to me, but above email address is not valid.
> The correct should be: <ginger.jzllee@gmail.com>
> 

Oops, my mistake. Thank you for pointing out this.

Thanks,
Joseph

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-02  5:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-01 12:16 [PATCH] ocfs2: fix race between ocfs2_control_install_private() and ocfs2_control_release() Joseph Qi
2026-06-02  4:18 ` Heming Zhao
2026-06-02  4:40   ` Andrew Morton
2026-06-02  5:37   ` Joseph Qi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.