From: Florian Fainelli Date: Wed, 26 Apr 2017 00:56:12 +0000 (-0700) Subject: usb: udc: core: Error if req->buf is either from vmalloc or stack X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=614536dac7f33c64a58fab4767a325d52572a7d1;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git usb: udc: core: Error if req->buf is either from vmalloc or stack Check that req->buf is a valid DMA capable address, produce a warning and return an error if it's either coming from vmalloc space or is an on stack buffer. Signed-off-by: Florian Fainelli Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index efce68e9a8e0..a03aec574f64 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -798,6 +799,14 @@ int usb_gadget_map_request_by_dev(struct device *dev, req->num_mapped_sgs = mapped; } else { + if (is_vmalloc_addr(req->buf)) { + dev_err(dev, "buffer is not dma capable\n"); + return -EFAULT; + } else if (object_is_on_stack(req->buf)) { + dev_err(dev, "buffer is on stack\n"); + return -EFAULT; + } + req->dma = dma_map_single(dev, req->buf, req->length, is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);