Summary
pam_usb's deny_remote feature is intended to block USB-based authentication over remote sessions, allowing it only on local terminals.
Due to an incomplete check of the utmpx address field for IPv4-mapped IPv6 connections, some SSH logins are incorrectly classified as local, allowing an attacker with a registered USB token to authenticate remotely as if they were physically present.
Affected context
The vulnerability arises in Linux environments using pam_usb for hardware-backed authentication where:
- The deny_remote option is enabled to restrict USB logins to local sessions
- PAM is used for SSH authentication via pam_usb
- The SSH daemon listens on the IPv6 wildcard address (::) with AddressFamily any (commonly on Debian/Ubuntu)
- utmpx records incoming IPv4 SSH sessions as IPv4-mapped IPv6 addresses (::ffff:x.x.x.x)
In this context, IPv4 SSH connections can be misclassified as local sessions, weakening the intended remote-access control policy.
Exploit preconditions
- Attack surface: SSH or other remote login services that rely on pam_usb with deny_remote enabled.
- Required access:
- Ability to reach the target host over the network (e.g., SSH connectivity).
- Physical possession of a USB device or removable media that the system has been configured to trust for pam_usb authentication.
- Trigger point: A remote authentication attempt over SSH (or similar) where the connection is recorded in utmpx as an IPv4-mapped IPv6 address (::ffff:x.x.x.x).
- Why exploitation is possible:
- pam_usb only inspects the first 32 bits of the ut_addr_v6 field to determine if a session is remote.
- For IPv4-mapped IPv6 addresses, this word is zero while the actual IPv4 address is stored in a different word.
- As a result, the remote-detection code path is skipped and the session is treated as local, bypassing deny_remote=true.
Why this happens
This issue stems from a flawed access control decision based on incomplete inspection of session metadata.
The deny_remote logic attempts to distinguish local from remote sessions using utmpx.ut_addr_v6, but only checks ut_addr_v6[0] != 0 as a proxy for "has a network address."
On systems where IPv4 connections are recorded as IPv4-mapped IPv6 addresses (::ffff:x.x.x.x), the relevant address bits are stored in ut_addr_v6[3], leaving ut_addr_v6[0] as zero.
Because of this incorrect assumption about address layout, the remote-check branch is never executed for these sessions, causing remote logins to be treated as local.
This aligns with CWE-284 (Improper Access Control): the software enforces a policy ("no remote pam_usb authentication") using an incorrect condition that fails under a common configuration, effectively disabling the restriction for a large class of remote connections.
Potential impact
- Remote users in possession of a trusted USB device may be able to authenticate over SSH despite deny_remote being enabled.
- Administrative policies that require physical presence for certain accounts or operations can be undermined.
- Attackers who steal or temporarily obtain a registered USB token could gain full remote access to accounts protected by pam_usb.
- Security assumptions about "local-only" authentication workflows can be invalidated, impacting compliance and risk assessments.
General mitigation guidance
Effective mitigation focuses on making remote/local detection robust and reducing reliance on fragile connection heuristics:
- Implement address checks that correctly handle IPv4, IPv6, and IPv4-mapped IPv6 layouts rather than relying on a single word in ut_addr_v6.
- Favor higher-level indicators of session type (e.g., explicit TTY vs. network session classification) rather than inferring from raw address fields alone.
- Treat any session with a non-empty remote endpoint as remote by default, adopting a "secure by default" stance when detection is ambiguous.
- Where feasible, require an additional authentication factor for remote sessions instead of assuming USB tokens imply physical presence.
- Apply least-privilege principles to accounts using pam_usb, ensuring that a compromise of USB-based auth does not automatically grant broad administrative control.
- Consider segmenting policies so that critical accounts do not rely solely on USB-based local presence checks for security decisions.
How teams detect issues like this
Organizations can approach detection and assurance for this class of flaw through:
- Code-level review:
- Examine PAM modules and authentication helpers that branch on utmpx or similar session data to enforce "local-only" policies.
- Flag patterns where only a portion of an address structure is checked (e.g., single-element checks in multi-word address arrays).
- Static analysis and policy checks:
- Use static analyzers or linters to identify suspicious uses of ut_addr_v6 and similar structures where all components are not considered.
- Define internal coding guidelines for handling IP address representations, and enforce them in CI.
- Configuration and runtime validation:
- Review SSH daemon and PAM configurations to identify deployments that combine deny_remote-style options with AddressFamily any or :: listeners.
- Perform controlled tests: attempt USB-based authentication over SSH with deny_remote enabled and verify that it is rejected as expected.
- Automated code scanning tools:
- Integrate automated code review or SAST tools into the development workflow to surface access control decisions that depend on low-level address fields or brittle heuristics.

