dm-verity

On this page 7

dm-verity is a device-mapper target in the Linux kernel that provides transparent integrity checking of read-only block devices by verifying each data block against a cryptographic hash tree whose single root hash is trusted in advance. In Linux security, it is the standard building block for verified boot: if any byte of a protected partition changes, the read of that block fails instead of returning modified data.

The mechanism was developed for Chrome OS and later adopted by Android, embedded distributions, container hosts and immutable desktop systems. It protects data at rest against offline modification, which complements runtime controls such as SELinux, AppArmor and Integrity Measurement Architecture rather than replacing them.

How dm-verity verifies blocks with a hash tree

dm-verity works by computing a hash for every data block, grouping those hashes into hash blocks, and hashing those blocks again until a single root hash remains. This structure is a Merkle tree: changing any data block changes every hash on its path to the root, so a trusted root hash is enough to authenticate the entire device.

Verification is lazy and on demand. The kernel does not scan the whole partition at activation; when a filesystem reads a block, dm-verity hashes it, compares it with the stored leaf hash, and walks up the tree only until it reaches a hash level that was already verified and cached. A mismatch produces an I/O error or triggers a configured error policy, so tampered content never reaches user space.

The hash tree usually lives on a separate partition or at the end of the data device, and it is generated at build time with the veritysetup format command from the cryptsetup package. The table below lists the main components involved in a dm-verity mapping.

ComponentRoleTypical location
Data deviceHolds the read-only filesystem imageRoot or system partition
Hash deviceStores all levels of the hash treeSeparate partition or appended area
Root hashSingle trusted value that anchors the treeKernel command line, signed metadata or initramfs
SaltRandom value mixed into every hashSuperblock of the hash device
SuperblockRecords block sizes, algorithm and saltStart of the hash device
Main components of a dm-verity mapping

Key parameters and options of dm-verity

A dm-verity table is defined by a small set of parameters that must match exactly between image creation and activation. The hash algorithm is normally SHA-256, and both the data block size and the hash block size are typically 4096 bytes, which aligns with page size and filesystem block size on most systems.

ParameterCommon valueWhat it affects
Hash algorithmsha256Collision resistance and CPU cost per block
Data block size4096 bytesGranularity of each verification
Hash block size4096 bytesFan-out of the tree, 128 hashes per block with SHA-256
Format version1Salt placement and superblock layout
Error policyrestart_on_corruption or panic_on_corruptionSystem reaction to a failed check
Forward error correctionOptional Reed-Solomon dataRecovery from limited media corruption
Important dm-verity parameters

Optional arguments refine behavior. ignore_zero_blocks skips hashing of blocks known to be zero, check_at_most_once reduces overhead on slow devices at the cost of weaker protection, and forward error correction (FEC), used widely on Android, can repair a small number of corrupted blocks caused by flash wear instead of failing the read.

Since kernel 5.4, the root hash signature option lets the kernel verify a PKCS#7 signature of the root hash against a key in the kernel trusted keyring. This closes a gap in which an attacker who could edit the kernel command line could simply supply a new root hash for a modified image.

dm-verity is one of several Linux integrity technologies, and each covers a different layer. The key distinction is that dm-verity protects an entire read-only block device, while other mechanisms target files, writable storage or runtime behavior.

MechanismProtection scopeWritable dataMain purpose
dm-verityWhole block deviceNoTamper detection for system images
dm-integrityWhole block deviceYesPer-sector integrity tags, often with LUKS
fs-verityIndividual filesNo, per fileAuthenticity of selected read-only files
IMAFiles at open or executionYesMeasurement, appraisal and attestation
AIDEFiles on periodic scanYesOffline detection of changes after the fact
dm-verity and neighboring Linux integrity tools

dm-verity provides integrity, not confidentiality. An image protected only by dm-verity remains readable by anyone with physical access; when secrecy matters, it is combined with LUKS or another encryption layer. Unlike AIDE, which reports changes after a scan, dm-verity blocks modified data at the moment of reading.

Deploying dm-verity in a verified boot chain

dm-verity is only as trustworthy as the chain of trust that delivers the root hash. A typical design starts with UEFI Secure Boot or a hardware root of trust, verifies a signed kernel and initramfs, and then passes a root hash embedded in signed data to veritysetup open or to the kernel through the dm-mod.create boot parameter.

  • Build a read-only root image, typically squashfs or EROFS, and generate the hash tree at the end of the build pipeline.
  • Record the root hash in a signed unified kernel image or sign it separately for kernel keyring verification.
  • Keep mutable state on separate partitions, such as an encrypted /var or a home volume.
  • Ship updates as complete new images using A/B partition slots instead of patching files in place.

Tooling has matured considerably. systemd provides systemd-veritysetup, discoverable partitions with verity metadata, and systemd-repart support for building verity images, while distributions such as Fedora Silverblue, Flatcar Container Linux and various embedded build systems use the same principles. The table below matches common scenarios with appropriate configurations.

ScenarioRecommended setupReason
Consumer device with OTA updatesA/B slots, FEC, restart_on_corruptionResilient against flash wear and failed updates
Container host or applianceSigned root hash, immutable /usrPrevents persistent rootkits in system files
Development buildLogging mode without enforcementAllows debugging without constant reboots
High-assurance serverKernel keyring signature, Secure BootRemoves trust in the boot command line
Choosing a dm-verity configuration

Limitations and common mistakes with dm-verity

The most important limitation is that dm-verity cannot protect writable data. Configuration in /etc, logs and user files must live elsewhere, and attackers frequently target those locations instead. A system that verifies /usr but loads unsigned scripts from a writable partition still has a significant persistence path.

  • Unprotected root hash: passing the hash on an editable command line without Secure Boot or a signature defeats the design.
  • Logging-only mode in production: corruption is recorded but data is still returned to applications.
  • Mismatched parameters: a different salt or block size at activation makes every read fail.
  • Assuming runtime protection: dm-verity does not stop a compromised process from abusing memory or writable files.

Performance overhead is usually modest because hashing occurs only on cache misses and modern CPUs accelerate SHA-256, but first reads on slow storage can show measurable latency. dm-verity also offers no rollback protection on its own; an attacker could install an older, validly signed image unless the update system enforces version checks.

In everyday language

dm-verity is like a tamper-evident seal on every page of a book. Before the book is shipped, each page receives a unique fingerprint, and all fingerprints are combined into one master fingerprint that the reader already trusts.

Whenever the computer opens a page, it checks that page against its fingerprint. If someone secretly changed even one letter, the check fails and the computer refuses to use the altered page. The book cannot be edited, which is exactly the point: the operating system stays exactly as its maker built it.

Seen in the real world

A company that builds network routers running embedded Linux ships firmware as a 300 MB read-only squashfs image. Its build server runs veritysetup format on each release, stores the hash tree in a dedicated partition, and embeds the signed root hash in the kernel image that the bootloader verifies with Secure Boot keys.

Months later, a technician discovers that a device in the field was physically accessed and its flash chip rewritten to include a backdoored daemon. On the next boot, the first read of the modified binary fails verification, dm-verity triggers restart_on_corruption, and the router falls back to its intact second slot. The incident is logged, the tampered image never executes, and the company replaces the unit without any customer traffic being exposed.