CVE-2024-56631: scsi: sg: Fix slab-use-after-free read in sg_release()

Published Dec 27, 2024
·
Updated

In the Linux kernel, the following vulnerability has been resolved:

scsi: sg: Fix slab-use-after-free read in sgrelease()

Fix a use-after-free bug in sgrelease(), detected by syzbot with KASAN:

BUG: KASAN: slab-use-after-free in lockrelease+0x151/0xa30 kernel/locking/lockdep.c:5838 mutexunlockslowpath+0xe2/0x750 kernel/locking/mutex.c:912 sgrelease+0x1f4/0x2e0 drivers/scsi/sg.c:407

In sgrelease(), the function krefput(&sfp->fref, sgremovesfp) is called before releasing the openrellock mutex. The krefput() call may decrement the reference count of sfp to zero, triggering its cleanup through sgremovesfp(). This cleanup includes scheduling deferred work via sgremovesfpusercontext(), which ultimately frees sfp.

After krefput(), sgrelease() continues to unlock openrellock and may reference sfp or sdp. If sfp has already been freed, this results in a slab-use-after-free error.

Move the krefput(&sfp->fref, sgremovesfp) call after unlocking the openrellock mutex. This ensures:

- No references to sfp or sdp occur after the reference count is decremented.

- Cleanup functions such as sgremovesfp() and sgremovesfpusercontext() can safely execute without impacting the mutex handling in sgrelease().

The fix has been tested and validated by syzbot. This patch closes the bug reported at the following syzkaller link and ensures proper sequencing of resource cleanup and mutex operations, eliminating the risk of use-after-free errors in sgrelease().

Other sources

This CVE was automatically created from a reference found in an email or other text. If you are reading this, then this CVE entry is probably erroneous, since this text should be replaced by the official CVE description automatically.

Launchpad

Affected Software

5 affected componentsFixes available
Linux Linux kernel>=3.16.85<6.6.66
Linux Linux kernel>=6.7<6.12.5
Linux Linux kernel=6.13-rc1
debian/linux<=5.10.223-1
5.10.234-16.1.129-16.1.135-16.12.27-1
debian/linux-6.1
6.1.129-1~deb11u1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade debian/linux to a version that resolves this vulnerability.

    Fixed in 5.10.234-1Fixed in 6.1.129-1Fixed in 6.1.135-1Fixed in 6.12.27-1
  2. Upgrade

    Upgrade debian/linux-6.1 to a version that resolves this vulnerability.

    Fixed in 6.1.129-1~deb11u1
  3. Configuration

    In drivers/scsi/sg.c in sg_release(), move the call to kref_put(&sfp->f_ref, sg_remove_sfp) so it occurs after unlocking the open_rel_lock mutex. This ensures sg_remove_sfp_usercontext() cleanup can run without any use-after-free references to sfp/sdp after the reference count is decremented.

    Linux kernel (scsi: sg) sg_release() cleanup sequencing = kref_put after unlocking open_rel_lock

Event History

Dec 27, 2024
CVE Published
via MITRE·03:02 PM
Data Sourced
via MITRE·03:02 PM
DescriptionSeverity
Data Sourced
via NVD·03:15 PM
RemedyDescriptionSeverityWeaknessAffected Software
Data Sourced
via Red Hat·04:01 PM
DescriptionSeverityAffected Software
Mar 27, 2025
Data Sourced
via Launchpad·06:46 PM
Description
May 14, 2025
Data Sourced
via Ubuntu·06:57 PM
RemedyDescriptionSeverityAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2024-56631?

CVE-2024-56631 has a medium severity rating due to its potential to cause a use-after-free condition in the Linux kernel.

2

How do I fix CVE-2024-56631?

To fix CVE-2024-56631, upgrade your Linux kernel to a version that includes the patch for this vulnerability.

3

Which Linux kernel versions are affected by CVE-2024-56631?

CVE-2024-56631 affects Linux kernel versions from 3.16.85 to 6.6.66 and versions between 6.7 and 6.12.5.

4

What causes the CVE-2024-56631 vulnerability?

CVE-2024-56631 is caused by a use-after-free bug in the sg_release() function in the Linux kernel.

5

Is CVE-2024-56631 detectable by security tools?

Yes, CVE-2024-56631 can be detected by security tools that utilize Kernel Address Sanitizer (KASAN) during their testing processes.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203