Skip to contentSkip to conversation

ksmbd: use buf_data_size instead of recalculation in smb3_decrypt_req()

PATCH In review Namjae Jeon 2 participants 2 messages Oct 5, 2021

Subsystems (2)
lore
Share & tools
lore

Namjae Jeon

author maintainer
#0 lore raw

PATCH v2 1/1 ksmbd: use buf_data_size instead of recalculation in smb3_decrypt_req()

Tom suggested to use buf_data_size that is already calculated, to verify these offsets.

Cc Tom Talpey <[email protected]>
Cc Ronnie Sahlberg <[email protected]>
Cc Ralph Böhme <[email protected]>
Cc Steve French <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Hyunchul Lee <[email protected]>

---
v2:
- change data type of buf_data_size to signed to validate smb2_transfrom_hdr size.

 fs/ksmbd/smb2pdu.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
fs/ksmbd/smb2pdu.c +3 -5
index b06361313889..bb030e4366ad 100644
@@ -8452,20 +8452,18 @@ int smb3_decrypt_req(struct ksmbd_work *work)
 	struct smb2_hdr *hdr;
 	unsigned int pdu_length = get_rfc1002_len(buf);
 	struct kvec iov[2];
-	unsigned int buf_data_size = pdu_length + 4 -
+	int buf_data_size = pdu_length + 4 -
 		sizeof(struct smb2_transform_hdr);
 	struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
 	int rc = 0;
 
-	if (pdu_length + 4 <
-	    sizeof(struct smb2_transform_hdr) + sizeof(struct smb2_hdr)) {
+	if (buf_data_size < sizeof(struct smb2_hdr)) {
 		pr_err("Transform message is too small (%u)\n",
 		       pdu_length);
 		return -ECONNABORTED;
 	}
 
-	if (pdu_length + 4 <
-	    le32_to_cpu(tr_hdr->OriginalMessageSize) + sizeof(struct smb2_transform_hdr)) {
+	if (buf_data_size < le32_to_cpu(tr_hdr->OriginalMessageSize)) {
 		pr_err("Transform message is broken\n");
 		return -ECONNABORTED;
 	}
Signature · 1 line
2.25.1
Acked-by on v2 1/1
#1 lore raw

Looks good to me.

2021년 10월 5일 (화) 오전 10:20, Namjae Jeon <[email protected]>님이 작성:

Quoted 48 lines

Tom suggested to use buf_data_size that is already calculated, to verify these offsets.

Cc Tom Talpey <[email protected]>
Cc Ronnie Sahlberg <[email protected]>
Cc Ralph Böhme <[email protected]>
Cc Steve French <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Hyunchul Lee <[email protected]>

---
v2:
- change data type of buf_data_size to signed to validate smb2_transfrom_hdr size.

 fs/ksmbd/smb2pdu.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
fs/ksmbd/smb2pdu.c +3 -6
index b06361313889..bb030e4366ad 100644
@@ -8452,20 +8452,18 @@ int smb3_decrypt_req(struct ksmbd_work *work)
        struct smb2_hdr *hdr;
        unsigned int pdu_length = get_rfc1002_len(buf);
        struct kvec iov[2];
-       unsigned int buf_data_size = pdu_length + 4 -
+       int buf_data_size = pdu_length + 4 -
                sizeof(struct smb2_transform_hdr);
        struct smb2_transform_hdr *tr_hdr = (struct smb2_transform_hdr *)buf;
        int rc = 0;
 
-       if (pdu_length + 4 <
-           sizeof(struct smb2_transform_hdr) + sizeof(struct smb2_hdr)) {
+       if (buf_data_size < sizeof(struct smb2_hdr)) {
                pr_err("Transform message is too small (%u)\n",
                       pdu_length);
                return -ECONNABORTED;
        }
 
-       if (pdu_length + 4 <
-           le32_to_cpu(tr_hdr->OriginalMessageSize) + sizeof(struct smb2_transform_hdr)) {
+       if (buf_data_size < le32_to_cpu(tr_hdr->OriginalMessageSize)) {
                pr_err("Transform message is broken\n");
                return -ECONNABORTED;
        }
--
Quoted 2 lines

2.25.1

--
Thanks,
Hyunchul