Skip to content

Option to prevent disabling "Clear encryption keys from memory if a new device is inserted" until next reboot #1982

Open

Description

@amdigyira

Currently, the setting "Clear encryption keys from memory if a new device is inserted" (VC_DRIVER_CONFIG_CLEAR_KEYS_ON_NEW_DEVICE_INSERTION) can be disabled on the fly via Settings -> System Encryption... without requiring a system reboot or master password entry.

If an adversary seizes an unlocked machine (live forensics scenario) and is aware of this VeraCrypt feature, they can simply open VeraCrypt System Settings, uncheck "Clear encryption keys from memory if a new device is inserted", click OK, and then safely plug in a forensic USB drive to dump RAM without triggering VC_IOCTL_EMERGENCY_CLEAR_ALL_KEYS. If RAM key encryption is disabled, this possibility is more dangerous, but in my opinion this possibility is unsafe in any case.

Desired behavior

Add a sub-option (or make it default behavior): "Lock this setting until next reboot" (One-way latch in veracrypt.sys).
Once enabled in the current session, the driver should reject any IOCTL calls attempting to clear the VC_DRIVER_CONFIG_CLEAR_KEYS_ON_NEW_DEVICE_INSERTION flag in memory until the system is rebooted (or require the VeraCrypt system master password to disarm it).

Activity

  1. added 2 commits that reference this issue on Nov 2, 2026
    9739f99
    426ff60
  2. amdigyira commented on Nov 2, 2026

    @amdigyira
    Author

    Thank you @flatstik for implementing this so quickly in #1983!

    Regarding the limitation noted in the documentation and prompt:

    Note: this does not protect against someone with administrator privileges on this computer, who can, for example, terminate the VeraCrypt system service.

    Could we close this gap as well by making the locked state fail-closed if the service process is unexpectedly terminated?

    Proposed mechanism (Dead Man's Switch on Service Handle):

    Currently, VeraCryptSystemFavorites ignores SERVICE_CONTROL_STOP when locked and only stops on SERVICE_CONTROL_PRESHUTDOWN. However, an admin on an unlocked machine can still kill the user-mode service via TerminateProcess (taskkill /F), silently disarming device arrival monitoring.

    To prevent this without moving PnP monitoring entirely into kernel mode:

    1. When VC_IOCTL_LOCK_CLEAR_KEYS_ON_NEW_DEVICE_INSERTION is called, VeraCryptSystemFavorites keeps its hDriver handle open (or opens a dedicated watchdog handle to veracrypt.sys) for the lifetime of the service.
    2. If the service receives a legitimate SERVICE_CONTROL_PRESHUTDOWN, it sends a clean disarm/shutdown notification IOCTL to veracrypt.sys before exiting.
    3. If an attacker forcibly kills the service process (TerminateProcess), the Windows kernel automatically closes all handles owned by the process, triggering IRP_MJ_CLEANUP / IRP_MJ_CLOSE in veracrypt.sys.
    4. If veracrypt.sys receives IRP_MJ_CLEANUP on that watchdog handle while IsClearKeysOnNewDeviceInsertionLocked is active (and without a prior PRESHUTDOWN notification), the driver treats the unexpected termination of the service as tampering and immediately calls VC_IOCTL_EMERGENCY_CLEAR_ALL_KEYS.

    Alternatively, veracrypt.sys could register a kernel-mode PnP notification directly via IoRegisterPlugPlayNotification when the lock is engaged, removing the reliance on the user-mode service staying alive.

    What do you think? This would make the lock completely tamper-proof even in an unlocked admin session.

  3. flatstik commented on Nov 2, 2026

    @flatstik
    Contributor

    I'd rather wait @idrassi's opinions and comments before pushing any more further :)

  4. added 2 commits that reference this issue on Nov 2, 2026
    2632683
    dcf9858
  5. amdigyira commented on Nov 2, 2026

    @amdigyira
    Author

    I hope you don't mind that I partially conveyed my thoughts through AI, as my English isn't perfect. I also hope everything was clear. I often think about security like a paranoid person and try to think of all sorts of loopholes in feautures what I use personally. I could also translate this and some other commits (which I understand) into Russian for better localization. And also thank you @flatstik thank you for your contribution. It's so nice when ideas are implemented so quickly. <3

  6. added 2 commits that reference this issue on Nov 3, 2026
    cc92bb5
    8d75f16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions