[PATCH v2] lib: sbi_mpxy: fix integer overflow in attribute range endpoint
liutong
liutong at iscas.ac.cn
Tue Jul 28 23:42:36 PDT 2026
In sbi_mpxy_read_attrs() and sbi_mpxy_write_attrs(), the attribute range
endpoint is computed as:
u32 end_id = base_attr_id + attr_count - 1;
When base_attr_id + attr_count exceeds UINT32_MAX, end_id wraps around to
a small value. This makes downstream range checks such as
"end_id >= SBI_MPXY_ATTR_STD_ATTR_MAX_IDX" pass incorrectly, turning them
into dead code.
A malicious or misconfigured S-mode caller can supply crafted
base_attr_id and attr_count values that trigger the wraparound, bypassing
range validation and causing out-of-bounds read/write on the shared
memory attribute array.
Widen end_id to u64 so the addition cannot wrap within the u32 range.
Fixes: 7939bf1329eb ("lib: sbi: Add SBI Message Proxy (MPXY) framework")
Signed-off-by: liutong <liutong at iscas.ac.cn>
---
Thanks for the review, Rahul.
Changes in v2:
- Added Fixes tag as suggested
lib/sbi/sbi_mpxy.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/sbi/sbi_mpxy.c b/lib/sbi/sbi_mpxy.c
index 19f59f3a..37dc8e7e 100644
--- a/lib/sbi/sbi_mpxy.c
+++ b/lib/sbi/sbi_mpxy.c
@@ -475,7 +475,8 @@ int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count)
{
struct mpxy_state *ms = sbi_domain_mpxy_state_thishart_ptr();
int ret = SBI_SUCCESS;
- u32 *attr_ptr, end_id;
+ u32 *attr_ptr;
+ u64 end_id;
void *shmem_base;
struct sbi_domain *dom = sbi_domain_thishart_ptr();
@@ -625,7 +626,8 @@ static void mpxy_write_std_attr(struct sbi_mpxy_channel *channel, u32 attr_id,
int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count)
{
struct mpxy_state *ms = sbi_domain_mpxy_state_thishart_ptr();
- u32 *mem_ptr, attr_id, end_id, attr_val;
+ u32 *mem_ptr, attr_id, attr_val;
+ u64 end_id;
struct sbi_mpxy_channel *channel;
int ret, mem_idx;
void *shmem_base;
--
2.34.1
More information about the opensbi
mailing list