Commit Graph

3005 Commits

Author SHA1 Message Date
Alexandr Stelnykovych f6d4471bbb Merge pull request #2326 from safing/fix/2026.11-spn-fixes
fix(spn): observation hub, route simulation and SPN doc comments
2026-11-24 14:19:33 +02:00
Alexandr Stelnykovych 575d4aa53f ci: pin Go 1.26.x in the Go workflow
'^1.26' resolved to Go 1.27, whose export data golangci-lint v2.12.2 cannot read, so every typecheck failed. Match go.mod and the Earthfile, which use Go 1.26.
2026-11-24 14:11:28 +02:00
Alexandr Stelnykovych ab5ef3dedc feat(spn/navigator): note when debug output does not apply to this node
Add a note to the measurements and optimization tables on clients, and
to the route simulation on hubs.
2026-11-20 16:00:18 +02:00
Alexandr Stelnykovych 809ad61c42 feat(spn/navigator): add port and protocol to route simulation
Without a port or protocol, rules with a port never matched, so hubs
whose exit policy allows only some ports were always disregarded.

- Add "port" and "protocol" query parameters; parse "encrypted"
  (default: derived from the port, as the firewall does).
- Move the encrypted port list to netutils.IsEncryptedPort.
- Show the simulation inputs and what is not simulated.
- Note that routes do not apply with the "home" routing algorithm.
- Fix the disclaimer and the Connection.Encrypted comment.

Example:
  http://127.0.0.1:817/api/v1/spn/map/main/route/to/example.com?profile=global&port=443&protocol=tcp&encrypted=true
2026-11-20 14:23:16 +02:00
Alexandr Stelnykovych 8d0804cf70 Merge pull request #2321 from safing/fix/2026.11-observation-hub-fixes
fix(observation-hub): make the observation hub work again
2026-11-19 13:49:26 +02:00
Alexandr Stelnykovych 4a161ed718 fix(observation-hub): honor --spn-map
The observer always watched the map "main", whatever --spn-map said.
2026-11-19 12:27:02 +02:00
Alexandr Stelnykovych eb3bf5448a build(observation-hub): update the Dockerfile
Use Go 1.26, as go.mod requires, and the module path of the merged
repository.
2026-11-19 12:21:44 +02:00
Alexandr Stelnykovych f61db859a9 fix(observation-hub): stay compatible with existing deployments
The production deployment runs a build from the former stand-alone
safing/spn repository (v0.7.4). Its job passes --data and reads the log
from stdout.

- Accept --data as a second name of --data-dir.
- Log to stdout unless --log-dir is given.
2026-11-19 11:56:56 +02:00
Alexandr Stelnykovych eaa9fc84c7 fix(observation-hub): run on an instance of its own
The observation hub has been broken since November 2024 and could not
report anything:

- Since commit 706ce222d (2024-11-27, first in the repository tag
  v2.0.20) it used Portmaster's full instance. There the SPN modules only
  start for an integrated client, so the tool never connected and the
  observer waited forever. A failed instance creation also ended in a
  nil-pointer panic, because the error was ignored.
- Since commit 80664d1a2 (2024-08-09, first in the repository tag
  v1.6.19) the Apprise module was never added and the observer was added
  twice instead. Nothing was sent to the chat rooms, without any error
  message.

The hub's instance is no better fit: it installs binary updates by
itself, which here would install Portmaster's binaries, and it lacks the
notifications module. The SPN client's connection loop reports failures
as notifications and panics without that module; the hub never runs
that loop.

- Add a small instance with only the modules the tool uses: the SPN
  client, intel updates and notifications, but no binary updater and no
  core module. The tool is updated by replacing its container image.
- Add the Apprise module once and before the observer.
- Return the errors of the instance creation instead of ignoring them.
- Require a data directory, so that the data of an installed Portmaster
  is never used.
- Remove --bin-dir and the update command: there are no binaries to
  manage, and the command would install Portmaster's.
- Add a VS Code debug entry for the observation hub.
2026-11-19 11:49:42 +02:00
Alexandr Stelnykovych 3fa8d3a55d docs(spn): add doc comments to the main SPN flow functions
Comments only, no code changes.
2026-11-17 14:36:13 +02:00
Alexandr Stelnykovych e9ca8c4585 .gitignore update 2026-11-17 12:26:55 +02:00
Alexandr Stelnykovych ba00f816a4 Bump version 2.2.9 v2.2.9 2026-11-11 16:11:13 +02:00
Alexandr Stelnykovych 5ee8e28391 feat(updates): require a signed intel index
Portmaster, the SPN hub and the observation hub now verify the intel
index the way they verify the binary index: VerifyIntelUpdates is set
to a new trust store with two dedicated intel signing keys. An intel
index that is unsigned, signed with another key or changed after
signing is refused, and the intel files in use stay as they are.

The intel keys are kept apart from the code signing keys, so that an
intel key can only ever forge intel data, not binaries. A test makes
sure that no code signing key is in the intel trust store, and another
one that ParseIndex accepts exactly an index signed with a trusted key.
2026-11-04 15:22:00 +02:00
Alexandr Stelnykovych bffef134cd fix(UI): keep the top consumers chart rendering, open the app on click
The Recent Top Consumers widget on the dashboard went empty and stayed
empty until one of the apps left the top ten. The chart grouped its
bars by the profile name, and the grouping throws on duplicate keys.
Two different apps can share a name (the Codex CLI and the Codex
desktop app, for example), and after a rename one app has connections
stored with the old and the new name, which the query returned as two
rows for the same profile.

Group the query by the profile ID only, so the backend returns exactly
one row per app, and stack the bars by that ID. The profile name is
still selected and used for the labels and tooltips, with the ID as
fallback.

The labels of the chart already looked clickable but did nothing. Add
a click output to the circular bar chart that emits the stack key, and
let the dashboard open the app page for the clicked profile. The chart
is re-rendered from a ResizeObserver callback, which runs outside the
Angular zone, so the click is emitted inside the zone to make sure the
navigation is picked up by change detection.
2026-10-30 00:30:45 +02:00
Alexandr Stelnykovych 843166be22 fix(UI): show correct charts of the selected app in the connection list
Opening another app from the app list sometimes left the Data Usage
and Connections charts showing the previous app, or nothing if that
app had no traffic, until the user pressed Reload. Two defects caused
this.

The app page reuses the connection list when the user opens another
app, because the profile arrives synchronously from the watched
profiles cache and the page content is never torn down. It then
triggers the list's search from its own subscription, before Angular
has pushed the new profile to the list's mergeFilter input. The search
builds its query synchronously when the last reload is more than a
second ago, so the query still carried the profile of the previously
shown app. The connection rows were not affected, as the paginator
builds its query lazily when it loads a page, but the charts and the
total count used the captured query. Run change detection on the app
page before triggering the search, so the list holds the new profile
when it builds the query.

In the list itself, the guard that cancels the chart load on a
subsequent search sat before the chart requests in the pipe. Once the
requests were in flight, a new search could no longer cancel them, and
a late response overwrote the charts of the new search with the data
of the previous one. Move the guard after the requests so a new search
also drops pending chart responses. Handle a failed bandwidth chart
request like the connections chart already does: report the error and
leave that chart empty, instead of silently leaving both charts empty.
2026-10-28 12:45:23 +02:00
Alexandr Stelnykovych 5c82035444 Bump version 2.2.8
+ npm audit fix
v2.2.8
2026-10-27 20:21:05 +02:00
Alexandr Stelnykovych 7dd9e195b5 fix(netquery): remove bandwidth data of deleted connections
main.bandwidth declares ON DELETE CASCADE on conn_id, but foreign keys
are never enabled on the connection, so the cascade never runs. Cleanup
deleted the connections and left their bandwidth rows behind: one row
per connection per second of traffic, kept in memory for the whole
uptime of the process.

Delete the bandwidth rows of the connections that Cleanup is about to
remove, before removing them, and index conn_id, which the bandwidth
chart joins on and the cleanup deletes through. The delete is limited
to the connections being removed, so its cost does not grow with the
rows of live connections, and a bandwidth update that arrives before
its connection is saved is left alone.

Add a test for the cleanup and the index.
2026-10-27 18:11:39 +02:00
Alexandr Stelnykovych 3f22abb1a7 fix(netquery): stop fsyncing the history database on every write
The history database is attached to the in-memory connection database
without any configuration. The OpenWAL flag of the write connection only
applies to the main (in-memory) database, so the attached file ran with
the SQLite defaults: rollback journal and synchronous=FULL, which waits
for an fsync on every commit. Bandwidth updates write to it once per
second for every connection with history enabled, all on one goroutine
and under the connection lock.

