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-56631 Overview
CVE-2024-56631 is a use-after-free vulnerability in the Linux kernel's SCSI generic (sg) driver, specifically in the sg_release() function located in drivers/scsi/sg.c. The flaw was detected by syzbot using Kernel Address Sanitizer (KASAN) and is tracked as [CWE-416]. The issue stems from improper ordering of reference counting and mutex release during file descriptor cleanup. A local authenticated attacker with access to SCSI generic devices can trigger the condition to corrupt kernel memory, potentially leading to privilege escalation or denial of service. The vulnerability affects Linux kernel versions up to and including 6.13-rc1 and has been resolved in multiple stable kernel branches.
Critical Impact
A local attacker can trigger a slab-use-after-free read in kernel memory through the SCSI generic driver, risking kernel compromise, privilege escalation, or system crash.
Affected Products
- Linux kernel versions prior to the patched stable releases
- Linux kernel 6.13-rc1
- Downstream distributions including Debian LTS and Siemens industrial products referenced in advisories SSA-019113, SSA-265688, and SSA-457936
Discovery Timeline
- 2024-12-27 - CVE-2024-56631 published to the National Vulnerability Database
- 2026-10-15 - Last updated in NVD database
Technical Details for CVE-2024-56631
Vulnerability Analysis
The vulnerability resides in sg_release(), the release handler invoked when a process closes an open file descriptor on a SCSI generic device node. The function calls kref_put(&sfp->f_ref, sg_remove_sfp) before unlocking the open_rel_lock mutex. When kref_put() drops the reference count to zero, it triggers sg_remove_sfp(), which schedules deferred cleanup through sg_remove_sfp_usercontext(). That deferred work ultimately frees the sfp structure. After the kref_put() call returns, sg_release() still holds and must unlock open_rel_lock, and may dereference the already freed sfp or sdp objects. KASAN captured this condition as a slab-use-after-free in lock_release+0x151/0xa30 originating from __mutex_unlock_slowpath within sg_release. The fix moves the kref_put() call to occur after the mutex release, ensuring no stale references are accessed during cleanup.
Root Cause
The root cause is incorrect ordering of resource lifetime management and lock release. Decrementing the reference count before unlocking allowed cleanup paths to free memory still referenced by the enclosing function, violating object lifetime invariants expected by the mutex subsystem.
Attack Vector
Exploitation requires local access and the ability to open and close a SCSI generic device file (/dev/sg*). An attacker able to race file descriptor close operations against concurrent references can force the use-after-free condition. Technical details are available in the upstream commits linked under Kernel Git Change Log Entry.
// No verified proof-of-concept code is published for this issue.
// The vulnerability was reproduced by syzkaller/syzbot under KASAN instrumentation.
// See the upstream patch for the corrected code path in drivers/scsi/sg.c.
Detection Methods for CVE-2024-56631
Indicators of Compromise
- KASAN reports in dmesg or kernel logs matching slab-use-after-free in lock_release with a call trace through __mutex_unlock_slowpath and sg_release
- Unexpected kernel oops, panics, or soft lockups referencing drivers/scsi/sg.c
- Unusual process activity opening and rapidly closing /dev/sg* device nodes
Detection Strategies
- Enable KASAN on test or staging kernels to surface use-after-free conditions in the SCSI generic path
- Audit running kernel versions against patched stable releases listed in the vendor advisories
- Correlate kernel crash telemetry with user accounts holding access to SCSI generic devices
Monitoring Recommendations
- Collect and centralize kernel ring buffer messages for analysis of KASAN and oops signatures
- Monitor for unprivileged processes accessing /dev/sg* devices outside expected administrative workflows
- Alert on repeated kernel crashes or driver faults on hosts exposing SCSI generic interfaces
How to Mitigate CVE-2024-56631
Immediate Actions Required
- Update affected Linux kernels to the patched stable releases referenced in the kernel.org commits 1f5e2f1ca587, 59b30afa5786, and f10593ad9bc3
- Apply distribution updates for Debian LTS per the Debian LTS Announcement
- Review Siemens product exposure using advisories SSA-019113, SSA-265688, and SSA-457936
Patch Information
The upstream fix reorders the cleanup sequence in sg_release() so that kref_put(&sfp->f_ref, sg_remove_sfp) executes only after open_rel_lock has been released. Patched commits are available at Kernel Git Change Log Entry and across multiple stable branches. Rebuild and reboot into the updated kernel to apply the fix.
Workarounds
- Restrict access to /dev/sg* device nodes via file permissions and group membership where SCSI generic access is not required
- Unload or blacklist the sg kernel module on systems that do not require SCSI generic functionality
- Limit local shell access on multi-user systems until patched kernels are deployed
# Example: blacklist the sg module on systems that do not need it
echo "blacklist sg" | sudo tee /etc/modprobe.d/blacklist-sg.conf
sudo rmmod sg 2>/dev/null || true
# Example: restrict access to SCSI generic device nodes
sudo chmod 600 /dev/sg*
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

