@@ -432,3 +432,28 @@ int smb2_negotiate_request(struct ksmbd_work *work)
{
return ksmbd_smb_negotiate_common(work, SMB2_NEGOTIATE_HE);
}
+
+/**
+ * ksmbd_smb2_cur_pdu_buflen() - Get len of current SMB2 PDU buffer
+ * This returns the lenght including any possible padding.
+ * @work: smb work containing request buffer
+ */
+unsigned int ksmbd_smb2_cur_pdu_buflen(struct ksmbd_work *work)
+{
+ struct smb2_hdr *hdr = ksmbd_req_buf_next(work);
+ unsigned int buf_len;
+ unsigned int pdu_len;
+
+ if (hdr->NextCommand != 0) {
+ /*
+ * hdr->NextCommand has already been validated by
+ * init_chained_smb2_rsp().
+ */
+ return __le32_to_cpu(hdr->NextCommand);
+ }
+
+ buf_len = get_rfc1002_len(work->request_buf);
+ pdu_len = buf_len - work->next_smb2_rcv_hdr_off;
+ return pdu_len;
+}
+
@@ -1680,6 +1680,7 @@ int smb2_set_rsp_credits(struct ksmbd_work *work);
/* smb2 misc functions */
int ksmbd_smb2_check_message(struct ksmbd_work *work);
+unsigned int ksmbd_smb2_cur_pdu_buflen(struct ksmbd_work *work);
/* smb2 command handlers */
int smb2_handle_negotiate(struct ksmbd_work *work);
@@ -133,8 +133,16 @@ int ksmbd_lookup_protocol_idx(char *str)
int ksmbd_verify_smb_message(struct ksmbd_work *work)
{
struct smb2_hdr *smb2_hdr = ksmbd_req_buf_next(work);
+ unsigned int buflen = ksmbd_smb2_cur_pdu_buflen(work);
struct smb_hdr *hdr;
+ /*
+ * ksmbd_smb2_check_message() will verify all SMB2 PDU buffer sizes,
+ * here we just check we can access the ProtocolId field in the header.
+ */
+ if (buflen < sizeof(smb2_hdr->ProtocolId))
+ return -EINVAL;
+
if (smb2_hdr->ProtocolId == SMB2_PROTO_NUMBER)
return ksmbd_smb2_check_message(work);
Signed-off-by: Ralph Boehme <slow@samba.org> --- fs/ksmbd/smb2misc.c | 25 +++++++++++++++++++++++++ fs/ksmbd/smb2pdu.h | 1 + fs/ksmbd/smb_common.c | 8 ++++++++ 3 files changed, 34 insertions(+)