Commit b4d965a3 authored by Ronnie Sahlberg's avatar Ronnie Sahlberg Committed by Greg Kroah-Hartman

cifs: allow calling SMB2_xxx_free(NULL)

commit 32a1fb36 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:  1eb9fb52 ("cifs: create SMB2_open_init()/SMB2_open_free() helpers")
Signed-off-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
Reviewed-by: default avatarAurelien Aptel <aaptel@suse.com>
CC: Stable <stable@vger.kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e5d7b94c
...@@ -2243,10 +2243,12 @@ SMB2_open_free(struct smb_rqst *rqst) ...@@ -2243,10 +2243,12 @@ SMB2_open_free(struct smb_rqst *rqst)
{ {
int i; int i;
cifs_small_buf_release(rqst->rq_iov[0].iov_base); if (rqst && rqst->rq_iov) {
for (i = 1; i < rqst->rq_nvec; i++) cifs_small_buf_release(rqst->rq_iov[0].iov_base);
if (rqst->rq_iov[i].iov_base != smb2_padding) for (i = 1; i < rqst->rq_nvec; i++)
kfree(rqst->rq_iov[i].iov_base); if (rqst->rq_iov[i].iov_base != smb2_padding)
kfree(rqst->rq_iov[i].iov_base);
}
} }
int int
...@@ -2535,7 +2537,8 @@ SMB2_close_init(struct cifs_tcon *tcon, struct smb_rqst *rqst, ...@@ -2535,7 +2537,8 @@ SMB2_close_init(struct cifs_tcon *tcon, struct smb_rqst *rqst,
void void
SMB2_close_free(struct smb_rqst *rqst) 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 int
...@@ -2685,7 +2688,8 @@ SMB2_query_info_init(struct cifs_tcon *tcon, struct smb_rqst *rqst, ...@@ -2685,7 +2688,8 @@ SMB2_query_info_init(struct cifs_tcon *tcon, struct smb_rqst *rqst,
void void
SMB2_query_info_free(struct smb_rqst *rqst) 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 static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment