ksmbd: remove smb2_buf_length in smb2_hdr
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. Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
This commit is contained in:
parent
561a1cf575
commit
cb4517201b
10 changed files with 260 additions and 262 deletions
|
@ -873,9 +873,9 @@ int ksmbd_gen_preauth_integrity_hash(struct ksmbd_conn *conn, char *buf,
|
||||||
__u8 *pi_hash)
|
__u8 *pi_hash)
|
||||||
{
|
{
|
||||||
int rc;
|
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;
|
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;
|
struct ksmbd_crypto_ctx *ctx = NULL;
|
||||||
|
|
||||||
if (conn->preauth_info->Preauth_HashId !=
|
if (conn->preauth_info->Preauth_HashId !=
|
||||||
|
|
|
@ -158,14 +158,13 @@ void ksmbd_conn_wait_idle(struct ksmbd_conn *conn)
|
||||||
int ksmbd_conn_write(struct ksmbd_work *work)
|
int ksmbd_conn_write(struct ksmbd_work *work)
|
||||||
{
|
{
|
||||||
struct ksmbd_conn *conn = work->conn;
|
struct ksmbd_conn *conn = work->conn;
|
||||||
struct smb_hdr *rsp_hdr = work->response_buf;
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
int sent;
|
int sent;
|
||||||
struct kvec iov[3];
|
struct kvec iov[3];
|
||||||
int iov_idx = 0;
|
int iov_idx = 0;
|
||||||
|
|
||||||
ksmbd_conn_try_dequeue_request(work);
|
ksmbd_conn_try_dequeue_request(work);
|
||||||
if (!rsp_hdr) {
|
if (!work->response_buf) {
|
||||||
pr_err("NULL response header\n");
|
pr_err("NULL response header\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +176,7 @@ int ksmbd_conn_write(struct ksmbd_work *work)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (work->aux_payload_sz) {
|
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;
|
len += iov[iov_idx++].iov_len;
|
||||||
iov[iov_idx] = (struct kvec) { work->aux_payload_buf, work->aux_payload_sz };
|
iov[iov_idx] = (struct kvec) { work->aux_payload_buf, work->aux_payload_sz };
|
||||||
len += iov[iov_idx++].iov_len;
|
len += iov[iov_idx++].iov_len;
|
||||||
|
@ -185,8 +184,8 @@ int ksmbd_conn_write(struct ksmbd_work *work)
|
||||||
if (work->tr_buf)
|
if (work->tr_buf)
|
||||||
iov[iov_idx].iov_len = work->resp_hdr_sz;
|
iov[iov_idx].iov_len = work->resp_hdr_sz;
|
||||||
else
|
else
|
||||||
iov[iov_idx].iov_len = get_rfc1002_len(rsp_hdr) + 4;
|
iov[iov_idx].iov_len = get_rfc1002_len(work->response_buf) + 4;
|
||||||
iov[iov_idx].iov_base = rsp_hdr;
|
iov[iov_idx].iov_base = work->response_buf;
|
||||||
len += iov[iov_idx++].iov_len;
|
len += iov[iov_idx++].iov_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ struct ksmbd_work {
|
||||||
*/
|
*/
|
||||||
static inline void *ksmbd_resp_buf_next(struct ksmbd_work *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)
|
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);
|
struct ksmbd_work *ksmbd_alloc_work_struct(void);
|
||||||
|
|
|
@ -629,10 +629,10 @@ static void __smb2_oplock_break_noti(struct work_struct *wk)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp_hdr = work->response_buf;
|
rsp_hdr = smb2_get_msg(work->response_buf);
|
||||||
memset(rsp_hdr, 0, sizeof(struct smb2_hdr) + 2);
|
memset(rsp_hdr, 0, sizeof(struct smb2_hdr) + 2);
|
||||||
rsp_hdr->smb2_buf_length =
|
*(__be32 *)work->response_buf =
|
||||||
cpu_to_be32(smb2_hdr_size_no_buflen(conn->vals));
|
cpu_to_be32(conn->vals->header_size);
|
||||||
rsp_hdr->ProtocolId = SMB2_PROTO_NUMBER;
|
rsp_hdr->ProtocolId = SMB2_PROTO_NUMBER;
|
||||||
rsp_hdr->StructureSize = SMB2_HEADER_STRUCTURE_SIZE;
|
rsp_hdr->StructureSize = SMB2_HEADER_STRUCTURE_SIZE;
|
||||||
rsp_hdr->CreditRequest = cpu_to_le16(0);
|
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;
|
rsp_hdr->SessionId = 0;
|
||||||
memset(rsp_hdr->Signature, 0, 16);
|
memset(rsp_hdr->Signature, 0, 16);
|
||||||
|
|
||||||
rsp = work->response_buf;
|
rsp = smb2_get_msg(work->response_buf);
|
||||||
|
|
||||||
rsp->StructureSize = cpu_to_le16(24);
|
rsp->StructureSize = cpu_to_le16(24);
|
||||||
if (!br_info->open_trunc &&
|
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->PersistentFid = cpu_to_le64(fp->persistent_id);
|
||||||
rsp->VolatileFid = cpu_to_le64(fp->volatile_id);
|
rsp->VolatileFid = cpu_to_le64(fp->volatile_id);
|
||||||
|
|
||||||
inc_rfc1001_len(rsp, 24);
|
inc_rfc1001_len(work->response_buf, 24);
|
||||||
|
|
||||||
ksmbd_debug(OPLOCK,
|
ksmbd_debug(OPLOCK,
|
||||||
"sending oplock break v_id %llu p_id = %llu lock level = %d\n",
|
"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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp_hdr = work->response_buf;
|
rsp_hdr = smb2_get_msg(work->response_buf);
|
||||||
memset(rsp_hdr, 0, sizeof(struct smb2_hdr) + 2);
|
memset(rsp_hdr, 0, sizeof(struct smb2_hdr) + 2);
|
||||||
rsp_hdr->smb2_buf_length =
|
*(__be32 *)work->response_buf =
|
||||||
cpu_to_be32(smb2_hdr_size_no_buflen(conn->vals));
|
cpu_to_be32(conn->vals->header_size);
|
||||||
rsp_hdr->ProtocolId = SMB2_PROTO_NUMBER;
|
rsp_hdr->ProtocolId = SMB2_PROTO_NUMBER;
|
||||||
rsp_hdr->StructureSize = SMB2_HEADER_STRUCTURE_SIZE;
|
rsp_hdr->StructureSize = SMB2_HEADER_STRUCTURE_SIZE;
|
||||||
rsp_hdr->CreditRequest = cpu_to_le16(0);
|
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;
|
rsp_hdr->SessionId = 0;
|
||||||
memset(rsp_hdr->Signature, 0, 16);
|
memset(rsp_hdr->Signature, 0, 16);
|
||||||
|
|
||||||
rsp = work->response_buf;
|
rsp = smb2_get_msg(work->response_buf);
|
||||||
rsp->StructureSize = cpu_to_le16(44);
|
rsp->StructureSize = cpu_to_le16(44);
|
||||||
rsp->Epoch = br_info->epoch;
|
rsp->Epoch = br_info->epoch;
|
||||||
rsp->Flags = 0;
|
rsp->Flags = 0;
|
||||||
|
@ -768,7 +768,7 @@ static void __smb2_lease_break_noti(struct work_struct *wk)
|
||||||
rsp->AccessMaskHint = 0;
|
rsp->AccessMaskHint = 0;
|
||||||
rsp->ShareMaskHint = 0;
|
rsp->ShareMaskHint = 0;
|
||||||
|
|
||||||
inc_rfc1001_len(rsp, 44);
|
inc_rfc1001_len(work->response_buf, 44);
|
||||||
|
|
||||||
ksmbd_conn_write(work);
|
ksmbd_conn_write(work);
|
||||||
ksmbd_free_work_struct(work);
|
ksmbd_free_work_struct(work);
|
||||||
|
@ -1398,7 +1398,7 @@ struct lease_ctx_info *parse_lease_state(void *open_req)
|
||||||
if (!lreq)
|
if (!lreq)
|
||||||
return NULL;
|
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;
|
cc = (struct create_context *)data_offset;
|
||||||
do {
|
do {
|
||||||
cc = (struct create_context *)((char *)cc + next);
|
cc = (struct create_context *)((char *)cc + next);
|
||||||
|
@ -1462,7 +1462,7 @@ struct create_context *smb2_find_context_vals(void *open_req, const char *tag)
|
||||||
* CreateContextsOffset and CreateContextsLength are guaranteed to
|
* CreateContextsOffset and CreateContextsLength are guaranteed to
|
||||||
* be valid because of ksmbd_smb2_check_message().
|
* 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));
|
le32_to_cpu(req->CreateContextsOffset));
|
||||||
remain_len = le32_to_cpu(req->CreateContextsLength);
|
remain_len = le32_to_cpu(req->CreateContextsLength);
|
||||||
do {
|
do {
|
||||||
|
|
|
@ -351,7 +351,7 @@ int ksmbd_smb2_check_message(struct ksmbd_work *work)
|
||||||
struct smb2_hdr *hdr = &pdu->hdr;
|
struct smb2_hdr *hdr = &pdu->hdr;
|
||||||
int command;
|
int command;
|
||||||
__u32 clc_len; /* calculated length */
|
__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)
|
if (le32_to_cpu(hdr->NextCommand) > 0)
|
||||||
len = le32_to_cpu(hdr->NextCommand);
|
len = le32_to_cpu(hdr->NextCommand);
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -130,11 +130,6 @@
|
||||||
cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
|
cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
|
||||||
|
|
||||||
struct smb2_hdr {
|
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' */
|
__le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
|
||||||
__le16 StructureSize; /* 64 */
|
__le16 StructureSize; /* 64 */
|
||||||
__le16 CreditCharge; /* MBZ */
|
__le16 CreditCharge; /* MBZ */
|
||||||
|
@ -253,14 +248,14 @@ struct preauth_integrity_info {
|
||||||
__u8 Preauth_HashValue[PREAUTH_HASHVALUE_SIZE];
|
__u8 Preauth_HashValue[PREAUTH_HASHVALUE_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* offset is sizeof smb2_negotiate_rsp - 4 but rounded up to 8 bytes. */
|
/* offset is sizeof smb2_negotiate_rsp but rounded up to 8 bytes. */
|
||||||
#ifdef CONFIG_SMB_SERVER_KERBEROS5
|
#ifdef CONFIG_SMB_SERVER_KERBEROS5
|
||||||
/* sizeof(struct smb2_negotiate_rsp) - 4 =
|
/* sizeof(struct smb2_negotiate_rsp) =
|
||||||
* header(64) + response(64) + GSS_LENGTH(96) + GSS_PADDING(0)
|
* header(64) + response(64) + GSS_LENGTH(96) + GSS_PADDING(0)
|
||||||
*/
|
*/
|
||||||
#define OFFSET_OF_NEG_CONTEXT 0xe0
|
#define OFFSET_OF_NEG_CONTEXT 0xe0
|
||||||
#else
|
#else
|
||||||
/* sizeof(struct smb2_negotiate_rsp) - 4 =
|
/* sizeof(struct smb2_negotiate_rsp) =
|
||||||
* header(64) + response(64) + GSS_LENGTH(74) + GSS_PADDING(6)
|
* header(64) + response(64) + GSS_LENGTH(74) + GSS_PADDING(6)
|
||||||
*/
|
*/
|
||||||
#define OFFSET_OF_NEG_CONTEXT 0xd0
|
#define OFFSET_OF_NEG_CONTEXT 0xd0
|
||||||
|
@ -1705,4 +1700,13 @@ int smb2_ioctl(struct ksmbd_work *work);
|
||||||
int smb2_oplock_break(struct ksmbd_work *work);
|
int smb2_oplock_break(struct ksmbd_work *work);
|
||||||
int smb2_notify(struct ksmbd_work *ksmbd_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 */
|
#endif /* _SMB2PDU_H */
|
||||||
|
|
|
@ -239,14 +239,14 @@ int ksmbd_lookup_dialect_by_id(__le16 *cli_dialects, __le16 dialects_count)
|
||||||
static int ksmbd_negotiate_smb_dialect(void *buf)
|
static int ksmbd_negotiate_smb_dialect(void *buf)
|
||||||
{
|
{
|
||||||
int smb_buf_length = get_rfc1002_len(buf);
|
int smb_buf_length = get_rfc1002_len(buf);
|
||||||
__le32 proto = ((struct smb2_hdr *)buf)->ProtocolId;
|
__le32 proto = ((struct smb2_hdr *)smb2_get_msg(buf))->ProtocolId;
|
||||||
|
|
||||||
if (proto == SMB2_PROTO_NUMBER) {
|
if (proto == SMB2_PROTO_NUMBER) {
|
||||||
struct smb2_negotiate_req *req;
|
struct smb2_negotiate_req *req;
|
||||||
int smb2_neg_size =
|
int smb2_neg_size =
|
||||||
offsetof(struct smb2_negotiate_req, Dialects) - 4;
|
offsetof(struct smb2_negotiate_req, Dialects);
|
||||||
|
|
||||||
req = (struct smb2_negotiate_req *)buf;
|
req = (struct smb2_negotiate_req *)smb2_get_msg(buf);
|
||||||
if (smb2_neg_size > smb_buf_length)
|
if (smb2_neg_size > smb_buf_length)
|
||||||
goto err_out;
|
goto err_out;
|
||||||
|
|
||||||
|
@ -445,11 +445,12 @@ int ksmbd_smb_negotiate_common(struct ksmbd_work *work, unsigned int command)
|
||||||
struct ksmbd_conn *conn = work->conn;
|
struct ksmbd_conn *conn = work->conn;
|
||||||
int ret;
|
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);
|
ksmbd_debug(SMB, "conn->dialect 0x%x\n", conn->dialect);
|
||||||
|
|
||||||
if (command == SMB2_NEGOTIATE_HE) {
|
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) {
|
if (smb2_hdr->ProtocolId != SMB2_PROTO_NUMBER) {
|
||||||
ksmbd_debug(SMB, "Downgrade to SMB1 negotiation\n");
|
ksmbd_debug(SMB, "Downgrade to SMB1 negotiation\n");
|
||||||
|
|
|
@ -477,12 +477,6 @@ struct smb_version_cmds {
|
||||||
int (*proc)(struct ksmbd_work *swork);
|
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_min_protocol(void);
|
||||||
int ksmbd_max_protocol(void);
|
int ksmbd_max_protocol(void);
|
||||||
|
|
||||||
|
|
|
@ -484,7 +484,7 @@ static int smb_direct_check_recvmsg(struct smb_direct_recvmsg *recvmsg)
|
||||||
struct smb_direct_data_transfer *req =
|
struct smb_direct_data_transfer *req =
|
||||||
(struct smb_direct_data_transfer *)recvmsg->packet;
|
(struct smb_direct_data_transfer *)recvmsg->packet;
|
||||||
struct smb2_hdr *hdr = (struct smb2_hdr *)(recvmsg->packet
|
struct smb2_hdr *hdr = (struct smb2_hdr *)(recvmsg->packet
|
||||||
+ le32_to_cpu(req->data_offset) - 4);
|
+ le32_to_cpu(req->data_offset));
|
||||||
ksmbd_debug(RDMA,
|
ksmbd_debug(RDMA,
|
||||||
"CreditGranted: %u, CreditRequested: %u, DataLength: %u, RemainingDataLength: %u, SMB: %x, Command: %u\n",
|
"CreditGranted: %u, CreditRequested: %u, DataLength: %u, RemainingDataLength: %u, SMB: %x, Command: %u\n",
|
||||||
le16_to_cpu(req->credits_granted),
|
le16_to_cpu(req->credits_granted),
|
||||||
|
|
Loading…
Add table
Reference in a new issue