lkml.org 
[lkml]   [2023]   [Mar]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] driver core: platform: added arguments check for platform_device_add_resources()
Date
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
\
 
 \ /
  Last update: 2023-03-27 00:46    [W:0.135 / U:0.440 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site