Skip to content

Commit 0a70cac

Browse files
dhowellssmfrench
authored andcommitted
ksmbd: Fix to handle removal of rfc1002 header from smb_hdr
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. Fixes: 83bfbd0 ("cifs: Remove the RFC1002 header from smb_hdr") Reported-by: Namjae Jeon <linkinjeon@kernel.org> Link: https://lore.kernel.org/r/CAKYAXd9Ju4MFkkH5Jxfi1mO0AWEr=R35M3vQ_Xa7Yw34JoNZ0A@mail.gmail.com/ Cc: ChenXiaoSong <chenxiaosong.chenxiaosong@linux.dev> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 9448598 commit 0a70cac

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

fs/smb/server/server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static inline int check_conn_state(struct ksmbd_work *work)
9595

9696
if (ksmbd_conn_exiting(work->conn) ||
9797
ksmbd_conn_need_reconnect(work->conn)) {
98-
rsp_hdr = work->response_buf;
98+
rsp_hdr = smb2_get_msg(work->response_buf);
9999
rsp_hdr->Status.CifsError = STATUS_CONNECTION_DISCONNECTED;
100100
return 1;
101101
}

fs/smb/server/smb_common.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int ksmbd_verify_smb_message(struct ksmbd_work *work)
140140
if (smb2_hdr->ProtocolId == SMB2_PROTO_NUMBER)
141141
return ksmbd_smb2_check_message(work);
142142

143-
hdr = work->request_buf;
143+
hdr = smb2_get_msg(work->request_buf);
144144
if (*(__le32 *)hdr->Protocol == SMB1_PROTO_NUMBER &&
145145
hdr->Command == SMB_COM_NEGOTIATE) {
146146
work->conn->outstanding_credits++;
@@ -278,15 +278,14 @@ static int ksmbd_negotiate_smb_dialect(void *buf)
278278
req->DialectCount);
279279
}
280280

281-
proto = *(__le32 *)((struct smb_hdr *)buf)->Protocol;
282281
if (proto == SMB1_PROTO_NUMBER) {
283282
struct smb_negotiate_req *req;
284283

285-
req = (struct smb_negotiate_req *)buf;
284+
req = (struct smb_negotiate_req *)smb2_get_msg(buf);
286285
if (le16_to_cpu(req->ByteCount) < 2)
287286
goto err_out;
288287

289-
if (offsetof(struct smb_negotiate_req, DialectsArray) - 4 +
288+
if (offsetof(struct smb_negotiate_req, DialectsArray) +
290289
le16_to_cpu(req->ByteCount) > smb_buf_length) {
291290
goto err_out;
292291
}
@@ -320,8 +319,8 @@ static u16 get_smb1_cmd_val(struct ksmbd_work *work)
320319
*/
321320
static int init_smb1_rsp_hdr(struct ksmbd_work *work)
322321
{
323-
struct smb_hdr *rsp_hdr = (struct smb_hdr *)work->response_buf;
324-
struct smb_hdr *rcv_hdr = (struct smb_hdr *)work->request_buf;
322+
struct smb_hdr *rsp_hdr = (struct smb_hdr *)smb2_get_msg(work->response_buf);
323+
struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg(work->request_buf);
325324

326325
rsp_hdr->Command = SMB_COM_NEGOTIATE;
327326
*(__le32 *)rsp_hdr->Protocol = SMB1_PROTO_NUMBER;
@@ -412,9 +411,10 @@ static int init_smb1_server(struct ksmbd_conn *conn)
412411

413412
int ksmbd_init_smb_server(struct ksmbd_conn *conn)
414413
{
414+
struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg(conn->request_buf);
415415
__le32 proto;
416416

417-
proto = *(__le32 *)((struct smb_hdr *)conn->request_buf)->Protocol;
417+
proto = *(__le32 *)rcv_hdr->Protocol;
418418
if (conn->need_neg == false) {
419419
if (proto == SMB1_PROTO_NUMBER)
420420
return -EINVAL;
@@ -572,12 +572,12 @@ static int __smb2_negotiate(struct ksmbd_conn *conn)
572572

573573
static int smb_handle_negotiate(struct ksmbd_work *work)
574574
{
575-
struct smb_negotiate_rsp *neg_rsp = work->response_buf;
575+
struct smb_negotiate_rsp *neg_rsp = smb2_get_msg(work->response_buf);
576576

577577
ksmbd_debug(SMB, "Unsupported SMB1 protocol\n");
578578

579-
if (ksmbd_iov_pin_rsp(work, (void *)neg_rsp + 4,
580-
sizeof(struct smb_negotiate_rsp) - 4))
579+
if (ksmbd_iov_pin_rsp(work, (void *)neg_rsp,
580+
sizeof(struct smb_negotiate_rsp)))
581581
return -ENOMEM;
582582

583583
neg_rsp->hdr.Status.CifsError = STATUS_SUCCESS;

0 commit comments

Comments
 (0)