Skip to contentSkip to conversation

add check for function parameter

PATCH New [email protected] 2 participants 4 messages Nov 22, 2022 – Nov 23, 2022

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 786d2ac..3d4a367 100644
@@ -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
#2 lore raw

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.

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
index 786d2ac..3d4a367 100644
@@ -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
author
#3 lore raw

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.

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
index 786d2ac..3d4a367 100644
@@ -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
Signature · 3 lines
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi