linux-stable/fs/configfs
ChenXiaoSong b7e2b91fcb configfs: fix a race in configfs_{,un}register_subsystem()
[ Upstream commit 84ec758fb2 ]

When configfs_register_subsystem() or configfs_unregister_subsystem()
is executing link_group() or unlink_group(),
it is possible that two processes add or delete list concurrently.
Some unfortunate interleavings of them can cause kernel panic.

One of cases is:
A --> B --> C --> D
A <-- B <-- C <-- D

     delete list_head *B        |      delete list_head *C
--------------------------------|-----------------------------------
configfs_unregister_subsystem   |   configfs_unregister_subsystem
  unlink_group                  |     unlink_group
    unlink_obj                  |       unlink_obj
      list_del_init             |         list_del_init
        __list_del_entry        |           __list_del_entry
          __list_del            |             __list_del
            // next == C        |
            next->prev = prev   |
                                |               next->prev = prev
            prev->next = next   |
                                |                 // prev == B
                                |                 prev->next = next

Fix this by adding mutex when calling link_group() or unlink_group(),
but parent configfs_subsystem is NULL when config_item is root.
So I create a mutex configfs_subsystem_mutex.

Fixes: 7063fbf226 ("[PATCH] configfs: User-driven configuration filesystem")
Signed-off-by: ChenXiaoSong <chenxiaosong2@huawei.com>
Signed-off-by: Laibin Qiu <qiulaibin@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-03-02 11:41:10 +01:00
..
configfs_internal.h configfs: calculate the symlink target only once 2019-09-11 12:46:14 +02:00
dir.c configfs: fix a race in configfs_{,un}register_subsystem() 2022-03-02 11:41:10 +01:00
file.c configfs: fix memleak in configfs_release_bin_file 2021-07-14 16:53:46 +02:00
inode.c utimes: Clamp the timestamps in notify_change() 2020-02-11 04:35:12 -08:00
item.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 145 2019-05-30 11:25:18 -07:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
mount.c configfs: calculate the symlink target only once 2019-09-11 12:46:14 +02:00
symlink.c configfs: calculate the depth of parent item 2019-11-06 18:36:01 +01:00