dmicheck: checks (Extended) Maximum Capacity for type 16
diff mbox series

Message ID 20180905012737.16147-1-alex.hung@canonical.com
State Accepted
Headers show
Series
  • dmicheck: checks (Extended) Maximum Capacity for type 16
Related show

Commit Message

Alex Hung Sept. 5, 2018, 1:27 a.m. UTC
Signed-off-by: Alex Hung <alex.hung@canonical.com>
---
 src/dmi/dmicheck/dmicheck.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Comments

Ivan Hu Sept. 10, 2018, 4:21 a.m. UTC | #1
On 09/05/2018 09:27 AM, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/dmi/dmicheck/dmicheck.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>
> diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
> index 97305eca..cc8c2f46 100644
> --- a/src/dmi/dmicheck/dmicheck.c
> +++ b/src/dmi/dmicheck/dmicheck.c
> @@ -52,6 +52,7 @@
>  #define DMI_MGMT_CTRL_HOST_TYPE		"DMIMgmtCtrlHostType"
>  #define DMI_INVALID_ENTRY_LENGTH	"DMIInvalidEntryLength"
>  #define DMI_INVALID_HARDWARE_ENTRY	"DMIInvalidHardwareEntry"
> +#define DMI_INVALID_MEMORY_ENTRY	"DMIInvalidMemoryEntry"
>  #define DMI_RESERVED_VALUE_USED		"DMIReservedValueUsed"
>  #define DMI_RESERVED_BIT_USED		"DMIReservedBitUsed"
>  #define DMI_RESERVED_OFFSET_NONZERO	"DMIReservedOffsetNonZero"
> @@ -846,6 +847,28 @@ static void dmi_reserved_uint8_check(fwts_framework *fw,
>  	}
>  }
>  
> +static void dmi_min_max_uint32_check(fwts_framework *fw,
> +	const char *table,
> +	uint32_t addr,
> +	const char *field,
> +	const fwts_dmi_header *hdr,
> +	uint8_t offset,
> +	uint32_t min,
> +	uint32_t max)
> +{
> +	uint32_t val = GET_UINT32((hdr->data) + offset);
> +	if ((val < min) || (val > max)) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH,
> +			DMI_VALUE_OUT_OF_RANGE,
> +			"Out of range value 0x%4.4" PRIx32
> +			" (range allowed 0x%4.4" PRIx32 "..0x%4.4" PRIx32 ") "
> +			"while accessing entry '%s' @ 0x%8.8" PRIx32
> +			", field '%s', offset 0x%2.2" PRIx8,
> +			val, min, max, table, addr, field, offset);
> +		dmi_out_of_range_advice(fw, hdr->type, offset);
> +	}
> +}
> +
>  static void dmi_min_max_uint16_check(fwts_framework *fw,
>  	const char *table,
>  	uint32_t addr,
> @@ -1459,6 +1482,13 @@ static void dmicheck_entry(fwts_framework *fw,
>  					data[0x4], table, addr, "Location", 0x4);
>  			dmi_min_max_uint8_check(fw, table, addr, "Use", hdr, 0x5, 0x1, 0x7);
>  			dmi_min_max_uint8_check(fw, table, addr, "Error Corrrection Type", hdr, 0x6, 0x1, 0x7);
> +			dmi_min_max_uint32_check(fw, table, addr, "Maximum Capacity", hdr, 0x7, 0, 0x80000000 - 1);
> +			if (hdr->length < 0x17)
> +				break;
> +			if (GET_UINT64(data + 0xf) != 0 && GET_UINT32(data + 0x7) != 0x80000000)
> +				fwts_failed(fw, LOG_LEVEL_HIGH, DMI_INVALID_MEMORY_ENTRY,
> +					"An illegal value 0x%16.16" PRIx64 " for entry '%s' "
> +					"@ 0x%8.8" PRIx32, GET_UINT64(data + 0xf), table, addr);
>  			break;
>  
>  		case 17: /* 7.18 */
Acked-by: Ivan Hu <ivan.hu@canonical.com>
Colin Ian King Sept. 10, 2018, 1:04 p.m. UTC | #2
On 05/09/18 02:27, Alex Hung wrote:
> Signed-off-by: Alex Hung <alex.hung@canonical.com>
> ---
>  src/dmi/dmicheck/dmicheck.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
> index 97305eca..cc8c2f46 100644
> --- a/src/dmi/dmicheck/dmicheck.c
> +++ b/src/dmi/dmicheck/dmicheck.c
> @@ -52,6 +52,7 @@
>  #define DMI_MGMT_CTRL_HOST_TYPE		"DMIMgmtCtrlHostType"
>  #define DMI_INVALID_ENTRY_LENGTH	"DMIInvalidEntryLength"
>  #define DMI_INVALID_HARDWARE_ENTRY	"DMIInvalidHardwareEntry"
> +#define DMI_INVALID_MEMORY_ENTRY	"DMIInvalidMemoryEntry"
>  #define DMI_RESERVED_VALUE_USED		"DMIReservedValueUsed"
>  #define DMI_RESERVED_BIT_USED		"DMIReservedBitUsed"
>  #define DMI_RESERVED_OFFSET_NONZERO	"DMIReservedOffsetNonZero"
> @@ -846,6 +847,28 @@ static void dmi_reserved_uint8_check(fwts_framework *fw,
>  	}
>  }
>  
> +static void dmi_min_max_uint32_check(fwts_framework *fw,
> +	const char *table,
> +	uint32_t addr,
> +	const char *field,
> +	const fwts_dmi_header *hdr,
> +	uint8_t offset,
> +	uint32_t min,
> +	uint32_t max)
> +{
> +	uint32_t val = GET_UINT32((hdr->data) + offset);
> +	if ((val < min) || (val > max)) {
> +		fwts_failed(fw, LOG_LEVEL_HIGH,
> +			DMI_VALUE_OUT_OF_RANGE,
> +			"Out of range value 0x%4.4" PRIx32
> +			" (range allowed 0x%4.4" PRIx32 "..0x%4.4" PRIx32 ") "
> +			"while accessing entry '%s' @ 0x%8.8" PRIx32
> +			", field '%s', offset 0x%2.2" PRIx8,
> +			val, min, max, table, addr, field, offset);
> +		dmi_out_of_range_advice(fw, hdr->type, offset);
> +	}
> +}
> +
>  static void dmi_min_max_uint16_check(fwts_framework *fw,
>  	const char *table,
>  	uint32_t addr,
> @@ -1459,6 +1482,13 @@ static void dmicheck_entry(fwts_framework *fw,
>  					data[0x4], table, addr, "Location", 0x4);
>  			dmi_min_max_uint8_check(fw, table, addr, "Use", hdr, 0x5, 0x1, 0x7);
>  			dmi_min_max_uint8_check(fw, table, addr, "Error Corrrection Type", hdr, 0x6, 0x1, 0x7);
> +			dmi_min_max_uint32_check(fw, table, addr, "Maximum Capacity", hdr, 0x7, 0, 0x80000000 - 1);
> +			if (hdr->length < 0x17)
> +				break;
> +			if (GET_UINT64(data + 0xf) != 0 && GET_UINT32(data + 0x7) != 0x80000000)
> +				fwts_failed(fw, LOG_LEVEL_HIGH, DMI_INVALID_MEMORY_ENTRY,
> +					"An illegal value 0x%16.16" PRIx64 " for entry '%s' "
> +					"@ 0x%8.8" PRIx32, GET_UINT64(data + 0xf), table, addr);
>  			break;
>  
>  		case 17: /* 7.18 */
> 

Acked-by: Colin Ian King <colin.king@canonical.com>

Patch
diff mbox series

diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
index 97305eca..cc8c2f46 100644
--- a/src/dmi/dmicheck/dmicheck.c
+++ b/src/dmi/dmicheck/dmicheck.c
@@ -52,6 +52,7 @@ 
 #define DMI_MGMT_CTRL_HOST_TYPE		"DMIMgmtCtrlHostType"
 #define DMI_INVALID_ENTRY_LENGTH	"DMIInvalidEntryLength"
 #define DMI_INVALID_HARDWARE_ENTRY	"DMIInvalidHardwareEntry"
+#define DMI_INVALID_MEMORY_ENTRY	"DMIInvalidMemoryEntry"
 #define DMI_RESERVED_VALUE_USED		"DMIReservedValueUsed"
 #define DMI_RESERVED_BIT_USED		"DMIReservedBitUsed"
 #define DMI_RESERVED_OFFSET_NONZERO	"DMIReservedOffsetNonZero"
@@ -846,6 +847,28 @@  static void dmi_reserved_uint8_check(fwts_framework *fw,
 	}
 }
 
