diff mbox series

[v3,2/2] cifs: Fix use-after-free in SMB2_read

Message ID 1554690154-34236-3-git-send-email-zhangxiaoxu5@huawei.com (mailing list archive)
State New, archived
Headers show
Series Fix KASAN use-after free in SMB2_write and SMB2_read | expand

Commit Message

Zhang Xiaoxu April 8, 2019, 2:22 a.m. UTC
There is a KASAN use-after-free:
BUG: KASAN: use-after-free in SMB2_read+0x1136/0x1190
Read of size 8 at addr ffff8880b4e45e50 by task ln/1009

Should not release the 'req' because it will use in the trace.

Fixes: eccb4422cf97(smb3: Add ftrace tracepoints for improved SMB3 debugging)

cc: stable@vger.kernel.org (v4.18+)
Signed-off-by: ZhangXiaoxu <zhangxiaoxu5@huawei.com>
---
 fs/cifs/smb2pdu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Pavel Shilovsky April 8, 2019, 11:09 p.m. UTC | #1
вс, 7 апр. 2019 г. в 19:18, ZhangXiaoxu <zhangxiaoxu5@huawei.com>:
>
> There is a KASAN use-after-free:
> BUG: KASAN: use-after-free in SMB2_read+0x1136/0x1190
> Read of size 8 at addr ffff8880b4e45e50 by task ln/1009
>
> Should not release the 'req' because it will use in the trace.
>
> Fixes: eccb4422cf97(smb3: Add ftrace tracepoints for improved SMB3 debugging)
>
> cc: stable@vger.kernel.org (v4.18+)
> Signed-off-by: ZhangXiaoxu <zhangxiaoxu5@huawei.com>
> ---
>  fs/cifs/smb2pdu.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
> index fca5b0a..b8f7262 100644
> --- a/fs/cifs/smb2pdu.c
> +++ b/fs/cifs/smb2pdu.c
> @@ -3451,8 +3451,6 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
>         rqst.rq_nvec = 1;
>
>         rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags, &rsp_iov);
> -       cifs_small_buf_release(req);
> -
>         rsp = (struct smb2_read_rsp *)rsp_iov.iov_base;
>
>         if (rc) {
> @@ -3474,6 +3472,8 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
>                                     io_parms->tcon->tid, ses->Suid,
>                                     io_parms->offset, io_parms->length);
>
> +       cifs_small_buf_release(req);
> +
>         *nbytes = le32_to_cpu(rsp->DataLength);
>         if ((*nbytes > CIFS_MAX_MSGSIZE) ||
>             (*nbytes > io_parms->length)) {
> --
> 2.7.4
>

Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>

--
Best regards,
Pavel Shilovsky
diff mbox series

Patch

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index fca5b0a..b8f7262 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -3451,8 +3451,6 @@  SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
 	rqst.rq_nvec = 1;
 
 	rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags, &rsp_iov);
-	cifs_small_buf_release(req);
-
 	rsp = (struct smb2_read_rsp *)rsp_iov.iov_base;
 
 	if (rc) {
@@ -3474,6 +3472,8 @@  SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
 				    io_parms->tcon->tid, ses->Suid,
 				    io_parms->offset, io_parms->length);
 
+	cifs_small_buf_release(req);
+
 	*nbytes = le32_to_cpu(rsp->DataLength);
 	if ((*nbytes > CIFS_MAX_MSGSIZE) ||
 	    (*nbytes > io_parms->length)) {