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>
This commit is contained in:
2026-07-28 19:34:26 +10:00
co-authored by Claude Fable 5
parent 4f392ce95e
commit 6f1d069d14
+76 -1
View File
@@ -21,9 +21,10 @@
#include <net/if.h>
#ifdef __linux__
# include <sys/ioctl.h>
# include <sys/stat.h> // stat() — physical-NIC test in linuxIsPhysicalNic
# include <netinet/in.h>
# include <unistd.h>
# include <string.h>
# include <string.h> // strncmp/strlen (same test)
// Match Linux to FreeBSD
# define AF_LINK AF_PACKET
@@ -82,6 +83,47 @@ void GetCPUIDPropertyList(std::list<std::string>* propList)
propList->push_back(buf);
}
#ifdef __linux__
// A PHYSICAL network interface, i.e. one backed by a real hardware device.
//
// Why this exists: the hardware id is built from up to 6 enumerated MACs, and
// on Linux getifaddrs() also returns VIRTUAL interfaces — docker0 and the
// veth* pairs a container creates, tun*/wg* from a VPN, br-*/virbr* bridges.
// Container veths get RANDOM MACs and come and go with the containers, so an
// unfiltered enumeration can hand back a different set on every call: the id
// changes and an activated licence silently stops matching its machine. Boxes
// running Docker (the Coder feature) hit this routinely.
//
// The test mirrors what the Windows branch already does via WMI ("PNPDeviceId
// LIKE %PCI%" — physical adapters only). /sys/class/net/<name>/device is a
// symlink to the backing device and exists ONLY for hardware-backed
// interfaces; virtual ones have no such link. That is the kernel's own answer,
// so it stays correct as new virtual-interface flavours appear — unlike a name
// denylist, which is kept only as a cheap second line of defence.
static bool linuxIsPhysicalNic(const char* ifname)
{
if (ifname == NULL || ifname[0] == '\0') return false;
// Names that are virtual by construction. Not exhaustive on purpose — the
// /sys check below is the real test; this only catches oddities where /sys
// is unavailable (unusual containers, minimal namespaces).
static const char* kVirtualPrefixes[] = {
"lo", "docker", "veth", "br-", "virbr", "tun", "tap", "wg",
"vmnet", "vboxnet", "zt", "ppp", "dummy", "kube", "cni", "flannel",
"lxc", "lxd", "nerdctl", "podman", "cali", "weave"
};
for (const char* prefix : kVirtualPrefixes) {
if (strncmp(ifname, prefix, strlen(prefix)) == 0) return false;
}
std::string path = std::string("/sys/class/net/") + ifname + "/device";
struct stat st;
// stat() (not lstat) so the symlink is followed — we want "the target
// exists", i.e. a real backing device.
return stat(path.c_str(), &st) == 0;
}
#endif // __linux__
void GetMACPropertyList(std::list<std::string>* propList, int maxCount)
{
// Head of the interface address linked list
@@ -99,6 +141,14 @@ void GetMACPropertyList(std::list<std::string>* propList, int maxCount)
return;
}
#ifdef __linux__
// Collected separately so physical NICs can be preferred wholesale. Taking
// them inline would let a veth that merely appears EARLIER in the list
// consume one of the maxCount slots and push a real NIC out.
std::list<std::string> physical;
std::list<std::string> fallback;
#endif
while (current != NULL && maxCount > 0) {
const sockaddr_in* interfaceAddress = castToIP4(current->ifa_addr);
@@ -127,8 +177,18 @@ void GetMACPropertyList(std::list<std::string>* propList, int maxCount)
{
char buf[18];
sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]);
#ifdef __linux__
// Bucket now, choose after the walk (see the lists above).
// maxCount is NOT decremented here: the cap applies to the
// SELECTED set, not to whatever happened to be enumerated.
if (linuxIsPhysicalNic(current->ifa_name))
physical.push_back(buf);
else
fallback.push_back(buf);
#else
propList->push_back(buf);
maxCount--;
#endif
}
}
@@ -137,6 +197,21 @@ void GetMACPropertyList(std::list<std::string>* propList, int maxCount)
freeifaddrs(ifap);
ifap = NULL;
#ifdef __linux__
// Physical NICs only — that is the whole point. FAIL-SAFE: if the filter
// found none (no /sys, an exotic NIC driver, a network namespace with only
// virtual links) fall back to the unfiltered set rather than returning
// nothing. An empty list would drop ALL MAC entropy from the id, and with
// the system-UUID and disk-serial slots already constant on Linux that
// would leave near-identical ids across different machines — far worse
// than an id that occasionally drifts.
std::list<std::string>& chosen = physical.empty() ? fallback : physical;
for (std::list<std::string>::const_iterator it = chosen.begin();
it != chosen.end() && maxCount > 0; ++it, --maxCount) {
propList->push_back(*it);
}
#endif
}
void GetHDDPropertyList(std::list<std::string>* propList, int maxCount)