Revision 55e6d8037805b3400096d621091dfbf713f97e83 authored by Yang Yingliang on 12 October 2021, 02:37:35 UTC, committed by Mark Brown on 12 October 2021, 10:48:43 UTC
In regcache_rbtree_insert_to_block(), when 'present' realloc failed,
the 'blk' which is supposed to assign to 'rbnode->block' will be freed,
so 'rbnode->block' points a freed memory, in the error handling path of
regcache_rbtree_init(), 'rbnode->block' will be freed again in
regcache_rbtree_exit(), KASAN will report double-free as follows:

BUG: KASAN: double-free or invalid-free in kfree+0xce/0x390
Call Trace:
 slab_free_freelist_hook+0x10d/0x240
 kfree+0xce/0x390
 regcache_rbtree_exit+0x15d/0x1a0
 regcache_rbtree_init+0x224/0x2c0
 regcache_init+0x88d/0x1310
 __regmap_init+0x3151/0x4a80
 __devm_regmap_init+0x7d/0x100
 madera_spi_probe+0x10f/0x333 [madera_spi]
 spi_probe+0x183/0x210
 really_probe+0x285/0xc30

To fix this, moving up the assignment of rbnode->block to immediately after
the reallocation has succeeded so that the data structure stays valid even
if the second reallocation fails.

Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: 3f4ff561bc88b ("regmap: rbtree: Make cache_present bitmap per node")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20211012023735.1632786-1-yangyingliang@huawei.com
Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent d287801
History
File Mode Size
Kconfig -rw-r--r-- 5.1 KB
Makefile -rw-r--r-- 986 bytes
alarmtimer.c -rw-r--r-- 23.7 KB
clockevents.c -rw-r--r-- 19.5 KB
clocksource-wdtest.c -rw-r--r-- 5.8 KB
clocksource.c -rw-r--r-- 40.1 KB
hrtimer.c -rw-r--r-- 61.3 KB
itimer.c -rw-r--r-- 10.2 KB
jiffies.c -rw-r--r-- 3.2 KB
namespace.c -rw-r--r-- 10.4 KB
ntp.c -rw-r--r-- 28.3 KB
ntp_internal.h -rw-r--r-- 783 bytes
posix-clock.c -rw-r--r-- 5.6 KB
posix-cpu-timers.c -rw-r--r-- 42.4 KB
posix-stubs.c -rw-r--r-- 5.5 KB
posix-timers.c -rw-r--r-- 37.1 KB
posix-timers.h -rw-r--r-- 1.9 KB
sched_clock.c -rw-r--r-- 7.7 KB
test_udelay.c -rw-r--r-- 3.6 KB
tick-broadcast-hrtimer.c -rw-r--r-- 3.2 KB
tick-broadcast.c -rw-r--r-- 30.3 KB
tick-common.c -rw-r--r-- 14.5 KB
tick-internal.h -rw-r--r-- 6.9 KB
tick-legacy.c -rw-r--r-- 999 bytes
tick-oneshot.c -rw-r--r-- 3.2 KB
tick-sched.c -rw-r--r-- 38.0 KB
tick-sched.h -rw-r--r-- 3.3 KB
time.c -rw-r--r-- 22.9 KB
time_test.c -rw-r--r-- 2.0 KB
timeconst.bc -rw-r--r-- 3.0 KB
timeconv.c -rw-r--r-- 4.5 KB
timecounter.c -rw-r--r-- 2.5 KB
timekeeping.c -rw-r--r-- 69.6 KB
timekeeping.h -rw-r--r-- 983 bytes
timekeeping_debug.c -rw-r--r-- 1.3 KB
timekeeping_internal.h -rw-r--r-- 921 bytes
timer.c -rw-r--r-- 60.0 KB
timer_list.c -rw-r--r-- 8.6 KB
vsyscall.c -rw-r--r-- 4.9 KB

back to top