* [Linux-kernel-mentees] [PATCH v3] Media: Radio: Change devm_k*alloc to k*alloc
@ 2019-06-18 5:42 ` Luke Nowakowski-Krijger
0 siblings, 0 replies; 4+ messages in thread
From: lnowakow @ 2019-06-18 5:42 UTC (permalink / raw)
Change devm_k*alloc to k*alloc to manually allocate memory. Memory is freed in v4l2.release callback which now calls raremono_device_release to free up the appropriate memory, just like in radio-shark driver.
This patch aims to fix the use-after-free read described in
https://syzkaller.appspot.com/bug?extid=a4387f5b6b799f6becbf
Signed-off-by: Luke Nowakowski-Krijger <lnowakow at eng.ucsd.edu>
---
diff --git a/drivers/media/radio/radio-raremono.c b/drivers/media/radio/radio-raremono.c
index 5e782b3c2fa9..b467ad7fdd21 100644
--- a/drivers/media/radio/radio-raremono.c
+++ b/drivers/media/radio/radio-raremono.c
@@ -271,6 +271,15 @@ static int vidioc_g_frequency(struct file *file, void *priv,
return 0;
}
+static void raremono_device_release(struct v4l2_device *v4l2_dev)
+{
+ struct raremono_device *radio = to_raremono_dev(v4l2_dev);
+
+ kfree(radio->buffer);
+ kfree(radio);
+}
+
+
/* File system interface */
static const struct v4l2_file_operations usb_raremono_fops = {
.owner = THIS_MODULE,
@@ -295,12 +304,15 @@ static int usb_raremono_probe(struct usb_interface *intf,
struct raremono_device *radio;
int retval = 0;
- radio = devm_kzalloc(&intf->dev, sizeof(struct raremono_device), GFP_KERNEL);
- if (radio)
- radio->buffer = devm_kmalloc(&intf->dev, BUFFER_LENGTH, GFP_KERNEL);
-
- if (!radio || !radio->buffer)
+ radio = kzalloc(sizeof(struct raremono_device), GFP_KERNEL);
+ if (!radio)
return -ENOMEM;
+
+ radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
+ if (!radio->buffer) {
+ kfree(radio);
+ return -ENOMEM;
+ }
radio->usbdev = interface_to_usbdev(intf);
radio->intf = intf;
@@ -324,7 +336,9 @@ static int usb_raremono_probe(struct usb_interface *intf,
if (retval != 3 ||
(get_unaligned_be16(&radio->buffer[1]) & 0xfff) == 0x0242) {
dev_info(&intf->dev, "this is not Thanko's Raremono.\n");
- return -ENODEV;
+
+ retval = -ENODEV;
+ goto free_mem;
}
dev_info(&intf->dev, "Thanko's Raremono connected: (%04X:%04X)\n",
@@ -333,7 +347,7 @@ static int usb_raremono_probe(struct usb_interface *intf,
retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
if (retval < 0) {
dev_err(&intf->dev, "couldn't register v4l2_device\n");
- return retval;
+ goto free_mem;
}
mutex_init(&radio->lock);
@@ -345,6 +359,8 @@ static int usb_raremono_probe(struct usb_interface *intf,
radio->vdev.ioctl_ops = &usb_raremono_ioctl_ops;
radio->vdev.lock = &radio->lock;
radio->vdev.release = video_device_release_empty;
+
+ radio->v4l2_dev.release = raremono_device_release;
usb_set_intfdata(intf, &radio->v4l2_dev);
@@ -353,13 +369,20 @@ static int usb_raremono_probe(struct usb_interface *intf,
raremono_cmd_main(radio, BAND_FM, 95160);
retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO, -1);
+
if (retval == 0) {
dev_info(&intf->dev, "V4L2 device registered as %s\n",
video_device_node_name(&radio->vdev));
return 0;
}
+
dev_err(&intf->dev, "could not register video device\n");
v4l2_device_unregister(&radio->v4l2_dev);
+
+free_mem:
+ kfree(radio->buffer);
+ kfree(radio);
+
return retval;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Linux-kernel-mentees] [PATCH v3] Media: Radio: Change devm_k*alloc to k*alloc
@ 2019-06-18 5:42 ` Luke Nowakowski-Krijger
0 siblings, 0 replies; 4+ messages in thread
From: Luke Nowakowski-Krijger @ 2019-06-18 5:42 UTC (permalink / raw)
Change devm_k*alloc to k*alloc to manually allocate memory. Memory is freed in v4l2.release callback which now calls raremono_device_release to free up the appropriate memory, just like in radio-shark driver.
This patch aims to fix the use-after-free read described in
https://syzkaller.appspot.com/bug?extid=a4387f5b6b799f6becbf
Signed-off-by: Luke Nowakowski-Krijger <lnowakow at eng.ucsd.edu>
---
diff --git a/drivers/media/radio/radio-raremono.c b/drivers/media/radio/radio-raremono.c
index 5e782b3c2fa9..b467ad7fdd21 100644
--- a/drivers/media/radio/radio-raremono.c
+++ b/drivers/media/radio/radio-raremono.c
@@ -271,6 +271,15 @@ static int vidioc_g_frequency(struct file *file, void *priv,
return 0;
}
+static void raremono_device_release(struct v4l2_device *v4l2_dev)
+{
+ struct raremono_device *radio = to_raremono_dev(v4l2_dev);
+
+ kfree(radio->buffer);
+ kfree(radio);
+}
+
+
/* File system interface */
static const struct v4l2_file_operations usb_raremono_fops = {
.owner = THIS_MODULE,
@@ -295,12 +304,15 @@ static int usb_raremono_probe(struct usb_interface *intf,
struct raremono_device *radio;
int retval = 0;
- radio = devm_kzalloc(&intf->dev, sizeof(struct raremono_device), GFP_KERNEL);
- if (radio)
- radio->buffer = devm_kmalloc(&intf->dev, BUFFER_LENGTH, GFP_KERNEL);
-
- if (!radio || !radio->buffer)
+ radio = kzalloc(sizeof(struct raremono_device), GFP_KERNEL);
+ if (!radio)
return -ENOMEM;
+
+ radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
+ if (!radio->buffer) {
+ kfree(radio);
+ return -ENOMEM;
+ }
radio->usbdev = interface_to_usbdev(intf);
radio->intf = intf;
@@ -324,7 +336,9 @@ static int usb_raremono_probe(struct usb_interface *intf,
if (retval != 3 ||
(get_unaligned_be16(&radio->buffer[1]) & 0xfff) == 0x0242) {
dev_info(&intf->dev, "this is not Thanko's Raremono.\n");
- return -ENODEV;
+
+ retval = -ENODEV;
+ goto free_mem;
}
dev_info(&intf->dev, "Thanko's Raremono connected: (%04X:%04X)\n",
@@ -333,7 +347,7 @@ static int usb_raremono_probe(struct usb_interface *intf,
retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
if (retval < 0) {
dev_err(&intf->dev, "couldn't register v4l2_device\n");
- return retval;
+ goto free_mem;
}
mutex_init(&radio->lock);
@@ -345,6 +359,8 @@ static int usb_raremono_probe(struct usb_interface *intf,
radio->vdev.ioctl_ops = &usb_raremono_ioctl_ops;
radio->vdev.lock = &radio->lock;
radio->vdev.release = video_device_release_empty;
+
+ radio->v4l2_dev.release = raremono_device_release;
usb_set_intfdata(intf, &radio->v4l2_dev);
@@ -353,13 +369,20 @@ static int usb_raremono_probe(struct usb_interface *intf,
raremono_cmd_main(radio, BAND_FM, 95160);
retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO, -1);
+
if (retval == 0) {
dev_info(&intf->dev, "V4L2 device registered as %s\n",
video_device_node_name(&radio->vdev));
return 0;
}
+
dev_err(&intf->dev, "could not register video device\n");
v4l2_device_unregister(&radio->v4l2_dev);
+
+free_mem:
+ kfree(radio->buffer);
+ kfree(radio);
+
return retval;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Linux-kernel-mentees] [PATCH v3] Media: Radio: Change devm_k*alloc to k*alloc
@ 2019-06-18 6:10 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: gregkh @ 2019-06-18 6:10 UTC (permalink / raw)
On Mon, Jun 17, 2019 at 10:42:49PM -0700, Luke Nowakowski-Krijger wrote:
> Change devm_k*alloc to k*alloc to manually allocate memory. Memory is freed in v4l2.release callback which now calls raremono_device_release to free up the appropriate memory, just like in radio-shark driver.
Please properly wrap your changelog text at 72 columns and do not add
trailing whitespace.
>
> This patch aims to fix the use-after-free read described in
> https://syzkaller.appspot.com/bug?extid=a4387f5b6b799f6becbf
Does it? Did you submit it to syzkaller and get any results?
There is a proper way to credit the tool as well, please do that.
>
> Signed-off-by: Luke Nowakowski-Krijger <lnowakow at eng.ucsd.edu>
> ---
> diff --git a/drivers/media/radio/radio-raremono.c b/drivers/media/radio/radio-raremono.c
> index 5e782b3c2fa9..b467ad7fdd21 100644
> --- a/drivers/media/radio/radio-raremono.c
> +++ b/drivers/media/radio/radio-raremono.c
> @@ -271,6 +271,15 @@ static int vidioc_g_frequency(struct file *file, void *priv,
> return 0;
> }
>
> +static void raremono_device_release(struct v4l2_device *v4l2_dev)
> +{
> + struct raremono_device *radio = to_raremono_dev(v4l2_dev);
> +
Trailing whitespace :(
Did you run your patch through checkpatch?
> + kfree(radio->buffer);
> + kfree(radio);
> +}
> +
> +
> /* File system interface */
> static const struct v4l2_file_operations usb_raremono_fops = {
> .owner = THIS_MODULE,
> @@ -295,12 +304,15 @@ static int usb_raremono_probe(struct usb_interface *intf,
> struct raremono_device *radio;
> int retval = 0;
>
> - radio = devm_kzalloc(&intf->dev, sizeof(struct raremono_device), GFP_KERNEL);
> - if (radio)
> - radio->buffer = devm_kmalloc(&intf->dev, BUFFER_LENGTH, GFP_KERNEL);
> -
> - if (!radio || !radio->buffer)
> + radio = kzalloc(sizeof(struct raremono_device), GFP_KERNEL);
> + if (!radio)
> return -ENOMEM;
> +
Trailing whitespace :(
> + radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
> + if (!radio->buffer) {
> + kfree(radio);
> + return -ENOMEM;
> + }
>
> radio->usbdev = interface_to_usbdev(intf);
> radio->intf = intf;
> @@ -324,7 +336,9 @@ static int usb_raremono_probe(struct usb_interface *intf,
> if (retval != 3 ||
> (get_unaligned_be16(&radio->buffer[1]) & 0xfff) == 0x0242) {
> dev_info(&intf->dev, "this is not Thanko's Raremono.\n");
> - return -ENODEV;
> +
More trailing whitespace.
Please fix your editor to show this type of thing in bright red so you
know not to include it. It's all over this patch.
thanks.
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Linux-kernel-mentees] [PATCH v3] Media: Radio: Change devm_k*alloc to k*alloc
@ 2019-06-18 6:10 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2019-06-18 6:10 UTC (permalink / raw)
On Mon, Jun 17, 2019 at 10:42:49PM -0700, Luke Nowakowski-Krijger wrote:
> Change devm_k*alloc to k*alloc to manually allocate memory. Memory is freed in v4l2.release callback which now calls raremono_device_release to free up the appropriate memory, just like in radio-shark driver.
Please properly wrap your changelog text at 72 columns and do not add
trailing whitespace.
>
> This patch aims to fix the use-after-free read described in
> https://syzkaller.appspot.com/bug?extid=a4387f5b6b799f6becbf
Does it? Did you submit it to syzkaller and get any results?
There is a proper way to credit the tool as well, please do that.
>
> Signed-off-by: Luke Nowakowski-Krijger <lnowakow at eng.ucsd.edu>
> ---
> diff --git a/drivers/media/radio/radio-raremono.c b/drivers/media/radio/radio-raremono.c
> index 5e782b3c2fa9..b467ad7fdd21 100644
> --- a/drivers/media/radio/radio-raremono.c
> +++ b/drivers/media/radio/radio-raremono.c
> @@ -271,6 +271,15 @@ static int vidioc_g_frequency(struct file *file, void *priv,
> return 0;
> }
>
> +static void raremono_device_release(struct v4l2_device *v4l2_dev)
> +{
> + struct raremono_device *radio = to_raremono_dev(v4l2_dev);
> +
Trailing whitespace :(
Did you run your patch through checkpatch?
> + kfree(radio->buffer);
> + kfree(radio);
> +}
> +
> +
> /* File system interface */
> static const struct v4l2_file_operations usb_raremono_fops = {
> .owner = THIS_MODULE,
> @@ -295,12 +304,15 @@ static int usb_raremono_probe(struct usb_interface *intf,
> struct raremono_device *radio;
> int retval = 0;
>
> - radio = devm_kzalloc(&intf->dev, sizeof(struct raremono_device), GFP_KERNEL);
> - if (radio)
> - radio->buffer = devm_kmalloc(&intf->dev, BUFFER_LENGTH, GFP_KERNEL);
> -
> - if (!radio || !radio->buffer)
> + radio = kzalloc(sizeof(struct raremono_device), GFP_KERNEL);
> + if (!radio)
> return -ENOMEM;
> +
Trailing whitespace :(
> + radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
> + if (!radio->buffer) {
> + kfree(radio);
> + return -ENOMEM;
> + }
>
> radio->usbdev = interface_to_usbdev(intf);
> radio->intf = intf;
> @@ -324,7 +336,9 @@ static int usb_raremono_probe(struct usb_interface *intf,
> if (retval != 3 ||
> (get_unaligned_be16(&radio->buffer[1]) & 0xfff) == 0x0242) {
> dev_info(&intf->dev, "this is not Thanko's Raremono.\n");
> - return -ENODEV;
> +
More trailing whitespace.
Please fix your editor to show this type of thing in bright red so you
know not to include it. It's all over this patch.
thanks.
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-06-18 6:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-18 5:42 [Linux-kernel-mentees] [PATCH v3] Media: Radio: Change devm_k*alloc to k*alloc lnowakow
2019-06-18 5:42 ` Luke Nowakowski-Krijger
2019-06-18 6:10 ` gregkh
2019-06-18 6:10 ` Greg KH
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.