+static void dmi_min_max_uint32_check(fwts_framework *fw,
+	const char *table,
+	uint32_t addr,
+	const char *field,
+	const fwts_dmi_header *hdr,
+	uint8_t offset,
+	uint32_t min,
+	uint32_t max)
+{
+	uint32_t val = GET_UINT32((hdr->data) + offset);
+	if ((val < min) || (val > max)) {
+		fwts_failed(fw, LOG_LEVEL_HIGH,
+			DMI_VALUE_OUT_OF_RANGE,
+			"Out of range value 0x%4.4" PRIx32
+			" (range allowed 0x%4.4" PRIx32 "..0x%4.4" PRIx32 ") "
+			"while accessing entry '%s' @ 0x%8.8" PRIx32
+			", field '%s', offset 0x%2.2" PRIx8,
+			val, min, max, table, addr, field, offset);
+		dmi_out_of_range_advice(fw, hdr->type, offset);
+	}
+}
+
 static void dmi_min_max_uint16_check(fwts_framework *fw,
 	const char *table,
 	uint32_t addr,
@@ -1459,6 +1482,13 @@  static void dmicheck_entry(fwts_framework *fw,
 					data[0x4], table, addr, "Location", 0x4);
 			dmi_min_max_uint8_check(fw, table, addr, "Use", hdr, 0x5, 0x1, 0x7);
 			dmi_min_max_uint8_check(fw, table, addr, "Error Corrrection Type", hdr, 0x6, 0x1, 0x7);
+			dmi_min_max_uint32_check(fw, table, addr, "Maximum Capacity", hdr, 0x7, 0, 0x80000000 - 1);
+			if (hdr->length < 0x17)
+				break;
+			if (GET_UINT64(data + 0xf) != 0 && GET_UINT32(data + 0x7) != 0x80000000)
+				fwts_failed(fw, LOG_LEVEL_HIGH, DMI_INVALID_MEMORY_ENTRY,
+					"An illegal value 0x%16.16" PRIx64 " for entry '%s' "
+					"@ 0x%8.8" PRIx32, GET_UINT64(data + 0xf), table, addr);
 			break;
 
 		case 17: /* 7.18 */