CVE-2025-21739: scsi: ufs: core: Fix use-after free in init error and remove paths
In the Linux kernel, the following vulnerability has been resolved:
scsi: ufs: core: Fix use-after free in init error and remove paths
devm_blk_crypto_profile_init() registers a cleanup handler to run when
the associated (platform-) device is being released. For UFS, the
crypto private data and pointers are stored as part of the ufs_hba's
data structure 'struct ufs_hba::crypto_profile'. This structure is
allocated as part of the underlying ufshcd and therefore Scsi_host
allocation.
During driver release or during error handling in ufshcd_pltfrm_init(),
this structure is released as part of ufshcd_dealloc_host() before the
(platform-) device associated with the crypto call above is released.
Once this device is released, the crypto cleanup code will run, using
the just-released 'struct ufs_hba::crypto_profile'. This causes a
use-after-free situation:
Call trace:
kfree+0x60/0x2d8 (P)
kvfree+0x44/0x60
blk_crypto_profile_destroy_callback+0x28/0x70
devm_action_release+0x1c/0x30
release_nodes+0x6c/0x108
devres_release_all+0x98/0x100
device_unbind_cleanup+0x20/0x70
really_probe+0x218/0x2d0
In other words, the initialisation code flow is:
platform-device probe
ufshcd_pltfrm_init()
ufshcd_alloc_host()
scsi_host_alloc()
allocation of struct ufs_hba
creation of scsi-host devices
devm_blk_crypto_profile_init()
devm registration of cleanup handler using platform-device
and during error handling of ufshcd_pltfrm_init() or during driver
removal:
ufshcd_dealloc_host()
scsi_host_put()
put_device(scsi-host)
release of struct ufs_hba
put_device(platform-device)
crypto cleanup handler
To fix this use-after free, change ufshcd_alloc_host() to register a
devres action to automatically cleanup the underlying SCSI device on
ufshcd destruction, without requiring explicit calls to
ufshcd_dealloc_host(). This way:
* the crypto profile and all other ufs_hba-owned resources are
destroyed before SCSI (as they've been registered after)
* a memleak is plugged in tc-dwc-g210-pci.c remove() as a
side-effect
* EXPORT_SYMBOL_GPL(ufshcd_dealloc_host) can be removed fully as
it's not needed anymore
* no future drivers using ufshcd_alloc_host() could ever forget
adding the cleanup
Security readout for executives and security teams
Plain-English summary
CVE-2025-21739 is a Linux kernel use-after-free in the UFS storage driver cleanup path. A local user could potentially exploit memory corruption with high impact to confidentiality, integrity, and availability. The public source bundle identifies a kernel fix, but does not provide evidence of active exploitation.
Executive priority
Treat as high priority for Linux assets where local users, shared workloads, or UFS driver exposure exist. It is not currently source-supported as internet-exploitable or actively exploited, but kernel memory-safety impact justifies timely patching.
Technical view
The flaw occurs when UFS crypto profile cleanup is registered on the platform device while the underlying ufs_hba allocation can be released earlier through SCSI host deallocation. Later device release can dereference freed crypto_profile memory. The fix changes ufshcd_alloc_host() cleanup ordering using devres-managed SCSI device cleanup.
Likely exposure
Exposure is limited to Linux systems running affected kernel versions and using the UFS core driver paths described in the CVE. The CVSS vector requires local privileges, so remote-only exposure is not indicated by the supplied sources.
Exploitation context
The CVE is not listed as KEV in the supplied bundle, and no cited source states active exploitation. The CVSS vector is local, low complexity, low privileges, no user interaction, with high CIA impact.
Researcher notes
Focus validation on init error and driver removal cleanup ordering around devm_blk_crypto_profile_init(), ufshcd_alloc_host(), ufshcd_dealloc_host(), and SCSI host lifetime. Do not assume exploitability beyond the local CVSS scope without additional evidence.
Mitigation direction
Apply vendor kernel updates containing the referenced stable fixes.
Prioritize systems using UFS storage driver functionality.
Check distribution advisories for exact package versions and reboot requirements.
If patching is delayed, reduce local user access on exposed systems.
Monitor kernel and distribution advisories for updated affected-version guidance.
Validation and detection
Inventory Linux kernel versions across affected fleets.
Identify systems with UFS driver usage or relevant hardware paths.
Confirm fixed stable commits or downstream patches are present.
Review kernel package changelogs for CVE-2025-21739 references.
Verify patched systems have booted into the updated kernel.
Generated from the cited source records. This long-tail analysis has not been individually reviewed by a named human.
Potential ATT&CK relevance
Conservative CVE-to-ATT&CK context
These mappings and lookup hints may be relevant to the vulnerability behavior, CWE, affected product, or exposure path. Glexia-inferred context is not an official MITRE, ATT&CK, CWE, or CVE Program mapping.
ATT&CK lookup starting points
Use these exact CWE pages and searches to review the Glexia ATT&CK library from this CVE's weakness and description context.
cwe · low confidence lookup
CWE-416: Exact CWE lookup
Use the exact CWE identifier as the starting point before reviewing related ATT&CK behavior. Open the exact CWE lookup page first, then review the ATT&CK searches from that MITRE weakness context. This is a Glexia lookup hint, not an official ATT&CK mapping.
These fields come from the CVE record and ADP containers, not from Glexia's Take. They preserve time-varying source decisions such as CISA SSVC, KEV status, CVSS metrics, and provider references.
1CVSS vectors
3Timeline events
1ADP providers
7Source links
SSVC decision data
CISA-ADPCISA Coordinator
Timestamp
Version
2.0.3
Exploitation: noneAutomatable: noTechnical Impact: total
CVSS vector scores
1 official score
We collect every scored CVSS vector available in the official CNA and ADP containers. When more than one version is present, the table keeps the source vectors side by side instead of collapsing them into the highest score.
CWE links open Glexia weakness intelligence pages with official CWE context, developer remediation guidance, and related CVE mappings.
CWE-416 · source CWE mapping
Use After Free
Use After Free represents a recurring weakness pattern that can create exploitable paths when design, validation, or implementation controls are missing.