lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Fri, 14 Feb 2020 12:30:29 +0100
From:   Hans Verkuil <hverkuil@...all.nl>
To:     Laurent Pinchart <laurent.pinchart@...asonboard.com>
Cc:     Dan Carpenter <dan.carpenter@...cle.com>,
        syzbot <syzbot+75287f75e2fedd69d680@...kaller.appspotmail.com>,
        Hillf Danton <hdanton@...a.com>,
        Alan Stern <stern@...land.harvard.edu>,
        Allison Randal <allison@...utok.net>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Souptick Joarder <jrdr.linux@...il.com>, andreyknvl@...gle.com,
        bnvandana@...il.com, linux-kernel@...r.kernel.org,
        linux-media@...r.kernel.org, linux-usb@...r.kernel.org,
        mchehab@...nel.org, syzkaller-bugs@...glegroups.com
Subject: Re: [PATCH] media: usbvision: Fix a use after free in v4l2_release()

On 2/14/20 12:22 PM, Laurent Pinchart wrote:
> Hi Hans,
> 
> On Fri, Feb 14, 2020 at 11:06:36AM +0100, Hans Verkuil wrote:
>> On 1/24/20 3:13 PM, Dan Carpenter wrote:
>>> Syzbot triggered a use after free in v5.5-rc6:
>>>
>>> BUG: KASAN: use-after-free in v4l2_release+0x2f1/0x390 drivers/media/v4l2-core/v4l2-dev.c:459
>>>
>>> Allocated by task 94:
>>>  usbvision_alloc drivers/media/usb/usbvision/usbvision-video.c:1315 [inline]
>>>  usbvision_probe.cold+0x5c5/0x1f21 drivers/media/usb/usbvision/usbvision-video.c:1469
>>>
>>> Freed by task 1913:
>>>  kfree+0xd5/0x300 mm/slub.c:3957
>>>  usbvision_release+0x181/0x1c0 drivers/media/usb/usbvision/usbvision-video.c:1364
>>>  usbvision_radio_close.cold+0x2b/0x74 drivers/media/usb/usbvision/usbvision-video.c:1130
>>>  v4l2_release+0x2e7/0x390 drivers/media/v4l2-core/v4l2-dev.c:455
>>>
>>> The problem is that the v4l2_release() calls usbvision_release() which
>>> frees "usbvision" but v4l2_release() still wants to use
>>> "usbvision->vdev".  One solution is to make this devm_ allocated memory
>>> so the memory isn't freed until later.
>>
>> devm_ allocated memory is freed after disconnect, so I doubt this will help, or at
>> best it will just move the problem elsewhere.
> 
> Yes, devm_*alloc is evil :-( It has spread to many drivers and is used
> incorrectly in most cases.
> 
>> The right approach would be to use the release() callback from struct v4l2_device:
>> that's called when the very last open filehandle is closed.
> 
> Hillf Danton has sent a patch to do so in the "Re: KASAN: use-after-free
> Read in v4l2_release (3)" thread. Have you seen it ?

Ah, that was never mailed to linux-media, so never ended up in patchwork. And
if it ain't in patchwork, then I don't know about it :-)

Hillf, if you want your patch to be merged, then make sure it is CC-ed to
linux-media as well.

Regards,

	Hans

> 
>> But I'm not sure if it is worth the effort. The usbvision driver is a mess and
>> personally I think it should be deprecated.
> 
> I agree.
> 
>>> Reported-by: syzbot+75287f75e2fedd69d680@...kaller.appspotmail.com
>>> Signed-off-by: Dan Carpenter <dan.carpenter@...cle.com>
>>> ---
>>> I copied this idea from a different driver, but I haven't tested it.
>>> I wanted to try the #syz fix command to see if it works.
>>>
>>>  drivers/media/usb/usbvision/usbvision-video.c | 4 +---
>>>  1 file changed, 1 insertion(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/media/usb/usbvision/usbvision-video.c b/drivers/media/usb/usbvision/usbvision-video.c
>>> index 93d36aab824f..07b4763062c4 100644
>>> --- a/drivers/media/usb/usbvision/usbvision-video.c
>>> +++ b/drivers/media/usb/usbvision/usbvision-video.c
>>> @@ -1312,7 +1312,7 @@ static struct usb_usbvision *usbvision_alloc(struct usb_device *dev,
>>>  {
>>>  	struct usb_usbvision *usbvision;
>>>  
>>> -	usbvision = kzalloc(sizeof(*usbvision), GFP_KERNEL);
>>> +	usbvision = devm_kzalloc(&dev->dev, sizeof(*usbvision), GFP_KERNEL);
>>>  	if (!usbvision)
>>>  		return NULL;
>>>  
>>> @@ -1336,7 +1336,6 @@ static struct usb_usbvision *usbvision_alloc(struct usb_device *dev,
>>>  	v4l2_ctrl_handler_free(&usbvision->hdl);
>>>  	v4l2_device_unregister(&usbvision->v4l2_dev);
>>>  err_free:
>>> -	kfree(usbvision);
>>>  	return NULL;
>>>  }
>>>  
>>> @@ -1361,7 +1360,6 @@ static void usbvision_release(struct usb_usbvision *usbvision)
>>>  
>>>  	v4l2_ctrl_handler_free(&usbvision->hdl);
>>>  	v4l2_device_unregister(&usbvision->v4l2_dev);
>>> -	kfree(usbvision);
>>>  
>>>  	PDEBUG(DBG_PROBE, "success");
>>>  }
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