Skip to contentSkip to conversation

examples/fips_validation: fix checking return value

PATCH Superseded Ciara Power 2 participants 4 messages Oct 28, 2020 – Oct 31, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/fips_validation: fix checking return value

The return value was not being checked when calling the get_writeback_data function in the AES test case. On failure, this led to a NULL dereference when using memcpy later. The return value is now checked to avoid this NULL dereference.

Coverity issue: 363463

Fixes cd255ccf5764 ("examples/fips_validation: support AES parsing")
---
 examples/fips_validation/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
examples/fips_validation/main.c +3 -1
index 07532c9562..bc7abd2b8f 100644
@@ -1520,7 +1520,9 @@ fips_mct_aes_test(void)
 				return ret;
 			}
 
-			get_writeback_data(&val);
+			ret = get_writeback_data(&val);
+			if (ret < 0)
+				return ret;
 
 			if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
 				memcpy(prev_in, vec.ct.val, AES_BLOCK_SIZE);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · Ciara Power

The return value was not being checked when calling the get_writeback_data function in the AES test case. On failure, this led to a NULL dereference when using memcpy later. The return value is now checked to avoid this NULL dereference.

Coverity issue: 363463

Fixes cd255ccf5764 ("examples/fips_validation: support AES parsing")

I'd rather flag:

Fixes 952e10cdad5e ("examples/fips_validation: support scatter gather list")

Can you double check?

Quoted 14 lines
---
 examples/fips_validation/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
examples/fips_validation/main.c +0 -0
index 07532c9562..bc7abd2b8f 100644

examples/fips_validation/main.c fips_mct_aes_test(void) · line 1528

Quoted 10 lines
examples/fips_validation/main.c +3 -1
@@ -1520,7 +1520,9 @@ fips_mct_aes_test(void)
                                return ret;
                        }
 
-                       get_writeback_data(&val);
+                       ret = get_writeback_data(&val);
+                       if (ret < 0)
+                               return ret;
 
                        if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
                                memcpy(prev_in, vec.ct.val, AES_BLOCK_SIZE);

And I think we have the same issue in fips_mct_sha_test().

Signature · 1 line
David Marchand
#2 lore raw

PATCH v2 1/1 examples/fips_validation: fix checking return value

In reply to Ciara Power

The return value was not being checked when calling the get_writeback_data function in the AES test case. On failure, this led to a NULL dereference when using memcpy later. The return value is now checked to avoid this NULL dereference.

Coverity issue: 363463

Fixes 952e10cdad5e ("examples/fips_validation: support scatter gather list")

---
v2:
- Fixed incorrect "Fixes" tag.
- Added same fix to another test case.

---
 examples/fips_validation/main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
examples/fips_validation/main.c +6 -2
index 07532c9562..6a1cea36f5 100644
@@ -1520,7 +1520,9 @@ fips_mct_aes_test(void)
 				return ret;
 			}
 
-			get_writeback_data(&val);
+			ret = get_writeback_data(&val);
+			if (ret < 0)
+				return ret;
 
 			if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
 				memcpy(prev_in, vec.ct.val, AES_BLOCK_SIZE);
@@ -1649,7 +1651,9 @@ fips_mct_sha_test(void)
 				return ret;
 			}
 
-			get_writeback_data(&val);
+			ret = get_writeback_data(&val);
+			if (ret < 0)
+				return ret;
 
 			memcpy(md[0].val, md[1].val, md[1].len);
 			md[0].len = md[1].len;
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1 Applied
#3 lore raw
Quoted 10 lines · Ciara Power

The return value was not being checked when calling the get_writeback_data function in the AES test case. On failure, this led to a NULL dereference when using memcpy later. The return value is now checked to avoid this NULL dereference.

Coverity issue: 363463

Fixes 952e10cdad5e ("examples/fips_validation: support scatter gather list")

Applied, thanks.

Signature · 1 line
David Marchand