Skip to content

Commit 592a682

Browse files
Chen Ridonghtejun
authored andcommitted
cgroup/dmem: avoid rcu warning when unregister region
A warnning was detected: WARNING: suspicious RCU usage 6.19.0-rc7-next-20260129+ #1101 Tainted: G O kernel/cgroup/dmem.c:456 suspicious rcu_dereference_check() usage! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 1 lock held by insmod/532: #0: ffffffff85e78b38 (dmemcg_lock){+.+.}-dmem_cgroup_unregister_region+ stack backtrace: CPU: 2 UID: 0 PID: 532 Comm: insmod Tainted: 6.19.0-rc7-next- Tainted: [O]=OOT_MODULE Call Trace: <TASK> dump_stack_lvl+0xb0/0xd0 lockdep_rcu_suspicious+0x151/0x1c0 dmem_cgroup_unregister_region+0x1e2/0x380 ? __pfx_dmem_test_init+0x10/0x10 [dmem_uaf] dmem_test_init+0x65/0xff0 [dmem_uaf] do_one_initcall+0xbb/0x3a0 The macro list_for_each_rcu() must be used within an RCU read-side critical section (between rcu_read_lock() and rcu_read_unlock()). Using it outside that context, as seen in dmem_cgroup_unregister_region(), triggers the lockdep warning because the RCU protection is not guaranteed. Replace list_for_each_rcu() with list_for_each_entry_safe(), which is appropriate for traversal under spinlock protection where nodes may be deleted. Fixes: b168ed4 ("kernel/cgroup: Add "dmem" memory accounting cgroup") Cc: [email protected] # v6.14+ Signed-off-by: Chen Ridong <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 43151f8 commit 592a682

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

kernel/cgroup/dmem.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ static void dmemcg_free_region(struct kref *ref)
423423
*/
424424
void dmem_cgroup_unregister_region(struct dmem_cgroup_region *region)
425425
{
426-
struct list_head *entry;
426+
struct dmem_cgroup_pool_state *pool, *next;
427427

428428
if (!region)
429429
return;
@@ -433,10 +433,7 @@ void dmem_cgroup_unregister_region(struct dmem_cgroup_region *region)
433433
/* Remove from global region list */
434434
list_del_rcu(&region->region_node);
435435

436-
list_for_each_rcu(entry, &region->pools) {
437-
struct dmem_cgroup_pool_state *pool =
438-
container_of(entry, typeof(*pool), region_node);
439-
436+
list_for_each_entry_safe(pool, next, &region->pools, region_node) {
440437
list_del_rcu(&pool->css_node);
441438
}
442439

0 commit comments

Comments
 (0)