Skip to contentSkip to conversation

virt: nsm: decode all short CBOR array lengths

PATCH New Yousef Alhouseen 1 participant 1 message Jun 30

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

PATCH 1/1 virt: nsm: decode all short CBOR array lengths

CBOR encodes array lengths from zero through 23 directly in the initial byte. The decoder only handled 23, leaving array_len uninitialized for every other short-form length.

Accept the full short-form range and reject reserved additional-information values above the supported 64-bit encoding.

---
 drivers/misc/nsm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/misc/nsm.c +3 -1
index ef7b32742340..b4e608522340 100644
@@ -105,6 +105,8 @@ static int cbor_object_get_array(u8 *cbor_object, size_t cbor_object_size, u8 **
 		return -EFAULT;
 
 	cbor_short_size = (cbor_object[0] & 0x1F);
+	if (cbor_short_size > CBOR_LONG_SIZE_U64)
+		return -EFAULT;
 
 	/* Decoding byte array length */
 	array_offset = CBOR_HEADER_SIZE_SHORT;
@@ -117,7 +119,7 @@ static int cbor_object_get_array(u8 *cbor_object, size_t cbor_object_size, u8 **
 	array_len_p = &cbor_object[1];
 
 	switch (cbor_short_size) {
-	case CBOR_SHORT_SIZE_MAX_VALUE: /* short encoding */
+	case 0 ... CBOR_SHORT_SIZE_MAX_VALUE: /* short encoding */
 		array_len = cbor_short_size;
 		break;
 	case CBOR_LONG_SIZE_U8:
Signature · 1 line
2.54.0