2023-12-08 06:58:32

by Li Nan

[permalink] [raw]
Subject: [PATCH] ksmbd: validate the zero field of packet header

From: Li Nan <[email protected]>

The SMB2 Protocol requires that "The first byte of the Direct TCP
transport packet header MUST be zero (0x00)"[1]. Commit 1c1bcf2d3ea0
("ksmbd: validate smb request protocol id") removed the validation of
this 1-byte zero. Add the validation back now.

[1]: [MS-SMB2] - v20230227, page 30.
https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SMB2/%5bMS-SMB2%5d-230227.pdf

Fixes: 1c1bcf2d3ea0 ("ksmbd: validate smb request protocol id")
Signed-off-by: Li Nan <[email protected]>
---
fs/smb/server/smb_common.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/smb/server/smb_common.c b/fs/smb/server/smb_common.c
index 6691ae68af0c..7c98bf699772 100644
--- a/fs/smb/server/smb_common.c
+++ b/fs/smb/server/smb_common.c
@@ -158,8 +158,12 @@ int ksmbd_verify_smb_message(struct ksmbd_work *work)
*/
bool ksmbd_smb_request(struct ksmbd_conn *conn)
{
- __le32 *proto = (__le32 *)smb2_get_msg(conn->request_buf);
+ __le32 *proto;

+ if (conn->request_buf[0] != 0)
+ return false;
+
+ proto = (__le32 *)smb2_get_msg(conn->request_buf);
if (*proto == SMB2_COMPRESSION_TRANSFORM_ID) {
pr_err_ratelimited("smb2 compression not support yet");
return false;
--
2.39.2


2023-12-08 14:21:20

by Namjae Jeon

[permalink] [raw]
Subject: Re: [PATCH] ksmbd: validate the zero field of packet header

2023-12-08 15:56 GMT+09:00, [email protected] <[email protected]>:
> From: Li Nan <[email protected]>
>
> The SMB2 Protocol requires that "The first byte of the Direct TCP
> transport packet header MUST be zero (0x00)"[1]. Commit 1c1bcf2d3ea0
> ("ksmbd: validate smb request protocol id") removed the validation of
> this 1-byte zero. Add the validation back now.
>
> [1]: [MS-SMB2] - v20230227, page 30.
> https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SMB2/%5bMS-SMB2%5d-230227.pdf
>
> Fixes: 1c1bcf2d3ea0 ("ksmbd: validate smb request protocol id")
> Signed-off-by: Li Nan <[email protected]>
Acked-by: Namjae Jeon <[email protected]>
Applied it to #ksmbd-for-next-next.
Thanks for your patch!

2023-12-08 15:36:02

by Tom Talpey

[permalink] [raw]
Subject: Re: [PATCH] ksmbd: validate the zero field of packet header

On 12/8/2023 9:20 AM, Namjae Jeon wrote:
> 2023-12-08 15:56 GMT+09:00, [email protected] <[email protected]>:
>> From: Li Nan <[email protected]>
>>
>> The SMB2 Protocol requires that "The first byte of the Direct TCP
>> transport packet header MUST be zero (0x00)"[1]. Commit 1c1bcf2d3ea0
>> ("ksmbd: validate smb request protocol id") removed the validation of
>> this 1-byte zero. Add the validation back now.
>>
>> [1]: [MS-SMB2] - v20230227, page 30.
>> https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SMB2/%5bMS-SMB2%5d-230227.pdf
>>
>> Fixes: 1c1bcf2d3ea0 ("ksmbd: validate smb request protocol id")
>> Signed-off-by: Li Nan <[email protected]>
> Acked-by: Namjae Jeon <[email protected]>
> Applied it to #ksmbd-for-next-next.
> Thanks for your patch!
>
>

Technically speaking, the first byte of the 4-byte header is a flag
used for multi-segment continuation/reassembly. But since ksmbd does
not have any code to do such processing, it's best to deny the
message. So...

Acked-by: Tom Talpey <[email protected]>