提交 2dd9129f 编写于 作者: N Namjae Jeon 提交者: Steve French

ksmbd: remove smb2_buf_length in smb2_transform_hdr

To move smb2_transform_hdr to smbfs_common, This patch remove
smb2_buf_length variable in smb2_transform_hdr.

Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Signed-off-by: NNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: NSteve French <stfrench@microsoft.com>
上级 cb451720
...@@ -983,7 +983,7 @@ static struct scatterlist *ksmbd_init_sg(struct kvec *iov, unsigned int nvec, ...@@ -983,7 +983,7 @@ static struct scatterlist *ksmbd_init_sg(struct kvec *iov, unsigned int nvec,
u8 *sign) u8 *sign)
{ {
struct scatterlist *sg; 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; int i, nr_entries[3] = {0}, total_entries = 0, sg_idx = 0;
if (!nvec) if (!nvec)
...@@ -1047,9 +1047,8 @@ static struct scatterlist *ksmbd_init_sg(struct kvec *iov, unsigned int nvec, ...@@ -1047,9 +1047,8 @@ static struct scatterlist *ksmbd_init_sg(struct kvec *iov, unsigned int nvec,
int ksmbd_crypt_message(struct ksmbd_conn *conn, struct kvec *iov, int ksmbd_crypt_message(struct ksmbd_conn *conn, struct kvec *iov,
unsigned int nvec, int enc) unsigned int nvec, int enc)
{ {
struct smb2_transform_hdr *tr_hdr = struct smb2_transform_hdr *tr_hdr = smb2_get_msg(iov[0].iov_base);
(struct smb2_transform_hdr *)iov[0].iov_base; unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 20;
unsigned int assoc_data_len = sizeof(struct smb2_transform_hdr) - 24;
int rc; int rc;
struct scatterlist *sg; struct scatterlist *sg;
u8 sign[SMB2_SIGNATURE_SIZE] = {}; u8 sign[SMB2_SIGNATURE_SIZE] = {};
......
...@@ -171,7 +171,7 @@ int ksmbd_conn_write(struct ksmbd_work *work) ...@@ -171,7 +171,7 @@ int ksmbd_conn_write(struct ksmbd_work *work)
if (work->tr_buf) { if (work->tr_buf) {
iov[iov_idx] = (struct kvec) { 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; len += iov[iov_idx++].iov_len;
} }
......
...@@ -8424,13 +8424,13 @@ void smb3_preauth_hash_rsp(struct ksmbd_work *work) ...@@ -8424,13 +8424,13 @@ void smb3_preauth_hash_rsp(struct ksmbd_work *work)
} }
} }
static void fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, char *old_buf, static void fill_transform_hdr(void *tr_buf, char *old_buf, __le16 cipher_type)
__le16 cipher_type)
{ {
struct smb2_hdr *hdr = (struct smb2_hdr *)old_buf; struct smb2_transform_hdr *tr_hdr = tr_buf + 4;
struct smb2_hdr *hdr = smb2_get_msg(old_buf);
unsigned int orig_len = get_rfc1002_len(old_buf); unsigned int orig_len = get_rfc1002_len(old_buf);
memset(tr_hdr, 0, sizeof(struct smb2_transform_hdr)); memset(tr_buf, 0, sizeof(struct smb2_transform_hdr) + 4);
tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM; tr_hdr->ProtocolId = SMB2_TRANSFORM_PROTO_NUM;
tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len); tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
tr_hdr->Flags = cpu_to_le16(0x01); tr_hdr->Flags = cpu_to_le16(0x01);
...@@ -8440,14 +8440,13 @@ static void fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, char *old_buf, ...@@ -8440,14 +8440,13 @@ static void fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, char *old_buf,
else else
get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE); get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
memcpy(&tr_hdr->SessionId, &hdr->SessionId, 8); memcpy(&tr_hdr->SessionId, &hdr->SessionId, 8);
inc_rfc1001_len(tr_hdr, sizeof(struct smb2_transform_hdr) - 4); inc_rfc1001_len(tr_buf, sizeof(struct smb2_transform_hdr));
inc_rfc1001_len(tr_hdr, orig_len); inc_rfc1001_len(tr_buf, orig_len);
} }
int smb3_encrypt_resp(struct ksmbd_work *work) int smb3_encrypt_resp(struct ksmbd_work *work)
{ {
char *buf = work->response_buf; char *buf = work->response_buf;
struct smb2_transform_hdr *tr_hdr;
struct kvec iov[3]; struct kvec iov[3];
int rc = -ENOMEM; int rc = -ENOMEM;
int buf_size = 0, rq_nvec = 2 + (work->aux_payload_sz ? 1 : 0); int buf_size = 0, rq_nvec = 2 + (work->aux_payload_sz ? 1 : 0);
...@@ -8455,15 +8454,15 @@ int smb3_encrypt_resp(struct ksmbd_work *work) ...@@ -8455,15 +8454,15 @@ int smb3_encrypt_resp(struct ksmbd_work *work)
if (ARRAY_SIZE(iov) < rq_nvec) if (ARRAY_SIZE(iov) < rq_nvec)
return -ENOMEM; return -ENOMEM;
tr_hdr = kzalloc(sizeof(struct smb2_transform_hdr), GFP_KERNEL); work->tr_buf = kzalloc(sizeof(struct smb2_transform_hdr) + 4, GFP_KERNEL);
if (!tr_hdr) if (!work->tr_buf)
return rc; return rc;
/* fill transform header */ /* fill transform header */
fill_transform_hdr(tr_hdr, buf, work->conn->cipher_type); fill_transform_hdr(work->tr_buf, buf, work->conn->cipher_type);
iov[0].iov_base = tr_hdr; iov[0].iov_base = work->tr_buf;
iov[0].iov_len = sizeof(struct smb2_transform_hdr); iov[0].iov_len = sizeof(struct smb2_transform_hdr) + 4;
buf_size += iov[0].iov_len - 4; buf_size += iov[0].iov_len - 4;
iov[1].iov_base = buf + 4; iov[1].iov_base = buf + 4;
...@@ -8483,15 +8482,14 @@ int smb3_encrypt_resp(struct ksmbd_work *work) ...@@ -8483,15 +8482,14 @@ int smb3_encrypt_resp(struct ksmbd_work *work)
return rc; return rc;
memmove(buf, iov[1].iov_base, iov[1].iov_len); memmove(buf, iov[1].iov_base, iov[1].iov_len);
tr_hdr->smb2_buf_length = cpu_to_be32(buf_size); *(__be32 *)work->tr_buf = cpu_to_be32(buf_size);
work->tr_buf = tr_hdr;
return rc; return rc;
} }
bool smb3_is_transform_hdr(void *buf) bool smb3_is_transform_hdr(void *buf)
{ {
struct smb2_transform_hdr *trhdr = buf; struct smb2_transform_hdr *trhdr = smb2_get_msg(buf);
return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM; return trhdr->ProtocolId == SMB2_TRANSFORM_PROTO_NUM;
} }
...@@ -8503,9 +8501,8 @@ int smb3_decrypt_req(struct ksmbd_work *work) ...@@ -8503,9 +8501,8 @@ int smb3_decrypt_req(struct ksmbd_work *work)
char *buf = work->request_buf; char *buf = work->request_buf;
unsigned int pdu_length = get_rfc1002_len(buf); unsigned int pdu_length = get_rfc1002_len(buf);
struct kvec iov[2]; struct kvec iov[2];
int buf_data_size = pdu_length + 4 - int buf_data_size = pdu_length - sizeof(struct smb2_transform_hdr);
sizeof(struct smb2_transform_hdr); struct smb2_transform_hdr *tr_hdr = smb2_get_msg(buf);
struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
int rc = 0; int rc = 0;
if (buf_data_size < sizeof(struct smb2_hdr)) { if (buf_data_size < sizeof(struct smb2_hdr)) {
...@@ -8527,8 +8524,8 @@ int smb3_decrypt_req(struct ksmbd_work *work) ...@@ -8527,8 +8524,8 @@ int smb3_decrypt_req(struct ksmbd_work *work)
} }
iov[0].iov_base = buf; iov[0].iov_base = buf;
iov[0].iov_len = sizeof(struct smb2_transform_hdr); iov[0].iov_len = sizeof(struct smb2_transform_hdr) + 4;
iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr); iov[1].iov_base = buf + sizeof(struct smb2_transform_hdr) + 4;
iov[1].iov_len = buf_data_size; iov[1].iov_len = buf_data_size;
rc = ksmbd_crypt_message(conn, iov, 2, 0); rc = ksmbd_crypt_message(conn, iov, 2, 0);
if (rc) if (rc)
......
...@@ -159,11 +159,6 @@ struct smb2_pdu { ...@@ -159,11 +159,6 @@ struct smb2_pdu {
#define SMB3_AES_GCM_NONCE 12 #define SMB3_AES_GCM_NONCE 12
struct smb2_transform_hdr { struct 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' */ __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
__u8 Signature[16]; __u8 Signature[16];
__u8 Nonce[16]; __u8 Nonce[16];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册