linux/drivers/base
Charles Keepax 94cc89eb8f
regmap: debugfs: Fix handling of name string for debugfs init delays
In regmap_debugfs_init the initialisation of the debugfs is delayed
if the root node isn't ready yet. Most callers of regmap_debugfs_init
pass the name from the regmap_config, which is considered temporary
ie. may be unallocated after the regmap_init call returns. This leads
to a potential use after free, where config->name has been freed by
the time it is used in regmap_debugfs_initcall.

This situation can be seen on Zynq, where the architecture init_irq
callback registers a syscon device, using a local variable for the
regmap_config. As init_irq is very early in the platform bring up the
regmap debugfs root isn't ready yet. Although this doesn't crash it
does result in the debugfs entry not having the correct name.

Regmap already sets map->name from config->name on the regmap_init
path and the fact that a separate field is used to pass the name
to regmap_debugfs_init appears to be an artifact of the debugfs
name being added before the map name. As such this patch updates
regmap_debugfs_init to use map->name, which is already duplicated from
the config avoiding the issue.

This does however leave two lose ends, both regmap_attach_dev and
regmap_reinit_cache can be called after a regmap is registered and
would have had the effect of applying a new name to the debugfs
entries. In both of these cases it was chosen to update the map
name. In the case of regmap_attach_dev there are 3 users that
currently use this function to update the name, thus doing so avoids
changes for those users and it seems reasonable that attaching
a device would want to set the name of the map. In the case of
regmap_reinit_cache the primary use-case appears to be devices that
need some register access to identify the device (for example devices
in the same family) and then update the cache to match the exact
hardware. Whilst no users do currently update the name here, given the
use-case it seemed reasonable the name might want to be updated once
the device is better identified.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20200917120828.12987-1-ckeepax@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-09-17 18:54:20 +01:00
..
firmware_loader firmware_loader: EFI firmware loader must handle pre-allocated buffer 2020-07-25 12:06:33 +02:00
power PM: runtime: Improve kerneldoc of pm_runtime_get_if_active() 2020-08-04 12:40:10 +02:00
regmap regmap: debugfs: Fix handling of name string for debugfs init delays 2020-09-17 18:54:20 +01:00
test drivers: base: default KUNIT_* fragments to KUNIT_ALL_TESTS 2020-06-01 14:24:25 -06:00
arch_topology.c arch_topology, sched/core: Cleanup thermal pressure definition 2020-07-22 10:22:05 +02:00
attribute_container.c scsi: drivers: base: Support atomic version of attribute_container_device_trigger 2020-01-15 22:55:36 -05:00
base.h driver core: add deferring probe reason to devices_deferred property 2020-07-30 09:03:43 +02:00
bus.c device.h: move 'struct bus' stuff out to device/bus.h 2019-12-16 10:11:12 +01:00
cacheinfo.c Driver Core and debugfs changes for 5.3-rc1 2019-07-12 12:24:03 -07:00
class.c device.h: move 'struct class' stuff out to device/class.h 2019-12-16 10:11:14 +01:00
component.c component: Silence bind error on -EPROBE_DEFER 2020-04-28 17:54:15 +02:00
container.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
core.c Devicetree updates for v5.9: 2020-08-05 13:02:45 -07:00
cpu.c x86/speculation: Add Special Register Buffer Data Sampling (SRBDS) mitigation 2020-04-20 12:19:22 +02:00
dd.c driver core: add deferring probe reason to devices_deferred property 2020-07-30 09:03:43 +02:00
devcon.c Merge generic_lookup_helpers into usb-next 2019-09-03 17:11:07 +02:00
devcoredump.c devcoredump: fix typo in comment 2019-08-15 17:38:11 +02:00
devres.c devres: handle zero size in devm_kmalloc() 2020-07-02 14:36:02 +02:00
devtmpfs.c init: add an init_chroot helper 2020-07-31 08:17:52 +02:00
driver.c drivers: base: Convert to printk alias functions 2020-07-10 14:16:44 +02:00
firmware.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
hypervisor.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
init.c base: fix order of OF initialization 2018-07-07 17:54:29 +02:00
isa.c Merge 4.15-rc3 into driver-core-next 2017-12-11 08:50:05 +01:00
Kconfig drivers: base: default KUNIT_* fragments to KUNIT_ALL_TESTS 2020-06-01 14:24:25 -06:00
Makefile drivers: base: Introducing software nodes to the firmware node framework 2018-11-26 18:19:11 +01:00
map.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
memory.c drivers/base/memory: rename base_memory_block_id to memory_block_id 2020-07-10 14:38:44 +02:00
module.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
node.c mm: memcontrol: account kernel stack per node 2020-08-07 11:33:25 -07:00
pinctrl.c driver core: Remove redundant license text 2017-12-07 18:36:44 +01:00
platform-msi.c platform-msi: Fix typos in comment 2020-05-18 10:28:30 +01:00
platform.c driver core: platform: expose numa_node to users in sysfs 2020-07-10 14:14:37 +02:00
property.c device property: Avoid NULL pointer dereference in device_get_next_child_node() 2020-07-23 17:04:28 +02:00
soc.c driver/base/soc: Use kobj_to_dev() API 2020-04-28 21:05:42 +02:00
swnode.c software node: Use software_node_unregister() when unregistering group of nodes 2020-07-10 14:35:37 +02:00
syscore.c treewide: Switch printk users from %pf and %pF to %ps and %pS, respectively 2019-04-09 14:19:06 +02:00
topology.c topology: mark a function as __init to save some memory 2020-07-10 14:35:37 +02:00
transport_class.c scsi: drivers: base: Propagate errors through the transport component 2020-01-15 22:55:37 -05:00