[PR #3344] fix(windows): initialize split tunnel driver lazily to stop paged pool leak #3216

Open
opened 2026-10-30 04:58:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amnezia-client/pull/3344
Author: @zven73
Created: 10/28/2026
Status: 🔄 Open

Base: dev ← Head: fix/split-tunnel-paged-pool-leak


📝 Commits (1)

  • c55d494 fix(windows): initialize split tunnel driver lazily to stop paged pool leak

📊 Changes

2 files changed (+19 additions, -13 deletions)

View changed files

📝 client/platforms/windows/daemon/windowssplittunnel.cpp (+18 -12)
📝 client/platforms/windows/daemon/windowssplittunnel.h (+1 -1)

📄 Description

Fixes #3216.

Problem

With app split tunneling unused, kernel paged pool grows without bound while AmneziaVPN-service runs and is only freed by a reboot (or a service restart).

WindowsSplitTunnel::create() → initDriver() sends IOCTL_INITIALIZE at daemon start. In mullvad-split-tunnel.sys, initialization registers the process-notify routine, which allocates one PROCESS_EVENT (tag SPTU, paged pool) for every process arrival and departure and appends it to EventQueue (procmon.cpp). The worker drains the queue only after procmon::EnableDispatching(), i.e. after IOCTL_REGISTER_PROCESSES.

The daemon sends IOCTL_REGISTER_PROCESSES only from start(), when the config has excluded apps. Otherwise it calls stop() → IOCTL_CLEAR_CONFIGURATION, which the driver does not accept in STATE_INITIALIZED (only IOCTL_REGISTER_PROCESSES is valid there), so the queue never drains.

Fix

  • initDriver(): still resets a driver left at >= STATE_INITIALIZED, but no longer sends IOCTL_INITIALIZE; the driver stays in STATE_STARTED, where no process events are queued. start() already sends IOCTL_INITIALIZE when it finds STATE_STARTED, so enabling app split tunneling works as before.
  • stop(): returns early in STATE_STARTED; in STATE_INITIALIZED (a start() that failed before process registration) it sends IOCTL_ST_RESET, which is valid in that state and tears down the process monitor, freeing the queue. READY / RUNNING keep the existing IOCTL_CLEAR_CONFIGURATION path (dispatching is enabled there, so the queue drains).
  • Constructor assert and header comment updated to STATE_STARTED.

Measurements (before the fix)

Windows 11, AmneziaVPN 5.0.1.5, mullvad-split-tunnel.sys 1.2.5.0, app split tunneling not configured:

  • after 12 days of uptime: 31.6 M live SPTU allocations, 3.7 GB of paged pool (read with NtQuerySystemInformation(SystemPoolTagInformation));
  • about 5.5 records leaked per cmd.exe /c exit (cmd + conhost, arrival + departure), measured over 1000 runs with the background rate subtracted.

Testing

Not built locally (no Qt toolchain on this machine). The change was checked against the driver's IOCTL state machine (driverentry.cpp, ioctl.cpp Reset()), and the leak was measured live on the release build above. Reviewers with a Windows build: with app split tunneling off, SPTU live allocations should stay flat while processes start and exit; turning app split tunneling on should still reach STATE_RUNNING.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amnezia-vpn/amnezia-client/pull/3344 **Author:** [@zven73](https://github.com/zven73) **Created:** 10/28/2026 **Status:** 🔄 Open **Base:** `dev` ← **Head:** `fix/split-tunnel-paged-pool-leak` --- ### 📝 Commits (1) - [`c55d494`](https://github.com/amnezia-vpn/amnezia-client/commit/c55d494e9a33ce42fa29ab1a2edfb937cd0114e6) fix(windows): initialize split tunnel driver lazily to stop paged pool leak ### 📊 Changes **2 files changed** (+19 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `client/platforms/windows/daemon/windowssplittunnel.cpp` (+18 -12) 📝 `client/platforms/windows/daemon/windowssplittunnel.h` (+1 -1) </details> ### 📄 Description Fixes #3216. ## Problem With app split tunneling unused, kernel paged pool grows without bound while `AmneziaVPN-service` runs and is only freed by a reboot (or a service restart). `WindowsSplitTunnel::create()` → `initDriver()` sends `IOCTL_INITIALIZE` at daemon start. In `mullvad-split-tunnel.sys`, initialization registers the process-notify routine, which allocates one `PROCESS_EVENT` (tag `SPTU`, paged pool) for every process arrival and departure and appends it to `EventQueue` ([procmon.cpp](https://github.com/mullvad/win-split-tunnel/blob/main/src/procmon/procmon.cpp)). The worker drains the queue only after `procmon::EnableDispatching()`, i.e. after `IOCTL_REGISTER_PROCESSES`. The daemon sends `IOCTL_REGISTER_PROCESSES` only from `start()`, when the config has excluded apps. Otherwise it calls `stop()` → `IOCTL_CLEAR_CONFIGURATION`, which the driver does not accept in `STATE_INITIALIZED` (only `IOCTL_REGISTER_PROCESSES` is valid there), so the queue never drains. ## Fix - `initDriver()`: still resets a driver left at `>= STATE_INITIALIZED`, but no longer sends `IOCTL_INITIALIZE`; the driver stays in `STATE_STARTED`, where no process events are queued. `start()` already sends `IOCTL_INITIALIZE` when it finds `STATE_STARTED`, so enabling app split tunneling works as before. - `stop()`: returns early in `STATE_STARTED`; in `STATE_INITIALIZED` (a `start()` that failed before process registration) it sends `IOCTL_ST_RESET`, which is valid in that state and tears down the process monitor, freeing the queue. `READY` / `RUNNING` keep the existing `IOCTL_CLEAR_CONFIGURATION` path (dispatching is enabled there, so the queue drains). - Constructor assert and header comment updated to `STATE_STARTED`. ## Measurements (before the fix) Windows 11, AmneziaVPN 5.0.1.5, `mullvad-split-tunnel.sys` 1.2.5.0, app split tunneling not configured: - after 12 days of uptime: 31.6 M live `SPTU` allocations, 3.7 GB of paged pool (read with `NtQuerySystemInformation(SystemPoolTagInformation)`); - about 5.5 records leaked per `cmd.exe /c exit` (cmd + conhost, arrival + departure), measured over 1000 runs with the background rate subtracted. ## Testing Not built locally (no Qt toolchain on this machine). The change was checked against the driver's IOCTL state machine (`driverentry.cpp`, `ioctl.cpp` `Reset()`), and the leak was measured live on the release build above. Reviewers with a Windows build: with app split tunneling off, `SPTU` live allocations should stay flat while processes start and exit; turning app split tunneling on should still reach `STATE_RUNNING`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amnezia-client#3216
No description provided.