Re: [PATCH 1/3] kernfs: take kernfs_rename_lock for same-parent renames too

From: Tejun Heo

Date: Thu Sep 03 2026 - 16:37:11 EST


Hello,

On Wed, Sep 02, 2026 at 09:02:51PM -0700, Shakeel Butt wrote:
...
> CPU0 CPU1
> kernfs_path_from_node() on /a/b/c
> reads the name of a, gets "a"
> renames a to a2
> renames b to b2
> reads the name of b, gets "b2"
> returns "/a/b2/c"
>
> This hits roots without KERNFS_ROOT_INVARIANT_PARENT: sysfs, where the
> bad path can reach sysfs_warn_dup() and pr_cont_kernfs_path(), and
> resctrl, which renames a mon group inside its mon_groups directory.
> cgroup sets the flag, so it skips the lock and reads names under RCU
> alone; that case needs something else and is not addressed here.

Well, I'm not sure this is a real problem. Do we even have places where
multiple nodes along the hierarchy can be renamed? And the only thing we do
with the formatted paths is printing them out somewhere.

> So take the lock in both cases, and let kernfs_rcu_name() accept it the
> way kernfs_parent() already does for ->__parent. Same-parent renames
> are rare, the lock is per filesystem, and the locked section is at most
> three stores. It also gives a future rename sequence counter one place
> to sit that covers every rename.
>
> Fixes: 741c10b096bc ("kernfs: Use RCU to access kernfs_node::name.")
> Signed-off-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>

That said, it theoretically is a bug, so, why not?

Acked-by: Tejun Heo <tj@xxxxxxxxxx>

Thanks.

--
tejun