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
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
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
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.
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.
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.
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.
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.
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
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.
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
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.
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
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