From: <alucerop@amd.com>
To: <linux-pci@vger.kernel.org>, <bhelgaas@google.com>,
<alison.schofield@intel.com>
Cc: Alejandro Lucero <alucerop@amd.com>
Subject: [PATCH] resource: harden resource_contains
Date: Fri, 29 Nov 2024 09:15:12 +0000 [thread overview]
Message-ID: <20241129091512.15661-1-alucerop@amd.com> (raw)
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
next reply other threads:[~2024-11-29 9:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-29 9:15 alucerop [this message]
2024-12-04 23:06 ` [PATCH] resource: harden resource_contains 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241129091512.15661-1-alucerop@amd.com \
--to=alucerop@amd.com \
--cc=alison.schofield@intel.com \
--cc=bhelgaas@google.com \
--cc=linux-pci@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox