TL;DR
Plain dm-crypt encryption (using older ciphers or weak key setups) is vulnerable to attacks. We’ll cover how to spot it and what you can do to protect your data, from checking existing setups to using stronger methods like LUKS.
Detecting Plain dm-crypt Encryption
- Check the Cipher Used: The easiest way is to examine the device mapping configuration.
- Use
lsblk -fto see the filesystem type and UUID of your encrypted partitions. This won’t directly tell you the cipher, but it helps identify which devices need checking. - Then use
cryptsetup luksDump /dev/sdXN(replacesdXNwith your partition) if LUKS is used. If it reports ‘LUKS header not found’, it’s likely plain dm-crypt. - For plain dm-crypt, look at the device mapper configuration file:
cat /etc/dmsetup.confor examine active mappings usingls -l /dev/mapper/*and then inspect the relevant mapping details in/proc/self/mountinfo(this is more advanced).
- Check
cat /proc/cmdlinefor options like ‘cryptdevice=…’ or specific cipher names (e.g., ‘aes’).
- If you can access the encryption configuration, check if it uses MD5 or SHA1 as a KDF. These are considered weak. Modern systems should use PBKDF2, Argon2, or scrypt.
Countermeasures Against Weak dm-crypt Encryption
- Switch to LUKS: This is the most recommended solution. LUKS adds a header containing metadata about the encryption setup, including the cipher, key size and KDF used. It’s much more secure than plain dm-crypt.
- Backup your data! Before doing anything, make sure you have a complete backup of all data on the encrypted partition.
- Use
cryptsetup luksFormat /dev/sdXNto format the partition with LUKS (replacesdXN). This will erase existing data. - Then use
cryptsetup open /dev/sdXN myencryptedvolumeto unlock it and mount as normal.
- Use a Strong Cipher: AES with a 256-bit key is the minimum acceptable. Avoid older ciphers like DES or TripleDES.
- Strong Key Derivation Function (KDF): Use PBKDF2, Argon2, or scrypt with a high iteration count and a unique salt for each encryption setup. A good iteration count is at least 100,000, but higher is better.
- Long Passphrase: Use a long, complex passphrase (at least 16 characters) to increase the key space.
- Regular Key Rotation: Periodically change your encryption keys and passphrases.
Example dm-crypt configuration snippet (showing a weak setup – DO NOT USE)
cipher aes
key-file /etc/my_encryption_key
salt 1234567890
This example uses a simple key file and a short salt, making it vulnerable. A modern setup would use LUKS or dm-crypt with PBKDF2, Argon2, or scrypt, a long passphrase, and a randomly generated salt.