1. 08 Mar, 2024 1 commit
    • Yu Kuai's avatar
      raid1: fix use-after-free for original bio in raid1_write_request() · fcf3f7e2
      Yu Kuai authored
      r1_bio->bios[] is used to record new bios that will be issued to
      underlying disks, however, in raid1_write_request(), r1_bio->bios[]
      will set to the original bio temporarily. Meanwhile, if blocked rdev
      is set, free_r1bio() will be called causing that all r1_bio->bios[]
      to be freed:
      
      raid1_write_request()
       r1_bio = alloc_r1bio(mddev, bio); -> r1_bio->bios[] is NULL
       for (i = 0;  i < disks; i++) -> for each rdev in conf
        // first rdev is normal
        r1_bio->bios[0] = bio; -> set to original bio
        // second rdev is blocked
        if (test_bit(Blocked, &rdev->flags))
         break
      
       if (blocked_rdev)
        free_r1bio()
         put_all_bios()
          bio_put(r1_bio->bios[0]) -> original bio is freed
      
      Test scripts:
      
      mdadm -CR /dev/md0 -l1 -n4 /dev/sd[abcd] --assume-clean
      fio -filename=/dev/md0 -ioengine=libaio -rw=write -bs=4k -numjobs=1 \
          -iodepth=128 -name=test -direct=1
      echo blocked > /sys/block/md0/md/rd2/state
      
      Test result:
      
      BUG bio-264 (Not tainted): Object already free
      -----------------------------------------------------------------------------
      
      Allocated in mempool_alloc_slab+0x24/0x50 age=1 cpu=1 pid=869
       kmem_cache_alloc+0x324/0x480
       mempool_alloc_slab+0x24/0x50
       mempool_alloc+0x6e/0x220
       bio_alloc_bioset+0x1af/0x4d0
       blkdev_direct_IO+0x164/0x8a0
       blkdev_write_iter+0x309/0x440
       aio_write+0x139/0x2f0
       io_submit_one+0x5ca/0xb70
       __do_sys_io_submit+0x86/0x270
       __x64_sys_io_submit+0x22/0x30
       do_syscall_64+0xb1/0x210
       entry_SYSCALL_64_after_hwframe+0x6c/0x74
      Freed in mempool_free_slab+0x1f/0x30 age=1 cpu=1 pid=869
       kmem_cache_free+0x28c/0x550
       mempool_free_slab+0x1f/0x30
       mempool_free+0x40/0x100
       bio_free+0x59/0x80
       bio_put+0xf0/0x220
       free_r1bio+0x74/0xb0
       raid1_make_request+0xadf/0x1150
       md_handle_request+0xc7/0x3b0
       md_submit_bio+0x76/0x130
       __submit_bio+0xd8/0x1d0
       submit_bio_noacct_nocheck+0x1eb/0x5c0
       submit_bio_noacct+0x169/0xd40
       submit_bio+0xee/0x1d0
       blkdev_direct_IO+0x322/0x8a0
       blkdev_write_iter+0x309/0x440
       aio_write+0x139/0x2f0
      
      Since that bios for underlying disks are not allocated yet, fix this
      problem by using mempool_free() directly to free the r1_bio.
      
      Fixes: 992db13a ("md/raid1: free the r1bio before waiting for blocked rdev")
      Cc: stable@vger.kernel.org # v6.6+
      Reported-by: default avatarColy Li <colyli@suse.de>
      Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
      Tested-by: default avatarColy Li <colyli@suse.de>
      Signed-off-by: default avatarSong Liu <song@kernel.org>
      Link: https://lore.kernel.org/r/20240308093726.1047420-1-yukuai1@huaweicloud.com
      fcf3f7e2
  2. 07 Mar, 2024 2 commits
    • Uwe Kleine-König's avatar
      cdrom: gdrom: Convert to platform remove callback returning void · 0dc31b98
      Uwe Kleine-König authored
      The .remove() callback for a platform driver returns an int which makes
      many driver authors wrongly assume it's possible to do error handling by
      returning an error code. However the value returned is ignored (apart
      from emitting a warning) and this typically results in resource leaks.
      
      To improve here there is a quest to make the remove callback return
      void. In the first step of this quest all drivers are converted to
      .remove_new(), which already returns void. Eventually after all drivers
      are converted, .remove_new() will be renamed to .remove().
      
      Trivially convert this driver from always returning zero in the remove
      callback to the void returning variant.
      Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
      Link: https://lore.kernel.org/r/20240307180837.190626-2-u.kleine-koenig@pengutronix.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
      0dc31b98
    • Jens Axboe's avatar
      Merge tag 'nvme-6.9-2024-03-07' of git://git.infradead.org/nvme into for-6.9/block · 0f7223a3
      Jens Axboe authored
      Pull NVMe updates from Keith:
      
      "nvme updates for Linux 6.9
      
       - RDMA target enhancements (Max)
       - Fabrics fixes (Max, Guixin, Hannes)
       - Atomic queue_limits usage (Christoph)
       - Const use for class_register (Ricardo)
       - Identification error handling fixes (Shin'ichiro, Keith)"
      
      * tag 'nvme-6.9-2024-03-07' of git://git.infradead.org/nvme: (31 commits)
        nvme: clear caller pointer on identify failure
        nvme: host: fix double-free of struct nvme_id_ns in ns_update_nuse()
        nvme: fcloop: make fcloop_class constant
        nvme: fabrics: make nvmf_class constant
        nvme: core: constify struct class usage
        nvme-fabrics: typo in nvmf_parse_key()
        nvme-multipath: use atomic queue limits API for stacking limits
        nvme-multipath: pass queue_limits to blk_alloc_disk
        nvme: use the atomic queue limits update API
        nvme: cleanup nvme_configure_metadata
        nvme: don't query identify data in configure_metadata
        nvme: split out a nvme_identify_ns_nvm helper
        nvme: move common logic into nvme_update_ns_info
        nvme: move setting the write cache flags out of nvme_set_queue_limits
        nvme: move a few things out of nvme_update_disk_info
        nvme: don't use nvme_update_disk_info for the multipath disk
        nvme: move blk_integrity_unregister into nvme_init_integrity
        nvme: cleanup the nvme_init_integrity calling conventions
        nvme: move max_integrity_segments handling out of nvme_init_integrity
        nvme: remove nvme_revalidate_zones
        ...
      0f7223a3
  3. 06 Mar, 2024 36 commits
  4. 05 Mar, 2024 1 commit
    • Song Liu's avatar
      Merge branch 'dmraid-fix-6.9' into md-6.9 · 3a889fdc
      Song Liu authored
      This is the second half of fixes for dmraid. The first half is available
      at [1].
      
      This set contains fixes:
       - reshape can start unexpected, cause data corruption, patch 1,5,6;
       - deadlocks that reshape concurrent with IO, patch 8;
       - a lockdep warning, patch 9;
      
      For all the dmraid related tests in lvm2 suite, there is no new
      regressions compared against 6.6 kernels (which is good baseline before
      recent regressions).
      
      [1] https://lore.kernel.org/all/CAPhsuW7u1UKHCDOBDhD7DzOVtkGemDz_QnJ4DUq_kSN-Q3G66Q@mail.gmail.com/
      
      * dmraid-fix-6.9:
        dm-raid: fix lockdep waring in "pers->hot_add_disk"
        dm-raid456, md/raid456: fix a deadlock for dm-raid456 while io concurrent with reshape
        dm-raid: add a new helper prepare_suspend() in md_personality
        md/dm-raid: don't call md_reap_sync_thread() directly
        dm-raid: really frozen sync_thread during suspend
        md: add a new helper reshape_interrupted()
        md: export helper md_is_rdwr()
        md: export helpers to stop sync_thread
        md: don't clear MD_RECOVERY_FROZEN for new dm-raid until resume
      3a889fdc