Skip to content

Commit e203ef1

Browse files
author
Ian Kent
committed
kernfs: fix missing kernfs_iattr_rwsem locking
JIRA: https://issues.redhat.com/browse/RHEL-52956 Upstream status: Linus commit 0559f63 Author: Ian Kent <raven@themaw.net> Date: Sun Aug 6 09:26:49 2023 +0800 kernfs: fix missing kernfs_iattr_rwsem locking 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: 9caf696 ("kernfs: Introduce separate rwsem to protect inode attributes.") Cc: stable <stable@kernel.org> Signed-off-by: Ian Kent <raven@themaw.net> Reviewed-By: Imran Khan <imran.f.khan@oracle.com> Acked-by: Miklos Szeredi <mszeredi@redhat.com> Cc: Anders Roxell <anders.roxell@linaro.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Minchan Kim <minchan@kernel.org> Cc: Eric Sandeen <sandeen@sandeen.net> Link: https://lore.kernel.org/r/169128520941.68052.15749253469930138901.stgit@donald.themaw.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ian Kent <ikent@redhat.com>
1 parent cafaee9 commit e203ef1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/kernfs/dir.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,11 @@ static int kernfs_link_sibling(struct kernfs_node *kn)
374374
rb_insert_color(&kn->rb, &kn->parent->dir.children);
375375

376376
/* successfully added, account subdir number */
377+
down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
377378
if (kernfs_type(kn) == KERNFS_DIR)
378379
kn->parent->dir.subdirs++;
379380
kernfs_inc_rev(kn->parent);
381+
up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
380382

381383
return 0;
382384
}
@@ -397,9 +399,11 @@ static bool kernfs_unlink_sibling(struct kernfs_node *kn)
397399
if (RB_EMPTY_NODE(&kn->rb))
398400
return false;
399401

402+
down_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
400403
if (kernfs_type(kn) == KERNFS_DIR)
401404
kn->parent->dir.subdirs--;
402405
kernfs_inc_rev(kn->parent);
406+
up_write(&kernfs_root(kn)->kernfs_iattr_rwsem);
403407

404408
rb_erase(&kn->rb, &kn->parent->dir.children);
405409
RB_CLEAR_NODE(&kn->rb);

0 commit comments

Comments
 (0)