mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Andrea Parri <parri.andrea@gmail.com>
Cc: Tony Luck <tony.luck@intel.com>,
	"Guilherme G . Piccoli" <gpiccoli@igalia.com>,
	Anton Vorontsov <anton.vorontsov@linaro.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Colin Cross <ccross@android.com>,
	John Stultz <john.stultz@linaro.org>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 2/2] pstore: reject persistent RAM zones too small for the buffer header
Date: Mon, 21 Sep 2026 14:35:19 -0700	[thread overview]
Message-ID: <202609211431.11176F76@keescook> (raw)
In-Reply-To: <20260921202317.70595-3-parri.andrea@gmail.com>

On Mon, Sep 21, 2026 at 10:23:16PM +0200, Andrea Parri wrote:
> persistent_ram_buffer_map() computes
> 
> 	prz->buffer_size = size - sizeof(struct persistent_ram_buffer);
> 
> without checking that size is large enough to hold the header.  A
> ramoops zone configured with a tiny size (e.g. ramoops.pmsg_size=1)
> underflows buffer_size to a huge value, which defeats every bounds
> check in persistent_ram_write() and persistent_ram_write_user(); a
> write to /dev/pmsg0 then copies user data far past the end of the zone
> and corrupts kernel memory.
> 
> Reject zones that are not larger than the buffer header.
> 
> Fixes: 404a6043385de ("staging: android: persistent_ram: handle reserving and mapping memory")
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
> ---
>  fs/pstore/ram_core.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
> index b4ec8009b8dc9..ae941777037b8 100644
> --- a/fs/pstore/ram_core.c
> +++ b/fs/pstore/ram_core.c
> @@ -505,6 +505,12 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size,
>  	prz->paddr = start;
>  	prz->size = size;
>  
> +	if (size <= sizeof(struct persistent_ram_buffer)) {
> +		pr_err("%s: persistent ram zone too small (%#llx bytes)\n",
> +		       prz->label, (unsigned long long)size);
> +		return -EINVAL;
> +	}

Whoops. Luckily it's all system-owner or hardware defined (hardware
probes, and boot params).

I wonder if it should return ENOSPC instead, though?

> +
>  	if (pfn_valid(start >> PAGE_SHIFT))
>  		prz->vaddr = persistent_ram_vmap(start, size, memtype);
>  	else
> -- 
> 2.53.0
> 

Thanks for finding this!

-- 
Kees Cook

  reply	other threads:[~2026-09-21 21:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 20:23 [PATCH 0/2] pstore: fix two ramoops error-path bugs Andrea Parri
2026-09-21 20:23 ` [PATCH 1/2] pstore: don't leave an ERR_PTR in the ramoops zone pointer Andrea Parri
2026-09-21 20:23 ` [PATCH 2/2] pstore: reject persistent RAM zones too small for the buffer header Andrea Parri
2026-09-21 21:35   ` Kees Cook [this message]
2026-09-21 22:38     ` Andrea Parri
2026-09-21 23:11       ` Kees Cook
2026-09-21 21:38 ` [PATCH 0/2] pstore: fix two ramoops error-path bugs Kees Cook

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=202609211431.11176F76@keescook \
    --to=kees@kernel.org \
    --cc=anton.vorontsov@linaro.org \
    --cc=ccross@android.com \
    --cc=gpiccoli@igalia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=parri.andrea@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=tony.luck@intel.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

all inboxes | Powered by JetHome®