media: v4l2-core: set sd->devnode = NULL in v4l2_subdev_release
PATCH v2 1/1 media: v4l2-core: set sd->devnode = NULL in v4l2_subdev_release
The sd->devnode is release after calling this function. Therefore it should be set to NULL so that the subdev won't hold a pointer to a released object. This fixes a reference after free bug in function v4l2_device_unregister_subdev
---
changes since v1: move the line to the funtion v4l2_subdev_release from the funtion v4l2_subdev_release
drivers/media/v4l2-core/v4l2-device.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/v4l2-core/v4l2-device.c +1 -0
@@ -177,6 +177,7 @@ static void v4l2_subdev_release(struct v4l2_subdev *sd) {struct module *owner = !sd->owner_v4l2_dev ? sd->owner :NULL ; + sd->devnode =NULL ;if (sd->internal_ops && sd->internal_ops->release) sd->internal_ops->release (sd);module_put (owner);
Signature · 1 line
2.20.1
Quoted 1 line · Dafna Hirschfeld
The
sd->devnodeis release after calling this
s/release/released
Quoted 5 lines
function. Therefore it should be set to NULL so that the subdev won't hold a pointer to a released object. This fixes a reference after free bug in function
v4l2_device_unregister_subdev
You could mention that this patch fixes a regression, either in the commit description or in the commit title, or both.
I usually like to put the word "Fix" somewhere in the commit title, as a hint to people backporting patches.
Something like "Fix subdev release ...".
Also, see below.
Quoted 13 lines
Signed-off-by Dafna Hirschfeld <[email protected]>---
changes since v1: move the line to the funtionv4l2_subdev_releasefrom the funtionv4l2_subdev_releasedrivers/media/v4l2-core/v4l2-device.c | 1 + 1 file changed, 1 insertion(+)drivers/media/v4l2-core/v4l2-device.c +0
-0
drivers/media/v4l2-core/v4l2-device.c static void v4l2_subdev_release(struct v4l2_subdev *sd) · line 183
Quoted 7 lines
drivers/media/v4l2-core/v4l2-device.c +1
-0@@ -177,6 +177,7 @@ static void v4l2_subdev_release(struct v4l2_subdev *sd) {struct module *owner = !sd->owner_v4l2_dev ? sd->owner :NULL ; + sd->devnode =NULL ;if (sd->internal_ops && sd->internal_ops->release) sd->internal_ops->release (sd);module_put (owner);
The fix looks good. Interestingly, the devnode = NULL used to be here, but then got removed when the internal_ops.release was introduced in commit 0e43734d4c46e156785bb1d2acc5b3c10b7d5dd5.
This means:
Thanks,
Ezequiel