stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4.19.y] cifs: allow calling SMB2_xxx_free(NULL)
@ 2019-03-10 22:08 Remy Oudompheng
  2019-03-12 12:51 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Remy Oudompheng @ 2019-03-10 22:08 UTC (permalink / raw)
  To: stable

From: Ronnie Sahlberg <lsahlber@redhat.com>

commit 32a1fb36f6e50183871c2c1fcf5493c633e84732 upstream.

Change these free functions to allow passing NULL as the argument and
treat it as a no-op just like free(NULL) would.
Or, if rqst->rq_iov is NULL.

The second scenario could happen for smb2_queryfs() if the call
to SMB2_query_info_init() fails and we go to qfs_exit to clean up
and free all resources.
In that case we have not yet assigned rqst[2].rq_iov and thus
the rq_iov dereference in SMB2_close_free() will cause a NULL pointer
dereference.

[ bp: upstream patch also fixes SMB2_set_info_free which was introduced in 4.20 ]

Fixes:  1eb9fb52040f ("cifs: create SMB2_open_init()/SMB2_open_free() helpers")

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
CC: Stable <stable@vger.kernel.org>
---
 fs/cifs/smb2pdu.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 1e5a1171212f..a2d701775c49 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2243,10 +2243,12 @@ SMB2_open_free(struct smb_rqst *rqst)
 {
 	int i;
 
-	cifs_small_buf_release(rqst->rq_iov[0].iov_base);
-	for (i = 1; i < rqst->rq_nvec; i++)
-		if (rqst->rq_iov[i].iov_base != smb2_padding)
-			kfree(rqst->rq_iov[i].iov_base);
+	if (rqst && rqst->rq_iov) {
+		cifs_small_buf_release(rqst->rq_iov[0].iov_base);
+		for (i = 1; i < rqst->rq_nvec; i++)
+			if (rqst->rq_iov[i].iov_base != smb2_padding)
+				kfree(rqst->rq_iov[i].iov_base);
+	}
 }
 
 int
@@ -2535,7 +2537,8 @@ SMB2_close_init(struct cifs_tcon *tcon, struct smb_rqst *rqst,
 void
 SMB2_close_free(struct smb_rqst *rqst)
 {
-	cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */
+	if (rqst && rqst->rq_iov)
+		cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */
 }
 
 int
@@ -2685,7 +2688,8 @@ SMB2_query_info_init(struct cifs_tcon *tcon, struct smb_rqst *rqst,
 void
 SMB2_query_info_free(struct smb_rqst *rqst)
 {
-	cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */
+	if (rqst && rqst->rq_iov)
+		cifs_small_buf_release(rqst->rq_iov[0].iov_base); /* request */
 }
 
 static int
-- 
2.21.0


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

* Re: [PATCH 4.19.y] cifs: allow calling SMB2_xxx_free(NULL)
  2019-03-10 22:08 [PATCH 4.19.y] cifs: allow calling SMB2_xxx_free(NULL) Remy Oudompheng
@ 2019-03-12 12:51 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2019-03-12 12:51 UTC (permalink / raw)
  To: Remy Oudompheng; +Cc: stable

On Sun, Mar 10, 2019 at 11:08:10PM +0100, Remy Oudompheng wrote:
> From: Ronnie Sahlberg <lsahlber@redhat.com>
> 
> commit 32a1fb36f6e50183871c2c1fcf5493c633e84732 upstream.
> 
> Change these free functions to allow passing NULL as the argument and
> treat it as a no-op just like free(NULL) would.
> Or, if rqst->rq_iov is NULL.
> 
> The second scenario could happen for smb2_queryfs() if the call
> to SMB2_query_info_init() fails and we go to qfs_exit to clean up
> and free all resources.
> In that case we have not yet assigned rqst[2].rq_iov and thus
> the rq_iov dereference in SMB2_close_free() will cause a NULL pointer
> dereference.
> 
> [ bp: upstream patch also fixes SMB2_set_info_free which was introduced in 4.20 ]
> 
> Fixes:  1eb9fb52040f ("cifs: create SMB2_open_init()/SMB2_open_free() helpers")
> 
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> Signed-off-by: Steve French <stfrench@microsoft.com>
> Reviewed-by: Aurelien Aptel <aaptel@suse.com>
> CC: Stable <stable@vger.kernel.org>
> ---
>  fs/cifs/smb2pdu.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)

Now applied, thanks.

greg k-h

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

end of thread, other threads:[~2019-03-12 12:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-10 22:08 [PATCH 4.19.y] cifs: allow calling SMB2_xxx_free(NULL) Remy Oudompheng
2019-03-12 12:51 ` Greg KH

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).