Skip to main content
Vulnerability Database/CVE-2024-50086

CVE-2024-50086: Linux Kernel Use-After-Free Vulnerability

CVE-2024-50086 is a use-after-free flaw in the Linux Kernel ksmbd module caused by a race condition between SMB2 session logoff and setup. This post explains its technical details, affected versions, and mitigation steps.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2024-50086 Overview

CVE-2024-50086 is a use-after-free vulnerability [CWE-416] in the Linux kernel's ksmbd in-kernel SMB server. The flaw stems from a race condition between SMB2 session logoff and SMB2 session setup handlers. When one thread sets SMB2_SESSION_EXPIRED on a session structure, another thread can continue to reference the freed object, leading to memory corruption. The fix introduces a session_lock around the expiration state change and adds reference counting to the session struct so it is not released while in use.

Critical Impact

A local authenticated attacker can trigger memory corruption in the kernel's SMB server, potentially leading to privilege escalation or kernel denial of service on hosts running ksmbd.

Affected Products

  • Linux kernel branches prior to the stable fix commits
  • Linux kernel 6.12-rc1, 6.12-rc2, 6.12-rc3
  • Debian LTS distributions shipping affected kernels (see Debian LTS advisory)

Discovery Timeline

  • 2024-10-29 - CVE-2024-50086 published to NVD
  • 2026-08-04 - Last updated in NVD database

Technical Details for CVE-2024-50086

Vulnerability Analysis

The ksmbd kernel module implements an SMB3 server inside the Linux kernel. Session objects track authenticated SMB clients and are shared across concurrent request handlers. The vulnerability occurs when an SMB2 LOGOFF request and an SMB2 SESSION_SETUP request operate on the same session identifier concurrently.

The logoff path marks the session as expired and begins teardown. In parallel, the session setup path can still dereference the same session structure after it has been freed by the logoff worker. This produces a classic use-after-free condition in kernel memory.

Successful exploitation requires an authenticated local SMB client that can issue overlapping protocol messages against the kernel server. Because the corrupted object lives in the kernel's slab allocator, attackers who control subsequent allocations can influence kernel memory contents.

Root Cause

The original code lacked synchronization when transitioning session state to SMB2_SESSION_EXPIRED and did not reference-count session structures. A session pointer could therefore be freed by one handler while another handler was still using it. The upstream patches add a session_lock around the state transition and introduce reference counting so freeing is deferred until all users release their references.

Attack Vector

Exploitation requires network reachability to a ksmbd instance and valid SMB credentials, mapped as a local attack vector in the CVSS metrics because of the authentication requirement and timing complexity. The attacker races SMB2 LOGOFF against SMB2 SESSION_SETUP on the same session ID. Winning the race causes continued use of the freed session object. See the kernel patch commit 0f62358 and related stable commits 5511999, 7aa8804, a9839c3, and ee37189 for the applied fix.

No public proof-of-concept code has been released. Describing the race in prose is appropriate because no verified exploit code is available.

Detection Methods for CVE-2024-50086

Indicators of Compromise

  • Kernel oops or BUG: KASAN: use-after-free messages in dmesg referencing ksmbd session functions
  • Unexpected ksmbd worker crashes or kernel panics on hosts exporting SMB shares
  • Repeated, closely spaced SMB2 LOGOFF and SMB2 SESSION_SETUP requests from the same client against the same session ID

Detection Strategies

  • Enable KASAN on test kernels to surface use-after-free conditions in ksmbd during fuzz testing
  • Monitor kernel ring buffer and journald for ksmbd-related warnings, oopses, or stack traces
  • Capture SMB protocol telemetry at the network layer to flag abnormal session-churn patterns against Linux SMB servers

Monitoring Recommendations

  • Audit which Linux hosts load the ksmbd module using lsmod | grep ksmbd across the fleet
  • Alert on process restarts and crash signatures involving ksmbd_server or smb2_sess_setup
  • Correlate authentication failures and session resets originating from a single SMB client to identify race-attempt patterns

How to Mitigate CVE-2024-50086

Immediate Actions Required

  • Update to a Linux kernel version containing the fix commits referenced in the kernel.org stable advisories
  • Unload ksmbd on hosts that do not require in-kernel SMB server functionality: modprobe -r ksmbd
  • Restrict SMB access with host firewalls so only trusted authenticated clients can reach TCP/445

Patch Information

The fix is distributed across multiple stable branches via commits 0f62358, 5511999, 7aa8804, a9839c3, and ee37189. Debian users should apply the fix shipped in the Debian LTS Announcement. Rebuild and reboot into the patched kernel to activate the fix.

Workarounds

  • Disable ksmbd and migrate SMB file sharing to userspace Samba (smbd) until the kernel is patched
  • Blacklist the ksmbd module to prevent automatic loading: add blacklist ksmbd under /etc/modprobe.d/
  • Limit SMB exposure to authenticated management networks only via firewall rules on port 445
bash
# Verify running kernel and remove ksmbd where not required
uname -r
sudo modprobe -r ksmbd
echo 'blacklist ksmbd' | sudo tee /etc/modprobe.d/disable-ksmbd.conf
sudo systemctl disable --now ksmbd.service 2>/dev/null || true

# Restrict SMB access with nftables
sudo nft add rule inet filter input tcp dport 445 ip saddr != 10.0.0.0/24 drop

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.