platform: template: Add input validation to otp_nv_counters_backend
Check that erases do not go beyond the TFM_OTP_NV_COUNTERS_AREA.
This is an indirect input-validation for offset.
Change-Id: I9b226cd11d770c7532d87ac748ded43860c1e926
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
diff --git a/platform/ext/common/template/flash_otp_nv_counters_backend.c b/platform/ext/common/template/flash_otp_nv_counters_backend.c
index 4b77cae..b529d21 100644
--- a/platform/ext/common/template/flash_otp_nv_counters_backend.c
+++ b/platform/ext/common/template/flash_otp_nv_counters_backend.c
@@ -314,6 +314,11 @@
DriverCapabilities = OTP_NV_COUNTERS_FLASH_DEV.GetCapabilities();
data_width = data_width_byte[DriverCapabilities.data_width];
+ if (end > TFM_OTP_NV_COUNTERS_AREA_SIZE) {
+ /* Erase is beyond the TFM_OTP_NV_COUNTERS_AREA */
+ return TFM_PLAT_ERR_SYSTEM_ERR;
+ }
+
/* If it's not part of the sectors that are being erased, first erase the
* sector with the is_valid flag.
*/