All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] pstore/ram: Add kmsg hlen null check to ramoops_pstore_write
       [not found] <5c53f6d3.1c69fb81.a1e8c.eb7aSMTPIN_ADDED_BROKEN@mx.google.com>
@ 2019-02-12 20:27 ` Kees Cook
  0 siblings, 0 replies; only message in thread
From: Kees Cook @ 2019-02-12 20:27 UTC (permalink / raw)
  To: Yue Hu; +Cc: Anton Vorontsov, Colin Cross, Tony Luck, LKML

On Thu, Jan 31, 2019 at 11:35 PM Yue Hu <huyue2@yulong.com> wrote:
>
> From 9385613f546a4d0b2497dc2ed22cb9475eb3621c Mon Sep 17 00:00:00 2001
> From: Yue Hu <huyue2@yulong.com>
> Date: Fri, 1 Feb 2019 11:27:32 +0800
> Subject: [PATCH] pstore/ram: Add kmsg hlen null check to ramoops_pstore_write
>
> If null hdr happened in ramoops_write_kmsg_hdr(), that means
> we cannot get the dmesg record since it will be treated as
> invalid header in ramoops_pstore_read(). So we should not
> execute the following code but return the error.
>
> Signed-off-by: Yue Hu <huyue2@yulong.com>
> ---
>  fs/pstore/ram.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> index 7e188f6..4a06675 100644
> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c
> @@ -467,6 +467,9 @@ static int notrace ramoops_pstore_write(struct pstore_record *record)
>
>         /* Build header and append record contents. */
>         hlen = ramoops_write_kmsg_hdr(prz, record);
> +       if (!hlen)
> +               return -EINVAL;
> +
>         size = record->size;
>         if (size + hlen > prz->buffer_size)
>                 size = prz->buffer_size - hlen;

Yeah, this seems right. If we don't generate a header, then
ramoops_pstore_read() will ignore anything written there. This
probably means we need to refactor this to avoid memory allocation
during the write. I'll apply this and do some follow-up changes.

Thanks!

-- 
Kees Cook

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-02-12 20:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5c53f6d3.1c69fb81.a1e8c.eb7aSMTPIN_ADDED_BROKEN@mx.google.com>
2019-02-12 20:27 ` [PATCH] pstore/ram: Add kmsg hlen null check to ramoops_pstore_write Kees Cook

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.