]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
cifs: fix memory leak of an allocated cifs_ntsd structure
authorColin Ian King <colin.king@canonical.com>
Wed, 16 Jan 2019 16:28:59 +0000 (16:28 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 5 Mar 2019 16:59:41 +0000 (17:59 +0100)
commitcec01d9f56d739d364d45eda893cb112886e443e
tree92035de91ec52554f239d39a1bb0328c2f249c02
parent0581ea5469a6440eac207b225145bb6b45f43756
cifs: fix memory leak of an allocated cifs_ntsd structure

[ Upstream commit 73aaf920cc72024c4a4460cfa46d56e5014172f3 ]

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>
Signed-off-by: Steve French <stfrench@microsoft.com>
Reviewed-by: Dan Carpener <dan.carpenter@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/cifs/smb2pdu.c