]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
fix(rss): remove null-terminator from RSS metadata
authorDavid Vincze <david.vincze@arm.com>
Fri, 4 Nov 2022 17:28:12 +0000 (18:28 +0100)
committerDavid Vincze <david.vincze@arm.com>
Fri, 25 Nov 2022 17:31:14 +0000 (18:31 +0100)
Remove the null-terminator of the string-like data items
from the RSS measurement's metadata. The 'version' and
'sw_type' items have an associated length value which
should not include a null-terminator when storing the
measurement.

Change-Id: Ia91ace2fff8b6f75686dd2e1862475268300bbdb
Signed-off-by: David Vincze <david.vincze@arm.com>
include/lib/psa/measured_boot.h
lib/psa/measured_boot.c

index bdb79d5d6e7469d0f934f86983c820d090efb3c9..47aa0b905026f9ba3de0538f725d3fc72012c726 100644 (file)
  *
  * index                       Slot number in which measurement is to be stored
  * signer_id                   Pointer to signer_id buffer.
- * signer_id_size              Size of the signer_id buffer in bytes.
+ * signer_id_size              Size of the signer_id in bytes.
  * version                     Pointer to version buffer.
- * version_size                        Size of the version buffer in bytes.
+ * version_size                        Size of the version string in bytes (with \0).
  * measurement_algo            Algorithm identifier used for measurement.
  * sw_type                     Pointer to sw_type buffer.
- * sw_type_size                        Size of the sw_type buffer in bytes.
+ * sw_type_size                        Size of the sw_type string in bytes (with \0).
  * measurement_value           Pointer to measurement_value buffer.
- * measurement_value_size      Size of the measurement_value buffer in bytes.
+ * measurement_value_size      Size of the measurement_value in bytes.
  * lock_measurement            Boolean flag requesting whether the measurement
  *                             is to be locked.
  *
index 6e9ff78f260c10c228ae38c859932453706ed77f..61747f2157dd0c8a49875ec574b61ecd9f0048b0 100644 (file)
@@ -80,22 +80,24 @@ rss_measured_boot_extend_measurement(uint8_t index,
                .lock_measurement = lock_measurement,
                .measurement_algo = measurement_algo,
                .sw_type = {0},
-               .sw_type_size = sw_type_size,
+               /* Removing \0 */
+               .sw_type_size = (sw_type_size > 0) ? (sw_type_size - 1) : 0,
        };
 
        psa_invec in_vec[] = {
                {.base = &extend_iov,
                        .len = sizeof(struct measured_boot_extend_iovec_t)},
                {.base = signer_id, .len = signer_id_size},
-               {.base = version, .len = version_size},
+               {.base = version,
+                       .len = (version_size > 0) ? (version_size - 1) : 0},
                {.base = measurement_value, .len = measurement_value_size}
        };
 
        if (sw_type != NULL) {
-               if (sw_type_size > SW_TYPE_MAX_SIZE) {
+               if (extend_iov.sw_type_size > SW_TYPE_MAX_SIZE) {
                        return PSA_ERROR_INVALID_ARGUMENT;
                }
-               memcpy(extend_iov.sw_type, sw_type, sw_type_size);
+               memcpy(extend_iov.sw_type, sw_type, extend_iov.sw_type_size);
        }
 
        log_measurement(index, signer_id, signer_id_size,