From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Venkata Narendra Kumar Gutta <vnkgutta@codeaurora.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.4 03/16] driver core: platform: Fix the usage of platform device name(pdev->name)
Date: Fri, 25 Oct 2019 09:58:27 -0400 [thread overview]
Message-ID: <20191025135842.25977-3-sashal@kernel.org> (raw)
In-Reply-To: <20191025135842.25977-1-sashal@kernel.org>
From: Venkata Narendra Kumar Gutta <vnkgutta@codeaurora.org>
[ Upstream commit edb16da34b084c66763f29bee42b4e6bb33c3d66 ]
Platform core is using pdev->name as the platform device name to do
the binding of the devices with the drivers. But, when the platform
driver overrides the platform device name with dev_set_name(),
the pdev->name is pointing to a location which is freed and becomes
an invalid parameter to do the binding match.
use-after-free instance:
[ 33.325013] BUG: KASAN: use-after-free in strcmp+0x8c/0xb0
[ 33.330646] Read of size 1 at addr ffffffc10beae600 by task modprobe
[ 33.339068] CPU: 5 PID: 518 Comm: modprobe Tainted:
G S W O 4.19.30+ #3
[ 33.346835] Hardware name: MTP (DT)
[ 33.350419] Call trace:
[ 33.352941] dump_backtrace+0x0/0x3b8
[ 33.356713] show_stack+0x24/0x30
[ 33.360119] dump_stack+0x160/0x1d8
[ 33.363709] print_address_description+0x84/0x2e0
[ 33.368549] kasan_report+0x26c/0x2d0
[ 33.372322] __asan_report_load1_noabort+0x2c/0x38
[ 33.377248] strcmp+0x8c/0xb0
[ 33.380306] platform_match+0x70/0x1f8
[ 33.384168] __driver_attach+0x78/0x3a0
[ 33.388111] bus_for_each_dev+0x13c/0x1b8
[ 33.392237] driver_attach+0x4c/0x58
[ 33.395910] bus_add_driver+0x350/0x560
[ 33.399854] driver_register+0x23c/0x328
[ 33.403886] __platform_driver_register+0xd0/0xe0
So, use dev_name(&pdev->dev), which fetches the platform device name from
the kobject(dev->kobj->name) of the device instead of the pdev->name.
Signed-off-by: Venkata Narendra Kumar Gutta <vnkgutta@codeaurora.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/base/platform.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 065fcc4be263a..071dd053a917b 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -796,7 +796,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
if (len != -ENODEV)
return len;
- len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name);
+ len = snprintf(buf, PAGE_SIZE, "platform:%s\n", dev_name(&pdev->dev));
return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
}
@@ -872,7 +872,7 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
return rc;
add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX,
- pdev->name);
+ dev_name(&pdev->dev));
return 0;
}
@@ -881,7 +881,7 @@ static const struct platform_device_id *platform_match_id(
struct platform_device *pdev)
{
while (id->name[0]) {
- if (strcmp(pdev->name, id->name) == 0) {
+ if (strcmp(dev_name(&pdev->dev), id->name) == 0) {
pdev->id_entry = id;
return id;
}
@@ -925,7 +925,7 @@ static int platform_match(struct device *dev, struct device_driver *drv)
return platform_match_id(pdrv->id_table, pdev) != NULL;
/* fall-back to driver name match */
- return (strcmp(pdev->name, drv->name) == 0);
+ return (strcmp(dev_name(&pdev->dev), drv->name) == 0);
}
#ifdef CONFIG_PM_SLEEP
--
2.20.1
next prev parent reply other threads:[~2019-10-25 14:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-25 13:58 [PATCH AUTOSEL 4.4 01/16] PCI/ASPM: Do not initialize link state when aspm_disabled is set Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 02/16] ACPI: video: Use vendor backlight on Sony VPCEH3U1E Sasha Levin
2019-10-25 13:58 ` Sasha Levin [this message]
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 04/16] powerpc/pseries/hvconsole: Fix stack overread via udbg Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 05/16] scsi: RDMA/srp: Fix a sleep-in-invalid-context bug Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 06/16] sch_netem: fix rcu splat in netem_enqueue() Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 07/16] llc: fix sk_buff leak in llc_sap_state_process() Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 08/16] llc: fix sk_buff leak in llc_conn_service() Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 09/16] bonding: fix potential NULL deref in bond_update_slave_arr Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 10/16] net: usb: sr9800: fix uninitialized local variable Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 11/16] jbd2: flush_descriptor(): Do not decrease buffer head's ref count Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 12/16] ath9k: dynack: fix possible deadlock in ath_dynack_node_{de}init Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 13/16] Btrfs: fix hang when loading existing inode cache off disk Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 14/16] ubi: ubi_wl_get_peb: Increase the number of attempts while getting PEB Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 15/16] RDMA/iwcm: Fix a lock inversion issue Sasha Levin
2019-10-25 13:58 ` [PATCH AUTOSEL 4.4 16/16] bdi: Do not use freezable workqueue Sasha Levin
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=20191025135842.25977-3-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=vnkgutta@codeaurora.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