CVE-2025-40328: Linux SMB Client UAF Fixed with kref_put_lock

  • Thread Author
Neon circuit-board illustration centered on 'cfid' with locks and a Linux penguin.
A newly assigned CVE, CVE-2025-40328, documents a use-after-free (UAF) in the Linux kernel's SMB client implementation that could lead to memory corruption and instability on systems running affected kernel versions. The bug arises from a narrow race between reference-count manipulation and list locking in the SMB client's cached-file-ID codepath; maintainers fixed it by switching a plain kref_put to kref_put_lock so that the cfid_release callback runs while the cfid_list_lock is held, closing the window that previously allowed a freed object to be re-referenced.

Background​

SMB (Server Message Block) is a network file-sharing protocol widely used for Windows-style file access from Linux clients, among other uses. The Linux kernel's SMB client code manages cached representations of remote directories and file IDs (cfids) to optimize operations and support features such as leases. Reference counting and careful locking are central to ensuring those cached objects remain valid while multiple threads and workqueues access them.
CVE-2025-40328 targets this exact intersection of reference counting and locking. In short, a function named find_or_create_cached_dir could obtain a new reference to a cfid after another path had already caused kref_put to reduce the reference count to zero. If that reduction raced with acquiring the cfid_list_lock inside smb2_close_cached_fid, the cfid could be freed while another thread later holds a reference, producing a use-after-free. The kernel maintainers addressed the defect by replacing the vulnerable kref_put with kref_put_lock, ensuring that cfid_release executes while cfid_list_lock is held.

Why this matters: use-after-free in kernel SMB client​

Use-after-free bugs in kernel space are high-risk because they enable memory corruption in a privileged context. When a kernel object is accessed after it has been freed, the consequences range from kernel panics and denial-of-service to more severe outcomes, including potential arbitrary code execution when exploitation is feasible.
  • Memory corruption in kernel context often gives attackers an elevated surface for privilege escalation or persistent instability.
  • SMB client code runs in a privileged kernel context and is invoked across many operations (file metadata reads, directory enumerations, lease handling), increasing the attack surface for local and possibly network-triggered races.
  • Race bugs are notoriously hard to detect in testing, and they can remain dormant until a specific timing or workload triggers them; the kernel's asynchronous workqueues complicate reasoning about safe object lifetimes.
While there is no public evidence of in-the-wild exploitation tied to CVE-2025-40328 at the time of writing, the underlying class of bug — reference count races leading to UAF — is one that historically has been weaponized in more privileged code paths. Operators should treat it seriously and apply fixes per vendor guidance.

Technical overview: where the race lives​

Anatomy of the vulnerable codepath​

The vulnerability is localized in fs/smb/client/cached_dir.c within the Linux kernel SMB client implementation. The core issue occurs across two interacting functions:
  • find_or_create_cached_dir: looks up or creates a cached directory object (a cfid) and may grab a new reference to that object while other operations are racing on its lifetime.
  • smb2_close_cached_fid: closes a cached file ID; it expects to drop references and manage removal from cfids lists while holding cfid_list_lock.
The problem surfaced when find_or_create_cached_dir could obtain a reference after a kref_put elsewhere had already observed the reference count drop to zero but before smb2_close_cached_fid had acquired cfid_list_lock to perform the list update and call cfid_release. That interleaving allows a freed cfid to be re-referenced or accessed outside of the intended lock protection, producing a classical use-after-free.

The fix: kref_put_lock​

The practical correction is to call kref_put_lock instead of kref_put so that the final kref release path invokes cfid_release while the cfid_list_lock is still held. kref_put_lock ensures that the destructor callback is executed under a specified lock, preventing the race where the object’s refcount reaches zero but another thread grabs a new reference while list state is being updated.
This change closes the narrow window where a cfid could be freed and subsequently accessed; it modifies the reference-drop semantics to synchronize object destruction with the code paths that protect the in-list state. Kernel maintainers applied this fix across stable branches and listed the relevant commits and fixed kernel versions in the CVE announcement.

Affected kernels and timeline​

