diff options
author | Varun Wadekar <vwadekar@nvidia.com> | 2019-10-01 09:34:10 -0700 |
---|---|---|
committer | Manish Pandey <manish.pandey2@arm.com> | 2020-08-24 21:26:48 +0000 |
commit | 601e3ed209eb508c9e46a5ef18a562613338dcc8 (patch) | |
tree | c21b6a41d8e414068c5b6a7297bc14929cec57a7 /lib | |
parent | 64b2a237aaf06a472506d70fe9ccf809f8ac1b49 (diff) | |
download | trusted-firmware-a-601e3ed209eb508c9e46a5ef18a562613338dcc8.tar.gz |
lib: cpus: sanity check pointers before use
The cpu_ops structure contains a lot of function pointers. It
is a good idea to verify that the function pointer is not NULL
before executing it.
This patch sanity checks each pointer before use to prevent any
unforeseen crashes. These checks have been enabled for debug
builds only.
Change-Id: Ib208331c20e60f0c7c582a20eb3d8cc40fb99d21
Signed-off-by: Varun Wadekar <vwadekar@nvidia.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cpus/aarch64/cpu_helpers.S | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/cpus/aarch64/cpu_helpers.S b/lib/cpus/aarch64/cpu_helpers.S index 808c7f807a..da663be0e0 100644 --- a/lib/cpus/aarch64/cpu_helpers.S +++ b/lib/cpus/aarch64/cpu_helpers.S @@ -78,6 +78,10 @@ func prepare_cpu_pwr_dwn mov x1, #CPU_PWR_DWN_OPS add x1, x1, x2, lsl #3 ldr x1, [x0, x1] +#if ENABLE_ASSERTIONS + cmp x1, #0 + ASM_ASSERT(ne) +#endif br x1 endfunc prepare_cpu_pwr_dwn @@ -171,6 +175,10 @@ func get_cpu_ops_ptr /* Subtract the increment and offset to get the cpu-ops pointer */ sub x0, x4, #(CPU_OPS_SIZE + CPU_MIDR) +#if ENABLE_ASSERTIONS + cmp x0, #0 + ASM_ASSERT(ne) +#endif error_exit: ret endfunc get_cpu_ops_ptr @@ -276,7 +284,15 @@ func print_errata_status * turn. */ mrs x0, tpidr_el3 +#if ENABLE_ASSERTIONS + cmp x0, #0 + ASM_ASSERT(ne) +#endif ldr x1, [x0, #CPU_DATA_CPU_OPS_PTR] +#if ENABLE_ASSERTIONS + cmp x1, #0 + ASM_ASSERT(ne) +#endif ldr x0, [x1, #CPU_ERRATA_FUNC] cbz x0, .Lnoprint @@ -326,6 +342,10 @@ func check_wa_cve_2017_5715 ASM_ASSERT(ne) #endif ldr x0, [x0, #CPU_DATA_CPU_OPS_PTR] +#if ENABLE_ASSERTIONS + cmp x0, #0 + ASM_ASSERT(ne) +#endif ldr x0, [x0, #CPU_EXTRA1_FUNC] /* * If the reserved function pointer is NULL, this CPU @@ -359,6 +379,10 @@ func wa_cve_2018_3639_get_disable_ptr ASM_ASSERT(ne) #endif ldr x0, [x0, #CPU_DATA_CPU_OPS_PTR] +#if ENABLE_ASSERTIONS + cmp x0, #0 + ASM_ASSERT(ne) +#endif ldr x0, [x0, #CPU_EXTRA2_FUNC] ret endfunc wa_cve_2018_3639_get_disable_ptr |