diff mbox series

[v2,2/3] lib: sbi: add more restriction to domain region subset check

Message ID IA1PR20MB495351E19560D833EAC11BC8BBCDA@IA1PR20MB4953.namprd20.prod.outlook.com
State Superseded
Headers show
Series lib: sbi: Add sub-regions check for sanitizing domain | expand

Commit Message

Inochi Amaoto Oct. 10, 2023, 1 a.m. UTC
make is_region_subset() check the bound of the domain region, so it can
handle the domain region with the same base and length.

Signed-off-by: Inochi Amaoto <inochiama@outlook.com>
---
 lib/sbi/sbi_domain.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Anup Patel Nov. 14, 2023, 5:13 p.m. UTC | #1
On Tue, Oct 10, 2023 at 6:30 AM Inochi Amaoto <inochiama@outlook.com> wrote:
>
> make is_region_subset() check the bound of the domain region, so it can
> handle the domain region with the same base and length.
>
> Signed-off-by: Inochi Amaoto <inochiama@outlook.com>

Important fact here is that regB_start < regB_end and
regA_start < regA_end because order == 0 region is of
size 1 byte.

When regB_start == regA_start and regB_end == regA_end,
the following is the outcome of the expressions in the existing
"if ()" check.

(regB_start <= regA_start) == true
(regA_start < regB_end) == true
(regB_start < regA_end) == true
(regA_end <= regB_end) == true

Based on the above, I don't see how this patch helps.

Regards,
Anup



> ---
>  lib/sbi/sbi_domain.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
> index 283b598..2b9d16f 100644
> --- a/lib/sbi/sbi_domain.c
> +++ b/lib/sbi/sbi_domain.c
> @@ -185,8 +185,8 @@ static bool is_region_subset(const struct sbi_domain_memregion *regA,
>         ulong regB_end = regB->base + (BIT(regB->order) - 1);
>
>         if ((regB_start <= regA_start) &&
> -           (regA_start < regB_end) &&
> -           (regB_start < regA_end) &&
> +           (regB_start <= regA_end) &&
> +           (regA_start <= regB_end) &&
>             (regA_end <= regB_end))
>                 return true;
>
> --
> 2.42.0
>
Inochi Amaoto Nov. 15, 2023, 2:24 a.m. UTC | #2
>On Tue, Oct 10, 2023 at 6:30 AM Inochi Amaoto <inochiama@outlook.com> wrote:
>>
>> make is_region_subset() check the bound of the domain region, so it can
>> handle the domain region with the same base and length.
>>
>> Signed-off-by: Inochi Amaoto <inochiama@outlook.com>
>
>Important fact here is that regB_start < regB_end and
>regA_start < regA_end because order == 0 region is of
>size 1 byte.
>
>When regB_start == regA_start and regB_end == regA_end,
>the following is the outcome of the expressions in the existing
>"if ()" check.
>
>(regB_start <= regA_start) == true
>(regA_start < regB_end) == true
>(regB_start < regA_end) == true
>(regA_end <= regB_end) == true
>
>Based on the above, I don't see how this patch helps.
>

Yes, this is my mistake, drop this patch is just OK.

>Regards,
>Anup
>
>
>
>> ---
>>  lib/sbi/sbi_domain.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
>> index 283b598..2b9d16f 100644
>> --- a/lib/sbi/sbi_domain.c
>> +++ b/lib/sbi/sbi_domain.c
>> @@ -185,8 +185,8 @@ static bool is_region_subset(const struct sbi_domain_memregion *regA,
>>         ulong regB_end = regB->base + (BIT(regB->order) - 1);
>>
>>         if ((regB_start <= regA_start) &&
>> -           (regA_start < regB_end) &&
>> -           (regB_start < regA_end) &&
>> +           (regB_start <= regA_end) &&
>> +           (regA_start <= regB_end) &&
>>             (regA_end <= regB_end))
>>                 return true;
>>
>> --
>> 2.42.0
>>
>
diff mbox series

Patch

diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index 283b598..2b9d16f 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -185,8 +185,8 @@  static bool is_region_subset(const struct sbi_domain_memregion *regA,
 	ulong regB_end = regB->base + (BIT(regB->order) - 1);
 
 	if ((regB_start <= regA_start) &&
-	    (regA_start < regB_end) &&
-	    (regB_start < regA_end) &&
+	    (regB_start <= regA_end) &&
+	    (regA_start <= regB_end) &&
 	    (regA_end <= regB_end))
 		return true;