During the porting of the cryptsetup-suspend toolkit for NixOS, an error was discovered in the LUKS (Linux Unified Key Setup) disk encryption subsystem, which resulted in the failure to clear encryption keys from memory when the system entered sleep mode, starting with Linux kernel 6.9 (the problematic commit) released in May 2024.
The cryptsetup-suspend toolkit is used in Debian to automatically lock LUKS volumes before entering sleep mode. The assumption is that in the event of a laptop theft while in sleep mode, the intruder would be unable to access the data, as a password would need to be entered upon waking to regain access to the encrypted data. Due to a Linux kernel bug, after locking the LUKS volume with the 'cryptsetup luksSuspend' command, the keys were not cleared from memory and remained visible through /proc/keys, allowing an attacker to extract them, for example, using a 'cold boot' method, and leverage them to access the data.
The lack of key clearance was identified during debugging a race condition that caused issues with entering sleep mode. This bug arose after the refactoring in kernel 6.9, whereby keys were tied to the calling thread and were supposed to be deleted upon its completion, but remained in memory instead. A one-line patch has been proposed for inclusion in the Linux kernel to correct this oversight.
This patch has not been accepted into the kernel because a shortcoming was identified — the patch only works for physical drives and does not function for virtual loop devices. Instead of fixing the problem on the kernel side, the developers of the cryptsetup toolkit proposed a workaround for clearing the keys. This change has already been accepted and will be included in the release of cryptsetup 2.8.7.
Additionally, a custom implementation of scripts for locking encrypted disks before entering sleep mode was created for NixOS, utilizing an old kernel patch that was not accepted in 2015, which forcibly clears keys from memory before transitioning to sleep mode.
Source: opennet.ru