Set journal_mode=WAL and synchronous=NORMAL on the history database of
the write connection, the same settings the base sqlite storage already
uses. Set synchronous=NORMAL on every pooled read connection as well:
all connections share the pager of the history database (shared cache),
and attaching it from a reader applies the default FULL to that pager
again, silently undoing the setting of the writer.

Measured per history write (Windows, SSD): 5.3 ms before, 0.02 ms after;
the bandwidth update path 6.3 ms before, 0.03 ms after.

Add a test that checks the settings on the write and the pooled read
connections, and two benchmarks to compare the write cost.
2026-10-27 17:21:47 +02:00
Alexandr Stelnykovych cfffa7f43e fix(core): stop interception when the shutdown times out
When the shutdown did not complete within three minutes, the process
exited without stopping the interception. The kext then kept holding
every new connection for a verdict that never came, and the network
stayed dead until a reboot.

Add a shutdown-timeout hook to cmdbase and let portmaster-core use it
to stop the interception, bounded by ten seconds, before the exit.
2026-10-27 16:11:09 +02:00
Alexandr Stelnykovych 458e708f13 fix(netenv): do not block callers on the interface address refresh
IsMyIP and GetLocalNetwork held myNetworksLock while refreshMyNetworks
called the OS, and that call sometimes takes seconds. Every waiting
caller then made its own slow call once it got the lock, so the queue
of goroutines only grew and DNS stayed blocked.

The networks are now an atomic snapshot, read without a lock, and the
refresh runs through singleflight: callers that arrive during a refresh
share its result. The throttle counts from the end of the call, so slow
calls do not run back to back, and the changed flag is reset before the
call, so a change during it is not lost. Callers that arrive during a
refresh after a network change wait for the new networks.
2026-10-27 14:30:49 +02:00
Alexandr Stelnykovych cc164c7df6 spn/ships: bound HTTP ship handshake and abort it on ctx done
After the TCP connect, launchHTTPShip wrote the upgrade request and read
the response without a deadline, ignoring ctx. With keep-alive disabled,
a peer that accepts the connection but never answers blocked the caller
forever. After a sleep/resume cycle this left the SPN client stuck in
establishHomeHub: the 5 minute timeout in connectToHomeHub had no effect,
and the UI kept showing "Connecting to SPN..." until a restart.

Bound the handshake by a deadline of 30s, or the ctx deadline if that is
earlier, and close the connection when ctx is done. Both are lifted once
the handshake succeeds, so the ship's connection is unaffected.

Also close the connection on all handshake error paths, which previously
leaked it.

The new test covers a peer that accepts but never responds, for both a
ctx deadline and a ctx cancel.
2026-10-21 14:34:40 +03:00
Alexandr Stelnykovych b543aba6cf fix(resolver): ask failing DNS servers last instead of skipping them
Failing servers were skipped whenever another server in scope was not
marked, even if that server did not answer either. A wrongly marked
server, e.g. after a short stall under load, then stayed unused until the
recovery check.

Ask failing servers after all others, only if none of them answered. An
answer clears the failing state right away. In scopes that continue after
"not found" (.lan, .local, ...), failing servers are skipped once any
server answered, so their timeout does not turn "not found" into a
failure.

https://github.com/safing/portmaster/issues/1891
2026-10-21 13:49:01 +03:00
Alexandr Stelnykovych b56aba0c89 sqlite: write PutMany batches as multi-row upserts
modernc.org/sqlite re-parses the SQL text on every statement execution,
so the prepared statement in PutMany gave no benefit and parsing
accounted for about half of the time spent per record. Writing 50
records per INSERT ... ON CONFLICT DO UPDATE statement amortizes that
cost: the per-record time in BenchmarkPutManyPreparedStmt dropped from
roughly 100 µs to 50 µs on the same machine.

PutMany is used for the intel filter list import and for the resolver's
delayed cache flushes. Importing a filter list base update is now roughly
twice as fast on the database side.

Stored data is unchanged, including NULL format and value for records
without data. Duplicate keys within one statement resolve to the last
write, as before. A failed prepare now rolls the transaction back
instead of leaving it open.

The new test covers full and partial statements and re-writing existing
keys, for both the batched and the single-row PutMany path.
2026-10-19 16:46:04 +03:00
Alexandr Stelnykovych 760cd47b9f filterlists: increase bloom filter capacities and log fill level
The IPv4 filter was sized for 100 entries while the current base list
contains about 18k IPv4 addresses. The filter was fully saturated, so every
lookup of a global IPv4 address fell through to the cache database. The
domain filter was sized for 1M entries with about 843k domains in use, which
left little head room for additional intel sources.

Raise the capacities with head room for growth:
domain 1M -> 2M, ipv4 100 -> 200k, ipv6 100 -> 20k, asn 1k -> 10k,
country 100 -> 300. This adds about 2 MB of memory for the domain filter
and doubles the size of its record in the cache database.

Count the values added per entity type and log them next to the capacity
after a base list has been processed, so a list outgrowing its filter can be
spotted in the logs.

Filters restored from the cache database keep their stored size. Existing
installations pick up the new capacities with the next base list update.
2026-10-19 14:55:32 +03:00
Alexandr Stelnykovych cbab42bca3 Merge pull request #2300 from safing/fix/filterlists-base-update-cleanup
fix(filterlists): clean up obsolete entries and rebuild bloom filters on base list updates
2026-10-19 14:32:25 +03:00
Alexandr Stelnykovych 7476b19061 filterlists: add unit test for update order resolution
Pass the cache database version into resolveUpdateOrder so the ordering
logic can be tested without a database, and cover the base/diff
combinations, including a newer base skipping older diffs.
2026-10-16 18:06:44 +03:00
Alexandr Stelnykovych 84f7499359 filterlists: purge obsolete entries by update start time
The cleanup after a base update deleted entries older than "now - 1h".
If the import took longer than an hour of wall-clock time (system sleep,
slow disk), entries written by the import itself were deleted too, and
stayed unblocked until the next base update. Use the update start time,
minus a small margin for clock corrections, as the cutoff instead.
2026-10-16 17:49:33 +03:00
Alexandr Stelnykovych a47e5b0613 fix(filterlists): clean up obsolete entries on base list updates
The base/intermediate/urgent file variables used to detect the base file
and to compare versions were never assigned after the v2 updater
rewrite. As a result the "is this the base file" check never matched:
processing a new base.dsdl neither rebuilt the bloom filter from scratch
nor triggered the removal of obsolete entries. Entries that were removed
from the lists upstream stayed in the cache database and in the bloom
filter and kept blocking indefinitely, and both grew over time.

Detect the base file by filename, as the updater returns a new Artifact
instance on every GetFile call, so pointer identity could never match.
Drop the unused variables and the IsNewerThan checks: which files need
processing is already decided by comparing against the persisted cache
database version in resolveUpdateOrder.
2026-10-16 17:30:46 +03:00
Alexandr Stelnykovych e0b7d272be fix(UI; Linux): use WEBKIT_DISABLE_DMABUF_RENDERER for Wayland/NVIDIA crash workaround
Users reported that __NV_DISABLE_EXPLICIT_SYNC=1 does not prevent the
WebKitGTK "Error 71 (Protocol error)" crash on Wayland with the NVIDIA
driver. Switch to WEBKIT_DISABLE_DMABUF_RENDERER=1, which was confirmed
to fix it in #1898 and #1806.

The conditions are unchanged: only applied on a Wayland session with the
NVIDIA kernel module loaded, and an existing value in the environment is
never overridden. With this workaround the webview loses GPU acceleration
on affected systems; the log message now states this.
2026-10-15 17:08:04 +03:00
Alexandr Stelnykovych d82b33dad0 Merge pull request #2294 from safing/fix/1891-dns-failing-resolvers-nxdomain
fix(resolver): ask failing DNS servers instead of answering nothing
2026-10-15 16:43:12 +03:00
Alexandr Stelnykovych 99069f94bb fix(resolver): clear a failing DNS server when it answers the recovery check
A server is marked as failing when it does not answer: timeouts and
connection errors. The recovery check, however, only cleared the mark
when the online check domain resolved to exactly the expected IP. A
server that answers but filters or rewrites that name, for example a
blocklist, DNS rebind protection or a corporate resolver, stayed marked
until Portmaster restarted. With a working fallback configured, that
meant the LAN server and its filter were bypassed for good.

Clear the mark on any answer, whatever the answer is, which is the same
criterion normal queries already use. Timeouts and connection errors
keep the mark.

Issue: https://github.com/safing/portmaster/issues/1891
2026-10-15 16:13:42 +03:00
Alexandr Stelnykovych d268851b99 fix(resolver): ask failing DNS servers when no other server can be asked
A DNS server is marked as failing after a few timeouts and then skipped.
When every server in scope is marked, no server is asked at all and the
query is answered with NXDOMAIN, which clients cache. A server that was
wrongly marked, for example after a short stall, therefore breaks name
resolution until the next recovery check or until Portmaster restarts.

Skip failing servers only while another server can still be asked, that
is, one that is neither failing nor an unavailable link-local server.
Otherwise ask the failing servers in their configured order. A successful
answer clears the failing state right away, as it does for normal queries.

Behaviour is unchanged whenever a healthy server is available. When every
server is marked and really down, the query now fails with SERVFAIL after
the timeout instead of an instant, wrong NXDOMAIN.

Issue: https://github.com/safing/portmaster/issues/1891
2026-10-15 16:13:02 +03:00
Alexandr Stelnykovych f943e1eaf9 fix(api): remove unauthenticated updates/from-url endpoint
Issue:
The updates/from-url endpoint was registered with PermitAnyone, so any
local process could call it without authentication. Its handler passed the
request body as an index URL to UpdateFromURL, which ran the update with
the version checks and the auto-download/auto-apply settings bypassed.
Signatures were still verified, but a caller could point Portmaster at a
copy of any older signed index and have it installed without asking the
user, e.g. to bring back a version with an already fixed vulnerability.

Change:
- Remove the endpoint. It was left over from an unfinished feature and
  nothing (UI, tray app, scripts) calls it.
- Remove Updater.UpdateFromURL, which had no other callers.

ForceUpdate is unchanged: it is only used by the command line tools and
always uses the configured index URLs.

Fixes #2292
2026-10-15 13:04:44 +03:00
Alexandr Stelnykovych aea3aa4a2b linux: pass LOGLEVEL from the unit file, drop the unused PORTMASTER_ARGS
The unit file set LOGLEVEL=info and sourced /etc/default/portmaster, but
never passed the value to portmaster-core. Pass it as --log=${LOGLEVEL}.

An invalid level used to make ServiceConfig.Init fail, which would now turn
a mistyped LOGLEVEL into a service that does not start. Warn and fall back
to the default level instead, as the logger already does on its own.

PORTMASTER_ARGS was appended after "--", where cobra stops parsing flags and
the core ignores the rest, so it has had no effect since the v1 wrapper was
removed. Drop it, and replace the UI README instruction that relied on it
with the equivalent setting (Development Mode).
2026-10-15 12:54:54 +03:00
Alexandr Stelnykovych df9dffe118 Merge pull request #2293 from safing/fix/2233-Linux-process-lookup-overload
Linux: fix memory growth and verdict timeouts under many connections per socket
2026-10-15 12:10:02 +03:00
Alexandr Stelnykovych 42366c0d59 fix(linux): cache socket owners, scan /proc once per socket at a time
Issue:
Finding the process of a socket walks /proc/<pid>/fd of every process of the
user. The result was stored on the socket-table entry, which is replaced on
every table refresh (up to 100 per second), so every new connection of a
long-lived socket - a torrent's DHT socket, a listening socket, a resolver -
triggered a full scan. Under a burst, thousands of scans ran at once and
slowed each other down until packets timed out while their lookup was still
running; the connections with a lookup in flight were the memory growth
reported in #2233.

Change:
- Cache the found owner by socket inode for 1-2 s (two generations, lazy
  rotation, bounded size). A cache hit is only used if the PID is still in
  the user's PID list, so an exited owner is scanned for again.
- Run at most one scan per socket at a time (singleflight). Lookups that
  arrive while a scan runs wait for its result instead of scanning too.
  Without this the first scan under a burst never finished.
2026-10-14 17:51:18 +03:00
Alexandr Stelnykovych df06892918 firewall (Linux): skip packets that already have a verdict, drop packets that cannot be queued
Packets that received a verdict while waiting in a queue (the default-drop
after the 20 s verdict timeout) cannot be influenced anymore. Handling them
only created connections, handler workers and "verdict already set" noise,
which made a backlog grow instead of drain.

- packet.Packet gains VerdictSet(). nfqueue and both Windows kext packet
  types report their verdict flag; the base type reports false.
- The dispatcher and the per-connection handler skip packets whose verdict
  is already set.
- nfqueue: a packet that could not be handed to the handler queue within
  1 s will never get a verdict. Drop it right away instead of starting a
  watchdog and keeping it in the kernel queue for 20 s.

This reduces wasted work and log noise under load.

Refs #2233
2026-10-14 15:25:07 +03:00
Alexandr Stelnykovych bb6c44468a fix(geoip): reload the database when the updater replaced its file
The geoip reader memory-maps geoipv4/v6.mmdb once and only reopened
them on a new artifact version. The intel updater moves every file in
the intel directory on every update, even when unchanged, and the next
update renames the new copy over the moved one.

On Windows a mapped file without open handles cannot be deleted but can
be replaced by such a rename, after which the mapping has no backing
data: evicted pages come back zero-filled, maxminddb fails with
"invalid node in search tree", and geo rules block with "data not
available". Since the switch to Go 1.26 in v2.2.2 os.RemoveAll no
longer unlinks the mapped file on the first update, which is what kept
earlier releases safe.

- Detect a replaced file by its identity (file ID or inode, size and
  mtime), taken from an open handle since os.Stat resolves the Windows
  file ID lazily, and reload.
- Do not close the previous reader on reload; a lookup may still use
  it. The finalizer set by maxminddb.Open unmaps it later.
- Buffer the worker trigger so an update event during a load is not
  dropped, and do not hold the broadcaster lock during file access.

https://github.com/safing/portmaster/issues/2265
2026-10-12 18:29:31 +03:00
Alexandr Stelnykovych 882d900dad Merge pull request #2285 from safing/fix/2217-2104-windows-kext-fixes
fix(kext): Windows kext 2.1.2: CLOSE handling, shutdown pends, endpoint reuse, panic bug check
2026-10-06 12:48:20 +03:00
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 13a86a43cc fix(nameserver; resolver): bound the wait for in-flight DNS requests on shutdown
Related ticket: #2104

On shutdown the NameServer module stopped its listeners with
dns.Server.Shutdown, which waits without limit for all in-flight request
handlers to return. A handler can be stuck in an upstream connect that the
kernel never completes: a connection pended by a firewall driver cannot be
cancelled. In #2104 the pending driver was our own kext, because the
Interception module stops before Resolver and NameServer, so DoT dials
issued in that window had nobody left to answer their verdict. The module
Stop() has no time bound, so the whole shutdown stalled and the Windows
service stayed in "Stopping" until reboot.

- nameserver: stop listeners with ShutdownContext and a 10 second
  timeout. Reading from the listener socket stops immediately; only the
  wait for running handlers is bounded. Handlers still running
  afterwards are cancelled and waited for by the module manager as
  before.
- resolver: do not dial a new upstream connection once the instance
  has started shutting down. The instance context is cancelled before
  any module stops, so this closes the window in which a dial could be
  pended after interception is gone. Existing pooled connections are
  still used. The resolver instance interface gains ShuttingDown() for
  this.

The kext-side part (do not pend new connections after the Shutdown
command) is a separate change that needs a signed driver release.
2026-10-02 17:43:59 +03:00
Alexandr Stelnykovych b6a78eeaae Merge pull request #2281 from safing/fix/2255-2185-(Windows)-Tauri-UI-crash
fix(UI; Windows): patched tao with atomic refcount fixes random UI crash (0xc000001d)
2026-10-02 15:14:35 +03:00
Alexandr Stelnykovych 8b8167c1cf Merge pull request #2278 from safing/fix/1834-open-data-dir
feat(UI): implement "Open Data Directory" in the Tauri app
2026-10-02 15:13:22 +03:00
Alexandr Stelnykovych b61887ba77 Merge pull request #2272 from safing/fix/2066-dns-local-bind
fix(resolver): bind local port before pre-authenticating it (#2066)
2026-10-02 15:11:29 +03:00
Alexandr Stelnykovych 702ef660fa Merge pull request #2279 from safing/fix/2233-1870-LINUX-high-mem-usage-on-conns-burst
fix(network; Linux): fix high memory usage on connection bursts
2026-10-02 15:10:03 +03:00
Alexandr Stelnykovych 6a167b33d5 fix(network; Linux): drop both hint generations when taking a pid hint
SavePIDHint() always writes into the current generation and never checks
the previous one. When the same connection reports an info-only packet
before and after a rotation, both generations hold an entry for its ID.

takePIDHint() removed only the entry it returned. A later take for the
same connection ID then found the older entry in the previous generation
and returned a stale pid instead of a miss.

Delete the connection ID from the previous generation as well when the
current one is consumed. Add a regression test that saves a hint, rotates,
saves a newer hint for the same connection and checks that the second take
is a miss.
2026-10-02 15:07:43 +03:00