WSL2-Linux-Kernel/drivers/base/regmap
Laxman Dewangan 6560ffd1cc regmap: fix possible memory corruption in regmap_bulk_read()
The function regmap_bulk_read() calls the regmap_read() for
each register if set of register has volatile and cache is
enabled. In this case, last few register read makes the memory
corruption if the register size is not the size of unsigned int.
The regam_read() takes argument as unsigned int for returning
value and it update the value as
	*val = map->format.parse_val(map->work_buf);
This causes complete 4 bytes (size of unsigned int) to get written.
Now if client pass the memory pointer for value which is equal to the
required size of register count in regmap_bulk_read() then last few
register read actually update the memory beyond passed pointer size.

Avoid this by using local variable for read and then do memcpy()
for actual byte copy to passed pointer based on register size.

I allocated one pointer ptr and take first 16 bytes dump of that
pointer then call regmap_bulk_read() with pointer which is just
on top of this allocated pointer and register count of 128. Here
register size is 1 byte.
The memory trace of last 5 register read are as follows:

[    5.438589] regmap_bulk_read after regamp_read() for register 122
[    5.447421] 0xef993c20 0xef993c00 0x00000000 0x00000001
[    5.467535] regmap_bulk_read after regamp_read() for register 123
[    5.476374] 0xef993c20 0xef993c00 0x00000000 0x00000001
[    5.496425] regmap_bulk_read after regamp_read() for register 124
[    5.505260] 0xef993c20 0xef993c00 0x00000000 0x00000001
[    5.525372] regmap_bulk_read after regamp_read() for register 125
[    5.534205] 0xef993c00 0xef993c00 0x00000000 0x00000001
[    5.554258] regmap_bulk_read after regamp_read() for register 126
[    5.563100] 0xef990000 0xef993c00 0x00000000 0x00000001
[    5.554258] regmap_bulk_read after regamp_read() for register 127
[    5.587108] 0xef000000 0xef993c00 0x00000000 0x00000001

Here it is observed that the memory content at first word started changing
on last 3 regmap_read() and so corruption happened.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2012-05-09 15:44:11 +01:00
..
Kconfig regmap: Add a reusable irq_chip for regmap based interrupt controllers 2011-11-08 11:29:48 +00:00
Makefile regmap: Remove indexed cache type 2011-11-20 20:56:34 +00:00
internal.h Merge remote-tracking branches 'regmap/topic/patch' and 'regmap/topic/sync' into regmap-next 2012-03-14 13:14:24 +00:00
regcache-lzo.c The following text was taken from the original review request: 2012-03-24 10:41:37 -07:00
regcache-rbtree.c regmap: A couple of small fixes for 3.4 2012-04-07 09:56:00 -07:00
regcache.c regmap: Export regcache_sync_region() 2012-04-03 13:08:53 +01:00
regmap-debugfs.c simple_open: automatically convert to simple_open() 2012-04-05 15:25:50 -07:00
regmap-i2c.c regmap: Implement managed regmap_init() 2012-01-30 21:06:43 +00:00
regmap-irq.c device.h: cleanup users outside of linux/include (C files) 2012-03-11 14:27:37 -04:00
regmap-spi.c regmap: Implement managed regmap_init() 2012-01-30 21:06:43 +00:00
regmap.c regmap: fix possible memory corruption in regmap_bulk_read() 2012-05-09 15:44:11 +01:00