Commit Graph

71 Commits

Author SHA1 Message Date
Alexandr Stelnykovych 1d96934428 chore(kext): bump version to 2.1.2
Includes:
- handle IRP_MJ_CLOSE in the driver to keep WDF's handle count intact
- do not pend connections after the shutdown command
- do not let a reused local endpoint inherit the previous verdict
- stop with a dedicated bug check on a driver panic
2026-10-05 21:10:22 +03:00
Alexandr Stelnykovych c0a6ba6831 fix(kext): stop with a dedicated bug check on a driver panic
The panic handler logged the panic and entered an endless loop. A panic
inside a callout then pinned that CPU at DISPATCH_LEVEL until the system
crashed minutes later with DPC_WATCHDOG_VIOLATION, attributed to a
generic timeout instead of the driver. The log call also allocated,
which can panic again when the original panic was a failed allocation.

Stop the system immediately with KeBugCheckEx instead, using code
0x504D7273 ("PMrs", the pool tag). The parameters carry the source file
(pointer and length, `da <P1> L<P2>`), the line number, and the panic
message formatted into a NUL-terminated stack buffer (`da <P4>`), so a
crash dump names the panic location and keeps runtime-only details such
as the size of a failed allocation. Nothing on this path allocates, and
a guard skips the formatting when it panics itself or when several CPUs
panic at once, reporting the location alone in that case.

Related ticket: #2284
2026-10-05 18:04:07 +03:00
Alexandr Stelnykovych 381262b9d0 fix(kext): do not let a reused local endpoint inherit the previous verdict
The ALE authorization lookup matched cache entries by 5-tuple only. A new
socket reusing the local port and remote endpoint of a closed connection
(matchable for up to ~90 seconds until the entry is purged), or replying
to a flow first seen by the packet layer (recorded with process id 0),
inherited the previous verdict and was attributed to the previous owner's
process id in all events.

The lookup now drops a matching entry that has ended, or that has no
process id while the requester's is known, and requests a fresh verdict
for the new flow instead. Live entries are still shared regardless of the
owning process: processes can legitimately share a 5-tuple (for example
multicast senders on a port opened with SO_REUSEADDR), and evicting a
live entry would make the owners evict each other on every
re-authorization, each eviction triggering yet another verdict request.

Related ticket: #2271
2026-10-05 16:30:23 +03:00
Alexandr Stelnykovych 41a53f200c fix(kext): do not pend connections after the shutdown command
Related ticket: #2104

After Portmaster sends the shutdown command it stops reading events, but
the callouts stay registered until the driver is unloaded, up to the
10 second service stop timeout. The shutdown command resolves the
operations pended at that moment, but a connection classified
afterwards was pended again with nobody left to answer. A pended
operation cannot be cancelled by the owning process, so the process
could not exit. For Portmaster's own DNS dials this left
portmaster-core as an unkillable zombie and the Windows service in
"Stopping" until reboot.

Set a shutting_down flag in shutdown(). While it is set, new and
undecided connections in the ALE layer are permitted instead of pended,
and the packet layer permits instead of absorbing packets that wait for
a verdict. Permit matches the state after the unload that follows.
Verdicts that need no user space are unchanged.

Device::drop now also runs shutdown() so that an unload without a
preceding shutdown command resolves outstanding pends instead of leaking
them.
2026-10-05 11:33:28 +03:00
Alexandr Stelnykovych a370253026 fix(kext): handle IRP_MJ_CLOSE in the driver to keep WDF's handle count intact
Related ticket: #2271

Since 2.1.0 the driver overrides the IRP_MJ_CREATE and IRP_MJ_CLEANUP
dispatch entries of the WDF control device to record the PID of the
connected user-space process. IRP_MJ_CLOSE stayed with WDF. WDF counts
open handles on CREATE and CLOSE and destroys the control device when
the count drops to zero. With CREATE never reaching WDF, the first CLOSE
underflowed the count, WDF destroyed its device object, and the next
request routed through WDF, in practice the CLOSE of a second handle,
dereferenced the cleared device extension: BugCheck 0x50 in
Wdf01000!FxDevice::DispatchWithLock.

