Re: [PATCH v6 1/3] rpmb: core: Guard frame requests and teardown with mutex
From: Alexey Charkov
Date: Thu Nov 12 2026 - 07:43:10 EST
On Thu, Nov 12, 2026 at 4:41 AM Stanley Jhu <stanleyjhu@xxxxxxxxxx> wrote:
>
> rpmb_route_frames() invokes the provider callback without serialization,
> which causes two races:
>
> 1. Concurrent callers on the same rpmb_dev interleave multi-frame
> authenticated sequences on the region's single result register and
> receive each other's responses without error.
> 2. rpmb_dev_unregister() calls device_del() and allows the parent
> provider device to be freed while an in-flight rpmb_route_frames()
> call still dereferences rdev->dev.parent, causing a use-after-free.
>
> Serialize rpmb_route_frames() and rpmb_dev_unregister() with a mutex in
> struct rpmb_dev and clear descr.route_frames on unregistration so new
> requests fail with -ENODEV. Also update the stale kerneldoc note
> advising providers to unregister from their parent release callback,
> which cannot run while the child rpmb_dev still holds a parent
> reference.
>
> Fixes: 1e9046e3a154 ("rpmb: add Replay Protected Memory Block (RPMB) subsystem")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Stanley Jhu <stanleyjhu@xxxxxxxxxx>
> ---
> Jens, if this looks good to you, an Acked-by would let Martin take
> the whole series through the SCSI tree. Patches 2/3 and 3/3 depend
> on this one.
Thanks a lot Stanley!
Works on my Rockchip RK3576 with two UFS 2.2 parts, FORESEE C2G071 and
BIWIN BWU2A0526B128G. Two kthreads issuing GET_WRITE_COUNTER, 2000
requests each, without the series (bus registration restored by other
means):
FORESEE: MISMATCH=3814 ERRORS=0 (plus wrong response types)
BIWIN: MISMATCH=0 ERRORS=0
The BIWIN part keeps the responses apart even though a trace on the
RPMB WLUN shows the SECURITY PROTOCOL OUT/IN pairs interleaving, so
the corruption is device dependent. With the series applied both parts
report MISMATCH=0 ERRORS=0, and the trace shows each OUT/IN pair
dispatched together.
Tested-by: Alexey Charkov <alchark@xxxxxxxxxxx>
Best regards,
Alexey