Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regmap: Disable debugfs when locking is disabled

The recently added support for disabling the regmap internal locking left
debugfs enabled for devices with the locking disabled. This is a problem
since debugfs allows userspace to do things like initiate reads from the
hardware which will use the scratch buffers protected by the regmap locking
so could cause data corruption.

For safety address this by just disabling debugfs for these devices. That
is overly conservative since some of the debugfs files just read internal
data structures but it's much simpler to implmement and less likely to
lead to problems with tooling that works with debugfs.

Reported-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@kernel.org>

+12
+8
drivers/base/regmap/internal.h
··· 77 77 int async_ret; 78 78 79 79 #ifdef CONFIG_DEBUG_FS 80 + bool debugfs_disable; 80 81 struct dentry *debugfs; 81 82 const char *debugfs_name; 82 83 ··· 216 215 extern void regmap_debugfs_initcall(void); 217 216 extern void regmap_debugfs_init(struct regmap *map, const char *name); 218 217 extern void regmap_debugfs_exit(struct regmap *map); 218 + 219 + static inline void regmap_debugfs_disable(struct regmap *map) 220 + { 221 + map->debugfs_disable = true; 222 + } 223 + 219 224 #else 220 225 static inline void regmap_debugfs_initcall(void) { } 221 226 static inline void regmap_debugfs_init(struct regmap *map, const char *name) { } 222 227 static inline void regmap_debugfs_exit(struct regmap *map) { } 228 + static inline void regmap_debugfs_disable(struct regmap *map) { } 223 229 #endif 224 230 225 231 /* regcache core declarations */
+3
drivers/base/regmap/regmap-debugfs.c
··· 529 529 struct regmap_range_node *range_node; 530 530 const char *devname = "dummy"; 531 531 532 + if (map->debugfs_disable) 533 + return; 534 + 532 535 /* If we don't have the debugfs root yet, postpone init */ 533 536 if (!regmap_debugfs_root) { 534 537 struct regmap_debugfs_node *node;
+1
drivers/base/regmap/regmap.c
··· 676 676 677 677 if (config->disable_locking) { 678 678 map->lock = map->unlock = regmap_lock_unlock_none; 679 + regmap_debugfs_disable(map); 679 680 } else if (config->lock && config->unlock) { 680 681 map->lock = config->lock; 681 682 map->unlock = config->unlock;