ksmbd: remove smb2_buf_length in smb2_hdr
Subsystems (2)
Namjae Jeon
maintainerPATCH 1/2 ksmbd: remove smb2_buf_length in smb2_hdr
To move smb2_hdr to cifs_common, This patch remove smb2_buf_length variable in smb2_hdr. Also, declare smb2_get_msg function to get smb2 request/response from ->request/response_buf.
--- fs/ksmbd/auth.c | 4 +- fs/ksmbd/ksmbd_work.h | 4 +- fs/ksmbd/oplock.c | 22 +-- fs/ksmbd/server.c | 2 +- fs/ksmbd/smb2misc.c | 4 +- fs/ksmbd/smb2pdu.c | 439 +++++++++++++++++++++--------------------- fs/ksmbd/smb2pdu.h | 14 +- fs/ksmbd/smb_common.c | 11 +- fs/ksmbd/smb_common.h | 6 - 9 files changed, 255 insertions(+), 251 deletions(-)
fs/ksmbd/auth.c +2 -2
@@ -1076,9 +1076,9 @@ int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf, __u8 *pi_hash) {int rc; -struct smb2_hdr *rcv_hdr = (struct smb2_hdr *)buf; +struct smb2_hdr *rcv_hdr =smb2_get_msg (buf);char *all_bytes_msg = (char *)&rcv_hdr->ProtocolId; -int msg_size =be32_to_cpu (rcv_hdr->smb2_buf_length); +int msg_size =get_rfc1002_len (buf);struct ksmbd_crypto_ctx *ctx =NULL ; if (conn->preauth_info->Preauth_HashId !=
fs/ksmbd/ksmbd_work.h +2 -2
@@ -92,7 +92,7 @@ struct ksmbd_work {*/ static inline void *ksmbd_resp_buf_next (struct ksmbd_work *work) { -return work->response_buf + work->next_smb2_rsp_hdr_off; +return work->response_buf + work->next_smb2_rsp_hdr_off +4 ; }/**
@@ -101,7 +101,7 @@ static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work)*/ static inline void *ksmbd_req_buf_next (struct ksmbd_work *work) { -return work->request_buf + work->next_smb2_rcv_hdr_off; +return work->request_buf + work->next_smb2_rcv_hdr_off +4 ; }struct ksmbd_work *ksmbd_alloc_work_struct (void );
fs/ksmbd/oplock.c +11 -11
@@ -629,10 +629,10 @@ static void __smb2_oplock_break_noti(struct work_struct *wk)return ; } - rsp_hdr = work->response_buf; + rsp_hdr =smb2_get_msg (work->response_buf);memset (rsp_hdr,0 ,sizeof (struct smb2_hdr ) +2 ); - rsp_hdr->smb2_buf_length = -cpu_to_be32 (smb2_hdr_size_no_buflen (conn->vals)); + *(__be32 *)work->response_buf = +cpu_to_be32 (conn->vals->header_size); rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ; rsp_hdr->CreditRequest =cpu_to_le16 (0 );
@@ -645,7 +645,7 @@ static void __smb2_oplock_break_noti(struct work_struct *wk) rsp_hdr->SessionId =0 ;memset (rsp_hdr->Signature,0 ,16 ); - rsp = work->response_buf; + rsp =smb2_get_msg (work->response_buf); rsp->StructureSize =cpu_to_le16 (24 ); if (!br_info->open_trunc &&
@@ -659,7 +659,7 @@ static void __smb2_oplock_break_noti(struct work_struct *wk) rsp->PersistentFid =cpu_to_le64 (fp->persistent_id); rsp->VolatileFid =cpu_to_le64 (fp->volatile_id); -inc_rfc1001_len (rsp,24 ); +inc_rfc1001_len (work->response_buf,24 ); ksmbd_debug(OPLOCK, "sending oplock break v_id %llu p_id = %llu lock level = %d\n",
@@ -736,10 +736,10 @@ static void __smb2_lease_break_noti(struct work_struct *wk)return ; } - rsp_hdr = work->response_buf; + rsp_hdr =smb2_get_msg (work->response_buf);memset (rsp_hdr,0 ,sizeof (struct smb2_hdr ) +2 ); - rsp_hdr->smb2_buf_length = -cpu_to_be32 (smb2_hdr_size_no_buflen (conn->vals)); + *(__be32 *)work->response_buf = +cpu_to_be32 (conn->vals->header_size); rsp_hdr->ProtocolId =SMB2_PROTO_NUMBER ; rsp_hdr->StructureSize =SMB2_HEADER_STRUCTURE_SIZE ; rsp_hdr->CreditRequest =cpu_to_le16 (0 );
@@ -752,7 +752,7 @@ static void __smb2_lease_break_noti(struct work_struct *wk) rsp_hdr->SessionId =0 ;memset (rsp_hdr->Signature,0 ,16 ); - rsp = work->response_buf; + rsp =smb2_get_msg (work->response_buf); rsp->StructureSize =cpu_to_le16 (44 ); rsp->Epoch = br_info->epoch; rsp->Flags =0 ;
@@ -768,7 +768,7 @@ static void __smb2_lease_break_noti(struct work_struct *wk) rsp->AccessMaskHint =0 ; rsp->ShareMaskHint =0 ; -inc_rfc1001_len (rsp,44 ); +inc_rfc1001_len (work->response_buf,44 );ksmbd_conn_write (work);ksmbd_free_work_struct (work);
@@ -1457,7 +1457,7 @@ struct create_context *smb2_find_context_vals(void *open_req, const char *tag)char *name;struct smb2_create_req *req = (struct smb2_create_req *)open_req; - data_offset = (char *)req +4 +le32_to_cpu (req->CreateContextsOffset); + data_offset = (char *)req +le32_to_cpu (req->CreateContextsOffset); cc = (struct create_context *)data_offset; do { int val;
fs/ksmbd/server.c +1 -1
@@ -94,7 +94,7 @@ static inline int check_conn_state(struct ksmbd_work *work)struct smb_hdr *rsp_hdr;if (ksmbd_conn_exiting (work) ||ksmbd_conn_need_reconnect (work)) { - rsp_hdr = work->response_buf; + rsp_hdr =smb2_get_msg (work->response_buf); rsp_hdr->Status.CifsError =STATUS_CONNECTION_DISCONNECTED ;return 1 ; }
fs/ksmbd/smb2misc.c +2 -2
@@ -332,11 +332,11 @@ static int smb2_validate_credit_charge(struct smb2_hdr *hdr)int ksmbd_smb2_check_message (struct ksmbd_work *work) { -struct smb2_pdu *pdu = work->request_buf; +struct smb2_pdu *pdu =smb2_get_msg (work->request_buf);struct smb2_hdr *hdr = &pdu->hdr;int command;__u32 clc_len;/* calculated length */ -__u32 len =get_rfc1002_len (pdu); +__u32 len =get_rfc1002_len (work->request_buf);if (work->next_smb2_rcv_hdr_off) { pdu =ksmbd_req_buf_next (work);
fs/ksmbd/smb2pdu.c +222 -217
1,395 lines not on this page · raw message
fs/ksmbd/smb2pdu.h +9 -5
@@ -128,11 +128,6 @@cpu_to_le16 (__SMB2_HEADER_STRUCTURE_SIZE) struct smb2_hdr { -__be32 smb2_buf_length;/* big endian on wire */ -/* -* length is only two or three bytes - with -* one or two byte type preceding it that MBZ -*/ __le32 ProtocolId;/* 0xFE 'S' 'M' 'B' */ __le16 StructureSize;/* 64 */ __le16 CreditCharge;/* MBZ */
@@ -1695,4 +1690,13 @@ 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 ; +} +#endif /* _SMB2PDU_H */
fs/ksmbd/smb_common.c +6 -5
@@ -133,7 +133,7 @@ int ksmbd_lookup_protocol_idx(char *str)*/ int ksmbd_verify_smb_message (struct ksmbd_work *work) { -struct smb2_hdr *smb2_hdr = work->request_buf; +struct smb2_hdr *smb2_hdr =smb2_get_msg (work->request_buf);if (smb2_hdr->ProtocolId ==SMB2_PROTO_NUMBER )return ksmbd_smb2_check_message (work);
@@ -244,11 +244,11 @@ static int ksmbd_negotiate_smb_dialect(void *buf) {__le32 proto; - proto = ((struct smb2_hdr *)buf)->ProtocolId; + proto = ((struct smb2_hdr *)smb2_get_msg (buf))->ProtocolId;if (proto ==SMB2_PROTO_NUMBER ) {struct smb2_negotiate_req *req; - req = (struct smb2_negotiate_req *)buf; + req = (struct smb2_negotiate_req *)smb2_get_msg (buf);return ksmbd_lookup_dialect_by_id (req->Dialects, req->DialectCount); }
@@ -437,11 +437,12 @@ int ksmbd_smb_negotiate_common(struct ksmbd_work *work, unsigned int command)struct ksmbd_conn *conn = work->conn;int ret; - conn->dialect =ksmbd_negotiate_smb_dialect (work->request_buf); + conn->dialect = +ksmbd_negotiate_smb_dialect (work->request_buf);ksmbd_debug (SMB ,"conn->dialect 0x%x\n" , conn->dialect);if (command ==SMB2_NEGOTIATE_HE ) { -struct smb2_hdr *smb2_hdr = work->request_buf; +struct smb2_hdr *smb2_hdr =smb2_get_msg (work->request_buf);if (smb2_hdr->ProtocolId !=SMB2_PROTO_NUMBER ) {ksmbd_debug (SMB ,"Downgrade to SMB1 negotiation\n" );
fs/ksmbd/smb_common.h +0 -6
@@ -482,12 +482,6 @@ struct smb_version_cmds {int (*proc)(struct ksmbd_work *swork); }; -static inline size_t -smb2_hdr_size_no_buflen (struct smb_version_values *vals) -{ -return vals->header_size -4 ; -} -int ksmbd_min_protocol (void );int ksmbd_max_protocol (void );
Signature · 1 line
2.25.1
Namjae Jeon
maintainerPATCH 2/2 ksmbd: remove smb2_buf_length in smb2_transform_hdr
To move smb2_transform_hdr to cifs_common, This patch remove smb2_buf_length variable in smb2_transform_hdr.
--- fs/ksmbd/auth.c | 7 +++---- fs/ksmbd/connection.c | 2 +- fs/ksmbd/smb2pdu.c | 44 ++++++++++++++++++++----------------------- fs/ksmbd/smb2pdu.h | 5 ----- 4 files changed, 24 insertions(+), 34 deletions(-)
fs/ksmbd/auth.c +3 -4
@@ -1186,7 +1186,7 @@ static struct scatterlist *ksmbd_init_sg(struct kvec *iov, unsigned int nvec, u8 *sign) {struct scatterlist *sg; -unsigned int assoc_data_len =sizeof (struct smb2_transform_hdr ) -24 ; +unsigned int assoc_data_len =sizeof (struct smb2_transform_hdr ) -20 ;int i, nr_entries[3 ] = {0 }, total_entries =0 , sg_idx =0 ;if (!nvec)
@@ -1250,9 +1250,8 @@ static struct scatterlist *ksmbd_init_sg(struct kvec *iov, unsigned int nvec,int ksmbd_crypt_message (struct ksmbd_conn *conn,struct kvec *iov,unsigned int nvec,int enc) { -struct smb2_transform_hdr *tr_hdr = - (struct smb2_transform_hdr *)iov[0 ].iov_base; -unsigned int assoc_data_len =sizeof (struct smb2_transform_hdr ) -24 ; +struct smb2_transform_hdr *tr_hdr =smb2_get_msg (iov[0 ].iov_base); +unsigned int assoc_data_len =sizeof (struct smb2_transform_hdr ) -20 ;int rc;struct scatterlist *sg;u8 sign[SMB2_SIGNATURE_SIZE ] = {};
fs/ksmbd/connection.c +1 -1
@@ -170,7 +170,7 @@ int ksmbd_conn_write(struct ksmbd_work *work)if (work->tr_buf) { iov[iov_idx] = (struct kvec ) { work->tr_buf, -sizeof (struct smb2_transform_hdr ) }; +sizeof (struct smb2_transform_hdr ) +4 }; len += iov[iov_idx++].iov_len; }
fs/ksmbd/smb2pdu.c +20 -24
118 lines not on this page · raw message
fs/ksmbd/smb2pdu.h +0 -5
@@ -157,11 +157,6 @@ struct smb2_pdu {#define SMB3_AES_GCM_NONCE 12struct smb2_transform_hdr { -__be32 smb2_buf_length;/* big endian on wire */ -/* -* length is only two or three bytes - with -* one or two byte type preceding it that MBZ -*/ __le32 ProtocolId;/* 0xFD 'S' 'M' 'B' */ __u8 Signature[16 ];__u8 Nonce[16 ];
Signature · 1 line
2.25.1
kernel test robot
build botI love your patch! Yet something to improve:
Hi Namjae,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on next-20210903]
[cannot apply to v5.14]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Namjae-Jeon/ksmbd-remove-smb2_buf_length-in-smb2_hdr/20210905-201954 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 49624efa65ac9889f4e7c7b2452b2e6ce42ba37d config: arc-allyesconfig (attached as .config) compiler: arceb-elf-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/d2f95f18a469ebadd9ace677c8eb5d41f312c3ad
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Namjae-Jeon/ksmbd-remove-smb2_buf_length-in-smb2_hdr/20210905-201954 git checkout d2f95f18a469ebadd9ace677c8eb5d41f312c3ad
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
Note: the linux-review/Namjae-Jeon/ksmbd-remove-smb2_buf_length-in-smb2_hdr/20210905-201954 HEAD 804be918918f36b06325814fe4a257849ac15e4d builds fine.
It only hurts bisectability.
All errors (new ones prefixed by >>):
fs/ksmbd/smb2pdu.c: In function 'smb3_decrypt_req':
>> fs/ksmbd/smb2pdu.c:8358:12: error: 'struct smb2_hdr' has no member named 'smb2_buf_length'
8358 | hdr->smb2_buf_length = cpu_to_be32(buf_data_size);
| ^~
In file included from include/linux/perf_event.h:25,
from include/linux/trace_events.h:10,
from include/trace/syscall.h:7,
from include/linux/syscalls.h:87,
from fs/ksmbd/smb2pdu.c:9:
At top level:
arch/arc/include/asm/perf_event.h:126:27: warning: 'arc_pmu_cache_map' defined but not used [-Wunused-const-variable=]
126 | static const unsigned int arc_pmu_cache_map[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
| ^~~~~~~~~~~~~~~~~
arch/arc/include/asm/perf_event.h:91:27: warning: 'arc_pmu_ev_hw_map' defined but not used [-Wunused-const-variable=]
91 | static const char * const arc_pmu_ev_hw_map[] = {
| ^~~~~~~~~~~~~~~~~vim +8358 fs/ksmbd/smb2pdu.c
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8314
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8315 int smb3_decrypt_req(struct ksmbd_work *work)
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8316 {
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8317 struct ksmbd_conn *conn = work->conn;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8318 struct ksmbd_session *sess;
e5066499079de0 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-30 8319 char *buf = work->request_buf;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8320 struct smb2_hdr *hdr;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8321 unsigned int pdu_length = get_rfc1002_len(buf);
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8322 struct kvec iov[2];
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8323 unsigned int buf_data_size = pdu_length + 4 -
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8324 sizeof(struct smb2_transform_hdr);
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8325 struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8326 unsigned int orig_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8327 int rc = 0;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8328
f5a544e3bab781 fs/cifsd/smb2pdu.c Namjae Jeon 2021-06-18 8329 sess = ksmbd_session_lookup_all(conn, le64_to_cpu(tr_hdr->SessionId));
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8330 if (!sess) {
bde1694aecdb53 fs/cifsd/smb2pdu.c Namjae Jeon 2021-06-28 8331 pr_err("invalid session id(%llx) in transform header\n",
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8332 le64_to_cpu(tr_hdr->SessionId));
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8333 return -ECONNABORTED;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8334 }
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8335
070fb21e5912b6 fs/cifsd/smb2pdu.c Namjae Jeon 2021-05-26 8336 if (pdu_length + 4 <
070fb21e5912b6 fs/cifsd/smb2pdu.c Namjae Jeon 2021-05-26 8337 sizeof(struct smb2_transform_hdr) + sizeof(struct smb2_hdr)) {
bde1694aecdb53 fs/cifsd/smb2pdu.c Namjae Jeon 2021-06-28 8338 pr_err("Transform message is too small (%u)\n",
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8339 pdu_length);
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8340 return -ECONNABORTED;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8341 }
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8342
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8343 if (pdu_length + 4 < orig_len + sizeof(struct smb2_transform_hdr)) {
bde1694aecdb53 fs/cifsd/smb2pdu.c Namjae Jeon 2021-06-28 8344 pr_err("Transform message is broken\n");
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8345 return -ECONNABORTED;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8346 }
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8347
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8348 iov[0].iov_base = buf;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8349 iov[0].iov_len = sizeof(struct smb2_transform_hdr);
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8350 iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr);
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8351 iov[1].iov_len = buf_data_size;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8352 rc = ksmbd_crypt_message(conn, iov, 2, 0);
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8353 if (rc)
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8354 return rc;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8355
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8356 memmove(buf + 4, iov[1].iov_base, buf_data_size);
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8357 hdr = (struct smb2_hdr *)buf;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 @8358 hdr->smb2_buf_length = cpu_to_be32(buf_data_size);
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8359
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8360 return rc;
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8361 }
e2f34481b24db2 fs/cifsd/smb2pdu.c Namjae Jeon 2021-03-16 8362 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org