FAILED: patch "[PATCH] ksmbd: validate minimum PDU size for transform requests" failed to apply to 6.18-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x cfc0b8e5080aec87700774e8568765eaa4b7b92b
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072924-aviator-carton-3ed9@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From cfc0b8e5080aec87700774e8568765eaa4b7b92b Mon Sep 17 00:00:00 2001
From: Namjae Jeon <[email protected]>
Date: Sat, 4 Jul 2026 11:30:27 +0900
Subject: [PATCH] ksmbd: validate minimum PDU size for transform requests
The receive path applies the minimum SMB2 PDU size check only when ProtocolId is SMB2_PROTO_NUMBER. A packet carrying SMB2_TRANSFORM_PROTO_NUM bypasses the check even when the negotiated dialect does not provide transform handling.
On an SMB 2.1 connection, a short transform packet therefore reaches init_smb2_rsp_hdr(), which interprets the request as a full SMB2 header and reads beyond the request allocation. The copied fields can then be returned to the unauthenticated client.
Compression transforms are converted to ordinary SMB2 messages before protocol validation. After that conversion, validate ordinary SMB2 requests against SMB2_MIN_SUPPORTED_PDU_SIZE and require encryption transform requests to contain both a transform header and an SMB2 header. This rejects truncated requests before work allocation.
fs/smb/server/connection.c +11 -5
@@ -441,6 +441,8 @@ bool ksmbd_conn_alive(struct ksmbd_conn *conn)/* "+2" for BCC field (ByteCount, 2 bytes) */ #define SMB1_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb_hdr) + 2)#define SMB2_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb2_pdu)) +#define SMB2_TRANSFORM_MIN_SUPPORTED_PDU_SIZE \ + (sizeof(struct smb2_transform_hdr) + sizeof(struct smb2_hdr))/** * ksmbd_conn_handler_loop() - session thread to listen on new smb requests
@@ -455,6 +457,7 @@ int ksmbd_conn_handler_loop(void *p)struct ksmbd_conn *conn = (struct ksmbd_conn *)p;struct ksmbd_transport *t = conn->transport;unsigned int pdu_size, max_allowed_pdu_size, max_req; +__le32 proto;char hdr_buf[4 ] = {0 ,};int size;
@@ -546,11 +549,14 @@ int ksmbd_conn_handler_loop(void *p)if (!ksmbd_smb_request (conn))break ; -if (((struct smb2_hdr *)smb_get_msg (conn->request_buf))->ProtocolId == -SMB2_PROTO_NUMBER ) { -if (pdu_size <SMB2_MIN_SUPPORTED_PDU_SIZE ) -break ; - } + proto = *(__le32 *)smb_get_msg (conn->request_buf); +if (proto ==SMB2_PROTO_NUMBER && + pdu_size <SMB2_MIN_SUPPORTED_PDU_SIZE ) +break ; + +if (proto ==SMB2_TRANSFORM_PROTO_NUM && + pdu_size <SMB2_TRANSFORM_MIN_SUPPORTED_PDU_SIZE ) +break ;if (!default_conn_ops.process_fn) {pr_err ("No connection request callback\n" );
Sasha Levin
maintainerPATCH 1/7 smb: move get_rfc1002_len() to common/smbglob.h
From: ZhangGuoDong <[email protected]>
[ Upstream commit 36c31540cf5279262bfd148d8537cd04866499f2 ]
Rename get_rfc1002_length() to get_rfc1002_len(), then move duplicate definitions to common header file.
Stable-dep-of: cfc0b8e5080a ("ksmbd: validate minimum PDU size for transform requests")
--- fs/smb/client/cifsglob.h | 6 ------ fs/smb/client/cifssmb.c | 6 +++--- fs/smb/client/connect.c | 2 +- fs/smb/client/smb1transport.c | 8 ++++---- fs/smb/common/cifsglob.h | 5 +++++ fs/smb/server/smb_common.h | 5 ----- 6 files changed, 13 insertions(+), 19 deletions(-)
fs/smb/client/cifsglob.h +0 -6
@@ -671,12 +671,6 @@ struct cifs_mnt_data {int flags; }; -static inline unsigned int -get_rfc1002_length (void *buf) -{ -return be32_to_cpu (*((__be32 *)buf)) &0xffffff ; -} -struct TCP_Server_Info {struct list_head tcp_ses_list;struct list_head smb_ses_list;
fs/smb/client/cifssmb.c +3 -3
@@ -615,7 +615,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server) iov[0 ].iov_len =4 ; iov[0 ].iov_base = smb; - iov[1 ].iov_len =get_rfc1002_length (smb); + iov[1 ].iov_len =get_rfc1002_len (smb); iov[1 ].iov_base = (char *)smb +4 ; rc = cifs_call_async(server, &rqst, NULL, cifs_echo_callback, NULL,
@@ -1459,7 +1459,7 @@ cifs_async_readv(struct cifs_io_subrequest *rdata) rdata->iov[0 ].iov_base = smb; rdata->iov[0 ].iov_len =4 ; rdata->iov[1 ].iov_base = (char *)smb +4 ; - rdata->iov[1 ].iov_len =get_rfc1002_length (smb); + rdata->iov[1 ].iov_len =get_rfc1002_len (smb); trace_smb3_read_enter(rdata->rreq->debug_id, rdata->subreq.debug_index,
@@ -1831,7 +1831,7 @@ cifs_async_writev(struct cifs_io_subrequest *wdata)/* 4 for RFC1001 length + 1 for BCC */ iov[0 ].iov_len =4 ; iov[0 ].iov_base = smb; - iov[1 ].iov_len =get_rfc1002_length (smb) +1 ; + iov[1 ].iov_len =get_rfc1002_len (smb) +1 ; iov[1 ].iov_base = (char *)smb +4 ; rqst.rq_iov = iov;
fs/smb/client/connect.c +1 -1
@@ -1295,7 +1295,7 @@ cifs_demultiplex_thread(void *p)* The right amount was read from socket - 4 bytes, * so we can now interpret the length field. */ - pdu_length =get_rfc1002_length (buf); + pdu_length =get_rfc1002_len (buf);cifs_dbg (FYI ,"RFC1002 header 0x%x\n" , pdu_length);if (!is_smb_response (server, buf[0 ]))
fs/smb/client/smb1transport.c +4 -4
@@ -165,7 +165,7 @@ SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses,int resp_buf_type; iov[0 ].iov_base = in_buf; - iov[0 ].iov_len =get_rfc1002_length (in_buf) +4 ; + iov[0 ].iov_len =get_rfc1002_len (in_buf) +4 ; flags |=CIFS_NO_RSP_BUF ; rc =SendReceive2 (xid, ses, iov,1 , &resp_buf_type, flags, &rsp_iov);cifs_dbg (NOISY ,"SendRcvNoRsp flags %d rc %d\n" , flags, rc);
@@ -177,7 +177,7 @@ int cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server, bool log_error) { - unsigned int len = get_rfc1002_length(mid->resp_buf) + 4; + unsigned int len = get_rfc1002_len(mid->resp_buf) + 4;dump_smb (mid->resp_buf,min_t (u32,92 , len));
@@ -370,7 +370,7 @@ SendReceive(const unsigned int xid, struct cifs_ses *ses, goto out; } - *pbytes_returned =get_rfc1002_length (midQ->resp_buf); + *pbytes_returned =get_rfc1002_len (midQ->resp_buf);memcpy (out_buf, midQ->resp_buf, *pbytes_returned +4 ); rc =cifs_check_receive (midQ, server,0 ); out:
@@ -554,7 +554,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifs_tcon *tcon, goto out; } - *pbytes_returned =get_rfc1002_length (midQ->resp_buf); + *pbytes_returned =get_rfc1002_len (midQ->resp_buf);memcpy (out_buf, midQ->resp_buf, *pbytes_returned +4 ); rc =cifs_check_receive (midQ, server,0 ); out:
fs/smb/common/cifsglob.h +5 -0
@@ -40,6 +40,11 @@ struct smb_version_values {size_t create_posix_size; }; +static inline unsigned int get_rfc1002_len (void *buf) +{ +return be32_to_cpu (*((__be32 *)buf)) &0xffffff ; +} +static inline void inc_rfc1001_len (void *buf,int count) {be32_add_cpu ((__be32 *)buf, count);
fs/smb/server/smb_common.h +0 -5
@@ -423,9 +423,4 @@ unsigned int ksmbd_server_side_copy_max_chunk_size(void);unsigned int ksmbd_server_side_copy_max_total_size (void );bool is_asterisk (char *p);__le32 smb_map_generic_desired_access (__le32 daccess); - -static inline unsigned int get_rfc1002_len (void *buf) -{ -return be32_to_cpu (*((__be32 *)buf)) &0xffffff ; -}#endif /* __SMB_COMMON_H__ */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/7 smb/server: rename include guard in smb_common.h
From: ChenXiaoSong <[email protected]>
[ Upstream commit 01ab0d1640e379f0a0d6602250b33ff2b45e9560 ]
Make the include guard more descriptive to avoid conflicts with include guards that may be used in the future.
Stable-dep-of: cfc0b8e5080a ("ksmbd: validate minimum PDU size for transform requests")
--- fs/smb/server/smb_common.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/smb/server/smb_common.h +3 -3
@@ -3,8 +3,8 @@* Copyright (C) 2018 Samsung Electronics Co., Ltd. */ -#ifndef __SMB_COMMON_H__ -#define __SMB_COMMON_H__ +#ifndef __SMB_SERVER_COMMON_H__ +#define __SMB_SERVER_COMMON_H__#include <linux/kernel.h>
@@ -423,4 +423,4 @@ unsigned int ksmbd_server_side_copy_max_chunk_size(void);unsigned int ksmbd_server_side_copy_max_total_size (void );bool is_asterisk (char *p);__le32 smb_map_generic_desired_access (__le32 daccess); -#endif /* __SMB_COMMON_H__ */ +#endif /* __SMB_SERVER_COMMON_H__ */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/7 ksmbd: Fix to handle removal of rfc1002 header from smb_hdr
In reply to Sasha LevinFrom: David Howells <[email protected]>
[ Upstream commit 0a70cac7896712a08e3cd22c16f44be976d40dbf ]
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.
Stable-dep-of: cfc0b8e5080a ("ksmbd: validate minimum PDU size for transform requests")
--- fs/smb/server/server.c | 2 +- fs/smb/server/smb_common.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 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 +10 -10
@@ -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,15 +278,14 @@ 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; - req = (struct smb_negotiate_req *)buf; + req = (struct smb_negotiate_req *)smb2_get_msg (buf);if (le16_to_cpu (req->ByteCount) <2 ) goto err_out; -if (offsetof(struct smb_negotiate_req , DialectsArray) -4 + +if (offsetof(struct smb_negotiate_req , DialectsArray) +le16_to_cpu (req->ByteCount) > smb_buf_length) { goto err_out; }
@@ -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 ;
@@ -572,12 +572,12 @@ static int __smb2_negotiate(struct ksmbd_conn *conn)static int smb_handle_negotiate (struct ksmbd_work *work) { -struct smb_negotiate_rsp *neg_rsp = work->response_buf; +struct smb_negotiate_rsp *neg_rsp =smb2_get_msg (work->response_buf);ksmbd_debug (SMB ,"Unsupported SMB1 protocol\n" ); -if (ksmbd_iov_pin_rsp (work, (void *)neg_rsp +4 , -sizeof (struct smb_negotiate_rsp ) -4 )) +if (ksmbd_iov_pin_rsp (work, (void *)neg_rsp, +sizeof (struct smb_negotiate_rsp )))return -ENOMEM ; neg_rsp->hdr.Status.CifsError =STATUS_SUCCESS ;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/7 ksmbd: rename smb2_get_msg to smb_get_msg
In reply to Sasha LevinFrom: Namjae Jeon <[email protected]>
[ Upstream commit 0b444cfd8b74ebce421ccd96eac9c495e536c92e ]
With the removal of the RFC1002 length field from the SMB header, smb2_get_msg is now used to get the smb1 request from the request buffer. Since this function is no longer exclusive to smb2 and now supports smb1 as well, This patch rename it to smb_get_msg to better reflect its usage.
Stable-dep-of: cfc0b8e5080a ("ksmbd: validate minimum PDU size for transform requests")
--- fs/smb/server/auth.c | 4 +-- fs/smb/server/connection.c | 2 +- fs/smb/server/oplock.c | 8 ++--- fs/smb/server/server.c | 2 +- fs/smb/server/smb2pdu.c | 70 +++++++++++++++++++------------------- fs/smb/server/smb2pdu.h | 9 ----- fs/smb/server/smb_common.c | 18 +++++----- fs/smb/server/smb_common.h | 9 +++++ 8 files changed, 61 insertions(+), 61 deletions(-)
fs/smb/server/auth.c +2 -2
@@ -710,7 +710,7 @@ void ksmbd_gen_smb311_encryptionkey(struct ksmbd_conn *conn,int ksmbd_gen_preauth_integrity_hash (struct ksmbd_conn *conn,char *buf,__u8 *pi_hash) { -struct smb2_hdr *rcv_hdr =smb2_get_msg (buf); +struct smb2_hdr *rcv_hdr =smb_get_msg (buf);char *all_bytes_msg = (char *)&rcv_hdr->ProtocolId;int msg_size =get_rfc1002_len (buf);struct sha512_ctx sha_ctx;
@@ -837,7 +837,7 @@ int ksmbd_crypt_message(struct ksmbd_work *work, struct kvec *iov, unsigned int nvec, int enc) {struct ksmbd_conn *conn = work->conn; -struct smb2_transform_hdr *tr_hdr =smb2_get_msg (iov[0 ].iov_base); +struct smb2_transform_hdr *tr_hdr =smb_get_msg (iov[0 ].iov_base);unsigned int assoc_data_len =sizeof (struct smb2_transform_hdr ) -20 ;int rc;DECLARE_CRYPTO_WAIT (wait);
fs/smb/server/connection.c +1 -1
@@ -475,7 +475,7 @@ int ksmbd_conn_handler_loop(void *p)if (!ksmbd_smb_request (conn))break ; -if (((struct smb2_hdr *)smb2_get_msg (conn->request_buf))->ProtocolId == +if (((struct smb2_hdr *)smb_get_msg (conn->request_buf))->ProtocolId ==SMB2_PROTO_NUMBER ) {if (pdu_size <SMB2_MIN_SUPPORTED_HEADER_SIZE )break ;
fs/smb/server/oplock.c +4 -4
@@ -663,7 +663,7 @@ static void __smb2_oplock_break_noti(struct work_struct *wk) goto out; } - rsp_hdr =smb2_get_msg (work->response_buf); + rsp_hdr =smb_get_msg (work->response_buf);memset (rsp_hdr,0 ,sizeof (struct smb2_hdr ) +2 ); rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ;
@@ -677,7 +677,7 @@ static void __smb2_oplock_break_noti(struct work_struct *wk) rsp_hdr->SessionId =0 ;memset (rsp_hdr->Signature,0 ,16 ); - rsp =smb2_get_msg (work->response_buf); + rsp =smb_get_msg (work->response_buf); rsp->StructureSize =cpu_to_le16 (24 ); if (!br_info->open_trunc &&
@@ -776,7 +776,7 @@ static void __smb2_lease_break_noti(struct work_struct *wk) goto out; } - rsp_hdr =smb2_get_msg (work->response_buf); + rsp_hdr =smb_get_msg (work->response_buf);memset (rsp_hdr,0 ,sizeof (struct smb2_hdr ) +2 ); rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ;
@@ -790,7 +790,7 @@ static void __smb2_lease_break_noti(struct work_struct *wk) rsp_hdr->SessionId =0 ;memset (rsp_hdr->Signature,0 ,16 ); - rsp =smb2_get_msg (work->response_buf); + rsp =smb_get_msg (work->response_buf); rsp->StructureSize =cpu_to_le16 (44 ); rsp->Epoch = br_info->epoch; rsp->Flags =0 ;
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 =smb2_get_msg (work->response_buf); + rsp_hdr =smb_get_msg (work->response_buf); rsp_hdr->Status.CifsError =STATUS_CONNECTION_DISCONNECTED ;return 1 ; }
fs/smb/server/smb2pdu.c +35 -35
240 lines not on this page · raw message
fs/smb/server/smb2pdu.h +0 -9
@@ -490,15 +490,6 @@ int smb2_ioctl(struct ksmbd_work *work);int smb2_oplock_break (struct ksmbd_work *work);int smb2_notify (struct ksmbd_work *ksmbd_work); -/* -* Get the body of the smb2 message excluding the 4 byte rfc1002 headers -* from request/response buffer. -*/ -static inline void *smb2_get_msg (void *buf) -{ -return buf +4 ; -} -#define POSIX_TYPE_FILE 0#define POSIX_TYPE_DIR 1#define POSIX_TYPE_SYMLINK 2
fs/smb/server/smb_common.c +9 -9
@@ -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 =smb2_get_msg (work->request_buf); + hdr =smb_get_msg (work->request_buf);if (*(__le32 *)hdr->Protocol ==SMB1_PROTO_NUMBER && hdr->Command ==SMB_COM_NEGOTIATE ) { work->conn->outstanding_credits++;
@@ -163,7 +163,7 @@ bool ksmbd_smb_request(struct ksmbd_conn *conn)if (conn->request_buf[0 ] !=0 )return false; - proto = (__le32 *)smb2_get_msg (conn->request_buf); + proto = (__le32 *)smb_get_msg (conn->request_buf);if (*proto ==SMB2_COMPRESSION_TRANSFORM_ID ) {pr_err_ratelimited ("smb2 compression not support yet" );return false;
@@ -259,14 +259,14 @@ int ksmbd_lookup_dialect_by_id(__le16 *cli_dialects, __le16 dialects_count)static int ksmbd_negotiate_smb_dialect (void *buf) {int smb_buf_length =get_rfc1002_len (buf); -__le32 proto = ((struct smb2_hdr *)smb2_get_msg (buf))->ProtocolId; +__le32 proto = ((struct smb2_hdr *)smb_get_msg (buf))->ProtocolId;if (proto ==SMB2_PROTO_NUMBER ) {struct smb2_negotiate_req *req;int smb2_neg_size = offsetof(struct smb2_negotiate_req , Dialects); - req = (struct smb2_negotiate_req *)smb2_get_msg (buf); + req = (struct smb2_negotiate_req *)smb_get_msg (buf);if (smb2_neg_size > smb_buf_length) goto err_out;
@@ -281,7 +281,7 @@ static int ksmbd_negotiate_smb_dialect(void *buf)if (proto ==SMB1_PROTO_NUMBER ) {struct smb_negotiate_req *req; - req = (struct smb_negotiate_req *)smb2_get_msg (buf); + req = (struct smb_negotiate_req *)smb_get_msg (buf);if (le16_to_cpu (req->ByteCount) <2 ) goto err_out;
@@ -319,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 *)smb2_get_msg (work->response_buf); -struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb2_get_msg (work->request_buf); +struct smb_hdr *rsp_hdr = (struct smb_hdr *)smb_get_msg (work->response_buf); +struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb_get_msg (work->request_buf); rsp_hdr->Command =SMB_COM_NEGOTIATE ; *(__le32 *)rsp_hdr->Protocol =SMB1_PROTO_NUMBER ;
@@ -411,7 +411,7 @@ 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); +struct smb_hdr *rcv_hdr = (struct smb_hdr *)smb_get_msg (conn->request_buf);__le32 proto; proto = *(__le32 *)rcv_hdr->Protocol;
@@ -572,7 +572,7 @@ static int __smb2_negotiate(struct ksmbd_conn *conn)static int smb_handle_negotiate (struct ksmbd_work *work) { -struct smb_negotiate_rsp *neg_rsp =smb2_get_msg (work->response_buf); +struct smb_negotiate_rsp *neg_rsp =smb_get_msg (work->response_buf);ksmbd_debug (SMB ,"Unsupported SMB1 protocol\n" );
fs/smb/server/smb_common.h +9 -0
@@ -423,4 +423,13 @@ unsigned int ksmbd_server_side_copy_max_chunk_size(void);unsigned int ksmbd_server_side_copy_max_total_size (void );bool is_asterisk (char *p);__le32 smb_map_generic_desired_access (__le32 daccess); + +/* +* Get the body of the smb message excluding the 4 byte rfc1002 headers +* from request/response buffer. +*/ +static inline void *smb_get_msg (void *buf) +{ +return buf +4 ; +}#endif /* __SMB_SERVER_COMMON_H__ */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 5/7 smb/server: fix minimum SMB1 PDU size
In reply to Sasha LevinFrom: ChenXiaoSong <[email protected]>
[ Upstream commit 3b9c30eb8f5aaad4a54cdfa470b74c0467cc71e8 ]
Since the RFC1002 header has been removed from struct smb_hdr, the minimum SMB1 PDU size should be updated as well.
Stable-dep-of: cfc0b8e5080a ("ksmbd: validate minimum PDU size for transform requests")
--- fs/smb/server/connection.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/smb/server/connection.c +3 -2
@@ -376,7 +376,8 @@ bool ksmbd_conn_alive(struct ksmbd_conn *conn)return true; } -#define SMB1_MIN_SUPPORTED_HEADER_SIZE (sizeof(struct smb_hdr)) +/* "+2" for BCC field (ByteCount, 2 bytes) */ +#define SMB1_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb_hdr) + 2)#define SMB2_MIN_SUPPORTED_HEADER_SIZE (sizeof(struct smb2_hdr) + 4)/**
@@ -444,7 +445,7 @@ int ksmbd_conn_handler_loop(void *p)if (pdu_size >MAX_STREAM_PROT_LEN )break ; -if (pdu_size <SMB1_MIN_SUPPORTED_HEADER_SIZE ) +if (pdu_size <SMB1_MIN_SUPPORTED_PDU_SIZE )break ;/* 4 for rfc1002 length field */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 6/7 smb/server: fix minimum SMB2 PDU size
In reply to Sasha LevinFrom: ChenXiaoSong <[email protected]>
[ Upstream commit 4c7d8eb9a79ae5400eac19c4f6f0815bff674452 ]
The minimum SMB2 PDU size should be updated to the size of struct smb2_pdu (that is, the size of struct smb2_hdr + 2).
Stable-dep-of: cfc0b8e5080a ("ksmbd: validate minimum PDU size for transform requests")
--- fs/smb/server/connection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/server/connection.c +2 -2
@@ -378,7 +378,7 @@ bool ksmbd_conn_alive(struct ksmbd_conn *conn)/* "+2" for BCC field (ByteCount, 2 bytes) */ #define SMB1_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb_hdr) + 2) -#define SMB2_MIN_SUPPORTED_HEADER_SIZE (sizeof(struct smb2_hdr) + 4) +#define SMB2_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb2_pdu))/** * ksmbd_conn_handler_loop() - session thread to listen on new smb requests
@@ -478,7 +478,7 @@ int ksmbd_conn_handler_loop(void *p)if (((struct smb2_hdr *)smb_get_msg (conn->request_buf))->ProtocolId ==SMB2_PROTO_NUMBER ) { -if (pdu_size <SMB2_MIN_SUPPORTED_HEADER_SIZE ) +if (pdu_size <SMB2_MIN_SUPPORTED_PDU_SIZE )break ; }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 7/7 ksmbd: validate minimum PDU size for transform requests
In reply to Sasha LevinFrom: Namjae Jeon <[email protected]>
[ Upstream commit cfc0b8e5080aec87700774e8568765eaa4b7b92b ]
The receive path applies the minimum SMB2 PDU size check only when ProtocolId is SMB2_PROTO_NUMBER. A packet carrying SMB2_TRANSFORM_PROTO_NUM bypasses the check even when the negotiated dialect does not provide transform handling.
On an SMB 2.1 connection, a short transform packet therefore reaches init_smb2_rsp_hdr(), which interprets the request as a full SMB2 header and reads beyond the request allocation. The copied fields can then be returned to the unauthenticated client.
Compression transforms are converted to ordinary SMB2 messages before protocol validation. After that conversion, validate ordinary SMB2 requests against SMB2_MIN_SUPPORTED_PDU_SIZE and require encryption transform requests to contain both a transform header and an SMB2 header. This rejects truncated requests before work allocation.
--- fs/smb/server/connection.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
fs/smb/server/connection.c +11 -5
@@ -379,6 +379,8 @@ bool ksmbd_conn_alive(struct ksmbd_conn *conn)/* "+2" for BCC field (ByteCount, 2 bytes) */ #define SMB1_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb_hdr) + 2)#define SMB2_MIN_SUPPORTED_PDU_SIZE (sizeof(struct smb2_pdu)) +#define SMB2_TRANSFORM_MIN_SUPPORTED_PDU_SIZE \ + (sizeof(struct smb2_transform_hdr) + sizeof(struct smb2_hdr))/** * ksmbd_conn_handler_loop() - session thread to listen on new smb requests
@@ -393,6 +395,7 @@ int ksmbd_conn_handler_loop(void *p)struct ksmbd_conn *conn = (struct ksmbd_conn *)p;struct ksmbd_transport *t = conn->transport;unsigned int pdu_size, max_allowed_pdu_size, max_req; +__le32 proto;char hdr_buf[4 ] = {0 ,};int size;
@@ -476,11 +479,14 @@ int ksmbd_conn_handler_loop(void *p)if (!ksmbd_smb_request (conn))break ; -if (((struct smb2_hdr *)smb_get_msg (conn->request_buf))->ProtocolId == -SMB2_PROTO_NUMBER ) { -if (pdu_size <SMB2_MIN_SUPPORTED_PDU_SIZE ) -break ; - } + proto = *(__le32 *)smb_get_msg (conn->request_buf); +if (proto ==SMB2_PROTO_NUMBER && + pdu_size <SMB2_MIN_SUPPORTED_PDU_SIZE ) +break ; + +if (proto ==SMB2_TRANSFORM_PROTO_NUM && + pdu_size <SMB2_TRANSFORM_MIN_SUPPORTED_PDU_SIZE ) +break ;if (!default_conn_ops.process_fn) {pr_err ("No connection request callback\n" );
Signature · 1 line
2.53.0