Skip to contentSkip to conversation

cifs: check offset in decode_ntlmssp_challenge()

PATCH Applied Dan Carpenter 3 participants 6 messages Jan 31, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: check offset in decode_ntlmssp_challenge()

We should check that we're not copying memory from beyond the end of the blob.

fs/cifs/sess.c +4 -0
index d85efad..eb76741 100644
@@ -395,6 +395,10 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
 	ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags);
 	tioffset = le32_to_cpu(pblob->TargetInfoArray.BufferOffset);
 	tilen = le16_to_cpu(pblob->TargetInfoArray.Length);
+	if (tioffset > blob_len || tioffset + tilen > blob_len) {
+		cERROR(1, "tioffset + tilen too high %u + %u", tioffset, tilen);
+		return -EINVAL;
+	}
 	if (tilen) {
 		ses->auth_key.response = kmalloc(tilen, GFP_KERNEL);
 		if (!ses->auth_key.response) {
#1 lore raw
Quoted 10 lines · On Tue, 31 Jan 2012 11:52:01 +0300 Dan Carpenter <[email protected]>…

We should check that we're not copying memory from beyond the end of the blob.

fs/cifs/sess.c +0 -0
index d85efad..eb76741 100644

fs/cifs/sess.c static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, · line 401

Quoted 7 lines
fs/cifs/sess.c +4 -0
@@ -395,6 +395,10 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
 	ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags);
 	tioffset = le32_to_cpu(pblob->TargetInfoArray.BufferOffset);
 	tilen = le16_to_cpu(pblob->TargetInfoArray.Length);
+	if (tioffset > blob_len || tioffset + tilen > blob_len) {
+		cERROR(1, "tioffset + tilen too high %u + %u", tioffset, tilen);
+		return -EINVAL;
+	}

Good catch.

Do we really need a || here though? Would it not be sufficient to check if tioffset + tilen > blob_len? Or are you concerned about that value wrapping?

Quoted 7 lines
fs/cifs/sess.c +0 -1
 	if (tilen) {
 		ses->auth_key.response = kmalloc(tilen, GFP_KERNEL);
 		if (!ses->auth_key.response) {
--

To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Jeff Layton <[email protected]>
#2 lore raw
Quoted 23 lines · Jeff Layton
Quoted 10 lines · On Tue, 31 Jan 2012 11:52:01 +0300 Dan Carpenter <[email protected]>…

We should check that we're not copying memory from beyond the end of the blob.

fs/cifs/sess.c +0 -0
index d85efad..eb76741 100644

fs/cifs/sess.c static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, · line 401

Quoted 7 lines
fs/cifs/sess.c +4 -0
@@ -395,6 +395,10 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
 	ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags);
 	tioffset = le32_to_cpu(pblob->TargetInfoArray.BufferOffset);
 	tilen = le16_to_cpu(pblob->TargetInfoArray.Length);
+	if (tioffset > blob_len || tioffset + tilen > blob_len) {
+		cERROR(1, "tioffset + tilen too high %u + %u", tioffset, tilen);
+		return -EINVAL;
+	}

Good catch.

Quoted 3 lines

Do we really need a || here though? Would it not be sufficient to check if tioffset + tilen > blob_len? Or are you concerned about that value wrapping?

Yep. I was concerned about value wrapping.

regards,
dan carpenter

Reviewed-by
#3 lore raw
Quoted 24 lines · On Tue, 31 Jan 2012 14:25:08 +0300 Dan Carpenter <[email protected]>…
Quoted 23 lines · Jeff Layton
Quoted 10 lines · On Tue, 31 Jan 2012 11:52:01 +0300 Dan Carpenter <[email protected]>…

We should check that we're not copying memory from beyond the end of the blob.

fs/cifs/sess.c +0 -0
index d85efad..eb76741 100644

fs/cifs/sess.c static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, · line 401

Quoted 7 lines
fs/cifs/sess.c +4 -0
@@ -395,6 +395,10 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
 	ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags);
 	tioffset = le32_to_cpu(pblob->TargetInfoArray.BufferOffset);
 	tilen = le16_to_cpu(pblob->TargetInfoArray.Length);
+	if (tioffset > blob_len || tioffset + tilen > blob_len) {
+		cERROR(1, "tioffset + tilen too high %u + %u", tioffset, tilen);
+		return -EINVAL;
+	}

Good catch.

Quoted 9 lines
Quoted 3 lines

Do we really need a || here though? Would it not be sufficient to check if tioffset + tilen > blob_len? Or are you concerned about that value wrapping?

Yep. I was concerned about value wrapping.

regards,
dan carpenter

Seems reasonable then. Thanks...

Applied
#4 lore raw
In reply to Dan Carpenter

merged to cifs-2.6.git

Quoted 23 lines · Dan Carpenter

We should check that we're not copying memory from beyond the end of the blob.

fs/cifs/sess.c +4 -0
index d85efad..eb76741 100644
@@ -395,6 +395,10 @@ static int decode_ntlmssp_challenge(char *bcc_ptr,
 int blob_len,
       ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags);
       tioffset = le32_to_cpu(pblob->TargetInfoArray.BufferOffset);
       tilen = le16_to_cpu(pblob->TargetInfoArray.Length);
+       if (tioffset > blob_len || tioffset + tilen > blob_len) {
+               cERROR(1, "tioffset + tilen too high %u + %u", tioffset,
 tilen);
+               return -EINVAL;
+       }
       if (tilen) {
               ses->auth_key.response = kmalloc(tilen, GFP_KERNEL);
               if (!ses->auth_key.response) {
Signature · 3 lines
Thanks,

Steve
Applied
#5 lore raw
In reply to Dan Carpenter

merged to cifs-2.6.git

Quoted 11 lines · Dan Carpenter

We should check that we're not copying memory from beyond the end of the blob.

fs/cifs/sess.c +0 -0
index d85efad..eb76741 100644

fs/cifs/sess.c static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, · line 404

Quoted 10 lines
fs/cifs/sess.c +4 -0
@@ -395,6 +395,10 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
        ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags);
        tioffset = le32_to_cpu(pblob->TargetInfoArray.BufferOffset);
        tilen = le16_to_cpu(pblob->TargetInfoArray.Length);
+       if (tioffset > blob_len || tioffset + tilen > blob_len) {
+               cERROR(1, "tioffset + tilen too high %u + %u", tioffset, tilen);
+               return -EINVAL;
+       }
        if (tilen) {
                ses->auth_key.response = kmalloc(tilen, GFP_KERNEL);
                if (!ses->auth_key.response) {

--
Thanks,

Steve
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html