* [PATCH] ARM/dma-mapping: Remove CMA code when not built with CMA
@ 2022-03-09 17:51 Kees Cook
2022-03-10 7:00 ` Christoph Hellwig
2022-03-10 8:23 ` David Hildenbrand
0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2022-03-09 17:51 UTC (permalink / raw)
To: Russell King
Cc: Kees Cook, Logan Gunthorpe, Martin Oliveira, David Hildenbrand,
Andrew Morton, Stephen Rothwell, Zi Yan, Hari Bathini,
Minchan Kim, Mike Kravetz, linux-arm-kernel, Christoph Hellwig,
linux-kernel, linux-hardening
The MAX_CMA_AREAS could be set to 0, which would result in code that would
attempt to operate beyond the end of a zero-sized array. If CONFIG_CMA
is disabled, just remove this code entirely. Found when building with
-Warray-bounds:
arch/arm/mm/dma-mapping.c:396:22: warning: array subscript <unknown> is outside array bounds of 'str
uct dma_contig_early_reserve[0]' [-Warray-bounds]
396 | dma_mmu_remap[dma_mmu_remap_num].size = size;
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
arch/arm/mm/dma-mapping.c:389:40: note: while referencing 'dma_mmu_remap'
389 | static struct dma_contig_early_reserve dma_mmu_remap[MAX_CMA_AREAS] __initdata;
| ^~~~~~~~~~~~~
Cc: Russell King <linux@armlinux.org.uk>
Cc: Logan Gunthorpe <logang@deltatee.com>
Cc: Martin Oliveira <martin.oliveira@eideticom.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
arch/arm/mm/dma-mapping.c | 2 ++
arch/arm/mm/mm.h | 4 ++++
include/linux/cma.h | 4 ----
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 4b61541853ea..82ffac621854 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -381,6 +381,7 @@ static int __init atomic_pool_init(void)
*/
postcore_initcall(atomic_pool_init);
+#ifdef CONFIG_CMA_AREAS
struct dma_contig_early_reserve {
phys_addr_t base;
unsigned long size;
@@ -435,6 +436,7 @@ void __init dma_contiguous_remap(void)
iotable_init(&map, 1);
}
}
+#endif
static int __dma_update_pte(pte_t *pte, unsigned long addr, void *data)
{
diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h
index 9ff683612f2a..d7ffccb7fea7 100644
--- a/arch/arm/mm/mm.h
+++ b/arch/arm/mm/mm.h
@@ -88,6 +88,10 @@ extern phys_addr_t arm_lowmem_limit;
void __init bootmem_init(void);
void arm_mm_memblock_reserve(void);
+#ifdef CONFIG_CMA_AREAS
void dma_contiguous_remap(void);
+#else
+static inline void dma_contiguous_remap(void) { }
+#endif
unsigned long __clear_cr(unsigned long mask);
diff --git a/include/linux/cma.h b/include/linux/cma.h
index 90fd742fd1ef..a6f637342740 100644
--- a/include/linux/cma.h
+++ b/include/linux/cma.h
@@ -12,10 +12,6 @@
*/
#ifdef CONFIG_CMA_AREAS
#define MAX_CMA_AREAS (1 + CONFIG_CMA_AREAS)
-
-#else
-#define MAX_CMA_AREAS (0)
-
#endif
#define CMA_MAX_NAME 64
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ARM/dma-mapping: Remove CMA code when not built with CMA
2022-03-09 17:51 [PATCH] ARM/dma-mapping: Remove CMA code when not built with CMA Kees Cook
@ 2022-03-10 7:00 ` Christoph Hellwig
2022-03-10 8:23 ` David Hildenbrand
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2022-03-10 7:00 UTC (permalink / raw)
To: Kees Cook
Cc: Russell King, Logan Gunthorpe, Martin Oliveira,
David Hildenbrand, Andrew Morton, Stephen Rothwell, Zi Yan,
Hari Bathini, Minchan Kim, Mike Kravetz, linux-arm-kernel,
Christoph Hellwig, linux-kernel, linux-hardening
On Wed, Mar 09, 2022 at 09:51:07AM -0800, Kees Cook wrote:
> The MAX_CMA_AREAS could be set to 0, which would result in code that would
> attempt to operate beyond the end of a zero-sized array. If CONFIG_CMA
> is disabled, just remove this code entirely. Found when building with
> -Warray-bounds:
>
> arch/arm/mm/dma-mapping.c:396:22: warning: array subscript <unknown> is outside array bounds of 'str
> uct dma_contig_early_reserve[0]' [-Warray-bounds]
> 396 | dma_mmu_remap[dma_mmu_remap_num].size = size;
> | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
> arch/arm/mm/dma-mapping.c:389:40: note: while referencing 'dma_mmu_remap'
> 389 | static struct dma_contig_early_reserve dma_mmu_remap[MAX_CMA_AREAS] __initdata;
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ARM/dma-mapping: Remove CMA code when not built with CMA
2022-03-09 17:51 [PATCH] ARM/dma-mapping: Remove CMA code when not built with CMA Kees Cook
2022-03-10 7:00 ` Christoph Hellwig
@ 2022-03-10 8:23 ` David Hildenbrand
1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2022-03-10 8:23 UTC (permalink / raw)
To: Kees Cook, Russell King
Cc: Logan Gunthorpe, Martin Oliveira, Andrew Morton,
Stephen Rothwell, Zi Yan, Hari Bathini, Minchan Kim,
Mike Kravetz, linux-arm-kernel, Christoph Hellwig, linux-kernel,
linux-hardening
On 09.03.22 18:51, Kees Cook wrote:
> The MAX_CMA_AREAS could be set to 0, which would result in code that would
> attempt to operate beyond the end of a zero-sized array. If CONFIG_CMA
> is disabled, just remove this code entirely. Found when building with
> -Warray-bounds:
>
> arch/arm/mm/dma-mapping.c:396:22: warning: array subscript <unknown> is outside array bounds of 'str
> uct dma_contig_early_reserve[0]' [-Warray-bounds]
> 396 | dma_mmu_remap[dma_mmu_remap_num].size = size;
> | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
> arch/arm/mm/dma-mapping.c:389:40: note: while referencing 'dma_mmu_remap'
> 389 | static struct dma_contig_early_reserve dma_mmu_remap[MAX_CMA_AREAS] __initdata;
> | ^~~~~~~~~~~~~
>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Logan Gunthorpe <logang@deltatee.com>
> Cc: Martin Oliveira <martin.oliveira@eideticom.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Stephen Rothwell <sfr@canb.auug.org.au>
> Cc: Zi Yan <ziy@nvidia.com>
> Cc: Hari Bathini <hbathini@linux.ibm.com>
> Cc: Minchan Kim <minchan@kernel.org>
> Cc: Mike Kravetz <mike.kravetz@oracle.com>
> Cc: linux-arm-kernel@lists.infradead.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: David Hildenbrand <david@redhat.com>
--
Thanks,
David / dhildenb
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-10 8:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09 17:51 [PATCH] ARM/dma-mapping: Remove CMA code when not built with CMA Kees Cook
2022-03-10 7:00 ` Christoph Hellwig
2022-03-10 8:23 ` David Hildenbrand
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).