Skip to content

Commit 3515503

Browse files
kappamosssmfrench
authored andcommitted
ksmbd: fix durable reconnect error path file lifetime
After a durable reconnect succeeds, ksmbd_reopen_durable_fd() republishes the same ksmbd_file into the session volatile-id table. If smb2_open() then takes a later error path, cleanup first calls ksmbd_fd_put(work, fp) and then unconditionally calls ksmbd_put_durable_fd(dh_info.fp). In this case fp and dh_info.fp are the same object. The first put drops the reconnect lookup reference, but the final durable put can run __ksmbd_close_fd(NULL, fp). Because the final close is not session-aware, it can free the file object without removing the volatile-id entry that was just published into the session table. Use the session-aware put for the final reconnect drop when the reconnect had already succeeded and the error path is cleaning up the republished file. Earlier reconnect failures, before fp is assigned to dh_info.fp, keep using the durable-only put path. Fixes: 1baff47 ("ksmbd: fix use-after-free in smb2_open during durable reconnect") Signed-off-by: Junyi Liu <moss80199@gmail.com> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 1a2ab0f commit 3515503

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

fs/smb/server/smb2pdu.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,8 +3804,19 @@ int smb2_open(struct ksmbd_work *work)
38043804
ksmbd_debug(SMB, "Error response: %x\n", rsp->hdr.Status);
38053805
}
38063806

3807-
if (dh_info.reconnected)
3808-
ksmbd_put_durable_fd(dh_info.fp);
3807+
if (dh_info.reconnected) {
3808+
/*
3809+
* If reconnect succeeded, fp was republished in the
3810+
* session file table. On a later error, ksmbd_fd_put()
3811+
* above drops the session reference; drop the durable
3812+
* lookup reference through the same session-aware path so
3813+
* final close removes the volatile id before freeing fp.
3814+
*/
3815+
if (rc && fp == dh_info.fp)
3816+
ksmbd_fd_put(work, dh_info.fp);
3817+
else
3818+
ksmbd_put_durable_fd(dh_info.fp);
3819+
}
38093820

38103821
kfree(name);
38113822
kfree(lc);

0 commit comments

Comments
 (0)