diff mbox series

[7/7] lib: sbi: sse: check handler entry to belong to supervisor mode

Message ID 20240409100216.263256-8-cleger@rivosinc.com
State Accepted
Headers show
Series lib: sbi: sse: fixes after review | expand

Commit Message

Clément Léger April 9, 2024, 10:02 a.m. UTC
When registering an SSE event, check for the handler_entry_pc to belong
to supervisor mode domain using sbi_domain_check_addr_range().

Signed-off-by: Clément Léger <cleger@rivosinc.com>
Reported-by: Samuel Holland <samuel.holland@sifive.com>
---
 lib/sbi/sbi_sse.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Anup Patel May 7, 2024, 11:50 a.m. UTC | #1
On Tue, Apr 9, 2024 at 3:32 PM Clément Léger <cleger@rivosinc.com> wrote:
>
> When registering an SSE event, check for the handler_entry_pc to belong
> to supervisor mode domain using sbi_domain_check_addr_range().
>
> Signed-off-by: Clément Léger <cleger@rivosinc.com>
> Reported-by: Samuel Holland <samuel.holland@sifive.com>

LGTM.

Reviewed-by: Anup Patel <anup@brainfault.org>

Regards,
Anup

> ---
>  lib/sbi/sbi_sse.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
> index 85137c2..8724f76 100644
> --- a/lib/sbi/sbi_sse.c
> +++ b/lib/sbi/sbi_sse.c
> @@ -959,6 +959,12 @@ int sbi_sse_register(uint32_t event_id, unsigned long handler_entry_pc,
>         if (handler_entry_pc & 0x1)
>                 return SBI_EINVAL;
>
> +       if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
> +                                        handler_entry_pc,
> +                                        sizeof(unsigned long), PRV_S,
> +                                        SBI_DOMAIN_EXECUTE))
> +               return SBI_EINVALID_ADDR;
> +
>         e = sse_event_get(event_id);
>         if (!e)
>                 return SBI_EINVAL;
> --
> 2.43.0
>
>
> --
> opensbi mailing list
> opensbi@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
diff mbox series

Patch

diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
index 85137c2..8724f76 100644
--- a/lib/sbi/sbi_sse.c
+++ b/lib/sbi/sbi_sse.c
@@ -959,6 +959,12 @@  int sbi_sse_register(uint32_t event_id, unsigned long handler_entry_pc,
 	if (handler_entry_pc & 0x1)
 		return SBI_EINVAL;
 
+	if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
+					 handler_entry_pc,
+					 sizeof(unsigned long), PRV_S,
+					 SBI_DOMAIN_EXECUTE))
+		return SBI_EINVALID_ADDR;
+
 	e = sse_event_get(event_id);
 	if (!e)
 		return SBI_EINVAL;