Repository navigation
Conversation
flatstik
force-pushed
the
fix-1982-unix-new-device
branch
from
November 2, 2026 20:15
426ff60 to
dcf9858
Compare
…nected On Windows, "Clear encryption keys from memory if a new device is inserted" protects an unlocked machine against devices connected to extract its memory (veracrypt#1982). Linux and macOS have no equivalent. Add "A new USB or Thunderbolt device is connected" to Preferences > Security > Unmount All Volumes When. The GUI listens to kernel uevents on Linux and to IOKit notifications on macOS. Devices connected when the option is enabled or VeraCrypt starts are ignored; a device is identified by its vendor, product and serial number, or by its port without a serial number. On a new device, all volumes are unmounted even if files are open, and the password cache is wiped. On Linux, a forced unmount detaches the filesystem lazily and removes the device-mapper devices when they are closed, so the keys would stay in memory while a file is open. EmergencyDismountVolume can now destroy the keys: it first replaces the table of the volume's device-mapper devices with an error target, and once the volume's loop and device-mapper devices are released, it aborts the FUSE connection, so that the FUSE service closes the volume, which erases its keys, and exits. Open files then fail with I/O errors. The CLI's --emergency-unmount is unchanged. When the option is enabled, the user can also lock it: the option then cannot be disabled, and VeraCrypt cannot be closed, until the session ends. On Linux, only this auto-unmount option is shown, as unmounting may require the administrator password. Tests/test_linux_new_device_unmount.py checks it against the installed GUI. It is skipped without the dummy_hcd module, as on the GitHub runners, unless --connect-command connects a new device. Related to veracrypt#1982
flatstik
force-pushed
the
fix-1982-unix-new-device
branch
from
November 3, 2026 17:04
dcf9858 to
8d75f16
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #1982 (the Windows part is #1983).
On Linux and macOS, VeraCrypt has no equivalent of "Clear encryption keys from memory if a new device is inserted". This PR adds one to Preferences > Security > Unmount All Volumes When: "A new USB or Thunderbolt device is connected".
Detecting devices. The GUI listens to kernel uevents on Linux (netlink, kernel messages only) and to IOKit first-match notifications on macOS. Devices connected when the option is enabled, or when VeraCrypt starts, are ignored. A device is identified by vendor, product and serial number, or by its port if it has no serial number.
On a new device. All volumes are unmounted even if files are open, and the password cache is wiped. A device connected while a wait dialog is open is handled once that dialog closes.
Linux: keys erased immediately. A forced unmount detaches the filesystem lazily, and the device-mapper devices are only removed once they are closed. So the keys would stay in memory while any file on the volume is open.
EmergencyDismountVolumegains adestroyKeysmode, used only by this option;--emergency-unmountis unchanged. It first:dmsetup wipe_table), which frees the dm-crypt keys at once;/sys/fs/fuse/connections/<n>/abort, mountingfusectlthere if needed). The FUSE service then closes the volume, which erases its keys, and exits.Open files then fail with I/O errors, and their unsaved data is lost. The warning shown when the option is enabled says so.
macOS. A forced unmount (
hdiutil detach -force) already releases the FUSE service.Linux preferences. Only this auto-unmount option is shown; the others stay hidden because unmounting may require the administrator password. If VeraCrypt has not obtained administrator privileges in the session, it asks for the password before unmounting, and the warning says so.
Lock. When the option is enabled, the user can also lock it. Until the session ends, the option cannot be disabled, the background task cannot be turned off, and VeraCrypt cannot be closed. The lock does not protect against someone who can run programs in the session, who can terminate VeraCrypt; the prompt says so.
Testing:
Tests/test_linux_new_device_unmount.pyruns as root against the installed GUI under Xvfb. It mounts a volume with kernel cryptography and one without, with a file open on each, and checks that:build-linux.yml. It is skipped on the GitHub runners, whose Azure kernel has nodummy_hcdmodule.--connect-command). All checks pass. A second run with/sys/fs/fuse/connectionsunmounted passes too: VeraCrypt mountsfusectlitself.NewDeviceMonitor.cppand the changed GUI and Core files) only passed aclang++ -fsyntax-onlycheck against Homebrew wxWidgets on a macOS runner. I do not have a Mac, so it is neither linked nor run-tested.Known limits:
Since I cannot test on Windows or macOS, please feel free to merge this, close it, or take it as a basis for your own implementation, as you see fit. I will adjust the Linux/Unix part according to your suggestions.