Back to home page

OSCL-LXR

 
 

    


0001 ============
0002 dm-integrity
0003 ============
0004 
0005 The dm-integrity target emulates a block device that has additional
0006 per-sector tags that can be used for storing integrity information.
0007 
0008 A general problem with storing integrity tags with every sector is that
0009 writing the sector and the integrity tag must be atomic - i.e. in case of
0010 crash, either both sector and integrity tag or none of them is written.
0011 
0012 To guarantee write atomicity, the dm-integrity target uses journal, it
0013 writes sector data and integrity tags into a journal, commits the journal
0014 and then copies the data and integrity tags to their respective location.
0015 
0016 The dm-integrity target can be used with the dm-crypt target - in this
0017 situation the dm-crypt target creates the integrity data and passes them
0018 to the dm-integrity target via bio_integrity_payload attached to the bio.
0019 In this mode, the dm-crypt and dm-integrity targets provide authenticated
0020 disk encryption - if the attacker modifies the encrypted device, an I/O
0021 error is returned instead of random data.
0022 
0023 The dm-integrity target can also be used as a standalone target, in this
0024 mode it calculates and verifies the integrity tag internally. In this
0025 mode, the dm-integrity target can be used to detect silent data
0026 corruption on the disk or in the I/O path.
0027 
0028 There's an alternate mode of operation where dm-integrity uses bitmap
0029 instead of a journal. If a bit in the bitmap is 1, the corresponding
0030 region's data and integrity tags are not synchronized - if the machine
0031 crashes, the unsynchronized regions will be recalculated. The bitmap mode
0032 is faster than the journal mode, because we don't have to write the data
0033 twice, but it is also less reliable, because if data corruption happens
0034 when the machine crashes, it may not be detected.
0035 
0036 When loading the target for the first time, the kernel driver will format
0037 the device. But it will only format the device if the superblock contains
0038 zeroes. If the superblock is neither valid nor zeroed, the dm-integrity
0039 target can't be loaded.
0040 
0041 To use the target for the first time:
0042 
0043 1. overwrite the superblock with zeroes
0044 2. load the dm-integrity target with one-sector size, the kernel driver
0045    will format the device
0046 3. unload the dm-integrity target
0047 4. read the "provided_data_sectors" value from the superblock
0048 5. load the dm-integrity target with the target size
0049    "provided_data_sectors"
0050 6. if you want to use dm-integrity with dm-crypt, load the dm-crypt target
0051    with the size "provided_data_sectors"
0052 
0053 
0054 Target arguments:
0055 
0056 1. the underlying block device
0057 
0058 2. the number of reserved sector at the beginning of the device - the
0059    dm-integrity won't read of write these sectors
0060 
0061 3. the size of the integrity tag (if "-" is used, the size is taken from
0062    the internal-hash algorithm)
0063 
0064 4. mode:
0065 
0066         D - direct writes (without journal)
0067                 in this mode, journaling is
0068                 not used and data sectors and integrity tags are written
0069                 separately. In case of crash, it is possible that the data
0070                 and integrity tag doesn't match.
0071         J - journaled writes
0072                 data and integrity tags are written to the
0073                 journal and atomicity is guaranteed. In case of crash,
0074                 either both data and tag or none of them are written. The
0075                 journaled mode degrades write throughput twice because the
0076                 data have to be written twice.
0077         B - bitmap mode - data and metadata are written without any
0078                 synchronization, the driver maintains a bitmap of dirty
0079                 regions where data and metadata don't match. This mode can
0080                 only be used with internal hash.
0081         R - recovery mode - in this mode, journal is not replayed,
0082                 checksums are not checked and writes to the device are not
0083                 allowed. This mode is useful for data recovery if the
0084                 device cannot be activated in any of the other standard
0085                 modes.
0086 
0087 5. the number of additional arguments
0088 
0089 Additional arguments:
0090 
0091 journal_sectors:number
0092         The size of journal, this argument is used only if formatting the
0093         device. If the device is already formatted, the value from the
0094         superblock is used.
0095 
0096 interleave_sectors:number
0097         The number of interleaved sectors. This values is rounded down to
0098         a power of two. If the device is already formatted, the value from
0099         the superblock is used.
0100 
0101 meta_device:device
0102         Don't interleave the data and metadata on the device. Use a
0103         separate device for metadata.
0104 
0105 buffer_sectors:number
0106         The number of sectors in one buffer. The value is rounded down to
0107         a power of two.
0108 
0109         The tag area is accessed using buffers, the buffer size is
0110         configurable. The large buffer size means that the I/O size will
0111         be larger, but there could be less I/Os issued.
0112 
0113 journal_watermark:number
0114         The journal watermark in percents. When the size of the journal
0115         exceeds this watermark, the thread that flushes the journal will
0116         be started.
0117 
0118 commit_time:number
0119         Commit time in milliseconds. When this time passes, the journal is
0120         written. The journal is also written immediately if the FLUSH
0121         request is received.
0122 
0123 internal_hash:algorithm(:key)   (the key is optional)
0124         Use internal hash or crc.
0125         When this argument is used, the dm-integrity target won't accept
0126         integrity tags from the upper target, but it will automatically
0127         generate and verify the integrity tags.
0128 
0129         You can use a crc algorithm (such as crc32), then integrity target
0130         will protect the data against accidental corruption.
0131         You can also use a hmac algorithm (for example
0132         "hmac(sha256):0123456789abcdef"), in this mode it will provide
0133         cryptographic authentication of the data without encryption.
0134 
0135         When this argument is not used, the integrity tags are accepted
0136         from an upper layer target, such as dm-crypt. The upper layer
0137         target should check the validity of the integrity tags.
0138 
0139 recalculate
0140         Recalculate the integrity tags automatically. It is only valid
0141         when using internal hash.
0142 
0143 journal_crypt:algorithm(:key)   (the key is optional)
0144         Encrypt the journal using given algorithm to make sure that the
0145         attacker can't read the journal. You can use a block cipher here
0146         (such as "cbc(aes)") or a stream cipher (for example "chacha20"
0147         or "ctr(aes)").
0148 
0149         The journal contains history of last writes to the block device,
0150         an attacker reading the journal could see the last sector numbers
0151         that were written. From the sector numbers, the attacker can infer
0152         the size of files that were written. To protect against this
0153         situation, you can encrypt the journal.
0154 
0155 journal_mac:algorithm(:key)     (the key is optional)
0156         Protect sector numbers in the journal from accidental or malicious
0157         modification. To protect against accidental modification, use a
0158         crc algorithm, to protect against malicious modification, use a
0159         hmac algorithm with a key.
0160 
0161         This option is not needed when using internal-hash because in this
0162         mode, the integrity of journal entries is checked when replaying
0163         the journal. Thus, modified sector number would be detected at
0164         this stage.
0165 
0166 block_size:number
0167         The size of a data block in bytes.  The larger the block size the
0168         less overhead there is for per-block integrity metadata.
0169         Supported values are 512, 1024, 2048 and 4096 bytes.  If not
0170         specified the default block size is 512 bytes.
0171 
0172 sectors_per_bit:number
0173         In the bitmap mode, this parameter specifies the number of
0174         512-byte sectors that corresponds to one bitmap bit.
0175 
0176 bitmap_flush_interval:number
0177         The bitmap flush interval in milliseconds. The metadata buffers
0178         are synchronized when this interval expires.
0179 
0180 allow_discards
0181         Allow block discard requests (a.k.a. TRIM) for the integrity device.
0182         Discards are only allowed to devices using internal hash.
0183 
0184 fix_padding
0185         Use a smaller padding of the tag area that is more
0186         space-efficient. If this option is not present, large padding is
0187         used - that is for compatibility with older kernels.
0188 
0189 fix_hmac
0190         Improve security of internal_hash and journal_mac:
0191 
0192         - the section number is mixed to the mac, so that an attacker can't
0193           copy sectors from one journal section to another journal section
0194         - the superblock is protected by journal_mac
0195         - a 16-byte salt stored in the superblock is mixed to the mac, so
0196           that the attacker can't detect that two disks have the same hmac
0197           key and also to disallow the attacker to move sectors from one
0198           disk to another
0199 
0200 legacy_recalculate
0201         Allow recalculating of volumes with HMAC keys. This is disabled by
0202         default for security reasons - an attacker could modify the volume,
0203         set recalc_sector to zero, and the kernel would not detect the
0204         modification.
0205 
0206 The journal mode (D/J), buffer_sectors, journal_watermark, commit_time and
0207 allow_discards can be changed when reloading the target (load an inactive
0208 table and swap the tables with suspend and resume). The other arguments
0209 should not be changed when reloading the target because the layout of disk
0210 data depend on them and the reloaded target would be non-functional.
0211 
0212 
0213 Status line:
0214 
0215 1. the number of integrity mismatches
0216 2. provided data sectors - that is the number of sectors that the user
0217    could use
0218 3. the current recalculating position (or '-' if we didn't recalculate)
0219 
0220 
0221 The layout of the formatted block device:
0222 
0223 * reserved sectors
0224     (they are not used by this target, they can be used for
0225     storing LUKS metadata or for other purpose), the size of the reserved
0226     area is specified in the target arguments
0227 
0228 * superblock (4kiB)
0229         * magic string - identifies that the device was formatted
0230         * version
0231         * log2(interleave sectors)
0232         * integrity tag size
0233         * the number of journal sections
0234         * provided data sectors - the number of sectors that this target
0235           provides (i.e. the size of the device minus the size of all
0236           metadata and padding). The user of this target should not send
0237           bios that access data beyond the "provided data sectors" limit.
0238         * flags
0239             SB_FLAG_HAVE_JOURNAL_MAC
0240                 - a flag is set if journal_mac is used
0241             SB_FLAG_RECALCULATING
0242                 - recalculating is in progress
0243             SB_FLAG_DIRTY_BITMAP
0244                 - journal area contains the bitmap of dirty
0245                   blocks
0246         * log2(sectors per block)
0247         * a position where recalculating finished
0248 * journal
0249         The journal is divided into sections, each section contains:
0250 
0251         * metadata area (4kiB), it contains journal entries
0252 
0253           - every journal entry contains:
0254 
0255                 * logical sector (specifies where the data and tag should
0256                   be written)
0257                 * last 8 bytes of data
0258                 * integrity tag (the size is specified in the superblock)
0259 
0260           - every metadata sector ends with
0261 
0262                 * mac (8-bytes), all the macs in 8 metadata sectors form a
0263                   64-byte value. It is used to store hmac of sector
0264                   numbers in the journal section, to protect against a
0265                   possibility that the attacker tampers with sector
0266                   numbers in the journal.
0267                 * commit id
0268 
0269         * data area (the size is variable; it depends on how many journal
0270           entries fit into the metadata area)
0271 
0272             - every sector in the data area contains:
0273 
0274                 * data (504 bytes of data, the last 8 bytes are stored in
0275                   the journal entry)
0276                 * commit id
0277 
0278         To test if the whole journal section was written correctly, every
0279         512-byte sector of the journal ends with 8-byte commit id. If the
0280         commit id matches on all sectors in a journal section, then it is
0281         assumed that the section was written correctly. If the commit id
0282         doesn't match, the section was written partially and it should not
0283         be replayed.
0284 
0285 * one or more runs of interleaved tags and data.
0286     Each run contains:
0287 
0288         * tag area - it contains integrity tags. There is one tag for each
0289           sector in the data area
0290         * data area - it contains data sectors. The number of data sectors
0291           in one run must be a power of two. log2 of this value is stored
0292           in the superblock.