rpmsg: virtio: fix posseble double free
v2 cover rpmsg: virtio: fix posseble double free
There are double free in rpmsg_probe() and rpmsg_virtio_add_ctrl_dev(). In addition, rpmsg_virtio_del_ctrl_dev() didn't use correct function to free the object.
v2:
Use a cover letter to integrate the three patches. Add comments in rpmsg_probe() and rpmsg_virtio_add_ctrl_dev().
Hangyu Hua (2):
rpmsg: virtio: fix possible double free in rpmsg_probe()
rpmsg: virtio: fix possible double free in rpmsg_virtio_add_ctrl_dev()
Arnaud Pouliquen (1):
rpmsg: virtio: Fix the unregistration of the device rpmsg_ctrl
drivers/rpmsg/virtio_rpmsg_bus.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/3 rpmsg: virtio: fix possible double free in rpmsg_probe()
vch will be free in virtio_rpmsg_release_device() when rpmsg_ns_register_device() fails. There is no need to call kfree() again.
Fix this by changing error path from free_vch to free_ctrldev.
--- drivers/rpmsg/virtio_rpmsg_bus.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/rpmsg/virtio_rpmsg_bus.c +2 -3
@@ -973,7 +973,8 @@ static int rpmsg_probe(struct virtio_device *vdev) err =rpmsg_ns_register_device (rpdev_ns);if (err) - goto free_vch; +/* vch will be free in virtio_rpmsg_release_device() */ + goto free_ctrldev; }/*
@@ -997,8 +998,6 @@ static int rpmsg_probe(struct virtio_device *vdev)return 0 ; -free_vch: -kfree (vch); free_ctrldev:rpmsg_virtio_del_ctrl_dev (rpdev_ctrl); free_coherent:
Signature · 1 line
2.25.1
PATCH v2 2/3 rpmsg: virtio: fix possible double free in rpmsg_virtio_add_ctrl_dev()
In reply to Hangyu Huavch will be free in virtio_rpmsg_release_device() when rpmsg_ctrldev_register_device() fails. There is no need to call kfree() again.
--- drivers/rpmsg/virtio_rpmsg_bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rpmsg/virtio_rpmsg_bus.c +1 -1
@@ -851,7 +851,7 @@ static struct rpmsg_device *rpmsg_virtio_add_ctrl_dev(struct virtio_device *vdev err =rpmsg_ctrldev_register_device (rpdev_ctrl);if (err) { -kfree (vch); +/* vch will be free in virtio_rpmsg_release_device() */ return ERR_PTR (err); }
Signature · 1 line
2.25.1
PATCH v2 3/3 rpmsg: virtio: Fix the unregistration of the device rpmsg_ctrl
In reply to Hangyu HuaUnregister the rpmsg_ctrl device instead of just freeing the the virtio_rpmsg_channel structure.
This will properly unregister the device and call virtio_rpmsg_release_device() that frees the structure.
--- drivers/rpmsg/virtio_rpmsg_bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rpmsg/virtio_rpmsg_bus.c +1 -1
@@ -862,7 +862,7 @@ static void rpmsg_virtio_del_ctrl_dev(struct rpmsg_device *rpdev_ctrl) {if (!rpdev_ctrl)return ; -kfree (to_virtio_rpmsg_channel (rpdev_ctrl)); +device_unregister (&rpdev_ctrl->dev); }static int rpmsg_probe (struct virtio_device *vdev)
Signature · 1 line
2.25.1
Mathieu Poirier
maintainerRe: [PATCH v2 3/3] rpmsg: virtio: Fix the unregistration of the device rpmsg_ctrl
Quoted 18 lines · Hangyu Hua
Unregister the
rpmsg_ctrldevice instead of just freeing the thevirtio_rpmsg_channelstructure.
This will properly unregister the device and callvirtio_rpmsg_release_device()that frees the structure.Fixes c486682ae1e2 ("rpmsg: virtio: Register the rpmsg_char device")Signed-off-by Arnaud Pouliquen <[email protected]>Cc Hangyu Hua <[email protected]>Reviewed-by Hangyu Hua <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/rpmsg/virtio_rpmsg_bus.c +0
-0
drivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_virtio_del_ctrl_dev(struct rpmsg_device *rpdev_ctrl) · line 865
Quoted 5 lines
drivers/rpmsg/virtio_rpmsg_bus.c +1
-1@@ -862,7 +862,7 @@ static void rpmsg_virtio_del_ctrl_dev(struct rpmsg_device *rpdev_ctrl) {if (!rpdev_ctrl)return ; -kfree (to_virtio_rpmsg_channel (rpdev_ctrl)); +device_unregister (&rpdev_ctrl->dev);
The author of this patch should have been Arnaud, something I have fixed before applying this set.
Thanks,
Mathieu
Quoted 6 lines
drivers/rpmsg/virtio_rpmsg_bus.c +0
-0}static int rpmsg_probe (struct virtio_device *vdev)Signature · 1 line
2.25.1
Re: [PATCH v2 3/3] rpmsg: virtio: Fix the unregistration of the device rpmsg_ctrl
Quoted 28 lines · Mathieu Poirier
Quoted 18 lines · Hangyu Hua
Unregister the
rpmsg_ctrldevice instead of just freeing the thevirtio_rpmsg_channelstructure.
This will properly unregister the device and callvirtio_rpmsg_release_device()that frees the structure.Fixes c486682ae1e2 ("rpmsg: virtio: Register the rpmsg_char device")Signed-off-by Arnaud Pouliquen <[email protected]>Cc Hangyu Hua <[email protected]>Reviewed-by Hangyu Hua <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/rpmsg/virtio_rpmsg_bus.c +0
-0drivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_virtio_del_ctrl_dev(struct rpmsg_device *rpdev_ctrl) · line 865
Quoted 5 lines
drivers/rpmsg/virtio_rpmsg_bus.c +1
-1@@ -862,7 +862,7 @@ static void rpmsg_virtio_del_ctrl_dev(struct rpmsg_device *rpdev_ctrl) {if (!rpdev_ctrl)return ; -kfree (to_virtio_rpmsg_channel (rpdev_ctrl)); +device_unregister (&rpdev_ctrl->dev);The author of this patch should have been Arnaud, something I have fixed before applying this set.
Quoted 3 lines
Thanks,
Mathieu
I get it. I'm sorry i thought Signed-off-by and a description in cover letter are enough to express. Do i need to do anything else?
Thanks,
Hangyu
Quoted 6 lines
Quoted 6 lines
drivers/rpmsg/virtio_rpmsg_bus.c +0
-0}static int rpmsg_probe (struct virtio_device *vdev)Signature · 1 line
2.25.1
Mathieu Poirier
maintainerRe: [PATCH v2 3/3] rpmsg: virtio: Fix the unregistration of the device rpmsg_ctrl
Quoted 30 lines · Hangyu Hua
Quoted 28 lines · Mathieu Poirier
Quoted 18 lines · Hangyu Hua
Unregister the
rpmsg_ctrldevice instead of just freeing the thevirtio_rpmsg_channelstructure.
This will properly unregister the device and callvirtio_rpmsg_release_device()that frees the structure.Fixes c486682ae1e2 ("rpmsg: virtio: Register the rpmsg_char device")Signed-off-by Arnaud Pouliquen <[email protected]>Cc Hangyu Hua <[email protected]>Reviewed-by Hangyu Hua <[email protected]>--- drivers/rpmsg/virtio_rpmsg_bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/rpmsg/virtio_rpmsg_bus.c +0
-0drivers/rpmsg/virtio_rpmsg_bus.c static void rpmsg_virtio_del_ctrl_dev(struct rpmsg_device *rpdev_ctrl) · line 865
Quoted 5 lines
drivers/rpmsg/virtio_rpmsg_bus.c +1
-1@@ -862,7 +862,7 @@ static void rpmsg_virtio_del_ctrl_dev(struct rpmsg_device *rpdev_ctrl) {if (!rpdev_ctrl)return ; -kfree (to_virtio_rpmsg_channel (rpdev_ctrl)); +device_unregister (&rpdev_ctrl->dev);The author of this patch should have been Arnaud, something I have fixed before applying this set.
Quoted 6 lines
Quoted 3 lines
Thanks,
MathieuI get it. I'm sorry i thought Signed-off-by and a description in cover letter are enough to express. Do i need to do anything else?
I don't.
Quoted 9 lines
Thanks,
HangyuQuoted 6 lines
Quoted 6 lines
drivers/rpmsg/virtio_rpmsg_bus.c +0
-1}static int rpmsg_probe (struct virtio_device *vdev) --2.25.1