• L
    dm: Fix UAF in run_timer_softirq() · 08f0d7c0
    Luo Meng 提交于
    hulk inclusion
    category: bugfix
    bugzilla: https://gitee.com/openeuler/kernel/issues/I5WBID
    CVE: NA
    
    --------------------------------
    
    When dm_resume() and dm_destroy() are concurrent, it will
    lead to UAF.
    
    One of the concurrency UAF can be shown as below:
    
            use                                  free
    do_resume                           |
      __find_device_hash_cell           |
        dm_get                          |
          atomic_inc(&md->holders)      |
                                        | dm_destroy
    				    |   __dm_destroy
    				    |     if (!dm_suspended_md(md))
                                        |     atomic_read(&md->holders)
    				    |     msleep(1)
      dm_resume                         |
        __dm_resume                     |
          dm_table_resume_targets       |
    	pool_resume                 |
    	  do_waker  #add delay work |
    				    |     dm_table_destroy
    				    |       pool_dtr
    				    |         __pool_dec
                                        |           __pool_destroy
                                        |             destroy_workqueue
                                        |             kfree(pool) # free pool
    	time out
    __do_softirq
      run_timer_softirq # pool has already been freed
    
    This can be easily reproduced using:
      1. create thin-pool
      2. dmsetup suspend pool
      3. dmsetup resume pool
      4. dmsetup remove_all # Concurrent with 3
    
    The root cause of UAF bugs is that dm_resume() adds timer after
    dm_destroy() skips cancel timer beause of suspend status. After
    timeout, it will call run_timer_softirq(), however pool has already
    been freed. The concurrency UAF bug will happen.
    
    Therefore, canceling timer is moved after md->holders is zero.
    Signed-off-by: NLuo Meng <luomeng12@huawei.com>
    Reviewed-by: NHou Tao <houtao1@huawei.com>
    Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
    08f0d7c0
dm.c 72.4 KB