Stock Portmaster opens a single handle per driver lifetime and did not
crash, but any second opener (a second core instance, a diagnostic tool,
a custom client) took the machine down on close.

Take over IRP_MJ_CLOSE as well, with a handler that only completes the
request. CREATE, CLEANUP and CLOSE are now all handled by the driver, so
WDF's count stays untouched until unload, as it was before 2.1.0.
2026-10-02 18:20:16 +03:00
Alexandr Stelnykovych 0fd3665ac0 kext: fast-track split-tunnel proxy packets on loopback
Add PM_SPLIT_TUN_PORT (719) to fast_track_pm_packets so that redirected
packets arriving at the local split-tunnel proxy are permitted immediately
by the kext, matching the existing behaviour for the SPN port (717) and
the DNS port (53). This prevents internal proxy connections from being
reported to Portmaster and appearing in the connection monitor UI.

Also simplify fast_track_pm_packets by removing the redundant
match-on-direction branches, which were identical for Outbound and
Inbound.

Bump kext interface patch version to 2.1.1.0.
2026-05-07 13:46:16 +03:00
Alexandr Stelnykovych 933323d5f9 feat: add VerdictRerouteToSplitTun verdict type
Add a new verdict (value 8) for routing connections through the split
tunnel. This prepares the infrastructure for the upcoming split-tunneling
feature without implementing the full feature yet.

Changes:
- Define VerdictRerouteToSplitTun in network/status.go with String() and Verb()
- Add RerouteToSplitTun() to the Packet interface and InfoPacket stub
- Implement RerouteToSplitTun() for windowskext (v1) and windowskext2 (v2) packets
- Map VerdictRerouteToSplitTun to KextVerdict 11 in kextinterface and kext2
- Handle the verdict in packet_handler.go dispatch, connection.go, api.go,
  metrics.go and nameserver.go
- Add VerdictRerouteToSplitTun = 8 to Angular Verdict enum and update
  stats counting, filter queries and verdict CSS class

(WIP) Note: Linux (nfq) implementation not updated yet. Therefore Linux build will fail.
2026-04-17 20:48:48 +03:00
Alexandr Stelnykovych f08707afc5 KEXT: Bump version 2.1.0 2026-03-10 15:52:57 +02:00
Alexandr Stelnykovych 6fd5c72b88 Merge pull request #2137 from safing/feature/kext-improvements
feat(windows-kext): owner PID tracking, downstream filter bypass, and split-tunneling routing support
2026-03-10 14:23:00 +02:00
Alexandr Stelnykovych 3b0b1745dc Merge pull request #2136 from safing/fix/windows-kext-bsod
fix(windows-kext): fix potential BSODs and block verdict bypass in WFP callouts
2026-03-10 14:20:23 +02:00
Alexandr Stelnykovych 8786aac857 Update callout_data.rs
Reverted changes to prevent merge conflicts
2026-03-10 14:05:17 +02:00
Alexandr Stelnykovych 0615270807 Update packet_callouts.rs
Added a comment for the recalc_header_checksums() call.
2026-03-10 14:02:45 +02:00
Alexandr Stelnykovych baf436c205 refactor(device): improve comments for clarity on event queue and caches in Device struct 2026-03-06 10:26:29 +02:00
Alexandr Stelnykovych d11b0ee763 feat(kext): bypass downstream filters for Portmaster's own outbound connections
When a permitted connection is initiated by Portmaster itself, clear the
write flag on the classify result so subsequent filters in the sublayer
chain cannot override the permit action.
2026-03-05 15:32:32 +02:00
Alexandr Stelnykovych 13f85929b2 feat(kext): track owner PID of connected user-space process
Add IRP_MJ_CREATE and IRP_MJ_CLEANUP handlers to capture and clear the
PID of the user-space process that holds the device handle open.

- wdk/ffi: expose PsGetCurrentProcessId kernel API
- wdk/irp_helpers: add CreateRequest and CleanupRequest wrappers
- driver/device: add owner_pid AtomicU32 field with lock-free access
  for callouts; add is_owner_pid() helper
- driver/entry: register driver_create/driver_cleanup dispatch routines
  that store/clear owner_pid on connect/disconnect
