iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single()
@ 2019-10-04 21:28 Kees Cook
  2019-10-04 21:38 ` Florian Fainelli
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Kees Cook @ 2019-10-04 21:28 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Greg Kroah-Hartman, linux-kernel, Stephen Boyd, iommu,
	Semmle Security Reports, Dan Carpenter, Jesper Dangaard Brouer,
	Thomas Gleixner, Laura Abbott, Christoph Hellwig, Allison Randal

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))
+		return DMA_MAPPING_ERROR;
+
 	debug_dma_map_single(dev, ptr, size);
 	return dma_map_page_attrs(dev, virt_to_page(ptr), offset_in_page(ptr),
 			size, dir, attrs);
-- 
2.17.1


-- 
Kees Cook
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single()
  2019-10-04 21:28 [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single() Kees Cook
@ 2019-10-04 21:38 ` Florian Fainelli
  2019-10-05  7:26 ` Greg Kroah-Hartman
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2019-10-04 21:38 UTC (permalink / raw)
  To: Kees Cook, Robin Murphy
  Cc: Greg Kroah-Hartman, linux-kernel, Stephen Boyd, iommu,
	Semmle Security Reports, Dan Carpenter, Jesper Dangaard Brouer,
	Thomas Gleixner, Laura Abbott, Christoph Hellwig, Allison Randal

On 10/4/19 2:28 PM, 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>

Nearly the same might be necessary for
drivers/usb/gadget/udc/core.c::usb_gadget_map_request_by_dev(). You
might also want to check other subsystems, SPI tries to be fairly smart
about vmalloc'd and kmap'd buffer, some I2C drivers have explicit checks
(they should probably rely on the core), and finally MTD is an area
where this has also been historically dealt with.

> ---
> 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))
> +		return DMA_MAPPING_ERROR;
> +
>  	debug_dma_map_single(dev, ptr, size);
>  	return dma_map_page_attrs(dev, virt_to_page(ptr), offset_in_page(ptr),
>  			size, dir, attrs);
> 


-- 
Florian
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single()
  2019-10-04 21:28 [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single() Kees Cook
  2019-10-04 21:38 ` Florian Fainelli
