[PATCH 3/7] lib: sbi: dbtr: check the whole shared memory range in SETUP_SHMEM
Heinrich Schuchardt
heinrich.schuchardt at canonical.com
Tue Nov 24 01:48:20 PST 2026
On 11/23/26 09:14, Himanshu Chauhan wrote:
> On Sat, Nov 21, 2026 at 12:11:15AM +0100, Heinrich Schuchardt wrote:
>> The shared memory of the debug trigger extension is trig_max * (XLEN / 2)
>> bytes long. The specification requires the SBI implementation to check
>> that the whole physical memory range is accessible for the caller, see the
>> chapter on the shared memory physical address range parameter.
> "see the chapter..." can be dropped. But I am okay with this right now.
>
>>
>> sbi_dbtr_setup_shmem() only tested the first address. A range that starts
>> in memory of S-mode and reaches into memory protected by PMP was
>> accepted. A later read of the triggers then makes M-mode write into the
>> protected memory. A range at the top of the address space that wraps
>
> This is a major gap you pointed out yet mentioned in a casual way. Thanks
> for fixing this. I request you to throughly review commit logs as well.
>
>> around was accepted too.
>>
>> Use sbi_domain_check_addr_range() with the size of the shared memory. It
>> also rejects a range that wraps around.
>>
>> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
>> ---
>> lib/sbi/sbi_dbtr.c | 17 ++++++++++++++---
>> 1 file changed, 14 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/sbi/sbi_dbtr.c b/lib/sbi/sbi_dbtr.c
>> index 53fcb0a2..fa0e5962 100644
>> --- a/lib/sbi/sbi_dbtr.c
>> +++ b/lib/sbi/sbi_dbtr.c
>> @@ -385,9 +385,20 @@ int sbi_dbtr_setup_shmem(const struct sbi_domain *dom, unsigned long smode,
>> if (shmem_phys_hi)
>> return SBI_EINVALID_ADDR;
>>
>> - if (dom && !sbi_domain_check_addr(dom,
>> - DBTR_SHMEM_MAKE_PHYS(shmem_phys_hi, shmem_phys_lo), smode,
>> - SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))
>> + /*
>> + * The shared memory is trig_max * (XLEN / 2) bytes. All of it has to be
>> + * readable and writable for the caller, not only its first byte,
>> + * otherwise a read of the triggers would write into memory that the
>> + * caller cannot access. A range that wraps around is rejected too.
>> + */
>> + if (dom &&
>> + !sbi_domain_check_addr_range(dom,
>> + DBTR_SHMEM_MAKE_PHYS(shmem_phys_hi,
>> + shmem_phys_lo),
>> + hart_state->total_trigs *
>> + sizeof(union sbi_dbtr_shmem_entry),
>> + smode,
>> + SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))
>> return SBI_ERR_INVALID_ADDRESS;
>>
>> hart_state->shmem.phys_lo = shmem_phys_lo;
> LGTM
>
> Reviewed-by: Himanshu Chauhan <himanshu.chauhan at oss.qualcomm.com>
The same change was already suggested by Pengpeng and reviewed positively in
[PATCH] lib: sbi: dbtr: validate complete shared memory range
https://lore.kernel.org/opensbi/CA+Ht8=ZJrfwk6DBk+Dyt71=2r66-N=WBbKnBu+npLekKUX45Sg@mail.gmail.com/
The discussion with Liutong seemed to have ended in Liutong accepting
Pengpeng's patch.
I wonder why Pengpeng's patch was not merged.
Best regards
Heinrich
>
>> --
>> 2.53.0
>>
>>
>> --
>> opensbi mailing list
>> opensbi at lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/opensbi
More information about the opensbi
mailing list