All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][V2] cifs: fix memory leak of an allocated cifs_ntsd structure
@ 2019-01-16 16:28 Colin King
  2019-01-17  7:10   ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Colin King @ 2019-01-16 16:28 UTC (permalink / raw)
  To: Steve French, linux-cifs, samba-technical; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The call to SMB2_queary_acl can allocate memory to pntsd and also
return a failure via a call to SMB2_query_acl (and then query_info).
This occurs when query_info allocates the structure and then in
query_info the call to smb2_validate_and_copy_iov fails. Currently the
failure just returns without kfree'ing pntsd hence causing a memory
leak.

Currently, *data is allocated if it's not already pointing to a buffer,
so it needs to be kfree'd only if was allocated in query_info, so the
fix adds an allocated flag to track this.  Also set *dlen to zero on
an error just to be safe since *data is kfree'd.

Also set errno to -ENOMEM if the allocation of *data fails.

Signed-off-by: Colin Ian King <colin.king@canonical.com>

---
 fs/cifs/smb2pdu.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 50811a7dc0e0..0af87bd0dc49 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -2816,6 +2816,7 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon,
 	int resp_buftype = CIFS_NO_BUFFER;
 	struct cifs_ses *ses = tcon->ses;
 	int flags = 0;
+	bool allocated = false;
 
 	cifs_dbg(FYI, "Query Info\n");
 
@@ -2855,14 +2856,21 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon,
 					"Error %d allocating memory for acl\n",
 					rc);
 				*dlen = 0;
+				rc = -ENOMEM;
 				goto qinf_exit;
 			}
+			allocated = true;
 		}
 	}
 
 	rc = smb2_validate_and_copy_iov(le16_to_cpu(rsp->OutputBufferOffset),
 					le32_to_cpu(rsp->OutputBufferLength),
 					&rsp_iov, min_len, *data);
+	if (rc && allocated) {
+		kfree(*data);
+		*data = NULL;
+		*dlen = 0;
+	}
 
 qinf_exit:
 	SMB2_query_info_free(&rqst);
-- 
2.19.1

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

* Re: [PATCH][V2] cifs: fix memory leak of an allocated cifs_ntsd structure
  2019-01-16 16:28 [PATCH][V2] cifs: fix memory leak of an allocated cifs_ntsd structure Colin King
@ 2019-01-17  7:10   ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2019-01-17  7:10 UTC (permalink / raw)
  To: Colin King
  Cc: Steve French, linux-cifs, samba-technical, kernel-janitors, linux-kernel

Thanks, Colin!

Reviewed-by: Dan Carpener <dan.carpenter@oracle.com>

regards,
dan carpenter

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

* Re: [PATCH][V2] cifs: fix memory leak of an allocated cifs_ntsd structure
@ 2019-01-17  7:10   ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2019-01-17  7:10 UTC (permalink / raw)
  To: Colin King
  Cc: Steve French, linux-cifs, samba-technical, kernel-janitors, linux-kernel

Thanks, Colin!

Reviewed-by: Dan Carpener <dan.carpenter@oracle.com>

regards,
dan carpenter

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

* Re: [PATCH][V2] cifs: fix memory leak of an allocated cifs_ntsd structure
  2019-01-17  7:10   ` Dan Carpenter
@ 2019-01-17 15:59     ` Steve French
  -1 siblings, 0 replies; 5+ messages in thread
From: Steve French @ 2019-01-17 15:59 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Colin King, Steve French, CIFS, kernel-janitors, samba-technical, LKML

merged into cifs-2.6.git for-next

On Thu, Jan 17, 2019 at 1:12 AM Dan Carpenter via samba-technical
<samba-technical@lists.samba.org> wrote:
>
> Thanks, Colin!
>
> Reviewed-by: Dan Carpener <dan.carpenter@oracle.com>
>
> regards,
> dan carpenter
>
>


-- 
Thanks,

Steve

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

* Re: [PATCH][V2] cifs: fix memory leak of an allocated cifs_ntsd structure
@ 2019-01-17 15:59     ` Steve French
  0 siblings, 0 replies; 5+ messages in thread
From: Steve French @ 2019-01-17 15:59 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Colin King, Steve French, CIFS, kernel-janitors, samba-technical, LKML

merged into cifs-2.6.git for-next

On Thu, Jan 17, 2019 at 1:12 AM Dan Carpenter via samba-technical
<samba-technical@lists.samba.org> wrote:
>
> Thanks, Colin!
>
> Reviewed-by: Dan Carpener <dan.carpenter@oracle.com>
>
> regards,
> dan carpenter
>
>


-- 
Thanks,

Steve

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

end of thread, other threads:[~2019-01-17 15:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-16 16:28 [PATCH][V2] cifs: fix memory leak of an allocated cifs_ntsd structure Colin King
2019-01-17  7:10 ` Dan Carpenter
2019-01-17  7:10   ` Dan Carpenter
2019-01-17 15:59   ` Steve French
2019-01-17 15:59     ` Steve French

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.