Re: [PATCH] x86/resctrl: Fix rdtgroup_mkdir()'s unlocked use of kernfs_node::name

Reinette Chatre
2025-04-07T18:08:16Z

Hi James,

On 4/7/25 5:46 AM, James Morse wrote:
> Since commit 741c10b096bc ("kernfs: Use RCU to access kernfs_node::name."),
> a helper rdt_kn_name() that checks that rdtgroup_mutex is held has been
> used for all accesses to the kernfs node name.
>
> rdtgroup_mkdir() uses the name to determine if a valid monitor group is
> being created by checking the parent name is "mon_groups". This is done
> without holding rdtgroup_mutex, and now triggers the following warning:
> | WARNING: suspicious RCU usage
> | 6.15.0-rc1 #4465 Tainted: G E
> | -----------------------------
> | arch/x86/kernel/cpu/resctrl/internal.h:408 suspicious rcu_dereference_check() usage!
> [...]
> | Call Trace:
> | <TASK>
> | dump_stack_lvl+0x6c/0xa0
> | lockdep_rcu_suspicious.cold+0x4e/0x96
> | is_mon_groups+0xba/0xd0
> | rdtgroup_mkdir+0x118/0x1970
> | kernfs_iop_mkdir+0xfa/0x1a0
> | vfs_mkdir+0x456/0x760
> | do_mkdirat+0x257/0x310
> | __x64_sys_mkdir+0xd4/0x120
> | do_syscall_64+0x6d/0x150
> | entry_SYSCALL_64_after_hwframe+0x76/0x7e
>
> Creating a control or monitor group calls mkdir_rdt_prepare(), which uses
> rdtgroup_kn_lock_live() to take the rdtgroup_mutex.
>
> To avoid taking and dropping the lock, move the check for the monitor group
> name and position into mkdir_rdt_prepare() so that it occurs under
> rdtgroup_mutex. Hoist is_mon_groups() earlier in the file.
>
> CC: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Fixes: 741c10b096bc ("kernfs: Use RCU to access kernfs_node::name.")
> Signed-off-by: James Morse <james.morse@arm.com>
> ---

Thank you very much.

Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>

Reinette