提交 77df5e38 编写于 作者: R Rafael J. Wysocki 提交者: Zhong Jinghua

ACPI: bus: Avoid non-ACPI device objects in walks over children

mainline inclusion
from mainline-v5.19-rc1
commit 10fa1b2c
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I67QNJ
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=10fa1b2cdc899ab471000968af56215bf3c90d8e

---------------------------------------------

When walking the children of an ACPI device, take extra care to avoid
using to_acpi_device() on the ones that are not ACPI devices, because
that may lead to out-of-bounds access and memory corruption.

While at it, make the function passed to acpi_dev_for_each_child()
take a struct acpi_device pointer argument (instead of a struct device
one), so it is more straightforward to use.

Fixes: b7dd6298 ("ACPI: PM: Introduce acpi_dev_power_up_children_with_adr()")
Reported-by: Nkernel test robot <oliver.sang@intel.com>
BugLink: https://lore.kernel.org/lkml/20220420064725.GB16310@xsang-OptiPlex-9020/Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: NMika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: NZhang Zekun <zhangzekun11@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
上级 8e98750f
无相关合并请求
......@@ -966,10 +966,30 @@ struct bus_type acpi_bus_type = {
.uevent = acpi_device_uevent,
};
struct acpi_dev_walk_context {
int (*fn)(struct acpi_device *, void *);
void *data;
};
static int acpi_dev_for_one_check(struct device *dev, void *context)
{
struct acpi_dev_walk_context *adwc = context;
if (dev->bus != &acpi_bus_type)
return 0;
return adwc->fn(to_acpi_device(dev), adwc->data);
}
int acpi_dev_for_each_child(struct acpi_device *adev,
int (*fn)(struct device *, void *), void *data)
int (*fn)(struct acpi_device *, void *), void *data)
{
return device_for_each_child(&adev->dev, data, fn);
struct acpi_dev_walk_context adwc = {
.fn = fn,
.data = data,
};
return device_for_each_child(&adev->dev, &adwc, acpi_dev_for_one_check);
}
/* --------------------------------------------------------------------------
......
......@@ -495,7 +495,7 @@ extern int acpi_notifier_call_chain(struct acpi_device *, u32, u32);
extern int register_acpi_notifier(struct notifier_block *);
extern int unregister_acpi_notifier(struct notifier_block *);
int acpi_dev_for_each_child(struct acpi_device *adev,
int (*fn)(struct device *, void *), void *data);
int (*fn)(struct acpi_device *, void *), void *data);
/*
* External Functions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部