Linux MOST USB Patch Fixes Use-After-Free in hdm_disconnect (CVE-2025-40223)

  • Thread Author
A small but important kernel patch fixing CVE-2025-40223 closes a race that could produce a use‑after‑free (UAF) in the MOST USB driver’s disconnect path, converting a KASAN‑reported crash into a deterministic and safe device release sequence and removing redundant device reference adjustments that could double‑free kernel objects.

Security-themed illustration with a glowing padlock, USB device, and module on a circuit board.Background / Overview​

The bug lives in the Linux kernel’s MOST (Media Oriented Systems Transport) USB adapter code, specifically in the hdm_disconnect routine used when a MOST-over-USB device is removed. In the vulnerable flow, hdm_disconnect called most_deregister_interface, a function that ultimately invokes device_unregister(iface->dev). If device_unregister dropped the final reference to the underlying device object, the kernel’s device core could call the device’s release callback (release_mdev immediately while hdm_disconnect continued executing. Because the original hdm_disconnect still freed several allocations owned by the most_dev structure after that point — and also issued additional put_device calls — the code could provoke a slab use‑after‑free (or, in some refcount interleavings, a double‑free). The upstream remedy moved mdev‑owned kfree calls into the dedicated release_mdev callback and removed redundant put_device calls in hdm_disconnect, ensuring the driver frees resources exactly once and only from the release context. This problem was discovered by automated kernel fuzzing and testing infrastructure (a KASAN slab-use-after-free trace from syzbot was reported), and it was fixed with a small, surgical change that preserves runtime semantics while eliminating the hazardous ordering. The patch author and reviewers followed the normal kernel review flow and the fix was committed upstream and prepared for stable backports across multiple kernel series.

What went wrong: technical anatomy of the vulnerability​

The lifecycle of a kernel device object​

Linux’s device model tracks device lifetimes using reference counting. Functions such as device_register / device_add increment the device’s refcount; device_unregister decrements it and can trigger the device’s release callback when the last reference goes away. Code that manages multiple objects which share or point to the same device instance must take care to only free per‑device resources from within the release callback or after ensuring the device will not be released prematurely. Failing to do so invites use‑after‑free races when refcount order changes under concurrent operations or in corner cases exercised by automated fuzzers.

The concrete flow in hdm_disconnect​

  • hdm_disconnect performed cleanup when a MOST USB interface disconnected.
  • It called most_deregister_interface as part of that cleanup. That call path can call device_unregister(iface->dev), which decrements the device refcount.
  • If device_unregister drops the last reference to the structure backing the device, the kernel calls its release callback (release_mdev immediately.
  • The original hdm_disconnect then continued and performed explicit kfree calls on mdev‑owned allocations and issued put_device calls afterwards.
  • If release_mdev had already freed mdev and its member resources, the subsequent kfree or put_device in hdm_disconnect could reference freed memory or double‑free the same buffers — producing a KASAN slab‑use‑after‑free trace or unstable kernel behavior under non‑KASAN builds.

Why the small code change is the right fix​

Rather than attempting a larger rework of lifetime semantics, maintainers moved the frees of mdev‑owned allocations into release_mdev so that resource destruction happens exactly once and at the canonical moment the device is truly released. They also removed redundant put_device calls that are no longer needed after device_unregister and most_deregister_interface were invoked. These changes eliminate the race regardless of the refcount ordering and do so with a minimal, trivially reviewable patch that is easy to backport to stable branches. The commit includes explicit kfree relocations and a short deletion of redundant put_device calls.

How the patch landed and where it can be found​

The fix was submitted through the usual kernel development channels as a small patch that modifies drivers/most/most_usb.c. The patch was reviewed and accepted, and stable branch backports were prepared for multiple kernel series (examples include 5.10, 5.15, 6.1, 6.6, 6.12, and 6.17). Patch emails and stable patch review posts show the upstream commit and the stable‑tree propagation. The change is deliberately minimal — four insertions and seven deletions in the upstream patch series — which lowered the barrier to backporting and inclusion in distribution kernels. The patch was reported as closing a syzbot KASAN report and explicitly references the commit that originally added the USB adapter driver.

Scope, impact and exploitability​

What the CVE record and trackers say​

Multiple vulnerability trackers and vendor security pages summarize the issue identically: a use‑after‑free in the MOST USB driver’s disconnect path (hdm_disconnect) that can be triggered during device removal and that was detected by KASAN via syzbot. The general classification across trackers places this as a local kernel robustness flaw: it can cause crashes, kernel oopses, and denial‑of‑service; some trackers mark the severity as high because a kernel UAF can lead to severe availability consequences and — in certain circumstances and with additional primitives — memory corruption could escalate further.

Real‑world attack model​

  • Attack vector: local; an attacker (or untrusted process) able to cause USB attach/detach or simulate disconnect conditions — including through virtualized passthrough — can exercise the vulnerable path.
  • Privilege: low for local attack scenarios where untrusted USB devices can be attached; exploitation does not require code execution before triggering the bug, but the attacker generally needs the ability to cause device disconnect events.
  • Complexity: low to moderate — the crash is reliably triggered by the refcount ordering exposed by automated testers; converting a UAF to reliable code execution would require additional memory manipulation primitives and platform-specific work.
  • Primary impact: availability (kernel oops, panic, or driver instability).
  • Secondary impact: theoretical memory corruption escalation remains a possibility in skilled hands but is not demonstrated in public proof‑of‑concepts as of the patch publication.

Who is affected​

Any Linux kernel build that includes the vulnerable commit range in the MOST USB adapter code was potentially exposed until the fix was applied. Because the MOST USB driver lives in mainline kernel trees and is propagated into numerous distribution kernels, exposure depends on whether a given distribution or vendor kernel package contains the upstream fix or a backport. Embedded and vendor kernels (for example, appliance images and automotive stacks that use MOST devices) are the highest‑risk category because those vendors often maintain extended or forked kernel trees and may patch on their own cadence. Enterprise distribution kernels (Debian, SUSE, Ubuntu, Red Hat derivatives) tend to publish security advisories and backport fixes quickly; operators should verify vendor advisories for mapping to package versions.

Detection, hunting and validation​

How the bug surfaced in the wild​

The immediate evidence for the defect came from automated testing: syzbot generated a kernel trace that KASAN flagged as a slab‑use‑after‑free in hdm_disconnect. The stack trace illustrated a read of freed memory and made clear the race between device_unregister → release_mdev and subsequent kfree calls in the disconnect path. That report formed the basis of the upstream bug report and the recommended patch.

What to look for in logs and telemetry​

  • Kernel KASAN output or oops traces mentioning hdm_disconnect or most_usb.
  • dmesg entries showing: “BUG: KASAN: slab‑use‑after‑free in hdm_disconnect” or call traces that include device_unregister, release_mdev, or the MOST USB driver symbols.
  • Repeated USB disconnect/reconnect churn correlated with kernel warnings or oops conditions.
  • For environments with thorough kernel logging, search for stack traces that contain the MOST driver symbols and for messages emitted by device core release functions. Use SIEM rules to scan aggregated kernel logs for KASAN and oops patterns. Operational guidance for device‑triggered kernel robustness issues suggests using the kernel log as primary telemetry and correlating device attachment timelines with oops occurrences.

Testing to validate the fix​

  • Install a kernel package that includes the upstream commit or backport.
  • Reboot hosts into the patched kernel.
  • Exercise representative USB‑attached MOST devices: attach and detach them repeatedly under stress to reproduce the prior conditions.
  • Monitor dmesg / journalctl for the absence of the previous KASAN/oops traces.
  • For embedded or vendor kernels, request vendor test cases to replicate disconnect paths and validate driver behavior.

Remediation and operational playbook​

Immediate steps (highest priority)​

  • Patch: Install a kernel that contains the upstream fix or a vendor backport. Kernel fixes require reboot to take effect — schedule accordingly. Stable branch backports were prepared and published for multiple kernel series; operators should match package changelogs to the stable commit IDs shown in kernel patch announcements.
  • Reboot: Reboot into the patched kernel during a maintenance window after validation testing.
  • Validate: Run representative attach/detach tests for relevant hardware to confirm the issue no longer appears in kernel logs.

Compensating controls while patching is pending​

  • Restrict USB attachment: Enforce port locking, device allowlists, or udev rules to prevent untrusted device attachments on critical hosts.
  • Disable USB passthrough in VMs: For virtualization hosts, disable untrusted USB passthrough until kernels are patched.
  • Limit device access: For systems that do not require MOST devices, ensure the kernel module is blacklisted or not loaded.
  • Increase kernel telemetry retention: Retain kernel logs for longer to facilitate post‑incident analysis and incident hunting.
These mitigations minimize the likelihood that an untrusted actor can reproduce the disconnect order that triggers the UAF while the kernel remains unpatched. Operational playbooks used for similar kernel robustness CVEs emphasize inventory, pilot testing, and staged rollouts — exactly the same pattern applies here.

Why this matters: the broader lesson in kernel device management​

This fix is a textbook example of three enduring kernel development truths:
  • Small ordering mistakes around reference counts and resource frees are a recurring source of UAF and double‑free bugs in kernel drivers.
  • The canonical remedy is to centralize object destruction in their release callbacks so that each object’s resources are freed exactly once and under a well‑defined lifetime boundary.
  • Automated fuzzing systems and KASAN dramatically lower the bar to discovery for such race‑condition defects; the kernel community’s response model — small, focused patches and timely stable backports — minimizes operational exposure across many distribution kernels.
The MOST USB fix is an example of a low‑risk, high‑value repair: it eliminates a crash path without changing normal driver behavior and it’s straightforward to backport.

Practical checklist for admins and integrators​

  • Inventory hosts that accept USB attachments (servers with local users, developer machines, virtualization hosts with passthrough).
  • Check current kernel package changelogs for inclusion of the stable commit that fixes hdm_disconnect; vendors typically list backported commit IDs.
  • For each affected host:
  • Test the updated kernel in a small pilot group with representative MOST devices.
  • Deploy to production in phases, monitoring kernel logs and device functionality.
  • If immediate patching is impossible, apply mitigations: disable USB passthrough, enforce device allowlists, or block untrusted USB use.
  • For embedded or vendor kernels, contact the supplier for firmware/kernel update schedules and request confirmation that the release includes the upstream fix.
  • Retain kernel logs and KASAN traces for forensic follow‑up if any oopses persist after patching.

Critical analysis: strengths, residual risks, and verification​

Strengths of the upstream response​

  • The patch is minimal and surgical, which reduces regression risk and makes backporting feasible.
  • The fix addresses the root cause — resource lifetime — rather than adding superficial guards that might mask the underlying problem.
  • The change was pushed through the standard review and stable backport process and explicitly references the syzbot report that drove discovery, demonstrating a reproducible, testable workflow from discovery to remediation.

Residual risks and caveats​

  • Distribution and vendor lag: Embedded devices, vendor kernels and appliances can remain vulnerable for long periods if their maintainers do not apply the upstream commit.
  • Attack surface: The vulnerability is local and requires device attach/detach capabilities; in many production datacenter environments this is a low‑probability vector. However, virtualization hosting or developer workstations that accept arbitrary USB devices are higher risk.
  • Escalation potential: While the publicly documented outcome is availability (DoS), UAFs in kernel space are intrinsically more serious than userland faults. Converting a UAF to a reliable privilege escalation requires more primitives; there is no public PoC demonstrating remote or unauthenticated exploitation for this CVE at the time of the patch. Treat claims of arbitrary code execution as unverified unless an authoritative exploit is published.

Verification steps recommended for security teams​

  • Cross‑check distribution kernel changelogs and vendor advisories to confirm the presence of the upstream commit IDs referenced in the patch announcements.
  • Reproduce the syzbot test case where feasible in a controlled lab to confirm the KASAN trace no longer appears under the patched kernel.
  • For vendor devices, request explicit confirmation that appliance firmware images include the backported change.
If verification fails or a vendor cannot confirm, escalate to the vendor’s security/engineering channel and isolate the affected hardware from high‑value networks until a fix is delivered.

Conclusion​

CVE‑2025‑40223 is a concise example of kernel engineering best practice: an automated tester (syzbot) exposed a race that could turn device refcount ordering into a KASAN‑flagged use‑after‑free; maintainers responded with a targeted rework that centralizes free operations in release_mdev, removes redundant put_device calls, and backported the fix into stable kernel series. The fix eliminates the immediate UAF and stabilizes the MOST USB disconnect path without changing normal behavior, but operators must still act: apply patched kernels, validate on representative hardware, and mitigate exposure where patching is delayed. For environments that accept untrusted USB devices or that use vendor kernels with long maintenance cycles, prioritizing this remediation is prudent because kernel UAFs carry outsized operational risk even when they appear to be simple robustness issues.
Source: MSRC Security Update Guide - Microsoft Security Response Center
 

Back
Top