CVE-2024-56631
Severity CVSS v4.0:
Pending analysis
Type:
CWE-416
Use After Free
Publication date:
27/12/2024
Last modified:
11/02/2025
Description
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
scsi: sg: Fix slab-use-after-free read in sg_release()<br />
<br />
Fix a use-after-free bug in sg_release(), detected by syzbot with KASAN:<br />
<br />
BUG: KASAN: slab-use-after-free in lock_release+0x151/0xa30<br />
kernel/locking/lockdep.c:5838<br />
__mutex_unlock_slowpath+0xe2/0x750 kernel/locking/mutex.c:912<br />
sg_release+0x1f4/0x2e0 drivers/scsi/sg.c:407<br />
<br />
In sg_release(), the function kref_put(&sfp->f_ref, sg_remove_sfp) is<br />
called before releasing the open_rel_lock mutex. The kref_put() call may<br />
decrement the reference count of sfp to zero, triggering its cleanup<br />
through sg_remove_sfp(). This cleanup includes scheduling deferred work<br />
via sg_remove_sfp_usercontext(), which ultimately frees sfp.<br />
<br />
After kref_put(), sg_release() continues to unlock open_rel_lock and may<br />
reference sfp or sdp. If sfp has already been freed, this results in a<br />
slab-use-after-free error.<br />
<br />
Move the kref_put(&sfp->f_ref, sg_remove_sfp) call after unlocking the<br />
open_rel_lock mutex. This ensures:<br />
<br />
- No references to sfp or sdp occur after the reference count is<br />
decremented.<br />
<br />
- Cleanup functions such as sg_remove_sfp() and<br />
sg_remove_sfp_usercontext() can safely execute without impacting the<br />
mutex handling in sg_release().<br />
<br />
The fix has been tested and validated by syzbot. This patch closes the<br />
bug reported at the following syzkaller link and ensures proper<br />
sequencing of resource cleanup and mutex operations, eliminating the<br />
risk of use-after-free errors in sg_release().
Impact
Base Score 3.x
7.80
Severity 3.x
HIGH
Vulnerable products and versions
| CPE | From | Up to |
|---|---|---|
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 3.16.85 (including) | 6.6.66 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.7 (including) | 6.12.5 (excluding) |
| cpe:2.3:o:linux:linux_kernel:6.13:rc1:*:*:*:*:*:* |
To consult the complete list of CPE names with products and versions, see this page
References to Advisories, Solutions, and Tools
- https://git.kernel.org/stable/c/198b89dd5a595ee3f96e5ce5c448b0484cd0e53c
- https://git.kernel.org/stable/c/1f5e2f1ca5875728fcf62bc1a054707444ab4960
- https://git.kernel.org/stable/c/275b8347e21ab8193e93223a8394a806e4ba8918
- https://git.kernel.org/stable/c/285ce1f89f8d414e7eecab5ef5118cd512596318
- https://git.kernel.org/stable/c/59b30afa578637169e2819536bb66459fdddc39d
- https://git.kernel.org/stable/c/e19acb1926c4a1f30ee1ec84d8afba2d975bd534
- https://git.kernel.org/stable/c/f10593ad9bc36921f623361c9e3dd96bd52d85ee



