From: Xujun Leng <lengxujun2007@126.com>
To: gregkh@linuxfoundation.org, rafael@kernel.org
Cc: linux-kernel@vger.kernel.org, Xujun Leng <lengxujun2007@126.com>
Subject: [PATCH] driver core: platform: added arguments check for platform_device_add_resources()
Date: Tue, 7 Mar 2023 13:01:16 +0800 [thread overview]
Message-ID: <20230307050116.12019-1-lengxujun2007@126.com> (raw)
In the follow two cases, platform_device_add_resources() can lead an
invalid address access:
1) If (!res && num > 0), pdev->resource will be set to NULL but
pdev->num_resources > 0, then a later platform_get_resource() will
cause invalid address access.
2) If (res && num == 0), because num == 0 cause kmalloc_slab() returns
ZERO_SIZE_PTR, then kmemdup() will copy data to the invalid address
ZERO_SIZE_PTR.
Signed-off-by: Xujun Leng <lengxujun2007@126.com>
---
drivers/base/platform.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 77510e4f47de..a060941c3076 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -606,6 +606,9 @@ int platform_device_add_resources(struct platform_device *pdev,
{
struct resource *r = NULL;
+ if ((!res && num > 0) || (res && num == 0))
+ return -EINVAL;
+
if (res) {
r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL);
if (!r)
--
2.25.1
next reply other threads:[~2023-03-07 5:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 5:01 Xujun Leng [this message]
2023-03-09 14:39 ` Greg KH
2023-03-10 6:55 ` Xujun Leng
2023-03-10 7:51 ` Greg KH
2023-03-10 12:57 ` Xujun Leng
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=20230307050116.12019-1-lengxujun2007@126.com \
--to=lengxujun2007@126.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@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
all inboxes | Powered by JetHome®