add check for function parameter
cover add check for function parameter
From: haijun qin <[email protected]>
sbi_ecall_base_handler is the interface for external calls, Object-oriented will be complex. So add pointer check to avoid calling errors.
haijun qin (1):
lib: sbi_ecall_base: add check for function parameter pointers
lib/sbi/sbi_ecall_base.c | 3 +++ 1 file changed, 3 insertions(+)
base-commit: 22f38ee6c658a660083aa45c4ec6c72f66a17260
Signature · 1 line
2.17.1
PATCH 1/1 lib: sbi_ecall_base: add check for function parameter pointers
From: haijun qin <[email protected]>
When a null pointer is passed in by mistake, the program will enter the trap, so the check for the pointer is added.
--- lib/sbi/sbi_ecall_base.c | 3 +++ 1 file changed, 3 insertions(+)
lib/sbi/sbi_ecall_base.c +3 -0
@@ -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 <<
Signature · 1 line
2.17.1
PATCH 1/1 lib: sbi_ecall_base: add check for function parameter pointers
? 2022-11-22???? 15:13 +0800?qinhaijun at eswincomputing.com???
Quoted 6 lines
From: haijun qin <[email protected]>
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 <[email protected]>
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
Quoted 22 lines
---
?lib/sbi/sbi_ecall_base.c | 3 +++
?1 file changed, 3 insertions(+)lib/sbi/sbi_ecall_base.c +0
-0@@ -39,6 +39,9 @@ static int sbi_ecall_base_handler(unsigned long extid, unsigned long funcid, ?{ ????????int ret = 0;?
+???????if(out_val == NULL) +???????????????returnSBI_EINVALID_ADDR;
+
????????switch (funcid) {
????????caseSBI_EXT_BASE_GET_SPEC_VERSION:
????????????????*out_val = (SBI_ECALL_VERSION_MAJOR<<Signature · 1 line
2.17.1
PATCH 1/1 lib: sbi_ecall_base: add check for function parameter pointers
Hi Xiang W
Thanks for your review, then keep it as it is.
Quoted 46 lines
? 2022-11-22???? 15:13 +0800?qinhaijun at eswincomputing.com???
Quoted 6 lines
From: haijun qin <[email protected]>
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 <[email protected]>
sbi_ecall_extension->handleis only called at
https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_ecall.c#L110,
whereout_valis 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 WQuoted 22 lines
---
?lib/sbi/sbi_ecall_base.c | 3 +++
?1 file changed, 3 insertions(+)lib/sbi/sbi_ecall_base.c +0
-0@@ -39,6 +39,9 @@ static int sbi_ecall_base_handler(unsigned long extid, unsigned long funcid, ?{ ????????int ret = 0;?
+???????if(out_val == NULL) +???????????????returnSBI_EINVALID_ADDR;
+
????????switch (funcid) {
????????caseSBI_EXT_BASE_GET_SPEC_VERSION:
????????????????*out_val = (SBI_ECALL_VERSION_MAJOR<<Signature · 1 line
2.17.1Signature · 3 lines
opensbi mailing list opensbi at lists.infradead.org http://lists.infradead.org/mailman/listinfo/opensbi