[v3,1/2] cifs: Fix use-after-free in SMB2_write
diff mbox series

Message ID 1554690154-34236-2-git-send-email-zhangxiaoxu5@huawei.com
State New
Headers show
Series
  • Fix KASAN use-after free in SMB2_write and SMB2_read
Related show

Commit Message

ZhangXiaoxu April 8, 2019, 2:22 a.m. UTC
There is a KASAN use-after-free:
BUG: KASAN: use-after-free in SMB2_write+0x1342/0x1580
Read of size 8 at addr ffff8880b6a8e450 by task ln/4196

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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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_write+0x1342/0x1580
> Read of size 8 at addr ffff8880b6a8e450 by task ln/4196
>
> 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 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
> index 0f14471..fca5b0a 100644
> --- a/fs/cifs/smb2pdu.c
> +++ b/fs/cifs/smb2pdu.c
> @@ -3772,7 +3772,6 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
>
>         rc = cifs_send_recv(xid, io_parms->tcon->ses, &rqst,
>                             &resp_buftype, flags, &rsp_iov);
> -       cifs_small_buf_release(req);
>         rsp = (struct smb2_write_rsp *)rsp_iov.iov_base;
>
>         if (rc) {
> @@ -3790,6 +3789,7 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
>                                      io_parms->offset, *nbytes);
>         }
>
> +       cifs_small_buf_release(req);
>         free_rsp_buf(resp_buftype, rsp);
>         return rc;
>  }
> --
> 2.7.4
>

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

--
Best regards,
Pavel Shilovsky

Patch
diff mbox series

diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
index 0f14471..fca5b0a 100644
--- a/fs/cifs/smb2pdu.c
+++ b/fs/cifs/smb2pdu.c
@@ -3772,7 +3772,6 @@  SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
 
 	rc = cifs_send_recv(xid, io_parms->tcon->ses, &rqst,
 			    &resp_buftype, flags, &rsp_iov);
-	cifs_small_buf_release(req);
 	rsp = (struct smb2_write_rsp *)rsp_iov.iov_base;
 
 	if (rc) {
@@ -3790,6 +3789,7 @@  SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
 				     io_parms->offset, *nbytes);
 	}
 
+	cifs_small_buf_release(req);
 	free_rsp_buf(resp_buftype, rsp);
 	return rc;
 }