The Linux kernel CVE announcement and downstream vulnerability databases concur on when the issue was introduced and which kernel branches received fixes:
  • The issue was introduced by a commit in the 6.1 time frame (commit ebe98f1447bbccf8....
  • Fixes were backported to multiple stable branches: the patch appears in kernel stable releases such as 6.6.117, 6.12.58, 6.17.8, and 6.18 with specific commit IDs referenced in the kernel mailing lists and CVE records.
Administrators should assume that any kernel built from a tree that contains the 6.1-introduced change and which predates the fixed stable updates listed above could be affected until patched. Distribution vendors may backport fixes differently; therefore, always rely on your vendor’s security advisory for the canonical status of kernel packages on your platforms.

Distribution handling and backports​

Major distributions typically handle kernel fixes in one of two ways:
  • Shipping an updated kernel package (preferred), which incorporates the stable commit containing the fix.
  • Backporting the individual patch to the distribution’s maintained kernel branch and releasing that as a security update.
The kernel community’s recommendation is to update to the latest stable kernel rather than cherry-picking individual commits. For environments where a full kernel upgrade is not feasible, vendors frequently provide a backported patch in a kernel security update; check your distribution’s security tracker for confirmation.

Exploitability and attacker model​

Not every use-after-free leads directly to remote code execution. Exploitability depends on several factors:
  • Where the code executes: The bug is in the SMB client, which can be invoked by user processes performing network file operations. This suggests a local or remotely-triggered scenario depending on how a victim interacts with an attacker-controlled SMB server or script.
  • Attack surface: If an attacker can coerce a client to access a malicious SMB server or deliver a crafted workload that exercises cached directory operations and lease handling, they might trigger the race condition. However, exploiting timing races reliably at scale is challenging without additional primitives.
  • Privileges required: Exploitation is likely to require the ability to run operations that cause the SMB client to exercise the vulnerable code (for instance, triggering cached-file operations by an unprivileged user). The exact privilege level needed can vary by call path and how system services expose SMB mounts.
Security databases that aggregate CVE metadata may list speculative impact scores, but those assessments are provisional until a public exploit or proof-of-concept appears. At the time of the fix, the emphasis from maintainers and distro security teams is to patch preemptively because UAFs in kernel code have a high potential impact if chained with other weaknesses.

What system administrators should do right now​

  1. Confirm whether systems use the kernel SMB client (CIFS/SMB client stacks) and whether those kernels match the affected ranges.
  2. Check kernel versions and vendor advisories. On a Linux host, run:
    • uname -r
    • Review distribution package changelogs for kernel/security updates
  3. Apply vendor-supplied kernel updates timely. Prefer fully patched kernel packages rather than attempting to cherry-pick patches unless guided by vendor instructions.
  4. If immediate reboot is not possible, plan an outage window to install the updated kernel and reboot systems to complete the remedy. Keep in mind that kernel fixes require running code to be replaced — a reboot is typically necessary to make the patch effective.
  5. For environments that cannot reboot quickly, isolate SMB client usage where feasible and monitor for signs of exploitation (unexpected crashes, KASAN reports if enabled, strange workqueue behavior).

Commands and checks​

  • To quickly inspect the running kernel: uname -r
  • To inspect distro kernel package versions: use your package manager (e.g., apt list --installed | grep linux-image, rpm -qa | grep kernel).
  • Consult your distribution’s security tracker (Ubuntu/Red Hat/SUSE advisories) for CVE-2025-40328 status and package versions that include the fix. If a distro-specific advisory is not yet available, consult the kernel stable commit IDs listed in the Linux CVE announcement.

Detection and monitoring​

There are no public, reliable exploit signatures tied specifically to CVE-2025-40328 at this time. However, administrators can monitor for indicators that may point to attempts to exercise the vulnerable code paths:
  • Kernel oops/panic logs referencing fs/smb/client cached_dir functions, cfid releases, or KASAN output that show use-after-free traces.
  • Unexpected crashes or increased kernel workqueue activity on systems that frequently access remote SMB servers.
  • Unusual or failed SMB client operations that coincide with kernel instability.
Enabling additional kernel logging or KASAN in non-production test environments can help reproduce and detect the failure mode, but KASAN is not suitable for production due to performance overhead.

Developer-level analysis of the fix​

The chosen repair — switching from kref_put to kref_put_lock — is a surgical, semantics-preserving way to bind the destructor invocation to the existing list-protection lock. This approach is preferable to broader changes that might overly serialize the code or introduce contention. Key pros and cons of the fix:
  • Benefits:
    • Minimal code change: The behavior change localizes synchronization semantics to the final release path.
    • Correctness alignment: The fix ties object destruction to the lock that protects list membership and invariants, closing the race window without a heavy rework.
    • Low performance impact: kref_put_lock avoids broad locking in the common case but synchronizes the critical destructor path.
  • Potential downsides and caveats:
    • Locking discipline must be consistent: Introducing kref_put_lock requires ensuring the destructor (cfid_release) does not perform operations that deadlock with other users of cfid_list_lock.
    • Testing surface: Race fixes demand heavy stress and concurrency testing; regression test coverage should include multithreaded workloads that exercise cached directory creation, lease handling, and close paths to avoid regressions or performance regressions under load.
The kernel stable commits for the fix reflect this design choice and were backported to multiple branches to protect long-term support kernels. Developers maintaining third-party or inline SMB client code should adopt the same locking discipline where reference-counted objects and list membership interact.

Practical mitigation strategies beyond patching​

While the single most effective mitigation remains applying the fixed kernel packages and rebooting, organizations with strict availability constraints can employ interim measures:
  • Harden the attack surface:
    • Restrict SMB client access to trusted servers only (network segmentation, firewall rules).
    • For systems mounting remote Windows shares automatically, consider temporarily disabling automounts or requiring explicit manual mounts from trusted administrators.
  • Monitoring and threat hunting:
    • Look for unusual mount activity, unexpected SMB connections, or repeated failures in SMB metadata queries.
    • Instrument kernel logging and gather crash dumps for forensic analysis if anomalies appear.
  • Staged rollouts:
    • Test patched kernels in representative staging environments with heavy SMB workload to validate performance and correctness before mass deployment.
Note that these are stop-gap approaches; none substitute for the definitive fix that a kernel update plus reboot provides.

Wider implications for kernel SMB code and similar races​

This CVE is the latest in a series of SMB-related use-after-free and reference-counting fixes in the kernel over the past year. They underscore broader engineering challenges:
  • Reference counting vs. list membership: Objects protected by both reference counts and linked-list membership require careful coordination between destruction callbacks and locks that govern list invariants.
  • Asynchrony and workqueues: The kernel often defers work via workqueues; those asynchronous paths complicate lifetime reasoning and increase the chance of subtle races.
  • Testing limitations: Concurrency bugs are often discovered through KASAN-enabled fuzzing or stress tests, but those techniques are typically feasible only in development labs, not production operations.
Maintaining robust defensive practices — including code audits, disciplined locking conventions (e.g., using kref_put_lock where appropriate), and thorough concurrency testing — reduces the likelihood of regressions. Vendors and maintainers must continue investing in these areas because the cost of kernel-level memory corruption is very high.

Verifiable claims and places where caution is warranted​

  • Verified claims:
    • The underlying vulnerability description, the code file implicated (fs/smb/client/cached_dir.c), and the chosen fix (switching to kref_put_lock) are documented in the Linux kernel CVE announcement and mirrored vulnerability databases. These are corroborated by kernel stable commit references that maintainers list as the fix points.
    • The kernel versions where fixes were applied (examples: 6.6.117, 6.12.58, 6.17.8, and 6.18) are enumerated in the Linux CVE announcement; distribution-specific adoption may vary.
  • Claims requiring caution:
    • Any statement asserting a confirmed exploit in the wild for CVE-2025-40328 is unverified at this time; no public exploit samples or weaponized code tied to this CVE were found in the referenced security databases during analysis. Treat unverified claims of exploitation skeptically and rely on vendor advisories for confirmed exploitation reports.
Where vendor advisories differ in timing or versioning, prioritize the vendor’s official security advisory for your distribution; distribution maintainers may apply backports or additional mitigations beyond the upstream patch.

Checklist for rapid response (operations-ready)​

  1. Inventory: Identify hosts that run kernel versions based on 6.1-era trees and are likely to use SMB client stacks.
  2. Patch: Apply vendor-supplied kernel/security updates that include the stable commit fixes mentioned in the kernel announcement.
  3. Reboot: Plan and execute reboots to ensure the updated kernel is running.
  4. Verify: Confirm new kernel versions with uname -r and package manager queries; validate that the fix commit appears in the kernel changelog where visible.
  5. Monitor: Increase vigilance for kernel oops/KASAN messages and for SMB client errors for a short period following updates.
  6. Document: Log patch deployment and any anomalous behavior for postmortem and compliance purposes.

Conclusion​

CVE-2025-40328 is a well-scoped but meaningful kernel-level use-after-free in the SMB client that highlights the fragile interplay between reference counting and list locking in asynchronous kernel code. The fix — switching to kref_put_lock so destructor callbacks run under the cfid_list_lock — is technically sound and has been applied to multiple stable kernel branches. System owners should treat the issue as high priority for patching: apply vendor kernels or vendor-provided backports, reboot to activate updates, and monitor systems for signs of instability.
Beyond the immediate remediation, the CVE serves as a reminder for kernel developers and maintainers to keep a conservative, scrutinized approach to reference-count/lock interactions, especially in code paths that serve asynchronous workloads like SMB. Operators should keep their pipelines for kernel updates and testing well-oiled to reduce windows of exposure for similar race-prone defects.
Source: MSRC Security Update Guide - Microsoft Security Response Center
 

Back
Top