diff mbox series

[v5,14/20] ksmbd: add ksmbd_smb2_cur_pdu_buflen()

Message ID 20211001120421.327245-15-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/smb2misc.c | 25 +++++++++++++++++++++++++
 fs/ksmbd/smb2pdu.h  |  1 +
 2 files changed, 26 insertions(+)

Comments

Namjae Jeon Oct. 2, 2021, 5:49 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/smb2misc.c | 25 +++++++++++++++++++++++++
>  fs/ksmbd/smb2pdu.h  |  1 +
>  2 files changed, 26 insertions(+)
>
> diff --git a/fs/ksmbd/smb2misc.c b/fs/ksmbd/smb2misc.c
> index 2cc031c39514..76f53db7db8d 100644
> --- a/fs/ksmbd/smb2misc.c
> +++ b/fs/ksmbd/smb2misc.c
> @@ -427,3 +427,28 @@ int smb2_negotiate_request(struct ksmbd_work *work)
>  {
>  	return ksmbd_smb_negotiate_common(work, SMB2_NEGOTIATE_HE);
>  }
> +
> +/**
> + * ksmbd_smb2_cur_pdu_buflen() - Get len of current SMB2 PDU buffer
> + * This returns the lenght including any possible padding.
> + * @work: smb work containing request buffer
> + */
> +unsigned int ksmbd_smb2_cur_pdu_buflen(struct ksmbd_work *work)
> +{
This patch will cause unused function build warning. so need to
combine it with "ksmbd: use ksmbd_smb2_cur_pdu_buflen() in
ksmbd_smb2_check_message() "

Thanks!
> +	struct smb2_hdr *hdr = ksmbd_req_buf_next(work);
> +	unsigned int buf_len;
> +	unsigned int pdu_len;
> +
> +	if (hdr->NextCommand != 0) {
> +		/*
> +		 * hdr->NextCommand has already been validated by
> +		 * init_chained_smb2_rsp().
> +		 */
> +		return __le32_to_cpu(hdr->NextCommand);
> +	}
> +
> +	buf_len = get_rfc1002_len(work->request_buf);
> +	pdu_len = buf_len - work->next_smb2_rcv_hdr_off;
> +	return pdu_len;
> +}
> +
> diff --git a/fs/ksmbd/smb2pdu.h b/fs/ksmbd/smb2pdu.h
> index a6dec5ec6a54..c5fa8256b0bb 100644
> --- a/fs/ksmbd/smb2pdu.h
> +++ b/fs/ksmbd/smb2pdu.h
> @@ -1680,6 +1680,7 @@ int smb2_set_rsp_credits(struct ksmbd_work *work);
>
>  /* smb2 misc functions */
>  int ksmbd_smb2_check_message(struct ksmbd_work *work);
> +unsigned int ksmbd_smb2_cur_pdu_buflen(struct ksmbd_work *work);
>
>  /* smb2 command handlers */
>  int smb2_handle_negotiate(struct ksmbd_work *work);
> --
> 2.31.1
>
>
Ralph Boehme Oct. 2, 2021, 11:55 a.m. UTC | #2
Am 02.10.21 um 07:49 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/smb2misc.c | 25 +++++++++++++++++++++++++
>>   fs/ksmbd/smb2pdu.h  |  1 +
>>   2 files changed, 26 insertions(+)
>>
>> diff --git a/fs/ksmbd/smb2misc.c b/fs/ksmbd/smb2misc.c
>> index 2cc031c39514..76f53db7db8d 100644
>> --- a/fs/ksmbd/smb2misc.c
>> +++ b/fs/ksmbd/smb2misc.c
>> @@ -427,3 +427,28 @@ int smb2_negotiate_request(struct ksmbd_work *work)
>>   {
>>   	return ksmbd_smb_negotiate_common(work, SMB2_NEGOTIATE_HE);
>>   }
>> +
>> +/**
>> + * ksmbd_smb2_cur_pdu_buflen() - Get len of current SMB2 PDU buffer
>> + * This returns the lenght including any possible padding.
>> + * @work: smb work containing request buffer
>> + */
>> +unsigned int ksmbd_smb2_cur_pdu_buflen(struct ksmbd_work *work)
>> +{
> This patch will cause unused function build warning. so need to
> combine it with "ksmbd: use ksmbd_smb2_cur_pdu_buflen() in
> ksmbd_smb2_check_message() "

ok, going to squash this into another commit that uses the function.

-slow
diff mbox series

Patch

diff --git a/fs/ksmbd/smb2misc.c b/fs/ksmbd/smb2misc.c
index 2cc031c39514..76f53db7db8d 100644
--- a/fs/ksmbd/smb2misc.c
+++ b/fs/ksmbd/smb2misc.c
@@ -427,3 +427,28 @@  int smb2_negotiate_request(struct ksmbd_work *work)
 {
 	return ksmbd_smb_negotiate_common(work, SMB2_NEGOTIATE_HE);
 }
+
+/**
+ * ksmbd_smb2_cur_pdu_buflen() - Get len of current SMB2 PDU buffer
+ * This returns the lenght including any possible padding.
+ * @work: smb work containing request buffer
+ */
+unsigned int ksmbd_smb2_cur_pdu_buflen(struct ksmbd_work *work)
+{
+	struct smb2_hdr *hdr = ksmbd_req_buf_next(work);
+	unsigned int buf_len;
+	unsigned int pdu_len;
+
+	if (hdr->NextCommand != 0) {
+		/*
+		 * hdr->NextCommand has already been validated by
+		 * init_chained_smb2_rsp().
+		 */
+		return __le32_to_cpu(hdr->NextCommand);
+	}
+
+	buf_len = get_rfc1002_len(work->request_buf);
+	pdu_len = buf_len - work->next_smb2_rcv_hdr_off;
+	return pdu_len;
+}
+
diff --git a/fs/ksmbd/smb2pdu.h b/fs/ksmbd/smb2pdu.h
index a6dec5ec6a54..c5fa8256b0bb 100644
--- a/fs/ksmbd/smb2pdu.h
+++ b/fs/ksmbd/smb2pdu.h
@@ -1680,6 +1680,7 @@  int smb2_set_rsp_credits(struct ksmbd_work *work);
 
 /* smb2 misc functions */
 int ksmbd_smb2_check_message(struct ksmbd_work *work);
+unsigned int ksmbd_smb2_cur_pdu_buflen(struct ksmbd_work *work);
 
 /* smb2 command handlers */
 int smb2_handle_negotiate(struct ksmbd_work *work);