This is a note to let you know that I've just added the patch titled kernfs: fix missing kernfs_iattr_rwsem locking to the 6.5-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: kernfs-fix-missing-kernfs_iattr_rwsem-locking.patch and it can be found in the queue-6.5 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 0559f63057f927d298d68294d6ff77ce09b99255 Mon Sep 17 00:00:00 2001 From: Ian Kent <raven@xxxxxxxxxx> Date: Sun, 6 Aug 2023 09:26:49 +0800 Subject: kernfs: fix missing kernfs_iattr_rwsem locking From: Ian Kent <raven@xxxxxxxxxx> commit 0559f63057f927d298d68294d6ff77ce09b99255 upstream. When the kernfs_iattr_rwsem was introduced a case was missed. The update of the kernfs directory node child count was also protected by the kernfs_rwsem and needs to be included in the change so that the child count (and so the inode n_link attribute) does not change while holding the rwsem for read. Fixes: 9caf69614225 ("kernfs: Introduce separate rwsem to protect inode attributes.") Cc: stable <stable@xxxxxxxxxx> Signed-off-by: Ian Kent <raven@xxxxxxxxxx> Reviewed-By: Imran Khan <imran.f.khan@xxxxxxxxxx> Acked-by: Miklos Szeredi <mszeredi@xxxxxxxxxx> Cc: Anders Roxell <anders.roxell@xxxxxxxxxx> Cc: Arnd Bergmann <arnd@xxxxxxxx> Cc: Minchan Kim <minchan@xxxxxxxxxx> Cc: Eric Sandeen <sandeen@xxxxxxxxxxx> Link: https://lore.kernel.org/r/169128520941.68052.15749253469930138901.stgit@xxxxxxxxxxxxxxxxx Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/kernfs/dir.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 5a1a4af9d3d2..bf243015834e 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -383,9 +383,11 @@ static int kernfs_link_sibling(struct kernfs_node *kn) rb_insert_color(&kn->rb, &kn->parent->dir.children); /* successfully added, account subdir number */ + down_write(&kernfs_root(kn)->kernfs_iattr_rwsem); if (kernfs_type(kn) == KERNFS_DIR) kn->parent->dir.subdirs++; kernfs_inc_rev(kn->parent); + up_write(&kernfs_root(kn)->kernfs_iattr_rwsem); return 0; } @@ -408,9 +410,11 @@ static bool kernfs_unlink_sibling(struct kernfs_node *kn) if (RB_EMPTY_NODE(&kn->rb)) return false; + down_write(&kernfs_root(kn)->kernfs_iattr_rwsem); if (kernfs_type(kn) == KERNFS_DIR) kn->parent->dir.subdirs--; kernfs_inc_rev(kn->parent); + up_write(&kernfs_root(kn)->kernfs_iattr_rwsem); rb_erase(&kn->rb, &kn->parent->dir.children); RB_CLEAR_NODE(&kn->rb); -- 2.42.0 Patches currently in stable-queue which might be from raven@xxxxxxxxxx are queue-6.5/kernfs-fix-missing-kernfs_iattr_rwsem-locking.patch