lib: sbi_mpxy: fix integer overflow in attribute range endpoint

sbi_mpxy_read_attrs() and sbi_mpxy_write_attrs() compute the end of the
requested range as a u32:

  end_id = base_attr_id + attr_count - 1;

Message protocol attribute ids extend to
SBI_MPXY_ATTR_MSGPROTO_ATTR_END (0xffffffff), so the guard
"end_id > SBI_MPXY_ATTR_MSGPROTO_ATTR_END" cannot hold for a u32 and
never rejects anything.

Such a request then reaches the message protocol driver, which computes
the same endpoint in a u32 and so passes its own range check as well,
and indexes its attribute array with attr_id2index(base_attr_id). For
base_attr_id 0xffffffff that is index 0x7fffffff, an out-of-bounds read
whose result is copied into the shared memory.

Widen end_id to u64 so the endpoint is exact and such a request is
rejected before a driver runs. The standard attribute path is not
affected, since attr_count is already limited to the shared memory size
there.

Fixes: 7939bf1329 ("lib: sbi: Add SBI Message Proxy (MPXY) framework")
Signed-off-by: liutong <liutong@iscas.ac.cn>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260910052629.3359493-5-liutong@iscas.ac.cn
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
liutong authored and Anup Patel committed 2026-10-26 11:43:21 +05:30
1 parent f45b9433ed
commit 2afa777592
1 file changed
+9 -7
+9 -7
View File
@@ -474,10 +474,11 @@ int sbi_mpxy_get_channel_ids(u32 start_index)
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;
void *shmem_base;
struct sbi_domain *dom = sbi_domain_thishart_ptr();
int ret = SBI_SUCCESS;
void *shmem_base;
u32 *attr_ptr;
u64 end_id;
if (!mpxy_shmem_enabled(ms))
return SBI_ERR_NO_SHMEM;
@@ -496,7 +497,7 @@ int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count)
return SBI_ERR_INVALID_PARAM;
shmem_base = hart_shmem_base(ms);
end_id = base_attr_id + attr_count - 1;
end_id = (u64)base_attr_id + attr_count - 1;
sbi_hart_protection_temp_map_range((unsigned long)hart_shmem_base(ms), mpxy_shmem_size);
@@ -625,11 +626,12 @@ 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;
struct sbi_domain *dom = sbi_domain_thishart_ptr();
u32 *mem_ptr, attr_id, attr_val;
struct sbi_mpxy_channel *channel;
int ret, mem_idx;
void *shmem_base;
struct sbi_domain *dom = sbi_domain_thishart_ptr();
u64 end_id;
if (!mpxy_shmem_enabled(ms))
return SBI_ERR_NO_SHMEM;
@@ -648,7 +650,7 @@ int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count)
return SBI_ERR_INVALID_PARAM;
shmem_base = hart_shmem_base(ms);
end_id = base_attr_id + attr_count - 1;
end_id = (u64)base_attr_id + attr_count - 1;
sbi_hart_protection_temp_map_range((unsigned long)shmem_base, mpxy_shmem_size);