From e3eb59a396ac55975e3debecfc5b71418eb62248 Mon Sep 17 00:00:00 2001 From: Xiang W Date: Wed, 3 Sep 2025 12:46:04 +0800 Subject: [PATCH] lib: sbi: Prevent target domain same as the current Add error handling code to sbi_domain_context_enter to prevent the target domain from being the same as the current domain. Signed-off-by: Xiang W Reviewed-by: Anup Patel Link: https://lore.kernel.org/r/20250903044619.394019-4-wxjstz@126.com Signed-off-by: Anup Patel --- lib/sbi/sbi_domain_context.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c index e909670c..5490df28 100644 --- a/lib/sbi/sbi_domain_context.c +++ b/lib/sbi/sbi_domain_context.c @@ -193,6 +193,10 @@ int sbi_domain_context_enter(struct sbi_domain *dom) struct hart_context *dom_ctx; struct hart_context *ctx = hart_context_thishart_get(); + /* Target domain must not be same as the current domain */ + if (!dom || dom == sbi_domain_thishart_ptr()) + return SBI_EINVAL; + /* * If it's first time to call `enter` on the current hart, no * context allocated before. Allocate context for each valid