From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Kees Cook <keescook@chromium.org>
Cc: Semmle Security Reports <security-reports@semmle.com>,
linux-kernel@vger.kernel.org, Stephen Boyd <swboyd@chromium.org>,
iommu@lists.linux-foundation.org,
Dan Carpenter <dan.carpenter@oracle.com>,
Jesper Dangaard Brouer <brouer@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Laura Abbott <labbott@redhat.com>,
Robin Murphy <robin.murphy@arm.com>,
Christoph Hellwig <hch@lst.de>,
Allison Randal <allison@lohutok.net>
Subject: Re: [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single()
Date: Sat, 5 Oct 2019 09:26:18 +0200 [thread overview]
Message-ID: <20191005072618.GA930906@kroah.com> (raw)
In-Reply-To: <201910041420.F6E55D29A@keescook>
On Fri, Oct 04, 2019 at 02:28:16PM -0700, Kees Cook wrote:
> As we've seen from USB and other areas, we need to always do runtime
> checks for DMA operating on memory regions that might be remapped. This
> moves the existing checks from USB into dma_map_single(), but leaves
> the slightly heavier checks as they are.
>
> Suggested-by: Laura Abbott <labbott@redhat.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> v2: Only add is_vmalloc_addr()
> v1: https://lore.kernel.org/lkml/201910021341.7819A660@keescook
> ---
> drivers/usb/core/hcd.c | 8 +-------
> include/linux/dma-mapping.h | 7 +++++++
> 2 files changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index f225eaa98ff8..281568d464f9 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -1410,10 +1410,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
> if (hcd->self.uses_pio_for_control)
> return ret;
> if (hcd_uses_dma(hcd)) {
> - if (is_vmalloc_addr(urb->setup_packet)) {
> - WARN_ONCE(1, "setup packet is not dma capable\n");
> - return -EAGAIN;
> - } else if (object_is_on_stack(urb->setup_packet)) {
> + if (object_is_on_stack(urb->setup_packet)) {
> WARN_ONCE(1, "setup packet is on stack\n");
> return -EAGAIN;
> }
> @@ -1479,9 +1476,6 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
> ret = -EAGAIN;
> else
> urb->transfer_flags |= URB_DMA_MAP_PAGE;
> - } else if (is_vmalloc_addr(urb->transfer_buffer)) {
> - WARN_ONCE(1, "transfer buffer not dma capable\n");
> - ret = -EAGAIN;
> } else if (object_is_on_stack(urb->transfer_buffer)) {
> WARN_ONCE(1, "transfer buffer is on stack\n");
> ret = -EAGAIN;
> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
> index 4a1c4fca475a..12dbd07f74f2 100644
> --- a/include/linux/dma-mapping.h
> +++ b/include/linux/dma-mapping.h
> @@ -583,6 +583,13 @@ static inline unsigned long dma_get_merge_boundary(struct device *dev)
> static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
> size_t size, enum dma_data_direction dir, unsigned long attrs)
> {
> + /* DMA must never operate on areas that might be remapped. */
> + if (WARN_ONCE(is_vmalloc_addr(ptr),
> + "%s %s: driver maps %lu bytes from vmalloc area\n",
> + dev ? dev_driver_string(dev) : "unknown driver",
> + dev ? dev_name(dev) : "unknown device", size))
If you use dev_warn() here you get all of that "unknown driver/device"
checking and handling set properly. And it's in the "standard" format
that userspace tools know how to check.
thanks,
greg k-h
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
WARNING: multiple messages have this Message-ID (diff)
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Kees Cook <keescook@chromium.org>
Cc: Robin Murphy <robin.murphy@arm.com>,
Laura Abbott <labbott@redhat.com>,
linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Jesper Dangaard Brouer <brouer@redhat.com>,
Allison Randal <allison@lohutok.net>,
Thomas Gleixner <tglx@linutronix.de>,
Stephen Boyd <swboyd@chromium.org>,
Dan Carpenter <dan.carpenter@oracle.com>,
Semmle Security Reports <security-reports@semmle.com>,
iommu@lists.linux-foundation.org
Subject: Re: [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single()
Date: Sat, 5 Oct 2019 09:26:18 +0200 [thread overview]
Message-ID: <20191005072618.GA930906@kroah.com> (raw)
In-Reply-To: <201910041420.F6E55D29A@keescook>
On Fri, Oct 04, 2019 at 02:28:16PM -0700, Kees Cook wrote:
> As we've seen from USB and other areas, we need to always do runtime
> checks for DMA operating on memory regions that might be remapped. This
> moves the existing checks from USB into dma_map_single(), but leaves
> the slightly heavier checks as they are.
>
> Suggested-by: Laura Abbott <labbott@redhat.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> v2: Only add is_vmalloc_addr()
> v1: https://lore.kernel.org/lkml/201910021341.7819A660@keescook
> ---
> drivers/usb/core/hcd.c | 8 +-------
> include/linux/dma-mapping.h | 7 +++++++
> 2 files changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index f225eaa98ff8..281568d464f9 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -1410,10 +1410,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
> if (hcd->self.uses_pio_for_control)
> return ret;
> if (hcd_uses_dma(hcd)) {
> - if (is_vmalloc_addr(urb->setup_packet)) {
> - WARN_ONCE(1, "setup packet is not dma capable\n");
> - return -EAGAIN;
> - } else if (object_is_on_stack(urb->setup_packet)) {
> + if (object_is_on_stack(urb->setup_packet)) {
> WARN_ONCE(1, "setup packet is on stack\n");
> return -EAGAIN;
> }
> @@ -1479,9 +1476,6 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
> ret = -EAGAIN;
> else
> urb->transfer_flags |= URB_DMA_MAP_PAGE;
> - } else if (is_vmalloc_addr(urb->transfer_buffer)) {
> - WARN_ONCE(1, "transfer buffer not dma capable\n");
> - ret = -EAGAIN;
> } else if (object_is_on_stack(urb->transfer_buffer)) {
> WARN_ONCE(1, "transfer buffer is on stack\n");
> ret = -EAGAIN;
> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
> index 4a1c4fca475a..12dbd07f74f2 100644
> --- a/include/linux/dma-mapping.h
> +++ b/include/linux/dma-mapping.h
> @@ -583,6 +583,13 @@ static inline unsigned long dma_get_merge_boundary(struct device *dev)
> static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
> size_t size, enum dma_data_direction dir, unsigned long attrs)
> {
> + /* DMA must never operate on areas that might be remapped. */
> + if (WARN_ONCE(is_vmalloc_addr(ptr),
> + "%s %s: driver maps %lu bytes from vmalloc area\n",
> + dev ? dev_driver_string(dev) : "unknown driver",
> + dev ? dev_name(dev) : "unknown device", size))
If you use dev_warn() here you get all of that "unknown driver/device"
checking and handling set properly. And it's in the "standard" format
that userspace tools know how to check.
thanks,
greg k-h
next prev parent reply other threads:[~2019-10-05 7:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-04 21:28 [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single() Kees Cook
2019-10-04 21:28 ` Kees Cook
2019-10-04 21:38 ` Florian Fainelli
2019-10-04 21:38 ` Florian Fainelli
2019-10-05 7:26 ` Greg Kroah-Hartman [this message]
2019-10-05 7:26 ` Greg Kroah-Hartman
2019-10-05 8:40 ` Christoph Hellwig
2019-10-05 8:40 ` Christoph Hellwig
2019-10-05 14:53 ` kbuild test robot
2019-10-05 14:53 ` kbuild test robot
2019-10-05 14:53 ` kbuild test robot
2019-10-11 7:20 ` kbuild test robot
2019-10-11 7:20 ` kbuild test robot
2019-10-11 7:20 ` kbuild test robot
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=20191005072618.GA930906@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=allison@lohutok.net \
--cc=brouer@redhat.com \
--cc=dan.carpenter@oracle.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=keescook@chromium.org \
--cc=labbott@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=security-reports@semmle.com \
--cc=swboyd@chromium.org \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.