1. 20 7月, 2023 2 次提交
  2. 08 6月, 2023 1 次提交
  3. 30 11月, 2022 1 次提交
    • L
      dm: Fix UAF in run_timer_softirq() · dbe740d5
      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>
      dbe740d5
  4. 18 11月, 2022 1 次提交
  5. 21 9月, 2022 1 次提交
  6. 04 8月, 2022 1 次提交
  7. 27 4月, 2022 1 次提交
  8. 08 3月, 2022 2 次提交
    • M
      dm rq: don't queue request to blk-mq during DM suspend · 3c04af00
      Ming Lei 提交于
      mainline inclusion
      from mainline-v5.15-rc6
      commit b4459b11
      category: panic
      bugzilla: 185513 https://gitee.com/openeuler/kernel/issues/I4V82O?from=project-issue
      CVE: NA
      
      -------------------------------------------------
      
      DM uses blk-mq's quiesce/unquiesce to stop/start device mapper queue.
      
      But blk-mq's unquiesce may come from outside events, such as elevator
      switch, updating nr_requests or others, and request may come during
      suspend, so simply ask for blk-mq to requeue it.
      
      Fixes one kernel panic issue when running updating nr_requests and
      dm-mpath suspend/resume stress test.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NMing Lei <ming.lei@redhat.com>
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      Signed-off-by: NLuo Meng <luomeng12@huawei.com>
      Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      3c04af00
    • J
      dm: fix mempool NULL pointer race when completing IO · 6bff3499
      Jiazi Li 提交于
      mainline inclusion
      from mainline-v5.15-rc6
      commit d208b894
      category: panic
      bugzilla: 185514 https://gitee.com/openeuler/kernel/issues/I4V6FT?from=project-issue
      CVE: NA
      
      -------------------------------------------------
      
      dm_io_dec_pending() calls end_io_acct() first and will then dec md
      in-flight pending count. But if a task is swapping DM table at same
      time this can result in a crash due to mempool->elements being NULL:
      
      task1                             task2
      do_resume
       ->do_suspend
        ->dm_wait_for_completion
                                        bio_endio
      				   ->clone_endio
      				    ->dm_io_dec_pending
      				     ->end_io_acct
      				      ->wakeup task1
       ->dm_swap_table
        ->__bind
         ->__bind_mempools
          ->bioset_exit
           ->mempool_exit
                                           ->free_io
      
      [ 67.330330] Unable to handle kernel NULL pointer dereference at
      virtual address 0000000000000000
      ......
      [ 67.330494] pstate: 80400085 (Nzcv daIf +PAN -UAO)
      [ 67.330510] pc : mempool_free+0x70/0xa0
      [ 67.330515] lr : mempool_free+0x4c/0xa0
      [ 67.330520] sp : ffffff8008013b20
      [ 67.330524] x29: ffffff8008013b20 x28: 0000000000000004
      [ 67.330530] x27: ffffffa8c2ff40a0 x26: 00000000ffff1cc8
      [ 67.330535] x25: 0000000000000000 x24: ffffffdada34c800
      [ 67.330541] x23: 0000000000000000 x22: ffffffdada34c800
      [ 67.330547] x21: 00000000ffff1cc8 x20: ffffffd9a1304d80
      [ 67.330552] x19: ffffffdada34c970 x18: 000000b312625d9c
      [ 67.330558] x17: 00000000002dcfbf x16: 00000000000006dd
      [ 67.330563] x15: 000000000093b41e x14: 0000000000000010
      [ 67.330569] x13: 0000000000007f7a x12: 0000000034155555
      [ 67.330574] x11: 0000000000000001 x10: 0000000000000001
      [ 67.330579] x9 : 0000000000000000 x8 : 0000000000000000
      [ 67.330585] x7 : 0000000000000000 x6 : ffffff80148b5c1a
      [ 67.330590] x5 : ffffff8008013ae0 x4 : 0000000000000001
      [ 67.330596] x3 : ffffff80080139c8 x2 : ffffff801083bab8
      [ 67.330601] x1 : 0000000000000000 x0 : ffffffdada34c970
      [ 67.330609] Call trace:
      [ 67.330616] mempool_free+0x70/0xa0
      [ 67.330627] bio_put+0xf8/0x110
      [ 67.330638] dec_pending+0x13c/0x230
      [ 67.330644] clone_endio+0x90/0x180
      [ 67.330649] bio_endio+0x198/0x1b8
      [ 67.330655] dec_pending+0x190/0x230
      [ 67.330660] clone_endio+0x90/0x180
      [ 67.330665] bio_endio+0x198/0x1b8
      [ 67.330673] blk_update_request+0x214/0x428
      [ 67.330683] scsi_end_request+0x2c/0x300
      [ 67.330688] scsi_io_completion+0xa0/0x710
      [ 67.330695] scsi_finish_command+0xd8/0x110
      [ 67.330700] scsi_softirq_done+0x114/0x148
      [ 67.330708] blk_done_softirq+0x74/0xd0
      [ 67.330716] __do_softirq+0x18c/0x374
      [ 67.330724] irq_exit+0xb4/0xb8
      [ 67.330732] __handle_domain_irq+0x84/0xc0
      [ 67.330737] gic_handle_irq+0x148/0x1b0
      [ 67.330744] el1_irq+0xe8/0x190
      [ 67.330753] lpm_cpuidle_enter+0x4f8/0x538
      [ 67.330759] cpuidle_enter_state+0x1fc/0x398
      [ 67.330764] cpuidle_enter+0x18/0x20
      [ 67.330772] do_idle+0x1b4/0x290
      [ 67.330778] cpu_startup_entry+0x20/0x28
      [ 67.330786] secondary_start_kernel+0x160/0x170
      
      Fix this by:
      1) Establishing pointers to 'struct dm_io' members in
      dm_io_dec_pending() so that they may be passed into end_io_acct()
      _after_ free_io() is called.
      2) Moving end_io_acct() after free_io().
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NJiazi Li <lijiazi@xiaomi.com>
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      Signed-off-by: NLuo Meng <luomeng12@huawei.com>
      Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      6bff3499
  9. 15 11月, 2021 1 次提交
  10. 15 10月, 2021 1 次提交
  11. 09 4月, 2021 2 次提交
  12. 28 1月, 2021 1 次提交
  13. 05 12月, 2020 3 次提交
    • M
      dm: remove invalid sparse __acquires and __releases annotations · bde3808b
      Mike Snitzer 提交于
      Fixes sparse warnings:
      drivers/md/dm.c:508:12: warning: context imbalance in 'dm_prepare_ioctl' - wrong count at exit
      drivers/md/dm.c:543:13: warning: context imbalance in 'dm_unprepare_ioctl' - wrong count at exit
      
      Fixes: 971888c4 ("dm: hold DM table for duration of ioctl rather than use blkdev_get")
      Cc: stable@vger.kernel.org
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      bde3808b
    • M
      dm: fix double RCU unlock in dm_dax_zero_page_range() error path · f05c4403
      Mike Snitzer 提交于
      Remove redundant dm_put_live_table() in dm_dax_zero_page_range() error
      path to fix sparse warning:
      drivers/md/dm.c:1208:9: warning: context imbalance in 'dm_dax_zero_page_range' - unexpected unlock
      
      Fixes: cdf6cdcd ("dm,dax: Add dax zero_page_range operation")
      Cc: stable@vger.kernel.org
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      f05c4403
    • M
      dm: fix IO splitting · 3ee16db3
      Mike Snitzer 提交于
      Commit 882ec4e6 ("dm table: stack 'chunk_sectors' limit to account
      for target-specific splitting") caused a couple regressions:
      1) Using lcm_not_zero() when stacking chunk_sectors was a bug because
         chunk_sectors must reflect the most limited of all devices in the
         IO stack.
      2) DM targets that set max_io_len but that do _not_ provide an
         .iterate_devices method no longer had there IO split properly.
      
      And commit 5091cdec ("dm: change max_io_len() to use
      blk_max_size_offset()") also caused a regression where DM no longer
      supported varied (per target) IO splitting. The implication being the
      potential for severely reduced performance for IO stacks that use a DM
      target like dm-cache to hide performance limitations of a slower
      device (e.g. one that requires 4K IO splitting).
      
      Coming full circle: Fix all these issues by discontinuing stacking
      chunk_sectors up using ti->max_io_len in dm_calculate_queue_limits(),
      add optional chunk_sectors override argument to blk_max_size_offset()
      and update DM's max_io_len() to pass ti->max_io_len to its
      blk_max_size_offset() call.
      
      Passing in an optional chunk_sectors override to blk_max_size_offset()
      allows for code reuse of block's centralized calculation for max IO
      size based on provided offset and split boundary.
      
      Fixes: 882ec4e6 ("dm table: stack 'chunk_sectors' limit to account for target-specific splitting")
      Fixes: 5091cdec ("dm: change max_io_len() to use blk_max_size_offset()")
      Cc: stable@vger.kernel.org
      Reported-by: NJohn Dorminy <jdorminy@redhat.com>
      Reported-by: NBruce Johnston <bjohnsto@redhat.com>
      Reported-by: NKirill Tkhai <ktkhai@virtuozzo.com>
      Reviewed-by: NJohn Dorminy <jdorminy@redhat.com>
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      Reviewed-by: NJens Axboe <axboe@kernel.dk>
      3ee16db3
  14. 02 12月, 2020 1 次提交
  15. 08 10月, 2020 2 次提交
  16. 06 10月, 2020 1 次提交
  17. 02 10月, 2020 2 次提交
  18. 01 10月, 2020 1 次提交
    • M
      dm: fix missing imposition of queue_limits from dm_wq_work() thread · 0c2915b8
      Mike Snitzer 提交于
      If a DM device was suspended when bios were issued to it, those bios
      would be deferred using queue_io(). Once the DM device was resumed
      dm_process_bio() could be called by dm_wq_work() for original bio that
      still needs splitting. dm_process_bio()'s check for current->bio_list
      (meaning call chain is within ->submit_bio) as a prerequisite for
      calling blk_queue_split() for "abnormal IO" would result in
      dm_process_bio() never imposing corresponding queue_limits
      (e.g. discard_granularity, discard_max_bytes, etc).
      
      Fix this by always having dm_wq_work() resubmit deferred bios using
      submit_bio_noacct().
      
      Side-effect is blk_queue_split() is always called for "abnormal IO" from
      ->submit_bio, be it from application thread or dm_wq_work() workqueue,
      so proper bio splitting and depth-first bio submission is performed.
      For sake of clarity, remove current->bio_list check before call to
      blk_queue_split().
      
      Also, remove dm_wq_work()'s use of dm_{get,put}_live_table() -- no
      longer needed since IO will be reissued in terms of ->submit_bio.
      And rename bio variable from 'c' to 'bio'.
      
      Fixes: cf9c3786 ("dm: fix comment in dm_process_bio()")
      Reported-by: NJeffle Xu <jefflexu@linux.alibaba.com>
      Reviewed-by: NMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      0c2915b8
  19. 30 9月, 2020 7 次提交
  20. 25 9月, 2020 1 次提交
  21. 22 9月, 2020 2 次提交
    • M
      dm: fix comment in dm_process_bio() · cf9c3786
      Mike Snitzer 提交于
      Refer to the correct function (->submit_bio instead of ->queue_bio).
      Also, add details about why using blk_queue_split() isn't needed for
      dm_wq_work()'s call to dm_process_bio().
      
      Fixes: c62b37d9 ("block: move ->make_request_fn to struct block_device_operations")
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      cf9c3786
    • M
      dm: fix bio splitting and its bio completion order for regular IO · ee1dfad5
      Mike Snitzer 提交于
      dm_queue_split() is removed because __split_and_process_bio() _must_
      handle splitting bios to ensure proper bio submission and completion
      ordering as a bio is split.
      
      Otherwise, multiple recursive calls to ->submit_bio will cause multiple
      split bios to be allocated from the same ->bio_split mempool at the same
      time. This would result in deadlock in low memory conditions because no
      progress could be made (only one bio is available in ->bio_split
      mempool).
      
      This fix has been verified to still fix the loss of performance, due
      to excess splitting, that commit 120c9257 provided.
      
      Fixes: 120c9257 ("Revert "dm: always call blk_queue_split() in dm_process_bio()"")
      Cc: stable@vger.kernel.org # 5.0+, requires custom backport due to 5.9 changes
      Reported-by: NMing Lei <ming.lei@redhat.com>
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      ee1dfad5
  22. 20 9月, 2020 1 次提交
    • D
      dm/dax: Fix table reference counts · 02186d88
      Dan Williams 提交于
      A recent fix to the dm_dax_supported() flow uncovered a latent bug. When
      dm_get_live_table() fails it is still required to drop the
      srcu_read_lock(). Without this change the lvm2 test-suite triggers this
      warning:
      
          # lvm2-testsuite --only pvmove-abort-all.sh
      
          WARNING: lock held when returning to user space!
          5.9.0-rc5+ #251 Tainted: G           OE
          ------------------------------------------------
          lvm/1318 is leaving the kernel with locks still held!
          1 lock held by lvm/1318:
           #0: ffff9372abb5a340 (&md->io_barrier){....}-{0:0}, at: dm_get_live_table+0x5/0xb0 [dm_mod]
      
      ...and later on this hang signature:
      
          INFO: task lvm:1344 blocked for more than 122 seconds.
                Tainted: G           OE     5.9.0-rc5+ #251
          "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
          task:lvm             state:D stack:    0 pid: 1344 ppid:     1 flags:0x00004000
          Call Trace:
           __schedule+0x45f/0xa80
           ? finish_task_switch+0x249/0x2c0
           ? wait_for_completion+0x86/0x110
           schedule+0x5f/0xd0
           schedule_timeout+0x212/0x2a0
           ? __schedule+0x467/0xa80
           ? wait_for_completion+0x86/0x110
           wait_for_completion+0xb0/0x110
           __synchronize_srcu+0xd1/0x160
           ? __bpf_trace_rcu_utilization+0x10/0x10
           __dm_suspend+0x6d/0x210 [dm_mod]
           dm_suspend+0xf6/0x140 [dm_mod]
      
      Fixes: 7bf7eac8 ("dax: Arrange for dax_supported check to span multiple devices")
      Cc: <stable@vger.kernel.org>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Alasdair Kergon <agk@redhat.com>
      Cc: Mike Snitzer <snitzer@redhat.com>
      Reported-by: NAdrian Huang <ahuang12@lenovo.com>
      Reviewed-by: NIra Weiny <ira.weiny@intel.com>
      Tested-by: NAdrian Huang <ahuang12@lenovo.com>
      Link: https://lore.kernel.org/r/160045867590.25663.7548541079217827340.stgit@dwillia2-desk3.amr.corp.intel.comSigned-off-by: NDan Williams <dan.j.williams@intel.com>
      02186d88
  23. 02 9月, 2020 1 次提交
  24. 24 8月, 2020 1 次提交
  25. 05 8月, 2020 1 次提交
  26. 24 7月, 2020 1 次提交
    • M
      dm integrity: fix integrity recalculation that is improperly skipped · 5df96f2b
      Mikulas Patocka 提交于
      Commit adc0daad ("dm: report suspended
      device during destroy") broke integrity recalculation.
      
      The problem is dm_suspended() returns true not only during suspend,
      but also during resume. So this race condition could occur:
      1. dm_integrity_resume calls queue_work(ic->recalc_wq, &ic->recalc_work)
      2. integrity_recalc (&ic->recalc_work) preempts the current thread
      3. integrity_recalc calls if (unlikely(dm_suspended(ic->ti))) goto unlock_ret;
      4. integrity_recalc exits and no recalculating is done.
      
      To fix this race condition, add a function dm_post_suspending that is
      only true during the postsuspend phase and use it instead of
      dm_suspended().
      
      Signed-off-by: Mikulas Patocka <mpatocka redhat com>
      Fixes: adc0daad ("dm: report suspended device during destroy")
      Cc: stable vger kernel org # v4.18+
      Signed-off-by: NMike Snitzer <snitzer@redhat.com>
      5df96f2b