[RFC PATCH 15/23] lib: sbi: sse: handle temporary attribute buffer map/unmap errors
Yu-Chien Peter Lin
peter.lin at sifive.com
Mon Nov 30 02:11:39 PST 2026
The SSE read and write attribute calls access the S-mode buffer
between sbi_hart_protection_temp_map_range() and
sbi_hart_protection_temp_unmap_range() but ignore both return values.
With Smepmp the temporary mapping is verified and can fail, and M-mode
must not touch the buffer without a valid mapping.
Return SBI_ERR_FAILED without accessing the buffer when the mapping
fails, releasing the event reference taken by the read path, and
report a failed unmap instead of returning success. When an attribute
check already failed, keep that error code.
Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
lib/sbi/sbi_sse.c | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c
index 767ea128..52c996b2 100644
--- a/lib/sbi/sbi_sse.c
+++ b/lib/sbi/sbi_sse.c
@@ -1022,7 +1022,13 @@ int sbi_sse_read_attrs(uint32_t event_id, uint32_t base_attr_id,
if (ret)
return ret;
- sbi_hart_protection_temp_map_range(output_phys_lo, sizeof(unsigned long) * attr_count);
+ ret = sbi_hart_protection_temp_map_range(output_phys_lo,
+ sizeof(unsigned long) *
+ attr_count);
+ if (ret) {
+ sse_event_put(e);
+ return SBI_ERR_FAILED;
+ }
/*
* Copy all attributes at once since struct sse_event_attrs is matching
@@ -1035,22 +1041,27 @@ int sbi_sse_read_attrs(uint32_t event_id, uint32_t base_attr_id,
attrs = (unsigned long *)output_phys_lo;
copy_attrs(attrs, &e_attrs[base_attr_id], attr_count);
- sbi_hart_protection_temp_unmap_range(output_phys_lo, sizeof(unsigned long) * attr_count);
-
+ ret = sbi_hart_protection_temp_unmap_range(output_phys_lo,
+ sizeof(unsigned long) *
+ attr_count);
sse_event_put(e);
- return SBI_OK;
+ return ret ? SBI_ERR_FAILED : SBI_OK;
}
static int sse_write_attrs(struct sbi_sse_event *e, uint32_t base_attr_id,
uint32_t attr_count, unsigned long input_phys)
{
- int ret = 0;
+ int ret = 0, rc;
unsigned long attr = 0, val;
uint32_t id, end_id = base_attr_id + attr_count;
unsigned long *attrs = (unsigned long *)input_phys;
- sbi_hart_protection_temp_map_range(input_phys, sizeof(unsigned long) * attr_count);
+ ret = sbi_hart_protection_temp_map_range(input_phys,
+ sizeof(unsigned long) *
+ attr_count);
+ if (ret)
+ return SBI_ERR_FAILED;
for (id = base_attr_id; id < end_id; id++) {
val = attrs[attr++];
@@ -1066,7 +1077,11 @@ static int sse_write_attrs(struct sbi_sse_event *e, uint32_t base_attr_id,
}
out:
- sbi_hart_protection_temp_unmap_range(input_phys, sizeof(unsigned long) * attr_count);
+ rc = sbi_hart_protection_temp_unmap_range(input_phys,
+ sizeof(unsigned long) *
+ attr_count);
+ if (rc && !ret)
+ ret = SBI_ERR_FAILED;
return ret;
}
--
2.43.7
More information about the opensbi
mailing list