Skip to content

Windows: allow keeping key clearing on device insertion enabled until restart - #1983

Open
flatstik wants to merge 1 commit into
veracrypt:masterfrom
flatstik:fix-1982-clear-keys-latch
Open

flatstik wants to merge 1 commit into
veracrypt:masterfrom
flatstik:fix-1982-clear-keys-latch

Conversation

@flatstik

@flatstik flatstik commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1982.

"Clear encryption keys from memory if a new device is inserted" can be disabled at any time without a restart: by unchecking it, by changing its registry value, or by stopping the VeraCrypt system service, which is what clears the keys.

This PR offers, when the option is enabled, to also prevent it from being disabled until Windows restarts. The prompt defaults to No, so nothing changes for users who answer No.

  • The settings dialog asks the system service, through the existing elevated NotifyService path, to lock the option. The service locks it in the driver with a new admin-only IOCTL; the driver keeps that state until Windows restarts. A second IOCTL reports the state.
  • While locked:
    • the service clears the keys on new device insertion, whatever the registry value says;
    • the service no longer rebuilds its list of known devices;
    • the service does not accept SERVICE_CONTROL_STOP;
    • the settings dialog shows the option checked and disabled.
  • Setup already replaces a service that cannot be stopped when Windows restarts. When stopping it fails, Setup now also tells the running service that it has been superseded (a new control code). That service then does not reinstall its own, older boot loader or SetupConfig until the restart.
  • The lock is requested after the other settings are saved. If the driver does not confirm it, an error is shown.
  • The lock does not protect against an administrator, who can still terminate the service process. The prompt and the documentation say so.

The Linux and macOS counterpart is in #1984.

Testing:

  • I do not have Windows, so this is not run-tested.
  • It compiles with MSVC 2022 and WDK 10.0.26100 on a GitHub Windows runner. That covers the driver (including Ntdriver.c), Mount, Format, ExpandVolume, Setup and SetupDLL; no compiler warnings came from the changed files.
  • An independent code review was done. Its findings are addressed: the superseded-service boot loader issue, the lock request no longer aborting the other settings, and the dialog when the service is not running while locked.

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.

… restart

"Clear encryption keys from memory if a new device is inserted" can be
disabled at any time without a restart: by unchecking it, by changing
its registry value, or by stopping the VeraCrypt system service, which
is what clears the keys. Someone at an unlocked machine can then
connect a device without the keys being cleared.

When the option is enabled, offer to also prevent it from being
disabled until Windows restarts. The service then asks the driver to
lock it, and the driver keeps this state until Windows restarts. While
locked:

- the service clears the keys on new device insertion whatever the
  registry value, and does not rebuild its list of known devices;
- the service does not accept SERVICE_CONTROL_STOP. Setup already
  replaces a service that cannot be stopped when Windows restarts; it
  now also tells the running service that it is superseded, so that
  it does not reinstall its own, older boot loader until then;
- the settings dialog shows the option as checked and disabled.

The lock is requested after the other settings are saved; if it cannot
be confirmed through the driver, an error is shown.
This does not protect against an administrator, who can still
terminate the service process.

Fixes veracrypt#1982
@flatstik
flatstik force-pushed the fix-1982-clear-keys-latch branch from 2632683 to cc92bb5 Compare November 3, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant