Skip to contentSkip to conversation

smb: client: fix potential UAF and double free it smb2_open_file()

PATCH In review Paulo Alcantara 3 participants 5 messages Feb 5

Subsystems (2)
lore
Share & tools
lore

Paulo Alcantara

author maintainer
#0 lore raw

PATCH 1/1 smb: client: fix potential UAF and double free it smb2_open_file()

Zero out @err_iov and @err_buftype before retrying SMB2_open() to prevent an UAF bug if @data != NULL, otherwise a double free.

Fixes e3a43633023e ("smb/client: fix memory leak in smb2_open_file()")
Cc ChenXiaoSong <[email protected]>
---
 fs/smb/client/smb2file.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2file.c +2 -0
index 2dd08388ea87..1f7f284a7844 100644
@@ -179,6 +179,8 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
 		       &err_buftype);
 	if (rc == -EACCES && retry_without_read_attributes) {
 		free_rsp_buf(err_buftype, err_iov.iov_base);
+		memset(&err_iov, 0, sizeof(err_iov));
+		err_buftype = CIFS_NO_BUFFER;
 		oparms->desired_access &= ~FILE_READ_ATTRIBUTES;
 		rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL, &err_iov,
 			       &err_buftype);
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw

Looks good. Feel free to add:

Quoted 27 lines · Paulo Alcantara

Zero out @err_iov and @err_buftype before retrying SMB2_open() to prevent an UAF bug if @data != NULL, otherwise a double free.

Fixes e3a43633023e ("smb/client: fix memory leak in smb2_open_file()")
Cc ChenXiaoSong <[email protected]>
---
  fs/smb/client/smb2file.c | 2 ++
  1 file changed, 2 insertions(+)
fs/smb/client/smb2file.c +2 -0
index 2dd08388ea87..1f7f284a7844 100644
@@ -179,6 +179,8 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
  		       &err_buftype);
  	if (rc == -EACCES && retry_without_read_attributes) {
  		free_rsp_buf(err_buftype, err_iov.iov_base);
+		memset(&err_iov, 0, sizeof(err_iov));
+		err_buftype = CIFS_NO_BUFFER;
  		oparms->desired_access &= ~FILE_READ_ATTRIBUTES;
  		rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL, &err_iov,
  			       &err_buftype);
#3 lore raw
Quoted 2 lines · ChenXiaoSong

Is there a typo in the subject? Should it be "in ..." instead of "it ..."?

Yes - I will fix the typo

Quoted 6 lines

Thanks,
ChenXiaoSong <[email protected]>

Quoted 1 line · Paulo Alcantara

[PATCH] smb: client: fix potential UAF and double free it smb2_open_file()

Signature · 3 lines
Thanks,

Steve
#4 lore raw
In reply to Paulo Alcantara

corrected typo and added Chen's Reviewed-by and merged into cifs-2.6.git for-next

Quoted 31 lines · Paulo Alcantara

Zero out @err_iov and @err_buftype before retrying SMB2_open() to prevent an UAF bug if @data != NULL, otherwise a double free.

Fixes e3a43633023e ("smb/client: fix memory leak in smb2_open_file()")
Cc ChenXiaoSong <[email protected]>
---
 fs/smb/client/smb2file.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2file.c +2 -1
index 2dd08388ea87..1f7f284a7844 100644
@@ -179,6 +179,8 @@ int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
                       &err_buftype);
        if (rc == -EACCES && retry_without_read_attributes) {
                free_rsp_buf(err_buftype, err_iov.iov_base);
+               memset(&err_iov, 0, sizeof(err_iov));
+               err_buftype = CIFS_NO_BUFFER;
                oparms->desired_access &= ~FILE_READ_ATTRIBUTES;
                rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL, &err_iov,
                               &err_buftype);
--

2.52.0

Signature · 3 lines
Thanks,

Steve