ocfs2: fix race between ocfs2_control_install_private() and ocfs2_control_release()
Joseph Qi
maintainerPATCH 1/1 ocfs2: fix race between ocfs2_control_install_private() and ocfs2_control_release()
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.
--- fs/ocfs2/stack_user.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
fs/ocfs2/stack_user.c +3 -7
@@ -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; }
Signature · 1 line
2.39.3
Heming Zhao
reviewerQuoted 9 lines · Joseph Qi
Move
atomic_inc(&ocfs2_control_opened)and the handshake state update insideocfs2_control_lockto close a race window whereocfs2_control_release()can observeocfs2_control_openeddropping to zero (resettingocfs2_control_this_nodeandrunning_proto) whileocfs2_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 <[email protected]>
The code looks good to me, but above email address is not valid. The correct should be: <[email protected]>
- Heming
Quoted 34 lines
Signed-off-by Joseph Qi <[email protected]>--- fs/ocfs2/stack_user.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)fs/ocfs2/stack_user.c +3
-7@@ -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; }Signature · 1 line
2.39.3
Quoted 8 lines · On Tue, 2 Jun 2026 12:18:59 +0800 Heming Zhao <[email protected]> wrote:
Quoted 7 lines · Joseph Qi
Move
atomic_inc(&ocfs2_control_opened)and the handshake state update insideocfs2_control_lockto close a race window whereocfs2_control_release()can observeocfs2_control_openeddropping to zero (resettingocfs2_control_this_nodeandrunning_proto) whileocfs2_control_install_private()is about to bump the counter and mark the connection valid.
Quoted 5 lines
Quoted 2 lines
Fixes 3cfd4ab6b6b4 ("ocfs2: Add the local node id to the handshake.")Reported-by Ginger <[email protected]>The code looks good to me, but above email address is not valid. The correct should be: <[email protected]>
Updated, thanks.
Joseph Qi
maintainerQuoted 8 lines · Heming Zhao
Quoted 7 lines · Joseph Qi
Move
atomic_inc(&ocfs2_control_opened)and the handshake state update insideocfs2_control_lockto close a race window whereocfs2_control_release()can observeocfs2_control_openeddropping to zero (resettingocfs2_control_this_nodeandrunning_proto) whileocfs2_control_install_private()is about to bump the counter and mark the connection valid.
Quoted 6 lines
Quoted 2 lines
Fixes 3cfd4ab6b6b4 ("ocfs2: Add the local node id to the handshake.")Reported-by Ginger <[email protected]>The code looks good to me, but above email address is not valid. The correct should be: <[email protected]>
Oops, my mistake. Thank you for pointing out this.
Thanks,
Joseph