Skip to content

scsi: ufs: rpmb: Fix bus registration and device lifecycle

Stanley Jhu linux-scsi lkml sashiko-reviews stable 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v3 Latest2 patches 2 repliesIn review

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2scsi: ufs: rpmb: Register and unregister ufs_rpmb_bus_typedrivers/ufs/core/ufs-rpmb.c drivers/ufs/core/ufshcd-priv.h drivers/ufs/core/ufshcd.c+36 -30 replies
2/2scsi: ufs: rpmb: Decouple device lifecycle from devres to avoid UAFdrivers/ufs/core/ufs-rpmb.c+55 -421 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/2] scsi: ufs: rpmb: Fix bus registration and device lifecycle

This series fixes bus registration and device lifecycle defects in the UFS OP-TEE RPMB driver.

Why:
1. ufs_rpmb_bus_type was never registered with bus_register(), causing device_register() in ufs_rpmb_probe() to unconditionally fail with -EINVAL.
2. struct ufs_rpmb_dev embeds struct device but was allocated via devm_kzalloc() tied to hba->dev. On host unbind, devres frees the structure prematurely while external references remain active, causing a Use-After-Free (UAF) Oops.

What:
- Patch 1: Register ufs_rpmb_bus_type during ufshcd_core_init() and unregister it in ufshcd_core_exit(), with stubs for !CONFIG_RPMB.
- Patch 2: Allocate ufs_rpmb with kzalloc_obj() and free it via kfree() in ufs_rpmb_device_release(). Pin the underlying SCSI WLUN via scsi_device_get/put() and unregister in ufs_rpmb_remove().

Differences from v2:
- Drop generic RPMB core changes (sent as a separate patch).
- Reorder patches so bus registration comes first for bisectability.
- Call rpmb_dev_unregister() in ufs_rpmb_remove() to break cyclic refcount.
- Pin underlying SCSI WLUN via scsi_device_get/put().

Tested:
- Verified clean probe, RPMB I/O, and unbind on QEMU ARM64 without UAF.

Stanley Jhu (2):
scsi: ufs: rpmb: Register and unregister ufs_rpmb_bus_type
scsi: ufs: rpmb: Decouple device lifecycle from devres to avoid UAF

 drivers/ufs/core/ufs-rpmb.c    | 107 ++++++++++++++++++++-------------
 drivers/ufs/core/ufshcd-priv.h |  13 +++-
 drivers/ufs/core/ufshcd.c      |  16 ++++-
 3 files changed, 91 insertions(+), 45 deletions(-)
Signature · 1 line
2.55.0.1007.g17ff1f9808-goog