Re: [PATCH] rnbd-srv: Fix sess_dev use-after-free in process_msg_close()

From: Wentao Liang

Date: Sat Nov 07 2026 - 13:41:07 EST


Hi Haris,

Sorry for the very late reply. Your message arrived when I was already
behind on this thread, and then it sat far longer than it should have.
That is my fault, not a sign that the report was unimportant.

I have now gone through the Sashiko report, and it is right: the patch is
wrong in exactly the way it describes.

process_msg_close() takes a kref with rnbd_get_sess_dev() and then calls
rnbd_srv_destroy_dev_session_sysfs(). That kobject_put() drops the last
kobject reference, so rnbd_srv_sess_dev_release() -> rnbd_destroy_sess_dev()
runs synchronously in the same thread, still under srv_sess->lock. That
function does rnbd_put_sess_dev() and then waits on destroy_comp, but the
reference this thread holds is only dropped after the wait returns. So a
single CLOSE from a client hangs the teardown thread with the session lock
held - I traded the race for a guaranteed deadlock, which is worse than
what I set out to fix.

While checking this against the current tree I also found that the race
itself has meanwhile been fixed upstream:

4912dab88baa ("rnbd-srv: fix use-after-free on two CLOSE messages")

It takes srv_sess->lock first and looks the ID up with xa_load() under it,
so a second teardown of the same ID finds nothing. It is in v7.4-rc1, and
it also covers the force_close() interleaving that my patch was trying to
address. A v2 of my patch would therefore only duplicate work that is
already merged, so please drop this one - there is nothing here for you to
apply.

Thanks for pointing me at the Sashiko report.

Regards,
Wentao