• L
    dm-mpath: fix UAF in multipath_message() · c5012bd4
    Luo Meng 提交于
    hulk inclusion
    category: bugfix
    bugzilla: https://gitee.com/openeuler/kernel/issues/I5KK52
    CVE: NA
    
    --------------------------------
    
    If dm_get_device() create dd in multipath_message(),
    and then call table_deps() after dm_put_table_device(),
    it will lead to concurrency UAF bugs.
    
    One of the concurrency UAF can be shown as below:
    
             (USE)                        |    (FREE)
                                          |  target_message
                                          |    multipath_message
                                          |      dm_put_device
                                          |        dm_put_table_device #
                                          |          kfree(td) # table_device *td
    ioctl # DM_TABLE_DEPS_CMD             |         ...
      table_deps                          |         ...
      dm_get_live_or_inactive_table       |         ...
        retrieve_dep                      |         ...
        list_for_each_entry               |         ...
          deps->dev[count++] =            |         ...
              huge_encode_dev             |         ...
              (dd->dm_dev->bdev->bd_dev)  |        list_del(&dd->list)
                                          |        kfree(dd) # dm_dev_internal
    
    The root cause of UAF bugs is that find_device() failed in
    dm_get_device() and will create dd and refcount set 1, kfree()
    in dm_put_table() is not protected. When td, which there are
    still pointers point to, is released, the concurrency UAF bug
    will happen.
    
    This patch add a flag to determine whether to create a new dd.
    Signed-off-by: NLuo Meng <luomeng12@huawei.com>
    Reviewed-by: NJason Yan <yanaijie@huawei.com>
    Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
    c5012bd4
dm-mpath.c 54.3 KB