提交 50440213 编写于 作者: C Colin Ian King 提交者: Xie XiuQi

cifs: fix memory leak of an allocated cifs_ntsd structure

mainline inclusion
from mainline-5.0
commit 73aaf920
category: bugfix
bugzilla: 7230
CVE: NA

-------------------------------------------------

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.

conflict:
	fs/cifs/smb2pdu.c
conflict with:c5a5f38f
	cifs: add a smb2_compound_op and change QUERY_INFO to use it
Signed-off-by: NColin Ian King <colin.king@canonical.com>
Signed-off-by: NSteve French <stfrench@microsoft.com>
Reviewed-by: NDan Carpener <dan.carpenter@oracle.com>
Signed-off-by: NZhangXiaoxu <zhangxiaoxu5@huawei.com>
Reviewed-by: NMiao Xie <miaoxie@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 d1bb3b81
...@@ -2706,6 +2706,7 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -2706,6 +2706,7 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon,
int resp_buftype; int resp_buftype;
struct cifs_ses *ses = tcon->ses; struct cifs_ses *ses = tcon->ses;
int flags = 0; int flags = 0;
bool allocated = false;
cifs_dbg(FYI, "Query Info\n"); cifs_dbg(FYI, "Query Info\n");
...@@ -2745,14 +2746,21 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -2745,14 +2746,21 @@ query_info(const unsigned int xid, struct cifs_tcon *tcon,
"Error %d allocating memory for acl\n", "Error %d allocating memory for acl\n",
rc); rc);
*dlen = 0; *dlen = 0;
rc = -ENOMEM;
goto qinf_exit; goto qinf_exit;
} }
allocated = true;
} }
} }
rc = validate_and_copy_iov(le16_to_cpu(rsp->OutputBufferOffset), rc = validate_and_copy_iov(le16_to_cpu(rsp->OutputBufferOffset),
le32_to_cpu(rsp->OutputBufferLength), le32_to_cpu(rsp->OutputBufferLength),
&rsp_iov, min_len, *data); &rsp_iov, min_len, *data);
if (rc && allocated) {
kfree(*data);
*data = NULL;
*dlen = 0;
}
qinf_exit: qinf_exit:
SMB2_query_info_free(&rqst); SMB2_query_info_free(&rqst);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册