@ 2019-10-05  7:26 ` Greg Kroah-Hartman
  2019-10-05  8:40 ` Christoph Hellwig
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2019-10-05  7:26 UTC (permalink / raw)
  To: Kees Cook
  Cc: Semmle Security Reports, linux-kernel, Stephen Boyd, iommu,
	Dan Carpenter, Jesper Dangaard Brouer, Thomas Gleixner,
	Laura Abbott, Robin Murphy, Christoph Hellwig, Allison Randal

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single()
  2019-10-04 21:28 [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single() Kees Cook
  2019-10-04 21:38 ` Florian Fainelli
  2019-10-05  7:26 ` Greg Kroah-Hartman
@ 2019-10-05  8:40 ` Christoph Hellwig
  2019-10-05 14:53 ` kbuild test robot
  2019-10-11  7:20 ` kbuild test robot
  4 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2019-10-05  8:40 UTC (permalink / raw)
  To: Kees Cook
  Cc: Greg Kroah-Hartman, linux-kernel, Stephen Boyd, iommu,
	Semmle Security Reports, Dan Carpenter, Jesper Dangaard Brouer,
	Thomas Gleixner, Laura Abbott, Robin Murphy, Christoph Hellwig,
	Allison Randal

Please split the usb and dma-mapping parts into separate patches.

> 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))
> +		return DMA_MAPPING_ERROR;

a NULL device isn't supported any more, so we can remove the handling
for it here.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single()
  2019-10-04 21:28 [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single() Kees Cook
                   ` (2 preceding siblings ...)
  2019-10-05  8:40 ` Christoph Hellwig
@ 2019-10-05 14:53 ` kbuild test robot
  2019-10-11  7:20 ` kbuild test robot
  4 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2019-10-05 14:53 UTC (permalink / raw)
  To: Kees Cook
  Cc: Dan Carpenter, Greg Kroah-Hartman, linux-kernel, Stephen Boyd,
	iommu, Semmle Security Reports, kbuild-all,
	Jesper Dangaard Brouer, Thomas Gleixner, Laura Abbott,
	Robin Murphy, Christoph Hellwig, Allison Randal

[-- Attachment #1: Type: text/plain, Size: 8792 bytes --]

Hi Kees,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[cannot apply to v5.4-rc1 next-20191004]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Kees-Cook/dma-mapping-Move-vmap-address-checks-into-dma_map_single/20191005-073954
config: i386-randconfig-d001-201939 (attached as .config)
compiler: gcc-7 (Debian 7.4.0-13) 7.4.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from include/linux/init.h:5:0,
                    from sound/pci/ad1889.c:23:
   include/linux/dma-mapping.h: In function 'dma_map_single_attrs':
   include/linux/dma-mapping.h:588:9: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat=]
            "%s %s: driver maps %lu bytes from vmalloc area\n",
            ^
   include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
    #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                       ^~~~
>> include/linux/dma-mapping.h:587:2: note: in expansion of macro 'if'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
     ^~
   include/asm-generic/bug.h:124:3: note: in expansion of macro '__WARN_printf'
      __WARN_printf(TAINT_WARN, format);   \
      ^~~~~~~~~~~~~
   include/asm-generic/bug.h:155:3: note: in expansion of macro 'WARN'
      WARN(1, format);    \
      ^~~~
   include/linux/dma-mapping.h:587:6: note: in expansion of macro 'WARN_ONCE'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
         ^~~~~~~~~
   include/linux/dma-mapping.h:588:9: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat=]
            "%s %s: driver maps %lu bytes from vmalloc area\n",
            ^
   include/linux/compiler.h:58:61: note: in definition of macro '__trace_if_var'
    #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                                ^~~~
>> include/linux/dma-mapping.h:587:2: note: in expansion of macro 'if'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
     ^~
   include/asm-generic/bug.h:124:3: note: in expansion of macro '__WARN_printf'
      __WARN_printf(TAINT_WARN, format);   \
      ^~~~~~~~~~~~~
   include/asm-generic/bug.h:155:3: note: in expansion of macro 'WARN'
      WARN(1, format);    \
      ^~~~
   include/linux/dma-mapping.h:587:6: note: in expansion of macro 'WARN_ONCE'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
         ^~~~~~~~~
   include/linux/dma-mapping.h:588:9: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat=]
            "%s %s: driver maps %lu bytes from vmalloc area\n",
            ^
   include/linux/compiler.h:69:3: note: in definition of macro '__trace_if_value'
     (cond) ?     \
      ^~~~
   include/linux/compiler.h:56:28: note: in expansion of macro '__trace_if_var'
    #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                               ^~~~~~~~~~~~~~
>> include/linux/dma-mapping.h:587:2: note: in expansion of macro 'if'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
     ^~
   include/asm-generic/bug.h:124:3: note: in expansion of macro '__WARN_printf'
      __WARN_printf(TAINT_WARN, format);   \
      ^~~~~~~~~~~~~
   include/asm-generic/bug.h:155:3: note: in expansion of macro 'WARN'
      WARN(1, format);    \
      ^~~~
   include/linux/dma-mapping.h:587:6: note: in expansion of macro 'WARN_ONCE'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
         ^~~~~~~~~
--
   In file included from include/linux/export.h:44:0,
                    from include/linux/linkage.h:7,
                    from include/linux/kernel.h:8,
                    from include/linux/delay.h:22,
                    from sound/pci//hda/hda_intel.c:23:
   include/linux/dma-mapping.h: In function 'dma_map_single_attrs':
   include/linux/dma-mapping.h:588:9: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat=]
            "%s %s: driver maps %lu bytes from vmalloc area\n",
            ^
   include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
    #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                       ^~~~
>> include/linux/dma-mapping.h:587:2: note: in expansion of macro 'if'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
     ^~
   include/asm-generic/bug.h:124:3: note: in expansion of macro '__WARN_printf'
      __WARN_printf(TAINT_WARN, format);   \
      ^~~~~~~~~~~~~
   include/asm-generic/bug.h:155:3: note: in expansion of macro 'WARN'
      WARN(1, format);    \
      ^~~~
   include/linux/dma-mapping.h:587:6: note: in expansion of macro 'WARN_ONCE'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
         ^~~~~~~~~
   include/linux/dma-mapping.h:588:9: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat=]
            "%s %s: driver maps %lu bytes from vmalloc area\n",
            ^
   include/linux/compiler.h:58:61: note: in definition of macro '__trace_if_var'
    #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                                ^~~~
>> include/linux/dma-mapping.h:587:2: note: in expansion of macro 'if'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
     ^~
   include/asm-generic/bug.h:124:3: note: in expansion of macro '__WARN_printf'
      __WARN_printf(TAINT_WARN, format);   \
      ^~~~~~~~~~~~~
   include/asm-generic/bug.h:155:3: note: in expansion of macro 'WARN'
      WARN(1, format);    \
      ^~~~
   include/linux/dma-mapping.h:587:6: note: in expansion of macro 'WARN_ONCE'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
         ^~~~~~~~~
   include/linux/dma-mapping.h:588:9: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t {aka unsigned int}' [-Wformat=]
            "%s %s: driver maps %lu bytes from vmalloc area\n",
            ^
   include/linux/compiler.h:69:3: note: in definition of macro '__trace_if_value'
     (cond) ?     \
      ^~~~
   include/linux/compiler.h:56:28: note: in expansion of macro '__trace_if_var'
    #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                               ^~~~~~~~~~~~~~
>> include/linux/dma-mapping.h:587:2: note: in expansion of macro 'if'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
     ^~
   include/asm-generic/bug.h:124:3: note: in expansion of macro '__WARN_printf'
      __WARN_printf(TAINT_WARN, format);   \
      ^~~~~~~~~~~~~
   include/asm-generic/bug.h:155:3: note: in expansion of macro 'WARN'
      WARN(1, format);    \
      ^~~~
   include/linux/dma-mapping.h:587:6: note: in expansion of macro 'WARN_ONCE'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
         ^~~~~~~~~
   In file included from sound/pci//hda/hda_intel_trace.h:54:0,
                    from sound/pci//hda/hda_intel.c:58:
   include/trace/define_trace.h: At top level:
   include/trace/define_trace.h:95:42: fatal error: ./hda_intel_trace.h: No such file or directory
    #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
                                             ^
   compilation terminated.

vim +/if +587 include/linux/dma-mapping.h

   582	
   583	static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
   584			size_t size, enum dma_data_direction dir, unsigned long attrs)
   585	{
   586		/* DMA must never operate on areas that might be remapped. */
 > 587		if (WARN_ONCE(is_vmalloc_addr(ptr),
 > 588			      "%s %s: driver maps %lu bytes from vmalloc area\n",
   589			      dev ? dev_driver_string(dev) : "unknown driver",
   590			      dev ? dev_name(dev) : "unknown device", size))
   591			return DMA_MAPPING_ERROR;
   592	
   593		debug_dma_map_single(dev, ptr, size);
   594		return dma_map_page_attrs(dev, virt_to_page(ptr), offset_in_page(ptr),
   595				size, dir, attrs);
   596	}
   597	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33925 bytes --]

[-- Attachment #3: Type: text/plain, Size: 156 bytes --]

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single()
  2019-10-04 21:28 [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single() Kees Cook
                   ` (3 preceding siblings ...)
  2019-10-05 14:53 ` kbuild test robot
@ 2019-10-11  7:20 ` kbuild test robot
  4 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2019-10-11  7:20 UTC (permalink / raw)
  To: Kees Cook
  Cc: Dan Carpenter, Greg Kroah-Hartman, linux-kernel, Stephen Boyd,
	iommu, Semmle Security Reports, kbuild-all,
	Jesper Dangaard Brouer, Thomas Gleixner, Laura Abbott,
	Robin Murphy, Christoph Hellwig, Allison Randal

[-- Attachment #1: Type: text/plain, Size: 3282 bytes --]

Hi Kees,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.4-rc2 next-20191010]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Kees-Cook/dma-mapping-Move-vmap-address-checks-into-dma_map_single/20191005-073954
config: sh-magicpanelr2_defconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 7.4.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.4.0 make.cross ARCH=sh 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from arch/sh/include/asm/bug.h:112:0,
                    from include/linux/bug.h:5,
                    from include/linux/thread_info.h:12,
                    from include/asm-generic/preempt.h:5,
                    from ./arch/sh/include/generated/asm/preempt.h:1,
                    from include/linux/preempt.h:78,
                    from include/linux/spinlock.h:51,
                    from include/linux/seqlock.h:36,
                    from include/linux/time.h:6,
                    from include/linux/stat.h:19,
                    from include/linux/module.h:10,
                    from arch/sh/kernel/io.c:8:
   include/linux/dma-mapping.h: In function 'dma_map_single_attrs':
>> include/linux/dma-mapping.h:588:9: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t {aka unsigned int}' [-Werror=format=]
            "%s %s: driver maps %lu bytes from vmalloc area\n",
            ^
   include/asm-generic/bug.h:92:17: note: in definition of macro '__WARN_printf'
      __warn_printk(arg);     \
                    ^~~
   include/asm-generic/bug.h:155:3: note: in expansion of macro 'WARN'
      WARN(1, format);    \
      ^~~~
   include/linux/dma-mapping.h:587:6: note: in expansion of macro 'WARN_ONCE'
     if (WARN_ONCE(is_vmalloc_addr(ptr),
         ^~~~~~~~~
   cc1: all warnings being treated as errors

vim +588 include/linux/dma-mapping.h

   582	
   583	static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
   584			size_t size, enum dma_data_direction dir, unsigned long attrs)
   585	{
   586		/* DMA must never operate on areas that might be remapped. */
   587		if (WARN_ONCE(is_vmalloc_addr(ptr),
 > 588			      "%s %s: driver maps %lu bytes from vmalloc area\n",
   589			      dev ? dev_driver_string(dev) : "unknown driver",
   590			      dev ? dev_name(dev) : "unknown device", size))
   591			return DMA_MAPPING_ERROR;
   592	
   593		debug_dma_map_single(dev, ptr, size);
   594		return dma_map_page_attrs(dev, virt_to_page(ptr), offset_in_page(ptr),
   595				size, dir, attrs);
   596	}
   597	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 12280 bytes --]

[-- Attachment #3: Type: text/plain, Size: 156 bytes --]

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-10-11  7:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04 21:28 [PATCH v2] dma-mapping: Move vmap address checks into dma_map_single() Kees Cook
2019-10-04 21:38 ` Florian Fainelli
2019-10-05  7:26 ` Greg Kroah-Hartman
2019-10-05  8:40 ` Christoph Hellwig
2019-10-05 14:53 ` kbuild test robot
2019-10-11  7:20 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).