ksmbd: Fix to handle removal of rfc1002 header from smb_hdr
David Howells
maintainerPATCH 1/1 ksmbd: Fix to handle removal of rfc1002 header from smb_hdr
Hi Namjae,
Does this (untested) patch fix the problem for you?
David
---
The commit that removed the RFC1002 header from struct smb_hdr didn't also fix the places in ksmbd that use it in order to provide graceful rejection of SMB1 protocol requests.
--- fs/smb/server/server.c | 2 +- fs/smb/server/smb_common.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
fs/smb/server/server.c +1 -1
@@ -95,7 +95,7 @@ static inline int check_conn_state(struct ksmbd_work *work)if (ksmbd_conn_exiting (work->conn) ||ksmbd_conn_need_reconnect (work->conn)) { - rsp_hdr = work->response_buf; + rsp_hdr =smb2_get_msg (work->response_buf); rsp_hdr->Status.CifsError =STATUS_CONNECTION_DISCONNECTED ;return 1 ; }
fs/smb/server/smb_common.c +5 -5
@@ -140,7 +140,7 @@ int ksmbd_verify_smb_message(struct ksmbd_work *work)if (smb2_hdr->ProtocolId ==SMB2_PROTO_NUMBER )return ksmbd_smb2_check_message (work); - hdr = work->request_buf; + hdr =smb2_get_msg (work->request_buf);if (*(__le32 *)hdr->Protocol ==SMB1_PROTO_NUMBER && hdr->Command ==SMB_COM_NEGOTIATE ) { work->conn->outstanding_credits++;
@@ -278,7 +278,6 @@ static int ksmbd_negotiate_smb_dialect(void *buf) req->DialectCount); } - proto = *(__le32 *)((struct smb_hdr *)buf)->Protocol;if (proto ==SMB1_PROTO_NUMBER ) {struct smb_negotiate_req *req;
@@ -320,8 +319,8 @@ static u16 get_smb1_cmd_val(struct ksmbd_work *work)*/ static int init_smb1_rsp_hdr (struct ksmbd_work *work) { -struct smb_hdr *rsp_hdr = (struct smb_hdr *)work->response_buf; -struct smb_hdr *rcv_hdr = (struct smb_hdr *)work->request_buf; +struct smb_hdr *rsp_hdr = (struct smb_hdr *)smb2_get_msg (work->response_buf); +struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg (work->request_buf); rsp_hdr->Command =SMB_COM_NEGOTIATE ; *(__le32 *)rsp_hdr->Protocol =SMB1_PROTO_NUMBER ;
@@ -412,9 +411,10 @@ static int init_smb1_server(struct ksmbd_conn *conn)int ksmbd_init_smb_server (struct ksmbd_conn *conn) { +struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg (conn->request_buf);__le32 proto; - proto = *(__le32 *)((struct smb_hdr *)conn->request_buf)->Protocol; + proto = *(__le32 *)rcv_hdr->Protocol;if (conn->need_neg == false) {if (proto ==SMB1_PROTO_NUMBER )return -EINVAL ;
ksmbd_conn_handler_loop() calls get_rfc1002_len(). Does this need to be updated as well?
Thanks,
ChenXiaoSong.
Quoted 86 lines · David Howells
Hi Namjae,
Does this (untested) patch fix the problem for you?
David
---
The commit that removed the RFC1002 header from structsmb_hdrdidn't also fix the places in ksmbd that use it in order to provide graceful rejection of SMB1 protocol requests.Fixes 83bfbd0bb902 ("cifs: Remove the RFC1002 header from smb_hdr")Reported-by Namjae Jeon <[email protected]>Link https://lore.kernel.org/r/CAKYAXd9Ju4MFkkH5Jxfi1mO0AWEr=R35M3vQ_Xa7Yw34JoNZ0A@mail.gmail.com/ open hereSigned-off-by David Howells <[email protected]>cc Steve French <[email protected]>cc Sergey Senozhatsky <[email protected]>cc Tom Talpey <[email protected]>cc Paulo Alcantara <[email protected]>cc Shyam Prasad N <[email protected]>--- fs/smb/server/server.c | 2 +- fs/smb/server/smb_common.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)fs/smb/server/server.c +1
-1@@ -95,7 +95,7 @@ static inline int check_conn_state(struct ksmbd_work *work)if (ksmbd_conn_exiting (work->conn) ||ksmbd_conn_need_reconnect (work->conn)) { - rsp_hdr = work->response_buf; + rsp_hdr =smb2_get_msg (work->response_buf); rsp_hdr->Status.CifsError =STATUS_CONNECTION_DISCONNECTED ;return 1 ; }fs/smb/server/smb_common.c +5
-5@@ -140,7 +140,7 @@ int ksmbd_verify_smb_message(struct ksmbd_work *work)if (smb2_hdr->ProtocolId ==SMB2_PROTO_NUMBER )return ksmbd_smb2_check_message (work); - hdr = work->request_buf; + hdr =smb2_get_msg (work->request_buf);if (*(__le32 *)hdr->Protocol ==SMB1_PROTO_NUMBER && hdr->Command ==SMB_COM_NEGOTIATE ) { work->conn->outstanding_credits++;@@ -278,7 +278,6 @@ static int ksmbd_negotiate_smb_dialect(void *buf) req->DialectCount); } - proto = *(__le32 *)((struct smb_hdr *)buf)->Protocol;if (proto ==SMB1_PROTO_NUMBER ) {struct smb_negotiate_req *req;@@ -320,8 +319,8 @@ static u16 get_smb1_cmd_val(struct ksmbd_work *work)*/ static int init_smb1_rsp_hdr (struct ksmbd_work *work) { -struct smb_hdr *rsp_hdr = (struct smb_hdr *)work->response_buf; -struct smb_hdr *rcv_hdr = (struct smb_hdr *)work->request_buf; +struct smb_hdr *rsp_hdr = (struct smb_hdr *)smb2_get_msg (work->response_buf); +struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg (work->request_buf); rsp_hdr->Command =SMB_COM_NEGOTIATE ; *(__le32 *)rsp_hdr->Protocol =SMB1_PROTO_NUMBER ;@@ -412,9 +411,10 @@ static int init_smb1_server(struct ksmbd_conn *conn)int ksmbd_init_smb_server (struct ksmbd_conn *conn) { +struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg (conn->request_buf);__le32 proto; - proto = *(__le32 *)((struct smb_hdr *)conn->request_buf)->Protocol; + proto = *(__le32 *)rcv_hdr->Protocol;if (conn->need_neg == false) {if (proto ==SMB1_PROTO_NUMBER )return -EINVAL ;
Hi David,
Since the size of struct smb_hdr has changed, the value of SMB1_MIN_SUPPORTED_HEADER_SIZE should also be updated to (sizeof(struct smb_hdr) + 4). SMB1_MIN_SUPPORTED_HEADER_SIZE is used in ksmbd_conn_handler_loop().
Thanks,
ChenXiaoSong.
Quoted 90 lines · ChenXiaoSong
ksmbd_conn_handler_loop()callsget_rfc1002_len(). Does this need to be updated as well?Thanks,
ChenXiaoSong.Quoted 83 lines · David Howells
Hi Namjae,
Does this (untested) patch fix the problem for you?
David
---
The commit that removed the RFC1002 header from structsmb_hdrdidn't also fix the places in ksmbd that use it in order to provide graceful rejection of SMB1 protocol requests.Fixes 83bfbd0bb902 ("cifs: Remove the RFC1002 header from smb_hdr")Reported-by Namjae Jeon <[email protected]>Link https://lore.kernel.org/r/ CAKYAXd9Ju4MFkkH5Jxfi1mO0AWEr=R35M3vQ_Xa7Yw34JoNZ0A@mail.gmail.com/Signed-off-by David Howells <[email protected]>cc Steve French <[email protected]>cc Sergey Senozhatsky <[email protected]>cc Tom Talpey <[email protected]>cc Paulo Alcantara <[email protected]>cc Shyam Prasad N <[email protected]>---
fs/smb/server/server.c | 2 +-
fs/smb/server/smb_common.c| 10 +++++-----2 files changed, 6 insertions(+), 6 deletions(-)fs/smb/server/server.c +0
-0@@ -95,7 +95,7 @@ static inline int check_conn_state(struct ksmbd_work *work)if (
ksmbd_conn_exiting(work->conn)||ksmbd_conn_need_reconnect(work->conn)) {
-rsp_hdr=work->response_buf;
+rsp_hdr=smb2_get_msg(work->response_buf);rsp_hdr->Status.CifsError=STATUS_CONNECTION_DISCONNECTED; return 1;
}fs/smb/server/smb_common.c +1
-1@@ -140,7 +140,7 @@ int ksmbd_verify_smb_message(struct ksmbd_work *work) if (smb2_hdr->ProtocolId == SMB2_PROTO_NUMBER) return ksmbd_smb2_check_message(work); - hdr = work->request_buf; + hdr = smb2_get_msg(work->request_buf);if (*(__le32 *)hdr->Protocol ==
SMB1_PROTO_NUMBER&&hdr->Command==SMB_COM_NEGOTIATE) { work->conn->outstanding_credits++;fs/smb/server/smb_common.c +2
-3@@ -278,7 +278,6 @@ static int ksmbd_negotiate_smb_dialect(void *buf) req->DialectCount); } - proto = *(__le32 *)((struct smb_hdr *)buf)->Protocol; if (proto == SMB1_PROTO_NUMBER) { struct smb_negotiate_req *req;@@ -320,8 +319,8 @@ static u16 get_smb1_cmd_val(struct ksmbd_work *work)*/ static int init_smb1_rsp_hdr(struct ksmbd_work *work) { - struct smb_hdr *rsp_hdr = (struct smb_hdr *)work->response_buf; - struct smb_hdr *rcv_hdr = (struct smb_hdr *)work->request_buf; + struct smb_hdr *rsp_hdr = (struct smb_hdr *)smb2_get_msg(work- >response_buf); + struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg(work- >request_buf); rsp_hdr->Command = SMB_COM_NEGOTIATE;*(__le32 *)rsp_hdr->Protocol =
SMB1_PROTO_NUMBER;fs/smb/server/smb_common.c +2
-1@@ -412,9 +411,10 @@ static int init_smb1_server(struct ksmbd_conn *conn) int ksmbd_init_smb_server(struct ksmbd_conn *conn) { + struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg(conn- >request_buf); __le32 proto; - proto = *(__le32 *)((struct smb_hdr *)conn->request_buf)->Protocol; + proto = *(__le32 *)rcv_hdr->Protocol; if (conn->need_neg == false) { if (proto == SMB1_PROTO_NUMBER) return -EINVAL;
Namjae Jeon
maintainerQuoted 7 lines · ChenXiaoSong
Hi David,
Since the size of
struct smb_hdrhas changed, the value ofSMB1_MIN_SUPPORTED_HEADER_SIZEshould also be updated to(sizeof(struct smb_hdr) + 4).SMB1_MIN_SUPPORTED_HEADER_SIZEis used inksmbd_conn_handler_loop().
Right. And there are other places that need to be changed as well, I will check it.
Thanks!
Quoted 100 lines
Thanks,
ChenXiaoSong.Quoted 94 lines · ChenXiaoSong
ksmbd_conn_handler_loop()callsget_rfc1002_len(). Does this need to be updated as well?Thanks,
ChenXiaoSong.Quoted 86 lines · David Howells
Hi Namjae,
Does this (untested) patch fix the problem for you?
David
---
The commit that removed the RFC1002 header from structsmb_hdrdidn't also
fix the places in ksmbd that use it in order to provide graceful rejection
of SMB1 protocol requests.Fixes 83bfbd0bb902 ("cifs: Remove the RFC1002 header from smb_hdr")Reported-by Namjae Jeon <[email protected]>CAKYAXd9Ju4MFkkH5Jxfi1mO0AWEr=R35M3vQ_Xa7Yw34JoNZ0A@mail.gmail.com/
Signed-off-by David Howells <[email protected]>cc Steve French <[email protected]>cc Sergey Senozhatsky <[email protected]>cc Tom Talpey <[email protected]>cc Paulo Alcantara <[email protected]>cc Shyam Prasad N <[email protected]>--- fs/smb/server/server.c | 2 +- fs/smb/server/smb_common.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)fs/smb/server/server.c +1
-1@@ -95,7 +95,7 @@ static inline int check_conn_state(struct ksmbd_work *work)if (ksmbd_conn_exiting (work->conn) ||ksmbd_conn_need_reconnect (work->conn)) { - rsp_hdr = work->response_buf; + rsp_hdr =smb2_get_msg (work->response_buf); rsp_hdr->Status.CifsError =STATUS_CONNECTION_DISCONNECTED ;return 1 ; }fs/smb/server/smb_common.c +3
-4@@ -140,7 +140,7 @@ int ksmbd_verify_smb_message(struct ksmbd_work *work)if (smb2_hdr->ProtocolId ==SMB2_PROTO_NUMBER )return ksmbd_smb2_check_message (work); - hdr = work->request_buf; + hdr =smb2_get_msg (work->request_buf);if (*(__le32 *)hdr->Protocol ==SMB1_PROTO_NUMBER && hdr->Command ==SMB_COM_NEGOTIATE ) { work->conn->outstanding_credits++;@@ -278,7 +278,6 @@ static int ksmbd_negotiate_smb_dialect(void *buf) req->DialectCount); } - proto = *(__le32 *)((struct smb_hdr *)buf)->Protocol;if (proto ==SMB1_PROTO_NUMBER ) {struct smb_negotiate_req *req;@@ -320,8 +319,8 @@ static u16 get_smb1_cmd_val(struct ksmbd_work *work)*/ static int init_smb1_rsp_hdr (struct ksmbd_work *work) { -struct smb_hdr *rsp_hdr = (struct smb_hdr *)work->response_buf; -struct smb_hdr *rcv_hdr = (struct smb_hdr *)work->request_buf; +struct smb_hdr *rsp_hdr = (struct smb_hdr *)smb2_get_msg (work- >response_buf); +struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg (work- >request_buf); rsp_hdr->Command =SMB_COM_NEGOTIATE ;*(__le32 *)rsp_hdr->Protocol = SMB1_PROTO_NUMBER;fs/smb/server/smb_common.c +2
-1@@ -412,9 +411,10 @@ static int init_smb1_server(struct ksmbd_conn *conn)int ksmbd_init_smb_server (struct ksmbd_conn *conn) { +struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg (conn- >request_buf);__le32 proto; - proto = *(__le32 *)((struct smb_hdr *)conn->request_buf)->Protocol; + proto = *(__le32 *)rcv_hdr->Protocol;if (conn->need_neg == false) {if (proto ==SMB1_PROTO_NUMBER )return -EINVAL ;
David Howells
maintainerQuoted 2 lines · ChenXiaoSong
ksmbd_conn_handler_loop()callsget_rfc1002_len(). Does this need to be updated as well?
I don't think so. It reads the RFC1002 header into a 4-byte array (hdr_buf) and calls get_rfc1002_len() on that, so that should be unaffected.
Quoted 4 lines
Since the size of
struct smb_hdrhas changed, the value ofSMB1_MIN_SUPPORTED_HEADER_SIZEshould also be updated to(sizeof(struct smb_hdr) + 4).SMB1_MIN_SUPPORTED_HEADER_SIZEis used inksmbd_conn_handler_loop().
Actually, should SMB2_MIN_SUPPORTED_HEADER_SIZE include the +4 at all? pdu_size is the length stored in the RFC1002 header, which does not include itself.
David
Hi Namjae,
It seems David is correct, the LENGTH field is described in RFC1002 section 4.3.1: https://www.rfc-editor.org/rfc/rfc1002#section-4.3.1
The LENGTH field is the number of bytes following the LENGTH field. In other words, LENGTH is the combined size of the TRAILER field(s).
Thanks,
ChenXiaoSong.
Quoted 8 lines · David Howells
ChenXiaoSong <[email protected]> wrote:
Actually, should
SMB2_MIN_SUPPORTED_HEADER_SIZEinclude the +4 at all?pdu_sizeis the length stored in the RFC1002 header, which does not include itself.David
Namjae Jeon
maintainerQuoted 2 lines · David Howells
Hi Namjae,
Hi David,
Quoted 2 lines
Does this (untested) patch fix the problem for you?
I sent the v2 patch to the list now. I have tested it with cifs.ko and windows clients.
Thanks!
Quoted 82 lines
David
---
The commit that removed the RFC1002 header from structsmb_hdrdidn't also fix the places in ksmbd that use it in order to provide graceful rejection of SMB1 protocol requests.Fixes 83bfbd0bb902 ("cifs: Remove the RFC1002 header from smb_hdr")Reported-by Namjae Jeon <[email protected]>Link https://lore.kernel.org/r/CAKYAXd9Ju4MFkkH5Jxfi1mO0AWEr=R35M3vQ_Xa7Yw34JoNZ0A@mail.gmail.com/ open hereSigned-off-by David Howells <[email protected]>cc Steve French <[email protected]>cc Sergey Senozhatsky <[email protected]>cc Tom Talpey <[email protected]>cc Paulo Alcantara <[email protected]>cc Shyam Prasad N <[email protected]>--- fs/smb/server/server.c | 2 +- fs/smb/server/smb_common.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)fs/smb/server/server.c +1
-1@@ -95,7 +95,7 @@ static inline int check_conn_state(struct ksmbd_work *work)if (ksmbd_conn_exiting (work->conn) ||ksmbd_conn_need_reconnect (work->conn)) { - rsp_hdr = work->response_buf; + rsp_hdr =smb2_get_msg (work->response_buf); rsp_hdr->Status.CifsError =STATUS_CONNECTION_DISCONNECTED ;return 1 ; }fs/smb/server/smb_common.c +5
-5@@ -140,7 +140,7 @@ int ksmbd_verify_smb_message(struct ksmbd_work *work)if (smb2_hdr->ProtocolId ==SMB2_PROTO_NUMBER )return ksmbd_smb2_check_message (work); - hdr = work->request_buf; + hdr =smb2_get_msg (work->request_buf);if (*(__le32 *)hdr->Protocol ==SMB1_PROTO_NUMBER && hdr->Command ==SMB_COM_NEGOTIATE ) { work->conn->outstanding_credits++;@@ -278,7 +278,6 @@ static int ksmbd_negotiate_smb_dialect(void *buf) req->DialectCount); } - proto = *(__le32 *)((struct smb_hdr *)buf)->Protocol;if (proto ==SMB1_PROTO_NUMBER ) {struct smb_negotiate_req *req;@@ -320,8 +319,8 @@ static u16 get_smb1_cmd_val(struct ksmbd_work *work)*/ static int init_smb1_rsp_hdr (struct ksmbd_work *work) { -struct smb_hdr *rsp_hdr = (struct smb_hdr *)work->response_buf; -struct smb_hdr *rcv_hdr = (struct smb_hdr *)work->request_buf; +struct smb_hdr *rsp_hdr = (struct smb_hdr *)smb2_get_msg (work->response_buf); +struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg (work->request_buf); rsp_hdr->Command =SMB_COM_NEGOTIATE ; *(__le32 *)rsp_hdr->Protocol =SMB1_PROTO_NUMBER ;@@ -412,9 +411,10 @@ static int init_smb1_server(struct ksmbd_conn *conn)int ksmbd_init_smb_server (struct ksmbd_conn *conn) { +struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg (conn->request_buf);__le32 proto; - proto = *(__le32 *)((struct smb_hdr *)conn->request_buf)->Protocol; + proto = *(__le32 *)rcv_hdr->Protocol;if (conn->need_neg == false) {if (proto ==SMB1_PROTO_NUMBER )return -EINVAL ;