[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202103171434.A04E5FAF@keescook>
Date: Wed, 17 Mar 2021 15:20:35 -0700
From: Kees Cook <keescook@...omium.org>
To: Mukesh Ojha <mojha@...eaurora.org>
Cc: linux-kernel@...r.kernel.org, anton@...msg.org, ccross@...roid.com,
tony.luck@...el.com, Huang Yiwei <hyiwei@...eaurora.org>
Subject: Re: [RESEND PATCH v2 2/2] pstore: Add buffer start check during init
On Thu, Feb 25, 2021 at 09:30:17PM +0530, Mukesh Ojha wrote:
> From: Huang Yiwei <hyiwei@...eaurora.org>
>
> In a scenario of panic, when we use DRAM to store log instead
> of persistant storage and during warm reset when we copy these
> data outside of ram. Missing check on prz->start(write position)
> can cause crash because it can be any value and can point outside
> the mapped region. So add the start check to avoid.
>
> Signed-off-by: Huang Yiwei <hyiwei@...eaurora.org>
> Signed-off-by: Mukesh Ojha <mojha@...eaurora.org>
> ---
> change in v2:
> - this is on top of first patchset.
>
> fs/pstore/ram_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
> index 0da012f..a15748a 100644
> --- a/fs/pstore/ram_core.c
> +++ b/fs/pstore/ram_core.c
> @@ -514,7 +514,7 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig,
> sig ^= PERSISTENT_RAM_SIG;
>
> if (prz->buffer->sig == sig) {
> - if (buffer_size(prz) == 0) {
> + if (buffer_size(prz) == 0 && buffer_start(prz) == 0) {
> pr_debug("found existing empty buffer\n");
> return 0;
Were you seeing cases where the sig was correct, size was zero and start
was non-zero but still smaller than buffer_size(prz)?
That should only happen if a prz changed in size (but not location)
across boots, and I guess, yes, should be detected and zapped. But that
means you need a case for size=0 buffer_start!=0 for zapping.
But you talk about a crash without this test? "any value" isn't true,
the next tests make sure it's within buffer_size:
if (buffer_size(prz) > prz->buffer_size ||
buffer_start(prz) > buffer_size(prz)) {
pr_info("found existing invalid buffer, size %zu, start %zu\n",
buffer_size(prz), buffer_start(prz));
zap = true;
can you tell me more about what you're seeing?
-Kees
--
Kees Cook
Powered by blists - more mailing lists