Skip to content

Commit 33f7361

Browse files
sprasad-microsoftsmfrench
authored andcommitted
cifs: prevent use-after-free by freeing the cfile later
In smb2_compound_op we have a possible use-after-free which can cause hard to debug problems later on. This was revealed during stress testing with KASAN enabled kernel. Fixing it by moving the cfile free call to a few lines below, after the usage. Fixes: 76894f3 ("cifs: improve symlink handling for smb2+") Reviewed-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Shyam Prasad N <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent f0b6a83 commit 33f7361

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/smb/client/smb2inode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
398398
rsp_iov);
399399

400400
finished:
401-
if (cfile)
402-
cifsFileInfo_put(cfile);
403-
404401
SMB2_open_free(&rqst[0]);
405402
if (rc == -EREMCHG) {
406403
pr_warn_once("server share %s deleted\n", tcon->tree_name);
@@ -529,6 +526,9 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
529526
break;
530527
}
531528

529+
if (cfile)
530+
cifsFileInfo_put(cfile);
531+
532532
if (rc && err_iov && err_buftype) {
533533
memcpy(err_iov, rsp_iov, 3 * sizeof(*err_iov));
534534
memcpy(err_buftype, resp_buftype, 3 * sizeof(*err_buftype));

0 commit comments

Comments
 (0)