Skip to content

support dm-integrity standalone mode #7757

Description

@jwwalton

https://github.com/torvalds/linux/blob/master/Documentation/device-mapper/dm-integrity.txt
https://gitlab.com/cryptsetup/cryptsetup/blob/master/src/integritysetup.c

note that there is another way to use dm-integrity together with dm-crypt

# fallocate -l 1G foobar.raw
# losetup -f foobar.raw
# integritysetup --integrity crc32c -s 4096 format --no-wipe /dev/loop0
Formatted with tag size 4, internal integrity crc32c.
# integritysetup open /dev/loop0 foobar -D

(open only)
udevadm monitor -p -u -k                                             
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[3086.163284] change   /devices/virtual/block/loop0 (block)
ACTION=change
DEVNAME=/dev/loop0
DEVPATH=/devices/virtual/block/loop0
DEVTYPE=disk
MAJOR=7
MINOR=0
SEQNUM=3300
SUBSYSTEM=block
SYNTH_UUID=0

KERNEL[3086.171087] add      /devices/virtual/bdi/254:17 (bdi)
ACTION=add
DEVPATH=/devices/virtual/bdi/254:17
SEQNUM=3301
SUBSYSTEM=bdi

KERNEL[3086.171408] add      /devices/virtual/block/dm-17 (block)
ACTION=add
DEVNAME=/dev/dm-17
DEVPATH=/devices/virtual/block/dm-17
DEVTYPE=disk
MAJOR=254
MINOR=17
SEQNUM=3302
SUBSYSTEM=block

UDEV  [3086.171431] add      /devices/virtual/bdi/254:17 (bdi)
ACTION=add
DEVPATH=/devices/virtual/bdi/254:17
SEQNUM=3301
SUBSYSTEM=bdi
USEC_INITIALIZED=3086171404

UDEV  [3086.171811] add      /devices/virtual/block/dm-17 (block)
ACTION=add
DEVNAME=/dev/dm-17
DEVPATH=/devices/virtual/block/dm-17
DEVTYPE=disk
DM_UDEV_DISABLE_DISK_RULES_FLAG=1
DM_UDEV_DISABLE_OTHER_RULES_FLAG=1
DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG=1
MAJOR=254
MINOR=17
SEQNUM=3302
SUBSYSTEM=block
SYSTEMD_READY=0
TAGS=:systemd:
USEC_INITIALIZED=3086171606

UDEV  [3086.171842] change   /devices/virtual/block/loop0 (block)
.ID_FS_TYPE_NEW=DM_integrity
ACTION=change
DEVNAME=/dev/loop0
DEVPATH=/devices/virtual/block/loop0
DEVTYPE=disk
ID_FS_TYPE=DM_integrity
ID_FS_USAGE=crypto
ID_FS_VERSION=1
MAJOR=7
MINOR=0
SEQNUM=3300
SUBSYSTEM=block
SYNTH_UUID=0
TAGS=:systemd:
USEC_INITIALIZED=2964857716

KERNEL[3086.173225] change   /devices/virtual/block/dm-17 (block)
ACTION=change
DEVNAME=/dev/dm-17
DEVPATH=/devices/virtual/block/dm-17
DEVTYPE=disk
DM_COOKIE=6351485
MAJOR=254
MINOR=17
SEQNUM=3303
SUBSYSTEM=block

UDEV  [3086.175837] change   /devices/virtual/block/dm-17 (block)
.ID_FS_TYPE_NEW=
ACTION=change
DEVLINKS=/dev/disk/by-id/dm-uuid-CRYPT-INTEGRITY-foobar /dev/disk/by-id/dm-name-foobar /dev/mapper/foobar
DEVNAME=/dev/dm-17
DEVPATH=/devices/virtual/block/dm-17
DEVTYPE=disk
DM_ACTIVATION=1
DM_COOKIE=6351485
DM_NAME=foobar
DM_SUSPENDED=0
DM_UDEV_DISABLE_LIBRARY_FALLBACK_FLAG=1
DM_UDEV_PRIMARY_SOURCE_FLAG=1
DM_UDEV_RULES_VSN=2
DM_UUID=CRYPT-INTEGRITY-foobar
ID_FS_TYPE=
MAJOR=254
MINOR=17
SEQNUM=3303
SUBSYSTEM=block
SYSTEMD_READY=0
TAGS=:systemd:
USEC_INITIALIZED=3086171606

Activity

  1. vermeeren commented on Apr 20, 2021

    @vermeeren

    Automated opening of dm-integrity devices cannot be done easily, as arguments are required when opening similar to cryptsetup. The superblock of integritysetup however contains less information that a LUKS superblock, in fact not even the integrity algorithm in stored and it is critical this is correctly passed or data loss may occur.

    This means that, in my opinion, dm-integrity devices are not suitable for automated opening without manual definitions. I have just submitted patches to Debian implementing a /etc/integritytab in similar fashion to /etc/crypttab, which allows for proper definition specification in configuration file.

    https://salsa.debian.org/cryptsetup-team/cryptsetup/-/merge_requests/22

    Edit: some integration could still be useful similar to /etc/crypttab integration with cryptsetup{,-pre}.target special built-in, though I am unsure how exactly that should work.

  2. tasleson commented on Sep 13, 2021

    @tasleson
    Contributor

    I've taken a look the @vermeeren merge request above for debian. Unless I'm missing something, it appears that it runs a script which systematically goes through and sets up items in /etc/integritytab. Thus, it's not udev driven. I do agree with @vermeeren that something like /etc/integritytab is needed.

    I've put together a proof of concept: https://github.com/tasleson/dm-integrity-standalone which consists of:

    From some very basic testing, it works. Before I invest more time in this I would like to get some feed back from others on this too. There is also an issue in upstream pertaining to this: https://gitlab.com/cryptsetup/cryptsetup/-/issues/385

    adding: @mbroz @vojtechtrefny to the discussion. Please add others as appropriate.

  3. poettering commented on Sep 13, 2021

    @poettering
    Member

    I'd be happy to merge a patch that adds proper support for /etc/integritytab to systemd. It should be done the same way /etc/crypttab and /etc/veritytab area already handled. i.e. see src/veritysetup/ in our tree.

    i.e. there should be a generator creating properly ordered service units, and one binary that it calls.

  4. oniko commented on Sep 14, 2021

    @oniko
    Contributor

    @tasleson

    I've put together a proof of concept: https://github.com/tasleson/dm-integrity-standalone which consists of:

    * [dracut module](https://github.com/tasleson/dm-integrity-standalone/blob/main/dracut/90dm-integrity/module-setup.sh) to allow for root FS support on an integrity target
    

    Pretty please, no more dracut modules for features that may be added in systemd via native services/generators

  5. tasleson commented on Sep 15, 2021

    @tasleson
    Contributor

    @oniko Trying to understand these native services/generators. It appears the systemd generator takes some input file and creates systemd unit file(s). The generators get copied into the initramfs image and systemd runs the generators before it processes the resulting unit files during early boot, before the pivot. How does the udev event from the kernel that a block device is present and blockid gets run end up causing the specific unit file(s) to be processed?

  6. poettering commented on Sep 17, 2021

    @poettering
    Member

    @tasleson that's handled like we do for mounts or any kinds of deps: the hypothetical systemd-integrity@.service service instances simply add dependencies on the .device units that encapsulate the devices they need. The systemd unit engine then takes care of running the stuff at the right moment when the devices have shown up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFE 🎁Request for Enhancement, i.e. a feature requestcryptsetup

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions