Patchwork media: imon: Fix null-ptr-deref in imon_probe

login
register
mail settings
Submitter Arvind Yadav
Date Oct. 9, 2017, 6:14 p.m.
Message ID <71782d84353db85a9fb9e45ac09f1c2b53c5a04a.1507572539.git.arvind.yadav.cs@gmail.com>
Download mbox | patch
Permalink /patch/9994017/
State New
Headers show

Comments

Arvind Yadav - Oct. 9, 2017, 6:14 p.m.
It seems that the return value of usb_ifnum_to_if() can be NULL and
needs to be checked.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
This bug report by Andrey Konovalov usb/media/imon: null-ptr-deref
in imon_probe

 drivers/media/rc/imon.c | 5 +++++
 1 file changed, 5 insertions(+)
Andrey Konovalov - Oct. 10, 2017, 11:26 a.m.
On Mon, Oct 9, 2017 at 8:14 PM, Arvind Yadav <arvind.yadav.cs@gmail.com> wrote:
> It seems that the return value of usb_ifnum_to_if() can be NULL and
> needs to be checked.

Hi Arvind,

Your patch fixes the issue.

Thanks!

Tested-by: Andrey Konovalov <andreyknvl@google.com>

>
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
> This bug report by Andrey Konovalov usb/media/imon: null-ptr-deref
> in imon_probe
>
>  drivers/media/rc/imon.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
> index 7b3f31c..0c46155 100644
> --- a/drivers/media/rc/imon.c
> +++ b/drivers/media/rc/imon.c
> @@ -2517,6 +2517,11 @@ static int imon_probe(struct usb_interface *interface,
>         mutex_lock(&driver_lock);
>
>         first_if = usb_ifnum_to_if(usbdev, 0);
> +       if (!first_if) {
> +               ret = -ENODEV;
> +               goto fail;
> +       }
> +
>         first_if_ctx = usb_get_intfdata(first_if);
>
>         if (ifnum == 0) {
> --
> 2.7.4
>

Patch

diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
index 7b3f31c..0c46155 100644
--- a/drivers/media/rc/imon.c
+++ b/drivers/media/rc/imon.c
@@ -2517,6 +2517,11 @@  static int imon_probe(struct usb_interface *interface,
 	mutex_lock(&driver_lock);
 
 	first_if = usb_ifnum_to_if(usbdev, 0);
+	if (!first_if) {
+		ret = -ENODEV;
+		goto fail;
+	}
+
 	first_if_ctx = usb_get_intfdata(first_if);
 
 	if (ifnum == 0) {