2026-03-05 14:54:11 +02:00
Alexandr Stelnykovych 78fce7650d feat(kext): add RedirectSplitTunnel verdict support
Add Verdict::RedirectSplitTunnel (11) with PM_SPLIT_TUN_PORT redirection.
Wire up the new verdict in ALE, packet, and device layers alongside the
existing redirect verdicts. RedirectSplitTunnel is kept last in the enum
so older Portmaster versions (which only know verdicts 0–10) remain
unaffected.
2026-03-05 14:11:21 +02:00
Alexandr Stelnykovych 35ecee89d5 fix(kext): prevent block verdicts from being overridden by downstream WFP filters
Rename action_block() to action_block_hard(), which additionally calls
clear_write_flag(). This prevents lower-weight filters in the same WFP
sublayer from overwriting a block action set by Portmaster's callout.

Updated call sites:
- ALE layer: PermanentBlock, Undeterminable, Failed, and inbound Block
- Packet layer: PermanentBlock
2026-03-03 18:15:47 +02:00
Alexandr Stelnykovych 72c048cb07 fix(kext): ignore STATUS_FWP_TXN_IN_PROGRESS in reset_all_filters
When completing a Reauthorization classify defer, reset_all_filters()
would fail with STATUS_FWP_TXN_IN_PROGRESS if another WFP transaction
was already running (e.g. from a concurrent ClearCache command). This
caused the packet to be silently dropped instead of injected.

This error is safe to ignore: the concurrent transaction will trigger
WFP reauthorization for all connections anyway, and the verdict for the
current connection is already written to the connection_cache before
complete() is called, so the callout will apply the correct verdict when
the injected packet passes through.

All other errors from reset_all_filters() are still propagated.
2026-03-03 18:07:55 +02:00
Alexandr Stelnykovych f586f23a3a fix(kext): change advance method to accept mutable reference for buffer modification 2026-03-03 13:39:20 +02:00
Alexandr Stelnykovych 489b9c0442 fix(kext): replace global device pointer with AtomicPtr for thread safety 2026-03-03 13:33:04 +02:00
Alexandr Stelnykovych 7b4d3a93c3 fix(kext): remove unused spin_lock module to clean up codebase 2026-03-02 19:21:30 +02:00
Alexandr Stelnykovych 2d6fd0ad09 fix(kext): potentially fix BSOD by copying WFP control data before callout returns
FwpsInjectTransportSendAsync1 reads control_data (WSACMSGHDR) asynchronously
after the ALE classify callout returns. The pointer was into WFP-managed
metadata memory that WFP frees immediately when the callout returns, leaving
a dangling pointer used during deferred injection. This could
cause PAGE_FAULT_IN_NONPAGED_AREA or DRIVER_IRQL_NOT_LESS_OR_EQUAL BSODs.

Candidate fix: change TransportPacketList.control_data from Option<NonNull<[u8]>>
to Option<Box<[u8]>> and copy the bytes inside from_ale_callout while the WFP
pointer is still valid. The owned copy lives on the heap as part of the boxed
TransportPacketList context and is freed by free_transport_packet after WFP
calls the completion callback.

https://github.com/safing/portmaster-shadow/issues/38
2026-03-02 19:06:26 +02:00
Alexandr Stelnykovych 674ff3f4dc fix(kext): potentially fix BSOD by heap-allocating WFP transport send params
FwpsInjectTransportSendAsync1 dereferences FWPS_TRANSPORT_SEND_PARAMS1
(and remote_address within it) asynchronously after the callsite returns.
The params were stack-allocated, so WFP may have accessed freed stack memory
at DISPATCH_LEVEL, potentially causing PAGE_FAULT_IN_NONPAGED_AREA or
DRIVER_IRQL_NOT_LESS_OR_EQUAL BSODs.

Candidate fix: embed send_params in TransportPacketList, box the whole struct
before calling the inject API, and populate send_params (remote_address points
into boxed remote_ip) only after boxing so all pointers are into stable
non-paged heap memory. Introduce free_transport_packet as the WFP completion
callback that drops Box<TransportPacketList> once injection is complete.

