lib: sbi: sse: check handler entry to belong to supervisor mode
authorClément Léger <cleger@rivosinc.com>
Tue, 9 Apr 2024 10:02:08 +0000 (12:02 +0200)
committerAnup Patel <anup@brainfault.org>
Tue, 7 May 2024 12:01:08 +0000 (17:31 +0530)
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>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/sbi/sbi_sse.c

index 76fbee457fc1108a3c67700bc1e4b3406e90c6f6..18dfdb6dc95664f548a0547a7c74d06cd5cbf652 100644 (file)
@@ -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;