mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
md/raid5: fix NULL pointer dereference in raid5_free_percpu
If cpuhp_state_add_instance() fails in raid5_alloc_percpu() (e.g., the
startup callback raid456_cpu_up_prepare fails due to an allocation
failure), conf->node is never added to the cpuhp instance list and
its pprev remains NULL (from kzalloc initialization).
When setup_conf() then jumps to abort, free_conf() calls
raid5_free_percpu(), which checks conf->percpu (non-NULL, since it was
allocated before the cpuhp failure) and proceeds to call
cpuhp_state_remove_instance(). This calls hlist_del() on the unhashed
node, which dereferences node->pprev (NULL), causing a kernel panic.
Guard the removal with hlist_unhashed_lockless() so that the cpuhp
instance is only removed if it was actually added. The lockless variant
uses READ_ONCE() for the pprev read, which is safe here because the
actual removal is synchronized by cpuhp_state_mutex inside
cpuhp_state_remove_instance().
Fixes: 29c6d1bbd7 ("md/raid5: Convert to hotplug state machine")
Cc: stable@vger.kernel.org
Signed-off-by: Cao Guanghui <caoguanghui@kylinos.cn>
Link: https://patch.msgid.link/20260827080341.112296-2-ghuicao@163.com
Signed-off-by: Yu Kuai <yukuai@fygo.io>
This commit is contained in:
parent
5028ceee17
commit
41742e3526
|
|
@ -7539,7 +7539,8 @@ static void raid5_free_percpu(struct r5conf *conf)
|
|||
if (!conf->percpu)
|
||||
return;
|
||||
|
||||
cpuhp_state_remove_instance(CPUHP_MD_RAID5_PREPARE, &conf->node);
|
||||
if (!hlist_unhashed_lockless(&conf->node))
|
||||
cpuhp_state_remove_instance(CPUHP_MD_RAID5_PREPARE, &conf->node);
|
||||
free_percpu(conf->percpu);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user