All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
Cc: robh@kernel.org, saravanak@kernel.org, akpm@linux-foundation.org,
	david@kernel.org, ljs@kernel.org, liam@infradead.org,
	vbabka@kernel.org, surenb@google.com, mhocko@suse.com,
	m.szyprowski@samsung.com, robin.murphy@arm.com,
	baoquan.he@linux.dev, pasha.tatashin@soleen.com,
	pratyush@kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	iommu@lists.linux.dev, kexec@lists.infradead.org
Subject: Re: [PATCH 3/4] mm/cma: reject CMA areas that overlap the kernel image
Date: Sun, 8 Nov 2026 13:05:11 +0200	[thread overview]
Message-ID: <avBXZ8iW2XPyVbmF@kernel.org> (raw)
In-Reply-To: <20261103162429.2053989-4-radhey.shyam.pandey@amd.com>

Hi,

On Tue, Nov 03, 2026 at 09:54:28PM +0530, Radhey Shyam Pandey wrote:
> cma_init_reserved_mem() takes a base chosen by its caller and only requires
> that the range already be reserved, so an overlap with the kernel image is
> indistinguishable from the normal case. cma_activate_area() then clears
> PageReserved on those pages and frees them into MIGRATE_CMA, overriding the
> memblock_reserve() of [_text, _end), so live kernel text reaches userspace.
> kexec reached this until the fix this series builds on; a device tree
> placing a shared-dma-pool over where the bootloader loaded the kernel still
> can. Reject the overlap rather than let such a caller corrupt the kernel.
> 
> Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
> ---
> Changes since RFC:
> - Drop Pratyush reviewed-by tag as there were few changes.
> - Trim the commit description.
> - Drop the redundant comment as suggested by Mike.
> - cma_overlaps_kernel_image() is kept as helpers in asm-generic/sections.h
>   are virtual-address helpers.
> ---
>  mm/cma.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/mm/cma.c b/mm/cma.c
> index 9c53b2b70dc8..3231a53161cd 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -31,6 +31,8 @@
>  #include <linux/kmemleak.h>
>  #include <trace/events/cma.h>
>  
> +#include <asm/sections.h>

You probably don't need this.

> +
>  #include "internal.h"
>  #include "cma.h"
>  #include "mm_init.h"
> @@ -68,6 +70,16 @@ bool cma_has_dynamic_base(const struct cma *cma)
>  	return test_bit(CMA_DYNAMIC_BASE, &cma->flags);
>  }
>  
> +static bool cma_overlaps_kernel_image(phys_addr_t base, phys_addr_t size)
> +{
> +	phys_addr_t end;
> +
> +	if (check_add_overflow(base, size, &end))
> +		return true;
> +
> +	return base < __pa_symbol(_end) && __pa_symbol(_text) < end;
> +}
> +
>  static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
>  					     unsigned int align_order)
>  {
> @@ -295,6 +307,15 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
>  	if (!size || !memblock_is_region_reserved(base, size))
>  		return -EINVAL;
>  
> +	if (cma_overlaps_kernel_image(base, size)) {
> +		phys_addr_t text = __pa_symbol(_text);
> +		phys_addr_t end = __pa_symbol(_end);
> +
> +		pr_err("area %s (%pa, size %pa) overlaps kernel image [%pa-%pa]\n",
> +		       name ?: "(unnamed)", &base, &size, &text, &end);

We don't want to expose addresses of the kernel image.
I'd drop text, end, and probably even base from the printout.

> +		return -EBUSY;
> +	}
> +
>  	/*
>  	 * CMA uses CMA_MIN_ALIGNMENT_BYTES as alignment requirement which
>  	 * needs pageblock_order to be initialized. Let's enforce it.
> -- 
> 2.44.4
> 

-- 
Sincerely yours,
Mike.


  parent reply	other threads:[~2026-11-08 11:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 16:24 [PATCH 0/4] kexec,mm/cma: do not run the next kernel from a fixed-base CMA area Radhey Shyam Pandey
2026-11-03 16:24 ` [PATCH 1/4] kexec: do not place the next kernel in a fixed-address " Radhey Shyam Pandey
2026-11-04 16:29   ` sashiko-bot
2026-11-03 16:24 ` [PATCH 2/4] of: reserved_mem: keep the reservation when node_init returns -EBUSY Radhey Shyam Pandey
2026-11-04 16:29   ` sashiko-bot
2026-11-03 16:24 ` [PATCH 3/4] mm/cma: reject CMA areas that overlap the kernel image Radhey Shyam Pandey
2026-11-04 16:29   ` sashiko-bot
2026-11-08 11:05   ` Mike Rapoport [this message]
2026-11-03 16:24 ` [PATCH 4/4] mm/cma: drop the duplicate alignment check in rmem_cma_setup() Radhey Shyam Pandey
2026-11-04 16:29   ` sashiko-bot

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=avBXZ8iW2XPyVbmF@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=baoquan.he@linux.dev \
    --cc=david@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=kexec@lists.infradead.org \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mhocko@suse.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=radhey.shyam.pandey@amd.com \
    --cc=robh@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=saravanak@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    /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.