diff mbox series

[2/2] cifs: use correct lock type in cifs_reconnect()

Message ID 20220421000546.5129-2-pc@cjr.nz
State New
Headers show
Series [1/2] cifs: fix NULL ptr dereference in refresh_mounts() | expand

Commit Message

Paulo Alcantara April 21, 2022, 12:05 a.m. UTC
TCP_Server_Info::origin_fullpath and TCP_Server_Info::leaf_fullpath
are protected by refpath_lock mutex and not cifs_tcp_ses_lock
spinlock.

Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
---
 fs/cifs/connect.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Ronnie Sahlberg April 21, 2022, 2:39 a.m. UTC | #1
looks good to me.
Reviewed-by me

On Thu, Apr 21, 2022 at 10:06 AM Paulo Alcantara <pc@cjr.nz> wrote:
>
> TCP_Server_Info::origin_fullpath and TCP_Server_Info::leaf_fullpath
> are protected by refpath_lock mutex and not cifs_tcp_ses_lock
> spinlock.
>
> Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
> ---
>  fs/cifs/connect.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> index 2c24d433061a..42e14f408856 100644
> --- a/fs/cifs/connect.c
> +++ b/fs/cifs/connect.c
> @@ -534,12 +534,19 @@ int cifs_reconnect(struct TCP_Server_Info *server, bool mark_smb_session)
>  {
>         /* If tcp session is not an dfs connection, then reconnect to last target server */
>         spin_lock(&cifs_tcp_ses_lock);
> -       if (!server->is_dfs_conn || !server->origin_fullpath || !server->leaf_fullpath) {
> +       if (!server->is_dfs_conn) {
>                 spin_unlock(&cifs_tcp_ses_lock);
>                 return __cifs_reconnect(server, mark_smb_session);
>         }
>         spin_unlock(&cifs_tcp_ses_lock);
>
> +       mutex_lock(&server->refpath_lock);
> +       if (!server->origin_fullpath || !server->leaf_fullpath) {
> +               mutex_unlock(&server->refpath_lock);
> +               return __cifs_reconnect(server, mark_smb_session);
> +       }
> +       mutex_unlock(&server->refpath_lock);
> +
>         return reconnect_dfs_server(server);
>  }
>  #else
> --
> 2.35.3
>
Steve French April 21, 2022, 3:56 a.m. UTC | #2
Added CC:Stable and Reviewed-by and pushed to cifs-2.6.git for-next
pending testing

On Wed, Apr 20, 2022 at 9:39 PM Leif Sahlberg <lsahlber@redhat.com> wrote:
>
> looks good to me.
> Reviewed-by me
>
> On Thu, Apr 21, 2022 at 10:06 AM Paulo Alcantara <pc@cjr.nz> wrote:
> >
> > TCP_Server_Info::origin_fullpath and TCP_Server_Info::leaf_fullpath
> > are protected by refpath_lock mutex and not cifs_tcp_ses_lock
> > spinlock.
> >
> > Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
> > ---
> >  fs/cifs/connect.c | 9 ++++++++-
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> > index 2c24d433061a..42e14f408856 100644
> > --- a/fs/cifs/connect.c
> > +++ b/fs/cifs/connect.c
> > @@ -534,12 +534,19 @@ int cifs_reconnect(struct TCP_Server_Info *server, bool mark_smb_session)
> >  {
> >         /* If tcp session is not an dfs connection, then reconnect to last target server */
> >         spin_lock(&cifs_tcp_ses_lock);
> > -       if (!server->is_dfs_conn || !server->origin_fullpath || !server->leaf_fullpath) {
> > +       if (!server->is_dfs_conn) {
> >                 spin_unlock(&cifs_tcp_ses_lock);
> >                 return __cifs_reconnect(server, mark_smb_session);
> >         }
> >         spin_unlock(&cifs_tcp_ses_lock);
> >
> > +       mutex_lock(&server->refpath_lock);
> > +       if (!server->origin_fullpath || !server->leaf_fullpath) {
> > +               mutex_unlock(&server->refpath_lock);
> > +               return __cifs_reconnect(server, mark_smb_session);
> > +       }
> > +       mutex_unlock(&server->refpath_lock);
> > +
> >         return reconnect_dfs_server(server);
> >  }
> >  #else
> > --
> > 2.35.3
> >
>
diff mbox series

Patch

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 2c24d433061a..42e14f408856 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -534,12 +534,19 @@  int cifs_reconnect(struct TCP_Server_Info *server, bool mark_smb_session)
 {
 	/* If tcp session is not an dfs connection, then reconnect to last target server */
 	spin_lock(&cifs_tcp_ses_lock);
-	if (!server->is_dfs_conn || !server->origin_fullpath || !server->leaf_fullpath) {
+	if (!server->is_dfs_conn) {
 		spin_unlock(&cifs_tcp_ses_lock);
 		return __cifs_reconnect(server, mark_smb_session);
 	}
 	spin_unlock(&cifs_tcp_ses_lock);
 
+	mutex_lock(&server->refpath_lock);
+	if (!server->origin_fullpath || !server->leaf_fullpath) {
+		mutex_unlock(&server->refpath_lock);
+		return __cifs_reconnect(server, mark_smb_session);
+	}
+	mutex_unlock(&server->refpath_lock);
+
 	return reconnect_dfs_server(server);
 }
 #else