1. 19 Apr, 2023 4 commits
    • Li Lingfeng's avatar
      dm: don't lock fs when the map is NULL in process of resume · 38d11da5
      Li Lingfeng authored
      Commit fa247089 ("dm: requeue IO if mapping table not yet available")
      added a detection of whether the mapping table is available in the IO
      submission process. If the mapping table is unavailable, it returns
      BLK_STS_RESOURCE and requeues the IO.
      This can lead to the following deadlock problem:
      
      dm create                                      mount
      ioctl(DM_DEV_CREATE_CMD)
      ioctl(DM_TABLE_LOAD_CMD)
                                     do_mount
                                      vfs_get_tree
                                       ext4_get_tree
                                        get_tree_bdev
                                         sget_fc
                                          alloc_super
                                           // got &s->s_umount
                                           down_write_nested(&s->s_umount, ...);
                                         ext4_fill_super
                                          ext4_load_super
                                           ext4_read_bh
                                            submit_bio
                                            // submit and wait io end
      ioctl(DM_DEV_SUSPEND_CMD)
      dev_suspend
       do_resume
        dm_suspend
         __dm_suspend
          lock_fs
           freeze_bdev
            get_active_super
             grab_super
              // wait for &s->s_umount
              down_write(&s->s_umount);
        dm_swap_table
         __bind
          // set md->map(can't get here)
      
      IO will be continuously requeued while holding the lock since mapping
      table is NULL. At the same time, mapping table won't be set since the
      lock is not available.
      Like request-based DM, bio-based DM also has the same problem.
      
      It's not proper to just abort IO if the mapping table not available.
      So clear DM_SKIP_LOCKFS_FLAG when the mapping table is NULL, this
      allows the DM table to be loaded and the IO submitted upon resume.
      
      Fixes: fa247089 ("dm: requeue IO if mapping table not yet available")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarLi Lingfeng <lilingfeng3@huawei.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      38d11da5
    • Mikulas Patocka's avatar
      dm flakey: add an "error_reads" option · aa7d7bc9
      Mikulas Patocka authored
      dm-flakey returns error on reads if no other argument is specified.
      This commit simplifies associated logic while formalizing an
      "error_reads" argument and an ERROR_READS flag.
      
      If no argument is specified, set ERROR_READS flag so that it behaves
      just like before this commit.
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      aa7d7bc9
    • Mikulas Patocka's avatar
      dm flakey: remove trailing space in the table line · e3675dc1
      Mikulas Patocka authored
      Don't return a trailing space in the output of STATUSTYPE_TABLE.
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      e3675dc1
    • Mikulas Patocka's avatar
      dm flakey: fix a crash with invalid table line · 98dba02d
      Mikulas Patocka authored
      This command will crash with NULL pointer dereference:
       dmsetup create flakey --table \
        "0 `blockdev --getsize /dev/ram0` flakey /dev/ram0 0 0 1 2 corrupt_bio_byte 512"
      
      Fix the crash by checking if arg_name is non-NULL before comparing it.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      98dba02d
  2. 17 Apr, 2023 1 commit
  3. 14 Apr, 2023 2 commits
  4. 11 Apr, 2023 5 commits
  5. 04 Apr, 2023 7 commits
    • Mike Snitzer's avatar
      dm integrity: call kmem_cache_destroy() in dm_integrity_init() error path · 6b79a428
      Mike Snitzer authored
      Otherwise the journal_io_cache will leak if dm_register_target() fails.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      6b79a428
    • Mike Snitzer's avatar
      dm clone: call kmem_cache_destroy() in dm_clone_init() error path · 6827af4a
      Mike Snitzer authored
      Otherwise the _hydration_cache will leak if dm_register_target() fails.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      6827af4a
    • Mikulas Patocka's avatar
      dm error: add discard support · b6bcb844
      Mikulas Patocka authored
      Add io_err_io_hints() and set discard limits so that the zero target
      advertises support for discards.
      
      The error target will return -EIO for discards.
      
      This is useful when the user combines dm-error with other
      discard-supporting targets in the same table; without dm-error
      support, discards would be disabled for the whole combined device.
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Tested-by: default avatarMilan Broz <gmazyland@gmail.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      b6bcb844
    • Mikulas Patocka's avatar
      dm zero: add discard support · 00065f92
      Mikulas Patocka authored
      Add zero_io_hints() and set discard limits so that the zero target
      advertises support for discards.
      
      The zero target will ignore discards.
      
      This is useful when the user combines dm-zero with other
      discard-supporting targets in the same table; without dm-zero support,
      discards would be disabled for the whole combined device.
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Tested-by: default avatarMilan Broz <gmazyland@gmail.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      00065f92
    • Mikulas Patocka's avatar
      dm table: allow targets without devices to set ->io_hints · 85c938e8
      Mikulas Patocka authored
      In dm_calculate_queue_limits, add call to ->io_hints hook if the
      target doesn't provide ->iterate_devices.
      
      This is needed so the "error" and "zero" targets may support
      discards. The 2 following commits will add their respective discard
      support.
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Tested-by: default avatarMilan Broz <gmazyland@gmail.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      85c938e8
    • Michael Weiß's avatar
      dm verity: emit audit events on verification failure and more · 074c4466
      Michael Weiß authored
      dm-verity signals integrity violations by returning I/O errors
      to user space. To identify integrity violations by a controlling
      instance, the kernel audit subsystem can be used to emit audit
      events to user space. Analogous to dm-integrity, we also use the
      dm-audit submodule allowing to emit audit events on verification
      failures of metadata and data blocks as well as if max corrupted
      errors are reached.
      
      The construction and destruction of verity device mappings are
      also relevant for auditing a system. Thus, those events are also
      logged as audit events.
      
      Tested by starting a container with the container manager (cmld) of
      GyroidOS which uses a dm-verity protected rootfs image root.img mapped
      to /dev/mapper/<uuid>-root. One block was manipulated in the
      underlying image file and repeated reads of the verity device were
      performed again until the max corrupted errors is reached, e.g.:
      
        dd if=/dev/urandom of=root.img bs=512 count=1 seek=1000
        for i in range {1..101}; do \
          dd if=/dev/mapper/<uuid>-root of=/dev/null bs=4096 \
             count=1 skip=1000 \
        done
      
      The resulting audit log looks as follows:
      
        type=DM_CTRL msg=audit(1677618791.876:962):
          module=verity op=ctr ppid=4876 pid=29102 auid=0 uid=0 gid=0
          euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=44
          comm="cmld" exe="/usr/sbin/cml/cmld" subj=unconfined
          dev=254:3 error_msg='success' res=1
      
        type=DM_EVENT msg=audit(1677619463.786:1074): module=verity
          op=verify-data dev=7:0 sector=1000 res=0
        ...
        type=DM_EVENT msg=audit(1677619596.727:1162): module=verity
          op=verify-data dev=7:0 sector=1000 res=0
      
        type=DM_EVENT msg=audit(1677619596.731:1163): module=verity
          op=max-corrupted-errors dev=254:3 sector=? res=0
      Signed-off-by: default avatarMichael Weiß <michael.weiss@aisec.fraunhofer.de>
      Acked-by: default avatarPaul Moore <paul@paul-moore.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      074c4466
    • Yeongjin Gil's avatar
      dm verity: fix error handling for check_at_most_once on FEC · e8c5d45f
      Yeongjin Gil authored
      In verity_end_io(), if bi_status is not BLK_STS_OK, it can be return
      directly. But if FEC configured, it is desired to correct the data page
      through verity_verify_io. And the return value will be converted to
      blk_status and passed to verity_finish_io().
      
      BTW, when a bit is set in v->validated_blocks, verity_verify_io() skips
      verification regardless of I/O error for the corresponding bio. In this
      case, the I/O error could not be returned properly, and as a result,
      there is a problem that abnormal data could be read for the
      corresponding block.
      
      To fix this problem, when an I/O error occurs, do not skip verification
      even if the bit related is set in v->validated_blocks.
      
      Fixes: 843f38d3 ("dm verity: add 'check_at_most_once' option to only validate hashes once")
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarSungjong Seo <sj1557.seo@samsung.com>
      Signed-off-by: default avatarYeongjin Gil <youngjin.gil@samsung.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      e8c5d45f
  6. 30 Mar, 2023 21 commits