Skip to content

Commit 0f82ecf

Browse files
kappamossopsiff
authored andcommitted
ksmbd: fix durable reconnect error path file lifetime
[ Upstream commit 3515503322f4819277091839eed46b695096aca5 ] 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: 1baff47b81f9 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit a1a39f227c80cbf369767badc32cba2b225147d1) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent aa85470 commit 0f82ecf

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
@@ -3812,8 +3812,19 @@ int smb2_open(struct ksmbd_work *work)
38123812
ksmbd_debug(SMB, "Error response: %x\n", rsp->hdr.Status);
38133813
}
38143814

3815-
if (dh_info.reconnected)
3816-
ksmbd_put_durable_fd(dh_info.fp);
3815+
if (dh_info.reconnected) {
3816+
/*
3817+
* If reconnect succeeded, fp was republished in the
3818+
* session file table. On a later error, ksmbd_fd_put()
3819+
* above drops the session reference; drop the durable
3820+
* lookup reference through the same session-aware path so
3821+
* final close removes the volatile id before freeing fp.
3822+
*/
3823+
if (rc && fp == dh_info.fp)
3824+
ksmbd_fd_put(work, dh_info.fp);
3825+
else
3826+
ksmbd_put_durable_fd(dh_info.fp);
3827+
}
38173828

38183829
kfree(name);
38193830
kfree(lc);

0 commit comments

Comments
 (0)