https://github.com/safing/portmaster-shadow/issues/38
2026-03-02 18:42:31 +02:00
Alexandr Stelnykovych def9d3407e feat(tests): add documentation and build script for Windows kernel driver testing 2026-03-02 17:08:47 +02:00
Vladimir Stoilov 04f8708448 Fix packet callout injection 2026-01-26 21:03:25 +02:00
Vladimir Stoilov 61c3443deb Fix verdict mutability 2026-01-26 20:50:15 +02:00
Alexandr Stelnykovych 9e8acb2d25 chore(windows_kext): reduce compiler warnings for cleaner build output 2026-01-12 17:01:27 +02:00
Alexandr Stelnykovych c7f2420c64 [kext] (inf): add PnpLockdown setting to PortmasterKext64.inf 2025-06-20 15:14:29 +03:00
Alexandr Stelnykovych e5c5ded5c5 [kext] (build): update cab removal commands in build_cab.ps1 2025-06-20 13:54:52 +03:00
Alexandr Stelnykovych f144e52b4a [kext] Bump version to 2.0.7.0 2025-06-20 13:01:31 +03:00
Vladimir Stoilov f5072fd838 [kext] Fix compiler warnings 2025-06-10 09:49:10 +03:00
Vladimir Stoilov 934480da0b [kext] Fix wrong buffer copy call 2025-06-09 20:25:47 +03:00
Vladimir Stoilov 10f2ef426e [kext] Resolve verdict of pending conn on shutdown 2025-06-09 20:11:26 +03:00
Alexandr Stelnykovych 857df4086f [kext] Fix dev build documentation (releasing procedure) 2025-01-28 14:26:44 +02:00
Vladimir Stoilov 32d6e1cb04 [kext] Fix dev build documentation 2025-01-28 11:49:23 +02:00
Daniel df4106fd70 Merge branch 'develop' 2024-11-27 16:40:03 +01:00
Daniel acaf98144a Bump kext version 2024-11-27 16:19:09 +01:00
Vladimir Stoilov fe070b4f56 Feature/kext default action drop (#1747)
* [windows_kext] Make default action to drop

* [windows_kext] Minor improvments
2024-11-25 14:03:35 +02:00
Daniel a4b76843e5 Bump kext version 2024-11-12 17:39:49 +01:00
Vladimir Stoilov af3bb804bf Fix reading only the needed TCP/UDP header bytes (#1730)
* [windows_kext] Fix reading only the needed TCP/UDP header bytes

* [windows_kext] Disable debug mode

* [windows_kext] Block all fragment packets

* [windows_kext] Improve wording for compiler error
2024-11-07 15:52:26 +02:00
Vladimir Stoilov 145f5e67de [windows_kext] Improve documentation (#1719) 2024-10-28 08:35:02 +02:00
Daniel d26ab22d92 Bump kext version 2024-10-16 13:53:48 +02:00
Vladimir Stoilov 355f74318d [service] Fix check for invalid kext handle (#1716)
* [service] Fix check for invalid kext handle

* [windows_kext] Use BTreeMap as cache structure

* [windows_kext] Fix synchronization bug

* Update windows_kext/kextinterface/kext_file.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update windows_kext/kextinterface/kext_file.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update windows_kext/kextinterface/kext_file.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2024-10-16 12:19:08 +03:00
Daniel b7ec90e2c5 [service] Fix windows build 2024-08-21 15:00:29 +02:00
Daniel 35ac64bd82 [windows_kext] Bump version 2024-07-02 15:06:18 +02:00
Vladimir Stoilov 8579958811 [windows_kext] Fix go compiler error 2024-07-01 18:28:16 +03:00
Vladimir Stoilov 2e3304809f [windows_kext] Fix minor problems 2024-07-01 15:06:54 +03:00
Vladimir Stoilov 89657123ec [windows_kext] Remove warning to reduce confusion. 2024-07-01 10:28:39 +03:00
Vladimir Stoilov ea59c11d0d [windows_kext] Fix some clippy warnings 2024-06-28 16:12:07 +03:00
Vladimir Stoilov 81bee82b8f [windows_kext] Update windows-rs 2024-06-28 16:06:30 +03:00