Skip to content

Commit

Permalink
ksmbd: remove smb2_buf_length in smb2_hdr
Browse files Browse the repository at this point in the history
To move smb2_hdr to smbfs_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.

Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
namjaejeon committed Jan 20, 2022
1 parent cf08ca6 commit 9bb4c47
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 264 deletions.
4 changes: 2 additions & 2 deletions auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,9 +1148,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 !=
Expand Down
9 changes: 4 additions & 5 deletions connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,13 @@ void ksmbd_conn_wait_idle(struct ksmbd_conn *conn)
int ksmbd_conn_write(struct ksmbd_work *work)
{
struct ksmbd_conn *conn = work->conn;
struct smb_hdr *rsp_hdr = work->response_buf;
size_t len = 0;
int sent;
struct kvec iov[3];
int iov_idx = 0;

ksmbd_conn_try_dequeue_request(work);
if (!rsp_hdr) {
if (!work->response_buf) {
pr_err("NULL response header\n");
return -EINVAL;
}
Expand All @@ -194,16 +193,16 @@ int ksmbd_conn_write(struct ksmbd_work *work)
}

if (work->aux_payload_sz) {
iov[iov_idx] = (struct kvec) { rsp_hdr, work->resp_hdr_sz };
iov[iov_idx] = (struct kvec) { work->response_buf, work->resp_hdr_sz };
len += iov[iov_idx++].iov_len;
iov[iov_idx] = (struct kvec) { work->aux_payload_buf, work->aux_payload_sz };
len += iov[iov_idx++].iov_len;
} else {
if (work->tr_buf)
iov[iov_idx].iov_len = work->resp_hdr_sz;
else
iov[iov_idx].iov_len = get_rfc1002_len(rsp_hdr) + 4;
iov[iov_idx].iov_base = rsp_hdr;
iov[iov_idx].iov_len = get_rfc1002_len(work->response_buf) + 4;
iov[iov_idx].iov_base = work->response_buf;
len += iov[iov_idx++].iov_len;
}

Expand Down
4 changes: 2 additions & 2 deletions ksmbd_work.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions oplock.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ static void __smb1_oplock_break_noti(struct work_struct *wk)
/* wct is 8 for locking andx(18) */
memset(rsp_hdr, 0, sizeof(struct smb_hdr) + 18);
rsp_hdr->smb_buf_length =
cpu_to_be32(smb2_hdr_size_no_buflen(conn->vals) + 18);
cpu_to_be32(conn->vals->header_size - 4 + 18);
rsp_hdr->Protocol[0] = 0xFF;
rsp_hdr->Protocol[1] = 'S';
rsp_hdr->Protocol[2] = 'M';
Expand Down Expand Up @@ -833,10 +833,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);
Expand All @@ -849,7 +849,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 &&
Expand All @@ -863,7 +863,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",
Expand Down Expand Up @@ -940,10 +940,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);
Expand All @@ -956,7 +956,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;
Expand All @@ -972,7 +972,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);
Expand Down Expand Up @@ -1647,7 +1647,7 @@ struct lease_ctx_info *parse_lease_state(void *open_req)
if (!lreq)
return NULL;

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 {
cc = (struct create_context *)((char *)cc + next);
Expand Down Expand Up @@ -1711,7 +1711,7 @@ struct create_context *smb2_find_context_vals(void *open_req, const char *tag)
* CreateContextsOffset and CreateContextsLength are guaranteed to
* be valid because of ksmbd_smb2_check_message().
*/
cc = (struct create_context *)((char *)req + 4 +
cc = (struct create_context *)((char *)req +
le32_to_cpu(req->CreateContextsOffset));
remain_len = le32_to_cpu(req->CreateContextsLength);
do {
Expand Down
2 changes: 1 addition & 1 deletion smb1pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int init_smb_rsp_hdr(struct ksmbd_work *work)

/* remove 4 byte direct TCP header, add 1 byte wc and 2 byte bcc */
rsp_hdr->smb_buf_length =
cpu_to_be32(smb2_hdr_size_no_buflen(conn->vals) + 2);
cpu_to_be32(conn->vals->header_size - 4 + 2);
memcpy(rsp_hdr->Protocol, rcv_hdr->Protocol, 4);
rsp_hdr->Command = rcv_hdr->Command;

Expand Down
2 changes: 1 addition & 1 deletion smb2misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
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 (le32_to_cpu(hdr->NextCommand) > 0)
len = le32_to_cpu(hdr->NextCommand);
Expand Down
Loading

0 comments on commit 9bb4c47

Please sign in to comment.