From: Florian Fainelli <f.fainelli@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: "Florian Fainelli" <f.fainelli@gmail.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Felipe Balbi" <balbi@kernel.org>,
"Peter Chen" <peter.chen@nxp.com>,
"Roger Quadros" <rogerq@ti.com>,
"Alan Stern" <stern@rowland.harvard.edu>,
"Mathias Nyman" <mathias.nyman@linux.intel.com>,
"Javier Martinez Canillas" <javier@osg.samsung.com>,
"Baoyou Xie" <baoyou.xie@linaro.org>,
"Sekhar Nori" <nsekhar@ti.com>,
"William wu" <wulf@rock-chips.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Chris Bainbridge" <chris.bainbridge@gmail.com>,
"Wolfram Sang" <wsa-dev@sang-engineering.com>,
"Krzysztof Opasiak" <k.opasiak@samsung.com>,
"Felix Hädicke" <felixhaedicke@web.de>,
"Colin Ian King" <colin.king@canonical.com>,
linux-usb@vger.kernel.org (open list:USB SUBSYSTEM),
clemens@ladisch.de, maksim.salau@gmail.com
Subject: [PATCH v3 2/2] usb: udc: core: Error if req->buf is either from vmalloc or stack
Date: Tue, 25 Apr 2017 17:56:12 -0700 [thread overview]
Message-ID: <20170426005612.24850-3-f.fainelli@gmail.com> (raw)
In-Reply-To: <20170426005612.24850-1-f.fainelli@gmail.com>
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 <f.fainelli@gmail.com>
---
drivers/usb/gadget/udc/core.c | 9 +++++++++
1 file changed, 9 insertions(+)
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 <linux/list.h>
#include <linux/err.h>
#include <linux/dma-mapping.h>
+#include <linux/sched/task_stack.h>
#include <linux/workqueue.h>
#include <linux/usb/ch9.h>
@@ -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);
--
2.9.3
next prev parent reply other threads:[~2017-04-26 1:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-26 0:56 [PATCH v3 0/2] usb: Check for DMA capable buffer sanity Florian Fainelli
2017-04-26 0:56 ` [PATCH v3 1/2] usb: core: Check URB setup_packet and transfer_buffer sanity Florian Fainelli
2017-04-26 0:56 ` Florian Fainelli [this message]
2017-05-05 21:08 ` [PATCH v3 0/2] usb: Check for DMA capable buffer sanity Florian Fainelli
2017-05-28 16:03 ` Wolfram Sang
2017-05-31 11:04 ` David Laight
2017-05-31 11:55 ` Vignesh R
2017-05-31 15:50 ` Wolfram Sang
2017-05-31 19:23 ` Wolfram Sang
2017-05-31 11:56 ` Vignesh R
2017-05-31 15:12 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170426005612.24850-3-f.fainelli@gmail.com \
--to=f.fainelli@gmail.com \
--cc=arnd@arndb.de \
--cc=balbi@kernel.org \
--cc=baoyou.xie@linaro.org \
--cc=chris.bainbridge@gmail.com \
--cc=clemens@ladisch.de \
--cc=colin.king@canonical.com \
--cc=felixhaedicke@web.de \
--cc=gregkh@linuxfoundation.org \
--cc=javier@osg.samsung.com \
--cc=k.opasiak@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=maksim.salau@gmail.com \
--cc=mathias.nyman@linux.intel.com \
--cc=nsekhar@ti.com \
--cc=peter.chen@nxp.com \
--cc=rogerq@ti.com \
--cc=stern@rowland.harvard.edu \
--cc=wsa-dev@sang-engineering.com \
--cc=wulf@rock-chips.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome