diff mbox series

[1/1] lib: sbi: missing values sbi_hart_ext[]

Message ID 20240408080551.50655-1-heinrich.schuchardt@canonical.com
State Not Applicable
Headers show
Series [1/1] lib: sbi: missing values sbi_hart_ext[] | expand

Commit Message

Heinrich Schuchardt April 8, 2024, 8:05 a.m. UTC
In sbi_hart_get_extensions_str() we assume that sbi_hart_ext[] has
SBI_HART_EXT_MAX entries.

* Add the missing entries for sscsrind, ssccfg.
* Add a static assert to avoid future discrepancies.

Addresses-Coverity-ID: 1584994 Out-of-bounds read
Fixes: 6bb6b61c27eb ("lib: sbi: Add support for smcsrind and smcdeleg")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 lib/sbi/sbi_hart.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Clément Léger April 8, 2024, 2:44 p.m. UTC | #1
Hi Heinrich,

I already fixed that a few days ago:

https://patchwork.ozlabs.org/project/opensbi/patch/20240320154531.1496553-1-cleger@rivosinc.com/

Thanks,

Clément

On 08/04/2024 10:05, Heinrich Schuchardt wrote:
> In sbi_hart_get_extensions_str() we assume that sbi_hart_ext[] has
> SBI_HART_EXT_MAX entries.
> 
> * Add the missing entries for sscsrind, ssccfg.
> * Add a static assert to avoid future discrepancies.
> 
> Addresses-Coverity-ID: 1584994 Out-of-bounds read
> Fixes: 6bb6b61c27eb ("lib: sbi: Add support for smcsrind and smcdeleg")
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  lib/sbi/sbi_hart.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
> index 3d13694..abec734 100644
> --- a/lib/sbi/sbi_hart.c
> +++ b/lib/sbi/sbi_hart.c
> @@ -666,8 +666,13 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = {
>  	__SBI_HART_EXT_DATA(sdtrig, SBI_HART_EXT_SDTRIG),
>  	__SBI_HART_EXT_DATA(smcsrind, SBI_HART_EXT_SMCSRIND),
>  	__SBI_HART_EXT_DATA(smcdeleg, SBI_HART_EXT_SMCDELEG),
> +	__SBI_HART_EXT_DATA(sscsrind, SBI_HART_EXT_SSCSRIND),
> +	__SBI_HART_EXT_DATA(ssccfg, SBI_HART_EXT_SSCCFG),
>  };
>  
> +_Static_assert(SBI_HART_EXT_MAX == array_size(sbi_hart_ext),
> +	       "sbi_hart_ext[]: wrong number of entries");
> +
>  /**
>   * Get the hart extensions in string format
>   *
diff mbox series

Patch

diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 3d13694..abec734 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -666,8 +666,13 @@  const struct sbi_hart_ext_data sbi_hart_ext[] = {
 	__SBI_HART_EXT_DATA(sdtrig, SBI_HART_EXT_SDTRIG),
 	__SBI_HART_EXT_DATA(smcsrind, SBI_HART_EXT_SMCSRIND),
 	__SBI_HART_EXT_DATA(smcdeleg, SBI_HART_EXT_SMCDELEG),
+	__SBI_HART_EXT_DATA(sscsrind, SBI_HART_EXT_SSCSRIND),
+	__SBI_HART_EXT_DATA(ssccfg, SBI_HART_EXT_SSCCFG),
 };
 
+_Static_assert(SBI_HART_EXT_MAX == array_size(sbi_hart_ext),
+	       "sbi_hart_ext[]: wrong number of entries");
+
 /**
  * Get the hart extensions in string format
  *