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:   Wed, 20 Sep 2017 14:53:30 +0300
From:   Felipe Balbi <balbi@...nel.org>
To:     Alexey Khoroshilov <khoroshilov@...ras.ru>,
        Jack Pham <jackp@...eaurora.org>
Cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
        ldv-project@...uxtesting.org
Subject: Re: [PATCH] usb: gadget: pch_udc: add checks for dma mapping errors


Hi,

Alexey Khoroshilov <khoroshilov@...ras.ru> writes:
>>> diff --git a/drivers/usb/gadget/udc/pch_udc.c b/drivers/usb/gadget/udc/pch_udc.c
>>> index 84dcbcd756f0..a305f8392082 100644
>>> --- a/drivers/usb/gadget/udc/pch_udc.c
>>> +++ b/drivers/usb/gadget/udc/pch_udc.c
>>> @@ -1767,7 +1767,7 @@ static struct usb_request *pch_udc_alloc_request(struct usb_ep *usbep,
>>>  	req->req.dma = DMA_ADDR_INVALID;
>>>  	req->dma = DMA_ADDR_INVALID;
>>>  	INIT_LIST_HEAD(&req->queue);
>>> -	if (!ep->dev->dma_addr)
>>> +	if (ep->dev->dma_addr != DMA_ADDR_INVALID)
>>>  		return &req->req;
>>>  	/* ep0 in requests are allocated from data pool here */
>>>  	dma_desc = dma_pool_alloc(ep->dev->data_requests, gfp,
>>> @@ -1879,6 +1879,13 @@ static int pch_udc_pcd_queue(struct usb_ep *usbep, struct usb_request *usbreq,
>>>  							  usbreq->length,
>>>  							  DMA_FROM_DEVICE);
>>>  		}
>>> +		if (dma_mapping_error(&dev->pdev->dev, req->dma)) {
>>> +			req->dma = DMA_ADDR_INVALID;
>>> +			retval = -ENOMEM;
>>> +			if ((unsigned long)(usbreq->buf) & 0x03)
>>> +				kfree(req->buf);
>>> +			goto probe_end;
>>> +		}
>>>  		req->dma_mapped = 1;
>>>  	}
>>>  	if (usbreq->length > 0) {
>>> @@ -2961,6 +2968,10 @@ static int init_dma_pools(struct pch_udc_dev *dev)
>>>  	dev->dma_addr = dma_map_single(&dev->pdev->dev, ep0out_buf,
>>>  				       UDC_EP0OUT_BUFF_SIZE * 4,
>>>  				       DMA_FROM_DEVICE);
>>> +	if (dma_mapping_error(&dev->pdev->dev, dev->dma_addr)) {
>>> +		dev->dma_addr = DMA_ADDR_INVALID;
>>> +		return -ENOMEM;
>>> +	}
>> 
>> Wouldn't this driver be better off using the
>> usb_gadget_{map,unmap}_request() functions provided by UDC core.c?
>> dma_mapping_error() is provided for free that way.
>> 
>
> I think so, but it requires quite significant rework of the driver.
> I would not do that without access to hardware.

I'd prefer to see a conversion to the generic helpers.

-- 
balbi

Download attachment "signature.asc" of type "application/pgp-signature" (833 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