|
|
cecfa4 |
From 77d4592e3eec9ec2c7932586f41f925b43ecc5ba Mon Sep 17 00:00:00 2001
|
|
|
cecfa4 |
From: Imran Desai <imran.desai@intel.com>
|
|
|
cecfa4 |
Date: Sun, 29 Mar 2020 10:22:42 -0700
|
|
|
cecfa4 |
Subject: [PATCH] tools/tpm2_nvcertify.c: Fix incompatible pointer cast that
|
|
|
cecfa4 |
may cause memory leak
|
|
|
cecfa4 |
|
|
|
cecfa4 |
Pointer "&ctx.size" and "&ctx.offset" points to an object whose effective type is
|
|
|
cecfa4 |
"unsigned short" (16 bits, unsigned) but is dereferenced as a wider
|
|
|
cecfa4 |
"unsigned int" (32 bits, unsigned). This may lead to memory corruption.
|
|
|
cecfa4 |
|
|
|
cecfa4 |
Signed-off-by: Imran Desai <imran.desai@intel.com>
|
|
|
cecfa4 |
---
|
|
|
cecfa4 |
tools/tpm2_nvcertify.c | 17 +++++++++++++++--
|
|
|
cecfa4 |
1 file changed, 15 insertions(+), 2 deletions(-)
|
|
|
cecfa4 |
|
|
|
cecfa4 |
diff --git a/tools/tpm2_nvcertify.c b/tools/tpm2_nvcertify.c
|
|
|
cecfa4 |
index b49f38dbff20..414cbea85574 100644
|
|
|
cecfa4 |
--- a/tools/tpm2_nvcertify.c
|
|
|
cecfa4 |
+++ b/tools/tpm2_nvcertify.c
|
|
|
cecfa4 |
@@ -80,6 +80,7 @@ static bool set_signature_format(char *value) {
|
|
|
cecfa4 |
static bool on_option(char key, char *value) {
|
|
|
cecfa4 |
|
|
|
cecfa4 |
bool result = true;
|
|
|
cecfa4 |
+ uint32_t input_value;
|
|
|
cecfa4 |
|
|
|
cecfa4 |
switch (key) {
|
|
|
cecfa4 |
case 'C':
|
|
|
cecfa4 |
@@ -110,18 +111,30 @@ static bool on_option(char key, char *value) {
|
|
|
cecfa4 |
ctx.policy_qualifier_arg = value;
|
|
|
cecfa4 |
break;
|
|
|
cecfa4 |
case 0:
|
|
|
cecfa4 |
- result = tpm2_util_string_to_uint32(value, (uint32_t*)&ctx.size);
|
|
|
cecfa4 |
+ result = tpm2_util_string_to_uint32(value, &input_value);
|
|
|
cecfa4 |
if (!result) {
|
|
|
cecfa4 |
LOG_ERR("Could not convert size to number, got: \"%s\"", value);
|
|
|
cecfa4 |
return false;
|
|
|
cecfa4 |
}
|
|
|
cecfa4 |
+ if (input_value > UINT16_MAX) {
|
|
|
cecfa4 |
+ LOG_ERR("Specified size is larger than that allowed by command");
|
|
|
cecfa4 |
+ return false;
|
|
|
cecfa4 |
+ } else {
|
|
|
cecfa4 |
+ ctx.size = input_value;
|
|
|
cecfa4 |
+ }
|
|
|
cecfa4 |
break;
|
|
|
cecfa4 |
case 1:
|
|
|
cecfa4 |
- result = tpm2_util_string_to_uint32(value, (uint32_t*)&ctx.offset);
|
|
|
cecfa4 |
+ result = tpm2_util_string_to_uint32(value, &input_value);
|
|
|
cecfa4 |
if (!result) {
|
|
|
cecfa4 |
LOG_ERR("Could not convert offset to number, got: \"%s\"", value);
|
|
|
cecfa4 |
return false;
|
|
|
cecfa4 |
}
|
|
|
cecfa4 |
+ if (input_value > UINT16_MAX) {
|
|
|
cecfa4 |
+ LOG_ERR("Specified offset is larger than that allowed by command");
|
|
|
cecfa4 |
+ return false;
|
|
|
cecfa4 |
+ } else {
|
|
|
cecfa4 |
+ ctx.offset = input_value;
|
|
|
cecfa4 |
+ }
|
|
|
cecfa4 |
break;
|
|
|
cecfa4 |
case 2:
|
|
|
cecfa4 |
ctx.certify_info_path = value;
|
|
|
cecfa4 |
--
|
|
|
cecfa4 |
2.31.0
|
|
|
cecfa4 |
|