* [PATCH] resource: harden resource_contains
@ 2024-11-29 9:15 alucerop
2024-12-04 23:06 ` Alison Schofield
2024-12-04 23:24 ` Bjorn Helgaas
0 siblings, 2 replies; 5+ messages in thread
From: alucerop @ 2024-11-29 9:15 UTC (permalink / raw)
To: linux-pci, bhelgaas, alison.schofield; +Cc: Alejandro Lucero
From: Alejandro Lucero <alucerop@amd.com>
While resource_contains checks for IORESOURCE_UNSET flag for the
resources given, if r1 was initialized with 0 size, the function
returns a false positive. This is so because resource start and
end fields are unsigned with end initialised to size - 1 by current
resource macros.
Make the function to check for the resource size for both resources
since r2 with size 0 should not be considered as valid for the function
purpose.
Signed-off-by: Alejandro Lucero <alucerop@amd.com>
Suggested-by: Alison Schofield <alison.schofield@intel.com>
---
include/linux/ioport.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 6e9fb667a1c5..6cb8a8494508 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -264,6 +264,8 @@ static inline unsigned long resource_ext_type(const struct resource *res)
/* True iff r1 completely contains r2 */
static inline bool resource_contains(const struct resource *r1, const struct resource *r2)
{
+ if (!resource_size(r1) || !resource_size(r2))
+ return false;
if (resource_type(r1) != resource_type(r2))
return false;
if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET)
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] resource: harden resource_contains
2024-11-29 9:15 [PATCH] resource: harden resource_contains alucerop
@ 2024-12-04 23:06 ` Alison Schofield
2024-12-08 11:20 ` Alejandro Lucero Palau
2024-12-04 23:24 ` Bjorn Helgaas
1 sibling, 1 reply; 5+ messages in thread
From: Alison Schofield @ 2024-12-04 23:06 UTC (permalink / raw)
To: alucerop; +Cc: linux-cxl, linux-pci, bhelgaas
+ linux-cxl
On Fri, Nov 29, 2024 at 09:15:12AM +0000, alucerop@amd.com wrote:
> From: Alejandro Lucero <alucerop@amd.com>
>
> While resource_contains checks for IORESOURCE_UNSET flag for the
> resources given, if r1 was initialized with 0 size, the function
> returns a false positive. This is so because resource start and
> end fields are unsigned with end initialised to size - 1 by current
> resource macros.
>
> Make the function to check for the resource size for both resources
> since r2 with size 0 should not be considered as valid for the function
> purpose.
>
Hi Alejandro,
Can this patch be included in the CXL Type-2 patchset, as a replacement for:
[PATCH v6 10/28] cxl: harden resource_contains checks to handle zero size resources
https://lore.kernel.org/20241202171222.62595-11-alejandro.lucero-palau@amd.com/T/#u
Keeping it in that set also keeps the discussion history.
DaveJ may be able to take it through the CXL tree with Bjorn's ACK.
--Alison
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Alejandro Lucero <alucerop@amd.com>
> Suggested-by: Alison Schofield <alison.schofield@intel.com>
> ---
> include/linux/ioport.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/include/linux/ioport.h b/include/linux/ioport.h
> index 6e9fb667a1c5..6cb8a8494508 100644
> --- a/include/linux/ioport.h
> +++ b/include/linux/ioport.h
> @@ -264,6 +264,8 @@ static inline unsigned long resource_ext_type(const struct resource *res)
> /* True iff r1 completely contains r2 */
> static inline bool resource_contains(const struct resource *r1, const struct resource *r2)
> {
> + if (!resource_size(r1) || !resource_size(r2))
> + return false;
> if (resource_type(r1) != resource_type(r2))
> return false;
> if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET)
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] resource: harden resource_contains
2024-12-04 23:06 ` Alison Schofield
@ 2024-12-08 11:20 ` Alejandro Lucero Palau
0 siblings, 0 replies; 5+ messages in thread
From: Alejandro Lucero Palau @ 2024-12-08 11:20 UTC (permalink / raw)
To: Alison Schofield; +Cc: linux-cxl, linux-pci, bhelgaas
On 12/4/24 23:06, Alison Schofield wrote:
> + linux-cxl
>
> On Fri, Nov 29, 2024 at 09:15:12AM +0000, alucerop@amd.com wrote:
>> From: Alejandro Lucero <alucerop@amd.com>
>>
>> While resource_contains checks for IORESOURCE_UNSET flag for the
>> resources given, if r1 was initialized with 0 size, the function
>> returns a false positive. This is so because resource start and
>> end fields are unsigned with end initialised to size - 1 by current
>> resource macros.
>>
>> Make the function to check for the resource size for both resources
>> since r2 with size 0 should not be considered as valid for the function
>> purpose.
>>
> Hi Alejandro,
>
> Can this patch be included in the CXL Type-2 patchset, as a replacement for:
>
> [PATCH v6 10/28] cxl: harden resource_contains checks to handle zero size resources
> https://lore.kernel.org/20241202171222.62595-11-alejandro.lucero-palau@amd.com/T/#u
>
> Keeping it in that set also keeps the discussion history.
>
> DaveJ may be able to take it through the CXL tree with Bjorn's ACK.
Sure. I'll do so in the almost ready v7.
>
> --Alison
>
>
> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Thank you
>
>> Signed-off-by: Alejandro Lucero <alucerop@amd.com>
>> Suggested-by: Alison Schofield <alison.schofield@intel.com>
>> ---
>> include/linux/ioport.h | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/include/linux/ioport.h b/include/linux/ioport.h
>> index 6e9fb667a1c5..6cb8a8494508 100644
>> --- a/include/linux/ioport.h
>> +++ b/include/linux/ioport.h
>> @@ -264,6 +264,8 @@ static inline unsigned long resource_ext_type(const struct resource *res)
>> /* True iff r1 completely contains r2 */
>> static inline bool resource_contains(const struct resource *r1, const struct resource *r2)
>> {
>> + if (!resource_size(r1) || !resource_size(r2))
>> + return false;
>> if (resource_type(r1) != resource_type(r2))
>> return false;
>> if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET)
>> --
>> 2.17.1
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] resource: harden resource_contains
2024-11-29 9:15 [PATCH] resource: harden resource_contains alucerop
2024-12-04 23:06 ` Alison Schofield
@ 2024-12-04 23:24 ` Bjorn Helgaas
2024-12-08 11:21 ` Alejandro Lucero Palau
1 sibling, 1 reply; 5+ messages in thread
From: Bjorn Helgaas @ 2024-12-04 23:24 UTC (permalink / raw)
To: alucerop; +Cc: linux-pci, bhelgaas, alison.schofield
On Fri, Nov 29, 2024 at 09:15:12AM +0000, alucerop@amd.com wrote:
> From: Alejandro Lucero <alucerop@amd.com>
>
> While resource_contains checks for IORESOURCE_UNSET flag for the
> resources given, if r1 was initialized with 0 size, the function
> returns a false positive. This is so because resource start and
> end fields are unsigned with end initialised to size - 1 by current
> resource macros.
>
> Make the function to check for the resource size for both resources
> since r2 with size 0 should not be considered as valid for the function
> purpose.
>
> Signed-off-by: Alejandro Lucero <alucerop@amd.com>
> Suggested-by: Alison Schofield <alison.schofield@intel.com>
Seems reasonable to me. FWIW,
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
> ---
> include/linux/ioport.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/include/linux/ioport.h b/include/linux/ioport.h
> index 6e9fb667a1c5..6cb8a8494508 100644
> --- a/include/linux/ioport.h
> +++ b/include/linux/ioport.h
> @@ -264,6 +264,8 @@ static inline unsigned long resource_ext_type(const struct resource *res)
> /* True iff r1 completely contains r2 */
> static inline bool resource_contains(const struct resource *r1, const struct resource *r2)
> {
> + if (!resource_size(r1) || !resource_size(r2))
> + return false;
> if (resource_type(r1) != resource_type(r2))
> return false;
> if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET)
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] resource: harden resource_contains
2024-12-04 23:24 ` Bjorn Helgaas
@ 2024-12-08 11:21 ` Alejandro Lucero Palau
0 siblings, 0 replies; 5+ messages in thread
From: Alejandro Lucero Palau @ 2024-12-08 11:21 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, bhelgaas, alison.schofield
On 12/4/24 23:24, Bjorn Helgaas wrote:
> On Fri, Nov 29, 2024 at 09:15:12AM +0000, alucerop@amd.com wrote:
>> From: Alejandro Lucero <alucerop@amd.com>
>>
>> While resource_contains checks for IORESOURCE_UNSET flag for the
>> resources given, if r1 was initialized with 0 size, the function
>> returns a false positive. This is so because resource start and
>> end fields are unsigned with end initialised to size - 1 by current
>> resource macros.
>>
>> Make the function to check for the resource size for both resources
>> since r2 with size 0 should not be considered as valid for the function
>> purpose.
>>
>> Signed-off-by: Alejandro Lucero <alucerop@amd.com>
>> Suggested-by: Alison Schofield <alison.schofield@intel.com>
> Seems reasonable to me. FWIW,
>
> Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Thanks!
>> ---
>> include/linux/ioport.h | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/include/linux/ioport.h b/include/linux/ioport.h
>> index 6e9fb667a1c5..6cb8a8494508 100644
>> --- a/include/linux/ioport.h
>> +++ b/include/linux/ioport.h
>> @@ -264,6 +264,8 @@ static inline unsigned long resource_ext_type(const struct resource *res)
>> /* True iff r1 completely contains r2 */
>> static inline bool resource_contains(const struct resource *r1, const struct resource *r2)
>> {
>> + if (!resource_size(r1) || !resource_size(r2))
>> + return false;
>> if (resource_type(r1) != resource_type(r2))
>> return false;
>> if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET)
>> --
>> 2.17.1
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-12-08 11:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-29 9:15 [PATCH] resource: harden resource_contains alucerop
2024-12-04 23:06 ` Alison Schofield
2024-12-08 11:20 ` Alejandro Lucero Palau
2024-12-04 23:24 ` Bjorn Helgaas
2024-12-08 11:21 ` Alejandro Lucero Palau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox