Commit Graph
3 Commits
Author SHA1 Message Date
nghianguyenandClaude Fable 5 6f1d069d14 anslicensing: Linux hardware id uses PHYSICAL NICs only
The id is built from up to 6 enumerated MACs. On Linux getifaddrs() also
returns virtual interfaces — docker0 and the veth* pairs each container
creates, tun*/wg* from a VPN, br-*/virbr* bridges. Container veths carry
RANDOM MACs and appear/disappear with the containers, so the enumerated set
can differ between calls: the hardware id changes and an activated licence
silently stops matching its machine. Boxes running Docker (the Coder feature)
would hit this routinely.

This matters more on Linux than elsewhere because two of the four id
components are already constant there: the system-UUID slot is a literal and
GetHDDPropertyList is an empty function on non-Windows. The id rests on CPU id
+ MACs, so unstable MACs are most of the instability.

Filter mirrors what the Windows branch already does via WMI (PNPDeviceId LIKE
%PCI% — physical adapters only). The test is /sys/class/net/<name>/device,
the kernel's own record of a hardware-backed interface, so it stays correct as
new virtual-interface flavours appear; a name-prefix denylist is kept only for
environments without /sys. MACs are bucketed during the walk and chosen after
it, so a veth appearing earlier in the list cannot consume a slot and push a
real NIC out.

FAIL-SAFE: if no physical NIC is found, fall back to the unfiltered set. An
empty list would drop all MAC entropy and — with the UUID and disk slots
already constant — leave near-identical ids across different machines.

Windows and macOS/BSD paths are untouched (both #else branches preserve the
existing behaviour exactly). Logic verified against a simulated Docker host:
enp3s0/wlp2s0 accepted; lo, docker0, veth*, br-*, tun0 rejected.

ORDERING: this CHANGES the id on any Linux box that has virtual interfaces, so
it must land BEFORE the first Linux licences are issued — afterwards it would
invalidate them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-28 19:34:26 +10:00
nghianguyenandClaude Fable 5 4f392ce95e anslicensing: fix 3-byte heap overflow in hardware-id BitStream3
GetCurrentHardwareId sized its bit stream at 125 bits (16 bytes) but
writes 147 (3 version + 9 x 16-bit hashes), so the last two hash slots
overflowed the heap block by 3 bytes on every id computation. The
Windows heap absorbed it silently for years; it SIGSEGVs under macOS
malloc — found when ANSGateway enabled this code on POSIX (fixed there
in ANSGateway 3a34c68/6c3cdfd; this is the upstream port).

Two parts, both id-preserving (only the first 16 bytes feed the base32
encode — verified byte-identical ids before/after in the gateway):
- hwid.cpp: size the stream to the 147 bits actually written.
- BitStream3: bounds-safe byteAt/setByte accessors on every Write/Read,
  Attach records the real buffer size, default ctor zero-inits — an
  under-sized stream can no longer corrupt the heap, and out-of-range
  reads return 0 (identical to the base32 padding zeros the Match path
  always read there).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-27 09:29:05 +10:00
nghianguyen 8a2e721058 Refactor project structure 2026-03-28 19:56:39 +11:00