CVE-2022-47939 Overview
CVE-2022-47939 is a use-after-free vulnerability discovered in the ksmbd (Kernel SMB Direct) module of the Linux kernel versions 5.15 through 5.19 before 5.19.2. The flaw exists in fs/ksmbd/smb2pdu.c and can be triggered when handling SMB2_TREE_DISCONNECT requests, potentially leading to kernel OOPS conditions and remote code execution.
Critical Impact
This use-after-free vulnerability in the Linux kernel's SMB server implementation allows unauthenticated remote attackers to execute arbitrary code at the kernel level, potentially achieving complete system compromise without any user interaction required.
Affected Products
- Linux Kernel versions 5.15 through 5.19 (before 5.19.2)
- Systems with ksmbd module enabled and exposed to the network
- Linux-based file servers using the in-kernel SMB implementation
Discovery Timeline
- December 23, 2022 - CVE-2022-47939 published to NVD
- April 14, 2025 - Last updated in NVD database
Technical Details for CVE-2022-47939
Vulnerability Analysis
The vulnerability exists within the ksmbd module, which provides an in-kernel SMB3 server implementation for the Linux kernel. The flaw is classified as CWE-416 (Use After Free), a memory corruption vulnerability that occurs when a program continues to use a pointer after the memory it references has been freed.
In this specific case, the vulnerability manifests in the smb2_tree_disconnect function within fs/ksmbd/smb2pdu.c. When processing SMB2_TREE_DISCONNECT requests, the code improperly handles the tree connection object, leaving a dangling pointer that can be subsequently accessed. The vulnerability is particularly dangerous because it can be triggered remotely over the network without requiring authentication or user interaction.
The exploitation potential is significant as successful exploitation grants attackers kernel-level code execution privileges on vulnerable systems. This represents the highest level of system access, allowing complete control over the affected machine.
Root Cause
The root cause of CVE-2022-47939 is improper memory management in the SMB2 tree disconnect handling code. After calling ksmbd_tree_conn_disconnect() to terminate the tree connection, the work->tcon pointer was not set to NULL. This left a dangling pointer that could be dereferenced in subsequent operations, leading to use-after-free conditions.
The vulnerable code path did not properly nullify the tree connection reference after disconnection, creating a window where freed memory could be accessed through the stale pointer.
Attack Vector
The attack can be executed remotely over the network against systems running the ksmbd module with SMB file sharing enabled. An attacker needs network access to the SMB server port (typically TCP 445) to exploit this vulnerability. The attack requires:
- Network connectivity to the target SMB server
- Ability to establish an SMB session and tree connection
- Sending a crafted SMB2_TREE_DISCONNECT request to trigger the use-after-free condition
No authentication or special privileges are required, making this vulnerability particularly dangerous for exposed SMB servers.
// Security patch from fs/ksmbd/smb2pdu.c
// Source: https://github.com/torvalds/linux/commit/cf6531d98190fa2cf92a6d8bbc8af0a4740a223c
ksmbd_close_tree_conn_fds(work);
ksmbd_tree_conn_disconnect(sess, tcon);
+ work->tcon = NULL;
return 0;
}
The fix adds a single line (work->tcon = NULL;) that nullifies the tree connection pointer after disconnection, preventing any subsequent use-after-free access to the freed memory.
Detection Methods for CVE-2022-47939
Indicators of Compromise
- Unexpected kernel OOPS or panic events related to ksmbd module operations
- Anomalous SMB2_TREE_DISCONNECT requests in network traffic, especially from unexpected sources
- Kernel log entries showing memory corruption or invalid memory access in ksmbd components
- Suspicious network connections to SMB ports (TCP 445) from untrusted IP addresses
Detection Strategies
- Monitor kernel logs for ksmbd-related crashes, memory errors, or unexpected behavior using dmesg or journald
- Implement network intrusion detection rules to identify abnormal SMB2 protocol sequences and malformed disconnect requests
- Deploy endpoint detection and response (EDR) solutions capable of monitoring kernel module activity and memory access patterns
- Use SentinelOne's Singularity platform to detect exploitation attempts through behavioral analysis of kernel-level anomalies
Monitoring Recommendations
- Enable detailed ksmbd logging and forward logs to a centralized SIEM for correlation and analysis
- Configure network monitoring to alert on high volumes of SMB tree disconnect operations or connections from unusual sources
- Implement file integrity monitoring on systems running ksmbd to detect unauthorized modifications
- Regularly audit systems for kernel version compliance and patch status
How to Mitigate CVE-2022-47939
Immediate Actions Required
- Update the Linux kernel to version 5.19.2 or later immediately on all systems running ksmbd
- If immediate patching is not possible, disable the ksmbd kernel module using modprobe -r ksmbd
- Restrict network access to SMB services using firewall rules to limit exposure to trusted networks only
- Consider migrating to user-space SMB implementations (such as Samba) until patching is complete
Patch Information
The vulnerability was patched in Linux kernel version 5.19.2. The fix is available in commit cf6531d98190fa2cf92a6d8bbc8af0a4740a223c. Organizations should apply this patch through their standard kernel update process. Detailed changelog information is available in the Linux Kernel Changelog 5.19.2.
Additional technical details about the patch can be found in the GitHub Linux Commit Record and the Zero Day Initiative Advisory ZDI-22-1690.
Workarounds
- Disable the ksmbd module entirely if SMB file sharing is not required: echo "blacklist ksmbd" >> /etc/modprobe.d/blacklist.conf
- Block external access to SMB ports (TCP 445, 139) at the network perimeter using firewall rules
- Use Samba as an alternative SMB implementation while awaiting kernel updates
- Implement network segmentation to isolate file servers from untrusted network segments
# Configuration example - Disable ksmbd module and block SMB access
# Blacklist ksmbd module to prevent loading
echo "blacklist ksmbd" >> /etc/modprobe.d/blacklist.conf
# Unload ksmbd if currently loaded
modprobe -r ksmbd
# Block external SMB access using iptables
iptables -A INPUT -p tcp --dport 445 -s ! 10.0.0.0/8 -j DROP
iptables -A INPUT -p tcp --dport 139 -s ! 10.0.0.0/8 -j DROP
# Verify ksmbd module is not loaded
lsmod | grep ksmbd
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

