]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
better lockdep annotations for simple_recursive_removal()
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 3 Jul 2025 02:30:32 +0000 (22:30 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 3 Jul 2025 02:30:32 +0000 (22:30 -0400)
We want a class that nests outside of I_MUTEX_NORMAL (for the sake of
callbacks that might want to lock the victim) and inside I_MUTEX_PARENT
(so that a variant of that could be used with parent of the victim
held locked by the caller).

In reality, simple_recursive_removal()
* never holds two locks at once
* holds the lock on parent of dentry passed to callback
* is used only on the trees with fixed topology, so the depths
are not changing.

So the locking order is actually fine.

AFAICS, the best solution is to assign I_MUTEX_CHILD to the locks
grabbed by that thing.

Reported-by: syzbot+169de184e9defe7fe709@syzkaller.appspotmail.com
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/libfs.c

index 42e226af6095a06ca39f899f474da758abda0da9..20b05a6db7701b70048a45377d8f1924a7c4da6a 100644 (file)
@@ -613,7 +613,7 @@ void simple_recursive_removal(struct dentry *dentry,
                struct dentry *victim = NULL, *child;
                struct inode *inode = this->d_inode;
 
-               inode_lock(inode);
+               inode_lock_nested(inode, I_MUTEX_CHILD);
                if (d_is_dir(this))
                        inode->i_flags |= S_DEAD;
                while ((child = find_next_child(this, victim)) == NULL) {
@@ -625,7 +625,7 @@ void simple_recursive_removal(struct dentry *dentry,
                        victim = this;
                        this = this->d_parent;
                        inode = this->d_inode;
-                       inode_lock(inode);
+                       inode_lock_nested(inode, I_MUTEX_CHILD);
                        if (simple_positive(victim)) {
                                d_invalidate(victim);   // avoid lost mounts
                                if (callback)