[PATCH 1/1] lib: sbi_ecall_base: add check for function parameter pointers

Xiang W wxjstz at 126.com
Tue Nov 22 00:17:21 PST 2022


在 2022-11-22星期二的 15:13 +0800,qinhaijun at eswincomputing.com写道:
> From: haijun qin <qinhaijun at eswincomputing.com>
> 
> When a null pointer is passed in by mistake, the program will
> enter the trap, so the check for the pointer is added.
> 
> Signed-off-by: haijun qin <qinhaijun at eswincomputing.com>

sbi_ecall_extension->handle is only called at
https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_ecall.c#L110, 
where out_val is not empty.

If you want to detect parameters, you also need to detect regs and out_trap. and
add code like this in each extension implementation.

Regards,
Xiang W
> ---
>  lib/sbi/sbi_ecall_base.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/sbi/sbi_ecall_base.c b/lib/sbi/sbi_ecall_base.c
> index 786d2ac..3d4a367 100644
> --- a/lib/sbi/sbi_ecall_base.c
> +++ b/lib/sbi/sbi_ecall_base.c
> @@ -39,6 +39,9 @@ static int sbi_ecall_base_handler(unsigned long extid, unsigned long funcid,
>  {
>         int ret = 0;
>  
> +       if(out_val == NULL)
> +               return SBI_EINVALID_ADDR;
> +
>         switch (funcid) {
>         case SBI_EXT_BASE_GET_SPEC_VERSION:
>                 *out_val = (SBI_ECALL_VERSION_MAJOR <<
> -- 
> 2.17.1
> 
> 





More information about the opensbi mailing list