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
devmblkcryptoprofileinit() 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 ufshba's data structure 'struct ufshba::cryptoprofile'. This structure is allocated as part of the underlying ufshcd and therefore Scsihost allocation.
During driver release or during error handling in ufshcdpltfrminit(), this structure is released as part of ufshcddeallochost() 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 ufshba::cryptoprofile'. This causes a use-after-free situation:
Call trace: kfree+0x60/0x2d8 (P) kvfree+0x44/0x60 blkcryptoprofiledestroycallback+0x28/0x70 devmactionrelease+0x1c/0x30 releasenodes+0x6c/0x108 devresreleaseall+0x98/0x100 deviceunbindcleanup+0x20/0x70 reallyprobe+0x218/0x2d0
In other words, the initialisation code flow is:
platform-device probe ufshcdpltfrminit() ufshcdallochost() scsihostalloc() allocation of struct ufshba creation of scsi-host devices devmblkcryptoprofileinit() devm registration of cleanup handler using platform-device
and during error handling of ufshcdpltfrminit() or during driver removal:
ufshcddeallochost() scsihostput() putdevice(scsi-host) release of struct ufshba putdevice(platform-device) crypto cleanup handler
To fix this use-after free, change ufshcdallochost() to register a devres action to automatically cleanup the underlying SCSI device on ufshcd destruction, without requiring explicit calls to ufshcddeallochost(). This way:
the crypto profile and all other ufshba-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 EXPORTSYMBOLGPL(ufshcddeallochost) can be removed fully as it's not needed anymore no future drivers using ufshcdallochost() could ever forget adding the cleanup
Affected Software
Event History
Frequently Asked Questions
What is the severity of CVE-2025-21739?
CVE-2025-21739 has been classified as a moderate severity vulnerability in the Linux kernel.
How do I fix CVE-2025-21739?
To fix CVE-2025-21739, update to the latest patched version of the Linux kernel as provided by your distribution.
What component of the Linux kernel is affected by CVE-2025-21739?
CVE-2025-21739 affects the SCSI UFS core component of the Linux kernel.
What type of vulnerability is CVE-2025-21739?
CVE-2025-21739 is categorized as a use-after-free vulnerability.
What are the potential impacts of exploiting CVE-2025-21739?
Exploitation of CVE-2025-21739 could lead to application crashes or possibly execution of arbitrary code in the context of the kernel.