linux-stable/fs/configfs
ChenXiaoSong d1654de19d 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:33:56 +01:00
..
Kconfig
Makefile
configfs_internal.h configfs: new object reprsenting tree fragments 2019-11-12 19:18:17 +01:00
dir.c configfs: fix a race in configfs_{,un}register_subsystem() 2022-03-02 11:33:56 +01:00
file.c configfs: fix memleak in configfs_release_bin_file 2021-07-20 16:17:41 +02:00
inode.c fs: Replace current_fs_time() with current_time() 2016-09-27 21:06:22 -04:00
item.c configfs: Introduce config_item_get_unless_zero() 2017-06-12 13:20:20 +02:00
mount.c
symlink.c configfs: fix a deadlock in configfs_symlink() 2019-11-12 19:18:18 +01:00