[PATCH v6 13/14] ksmdb: move session and tcon validation to ksmbd_smb2_check_message()

Ralph Boehme
2021-10-02T13:25:25Z

For compound non-related operations session id and tree id must be taken from
earch PDU.

Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Tom Talpey <tom@talpey.com>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: Steve French <smfrench@gmail.com>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Ralph Boehme <slow@samba.org>
---
fs/ksmbd/server.c | 46 +++++++++++++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/fs/ksmbd/server.c b/fs/ksmbd/server.c
index 2a2b2135bfde..5d1ef277653f 100644
--- a/fs/ksmbd/server.c
+++ b/fs/ksmbd/server.c
@@ -101,6 +101,32 @@ static inline int check_conn_state(struct ksmbd_work *work)
return 0;
}

+static int check_session_and_tcon(struct ksmbd_work *work)
+{
+ int rc;
+
+ if (work->conn->ops->check_user_session == NULL)
+ return 0;
+
+ rc = work->conn->ops->check_user_session(work);
+ if (rc < 0) {
+ work->conn->ops->set_rsp_status(work,
+ STATUS_USER_SESSION_DELETED);
+ return 1;
+ }
+ if (rc == 0)
+ return 0;
+
+ rc = work->conn->ops->get_ksmbd_tcon(work);
+ if (rc < 0) {
+ work->conn->ops->set_rsp_status(work,
+ STATUS_NETWORK_NAME_DELETED);
+ return 1;
+ }
+
+ return 0;
+}
+
#define SERVER_HANDLER_CONTINUE 0
#define SERVER_HANDLER_ABORT 1

@@ -117,6 +143,9 @@ static int __process_request(struct ksmbd_work *work, struct ksmbd_conn *conn,
if (ksmbd_verify_smb_message(work))
return SERVER_HANDLER_ABORT;

+ if (check_session_and_tcon(work))
+ return SERVER_HANDLER_ABORT;
+
command = conn->ops->get_cmd_val(work);
*cmd = command;

@@ -184,23 +213,6 @@ static void __handle_ksmbd_work(struct ksmbd_work *work,
goto send;
}

- if (conn->ops->check_user_session) {
- rc = conn->ops->check_user_session(work);
- if (rc < 0) {
- command = conn->ops->get_cmd_val(work);
- conn->ops->set_rsp_status(work,
- STATUS_USER_SESSION_DELETED);
- goto send;
- } else if (rc > 0) {
- rc = conn->ops->get_ksmbd_tcon(work);
- if (rc < 0) {
- conn->ops->set_rsp_status(work,
- STATUS_NETWORK_NAME_DELETED);
- goto send;
- }
- }
- }
-
do {
rc = __process_request(work, conn, &command);
if (rc == SERVER_HANDLER_ABORT)
--
2.31.1