diff mbox series

[v5,19/20] ksmbd: make smb2_check_user_session() callabe for compound PDUs

Message ID 20211001120421.327245-20-slow@samba.org (mailing list archive)
State New, archived
Headers show
Series Buffer validation patches | expand

Commit Message

Ralph Boehme Oct. 1, 2021, 12:04 p.m. UTC
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/smb2pdu.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Namjae Jeon Oct. 2, 2021, 6:01 a.m. UTC | #1
2021-10-01 21:04 GMT+09:00, Ralph Boehme <slow@samba.org>:
> 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/smb2pdu.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
> index 5b1fead05c49..ef551e3633db 100644
> --- a/fs/ksmbd/smb2pdu.c
> +++ b/fs/ksmbd/smb2pdu.c
> @@ -411,7 +411,6 @@ static void init_chained_smb2_rsp(struct ksmbd_work
> *work)
>  		work->compound_pfid =
>  			le64_to_cpu(((struct smb2_create_rsp *)rsp)->
>  				PersistentFileId);
> -		work->compound_sid = le64_to_cpu(rsp->SessionId);
>  	}
>
>  	len = get_rfc1002_len(work->response_buf) - work->next_smb2_rsp_hdr_off;
> @@ -592,6 +591,8 @@ int smb2_check_user_session(struct ksmbd_work *work)
>  	unsigned long long sess_id;
>
>  	work->sess = NULL;
> +	work->compound_sid = 0;
> +
>  	/*
>  	 * SMB2_ECHO, SMB2_NEGOTIATE, SMB2_SESSION_SETUP command do not
>  	 * require a session id, so no need to validate user session's for
> @@ -604,11 +605,17 @@ int smb2_check_user_session(struct ksmbd_work *work)
>  	if (!ksmbd_conn_good(work))
>  		return -EINVAL;
>
> -	sess_id = le64_to_cpu(req_hdr->SessionId);
> +	if (req_hdr->Flags & SMB2_FLAGS_RELATED_OPERATIONS)
> +		sess_id = work->compound_sid;
same comment with previous tree id patch.
> +	else
> +		sess_id = le64_to_cpu(req_hdr->SessionId);
> +
>  	/* Check for validity of user session */
>  	work->sess = ksmbd_session_lookup_all(conn, sess_id);
> -	if (work->sess)
> +	if (work->sess) {
> +		work->compound_sid = sess_id;
>  		return 1;
> +	}
>  	ksmbd_debug(SMB, "Invalid user session, Uid %llu\n", sess_id);
>  	return -EINVAL;
>  }
> --
> 2.31.1
>
>
Ralph Boehme Oct. 2, 2021, 12:08 p.m. UTC | #2
Am 02.10.21 um 08:01 schrieb Namjae Jeon:
> 2021-10-01 21:04 GMT+09:00, Ralph Boehme <slow@samba.org>:
>> 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/smb2pdu.c | 13 ++++++++++---
>>   1 file changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
>> index 5b1fead05c49..ef551e3633db 100644
>> --- a/fs/ksmbd/smb2pdu.c
>> +++ b/fs/ksmbd/smb2pdu.c
>> @@ -411,7 +411,6 @@ static void init_chained_smb2_rsp(struct ksmbd_work
>> *work)
>>   		work->compound_pfid =
>>   			le64_to_cpu(((struct smb2_create_rsp *)rsp)->
>>   				PersistentFileId);
>> -		work->compound_sid = le64_to_cpu(rsp->SessionId);
>>   	}
>>
>>   	len = get_rfc1002_len(work->response_buf) - work->next_smb2_rsp_hdr_off;
>> @@ -592,6 +591,8 @@ int smb2_check_user_session(struct ksmbd_work *work)
>>   	unsigned long long sess_id;
>>
>>   	work->sess = NULL;
>> +	work->compound_sid = 0;
>> +
>>   	/*
>>   	 * SMB2_ECHO, SMB2_NEGOTIATE, SMB2_SESSION_SETUP command do not
>>   	 * require a session id, so no need to validate user session's for
>> @@ -604,11 +605,17 @@ int smb2_check_user_session(struct ksmbd_work *work)
>>   	if (!ksmbd_conn_good(work))
>>   		return -EINVAL;
>>
>> -	sess_id = le64_to_cpu(req_hdr->SessionId);
>> +	if (req_hdr->Flags & SMB2_FLAGS_RELATED_OPERATIONS)
>> +		sess_id = work->compound_sid;
> same comment with previous tree id patch.

same answer. :)

-slow
diff mbox series

Patch

diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c
index 5b1fead05c49..ef551e3633db 100644
--- a/fs/ksmbd/smb2pdu.c
+++ b/fs/ksmbd/smb2pdu.c
@@ -411,7 +411,6 @@  static void init_chained_smb2_rsp(struct ksmbd_work *work)
 		work->compound_pfid =
 			le64_to_cpu(((struct smb2_create_rsp *)rsp)->
 				PersistentFileId);
-		work->compound_sid = le64_to_cpu(rsp->SessionId);
 	}
 
 	len = get_rfc1002_len(work->response_buf) - work->next_smb2_rsp_hdr_off;
@@ -592,6 +591,8 @@  int smb2_check_user_session(struct ksmbd_work *work)
 	unsigned long long sess_id;
 
 	work->sess = NULL;
+	work->compound_sid = 0;
+
 	/*
 	 * SMB2_ECHO, SMB2_NEGOTIATE, SMB2_SESSION_SETUP command do not
 	 * require a session id, so no need to validate user session's for
@@ -604,11 +605,17 @@  int smb2_check_user_session(struct ksmbd_work *work)
 	if (!ksmbd_conn_good(work))
 		return -EINVAL;
 
-	sess_id = le64_to_cpu(req_hdr->SessionId);
+	if (req_hdr->Flags & SMB2_FLAGS_RELATED_OPERATIONS)
+		sess_id = work->compound_sid;
+	else
+		sess_id = le64_to_cpu(req_hdr->SessionId);
+
 	/* Check for validity of user session */
 	work->sess = ksmbd_session_lookup_all(conn, sess_id);
-	if (work->sess)
+	if (work->sess) {
+		work->compound_sid = sess_id;
 		return 1;
+	}
 	ksmbd_debug(SMB, "Invalid user session, Uid %llu\n", sess_id);
 	return -EINVAL;
 }