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.
| Component | Role | Typical location |
|---|---|---|
| Data device | Holds the read-only filesystem image | Root or system partition |
| Hash device | Stores all levels of the hash tree | Separate partition or appended area |
| Root hash | Single trusted value that anchors the tree | Kernel command line, signed metadata or initramfs |
| Salt | Random value mixed into every hash | Superblock of the hash device |
| Superblock | Records block sizes, algorithm and salt | Start of the hash device |
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.
| Parameter | Common value | What it affects |
|---|---|---|
| Hash algorithm | sha256 | Collision resistance and CPU cost per block |
| Data block size | 4096 bytes | Granularity of each verification |
| Hash block size | 4096 bytes | Fan-out of the tree, 128 hashes per block with SHA-256 |
| Format version | 1 | Salt placement and superblock layout |
| Error policy | restart_on_corruption or panic_on_corruption | System reaction to a failed check |
| Forward error correction | Optional Reed-Solomon data | Recovery from limited media corruption |
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 compared with related integrity mechanisms
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.
| Mechanism | Protection scope | Writable data | Main purpose |
|---|---|---|---|
| dm-verity | Whole block device | No | Tamper detection for system images |
| dm-integrity | Whole block device | Yes | Per-sector integrity tags, often with LUKS |
| fs-verity | Individual files | No, per file | Authenticity of selected read-only files |
| IMA | Files at open or execution | Yes | Measurement, appraisal and attestation |
| AIDE | Files on periodic scan | Yes | Offline detection of changes after the fact |
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.
| Scenario | Recommended setup | Reason |
|---|---|---|
| Consumer device with OTA updates | A/B slots, FEC, restart_on_corruption | Resilient against flash wear and failed updates |
| Container host or appliance | Signed root hash, immutable /usr | Prevents persistent rootkits in system files |
| Development build | Logging mode without enforcement | Allows debugging without constant reboots |
| High-assurance server | Kernel keyring signature, Secure Boot | Removes trust in the boot command line |
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.