Skip to contentSkip to conversation

rpmsg: glink: Remove channel decouple from rpdev release

PATCH In review Chris Lew 2 participants 3 messages Oct 9, 2019 – Oct 11, 2019

Subsystems (2)
lore
Share & tools
lore

Chris Lew

author
#0 lore raw

PATCH 1/1 rpmsg: glink: Remove channel decouple from rpdev release

If a channel is being rapidly restarted and the kobj release worker is busy, there is a chance the the rpdev_release function will run after the channel struct itself has been released.

There should not be a need to decouple the channel from rpdev in the rpdev release since that should only happen from the channel close commands.

---
 drivers/rpmsg/qcom_glink_native.c | 2 --
 1 file changed, 2 deletions(-)
drivers/rpmsg/qcom_glink_native.c +0 -2
index 621f1afd4d6b..836a0bd99d11 100644
@@ -1350,9 +1350,7 @@ static const struct rpmsg_endpoint_ops glink_endpoint_ops = {
 static void qcom_glink_rpdev_release(struct device *dev)
 {
 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
-	struct glink_channel *channel = to_glink_channel(rpdev->ept);
 
-	channel->rpdev = NULL;
 	kfree(rpdev);
 }
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

Quoting Chris Lew (2019-10-08 18:33:45)

Quoted 9 lines

If a channel is being rapidly restarted and the kobj release worker is busy, there is a chance the the rpdev_release function will run after the channel struct itself has been released.

There should not be a need to decouple the channel from rpdev in the rpdev release since that should only happen from the channel close commands.

Fixes tag? The whole thing sounds broken and probably is still racy in the face of SMP given that channel->rpdev is tested for "published" or not. Can you describe the race that you're closing more?

author
#2 lore raw
Quoted 9 lines · Stephen Boyd

Quoting Chris Lew (2019-10-08 18:33:45)

Quoted 8 lines

If a channel is being rapidly restarted and the kobj release worker is busy, there is a chance the the rpdev_release function will run after the channel struct itself has been released.

There should not be a need to decouple the channel from rpdev in the rpdev release since that should only happen from the channel close commands.

Quoted 6 lines
Quoted 1 line

Fixes tag? The whole thing sounds broken and probably is still racy in the face of SMP given that channel->rpdev is tested for "published" or not. Can you describe the race that you're closing more?

Thanks Stephen, will add Fixes tag and try to describe the race better.

I agree that the whole thing sounds broken, the glink channel cleanup code has a couple bugs that need to be addressed in a more extensive patch. This patch is more to address the immediate issue of a use-after-free from one of the races.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project