Skip to content

Commit 1baff47

Browse files
Akif-Saitsmfrench
authored andcommitted
ksmbd: fix use-after-free in smb2_open during durable reconnect
In smb2_open, the call to ksmbd_put_durable_fd(fp) drops the reference to the durable file descriptor early during the durable reconnect process. If an error occurs subsequently (eg, ksmbd_iov_pin_rsp fails) or a scavenger accesses the file, it leads to a use-after-free when accessing fp properties (eg fp->create_time). Move the single put to the end of the function below err_out2 so fp stays valid until smb2_open returns. Fixes: c8efcc7 ("ksmbd: add support for durable handles v1/v2") Signed-off-by: Akif <akif.sait111@gmail.com> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 3e4e2ea commit 1baff47

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

fs/smb/server/smb2pdu.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3014,29 +3014,23 @@ int smb2_open(struct ksmbd_work *work)
30143014
if (dh_info.reconnected == true) {
30153015
rc = smb2_check_durable_oplock(conn, share, dh_info.fp,
30163016
lc, sess->user, name);
3017-
if (rc) {
3018-
ksmbd_put_durable_fd(dh_info.fp);
3017+
if (rc)
30193018
goto err_out2;
3020-
}
30213019

30223020
rc = ksmbd_reopen_durable_fd(work, dh_info.fp);
3023-
if (rc) {
3024-
ksmbd_put_durable_fd(dh_info.fp);
3021+
if (rc)
30253022
goto err_out2;
3026-
}
30273023

30283024
fp = dh_info.fp;
30293025

30303026
if (ksmbd_override_fsids(work)) {
30313027
rc = -ENOMEM;
3032-
ksmbd_put_durable_fd(dh_info.fp);
30333028
goto err_out2;
30343029
}
30353030

30363031
file_info = FILE_OPENED;
30373032

30383033
rc = ksmbd_vfs_getattr(&fp->filp->f_path, &stat);
3039-
ksmbd_put_durable_fd(fp);
30403034
if (rc)
30413035
goto err_out2;
30423036

@@ -3806,6 +3800,9 @@ int smb2_open(struct ksmbd_work *work)
38063800
ksmbd_debug(SMB, "Error response: %x\n", rsp->hdr.Status);
38073801
}
38083802

3803+
if (dh_info.reconnected)
3804+
ksmbd_put_durable_fd(dh_info.fp);
3805+
38093806
kfree(name);
38103807
kfree(lc);
38113808

0 commit comments

Comments
 (0)