linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Linn Crosetto <linn@hp.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	"the arch/x86 maintainers" <x86@kernel.org>,
	Paul McKenney <paulmck@linux.vnet.ibm.com>,
	David Howells <dhowells@redhat.com>,
	Michael Kerrisk-manpages <mtk.manpages@gmail.com>,
	Pekka Enberg <penberg@kernel.org>,
	Jacob Shin <jacob.shin@amd.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] x86: avoid remapping data in parse_setup_data()
Date: Tue, 13 Aug 2013 15:22:40 -0700	[thread overview]
Message-ID: <CAE9FiQUyGH94SAz_g3RqciB275sK_QEHSogiex5O9GNRSaAj1A@mail.gmail.com> (raw)
In-Reply-To: <1376430401-67445-1-git-send-email-linn@hp.com>

On Tue, Aug 13, 2013 at 2:46 PM, Linn Crosetto <linn@hp.com> wrote:
> Type SETUP_PCI, added by setup_efi_pci(), may advertise a ROM size
> larger than early_memremap() is able to handle, which is currently
> limited to 256kB. If this occurs it leads to a NULL dereference in
> parse_setup_data().
>
> To avoid this, remap the setup_data header and allow parsing functions
> for individual types to handle their own data remapping.
>
> Signed-off-by: Linn Crosetto <linn@hp.com>
> ---
> v3: Remove data remapping code from parse_setup_data() and add it to
> parse_e820_ext().

Acked-by: Yinghai Lu <yinghai@kernel.org>

>
>  arch/x86/include/asm/e820.h |  2 +-
>  arch/x86/kernel/e820.c      |  5 ++++-
>  arch/x86/kernel/setup.c     | 19 ++++++++-----------
>  3 files changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
> index cccd07f..779c2ef 100644
> --- a/arch/x86/include/asm/e820.h
> +++ b/arch/x86/include/asm/e820.h
> @@ -29,7 +29,7 @@ extern void e820_setup_gap(void);
>  extern int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
>                         unsigned long start_addr, unsigned long long end_addr);
>  struct setup_data;
> -extern void parse_e820_ext(struct setup_data *data);
> +extern void parse_e820_ext(u64 phys_addr, u32 data_len);
>
>  #if defined(CONFIG_X86_64) || \
>         (defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION))
> diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
> index d32abea..174da5f 100644
> --- a/arch/x86/kernel/e820.c
> +++ b/arch/x86/kernel/e820.c
> @@ -658,15 +658,18 @@ __init void e820_setup_gap(void)
>   * boot_params.e820_map, others are passed via SETUP_E820_EXT node of
>   * linked list of struct setup_data, which is parsed here.
>   */
> -void __init parse_e820_ext(struct setup_data *sdata)
> +void __init parse_e820_ext(u64 phys_addr, u32 data_len)
>  {
>         int entries;
>         struct e820entry *extmap;
> +       struct setup_data *sdata;
>
> +       sdata = early_memremap(phys_addr, data_len);
>         entries = sdata->len / sizeof(struct e820entry);
>         extmap = (struct e820entry *)(sdata->data);
>         __append_e820_map(extmap, entries);
>         sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
> +       early_iounmap(sdata, data_len);
>         printk(KERN_INFO "e820: extended physical RAM map:\n");
>         e820_print_map("extended");
>  }
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index f8ec578..234e1e3 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -426,25 +426,23 @@ static void __init reserve_initrd(void)
>  static void __init parse_setup_data(void)
>  {
>         struct setup_data *data;
> -       u64 pa_data;
> +       u64 pa_data, pa_next;
>
>         pa_data = boot_params.hdr.setup_data;
>         while (pa_data) {
> -               u32 data_len, map_len;
> +               u32 data_len, map_len, data_type;
>
>                 map_len = max(PAGE_SIZE - (pa_data & ~PAGE_MASK),
>                               (u64)sizeof(struct setup_data));
>                 data = early_memremap(pa_data, map_len);
>                 data_len = data->len + sizeof(struct setup_data);
> -               if (data_len > map_len) {
> -                       early_iounmap(data, map_len);
> -                       data = early_memremap(pa_data, data_len);
> -                       map_len = data_len;
> -               }
> +               data_type = data->type;
> +               pa_next = data->next;
> +               early_iounmap(data, map_len);
>
> -               switch (data->type) {
> +               switch (data_type) {
>                 case SETUP_E820_EXT:
> -                       parse_e820_ext(data);
> +                       parse_e820_ext(pa_data, data_len);
>                         break;
>                 case SETUP_DTB:
>                         add_dtb(pa_data);
> @@ -452,8 +450,7 @@ static void __init parse_setup_data(void)
>                 default:
>                         break;
>                 }
> -               pa_data = data->next;
> -               early_iounmap(data, map_len);
> +               pa_data = pa_next;
>         }
>  }

  reply	other threads:[~2013-08-13 22:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-12 21:00 [PATCH] x86: selective remapping in parse_setup_data() Linn Crosetto
2013-08-12 21:08 ` H. Peter Anvin
2013-08-12 23:01   ` [PATCH v2] " Linn Crosetto
2013-08-12 23:30     ` Yinghai Lu
2013-08-13 21:46     ` [PATCH v3] x86: avoid remapping data " Linn Crosetto
2013-08-13 22:22       ` Yinghai Lu [this message]
2013-08-14  6:26       ` Pekka Enberg
2013-09-01 11:40       ` [tip:x86/mm] " tip-bot for Linn Crosetto
2013-09-01 23:15       ` [PATCH v3] " H. Peter Anvin
2013-09-06 18:06         ` [PATCH 0/3] x86/mm: fix early_memremap() sparse warnings Linn Crosetto
2013-09-06 18:06           ` [PATCH 1/3] x86/mm: fix sparse warnings from early_memremap() Linn Crosetto
2013-09-06 18:06           ` [PATCH 2/3] x86: fix sparse warning in parse_e820_ext() Linn Crosetto
2013-09-06 18:06           ` [PATCH 3/3] x86: fix early_iounmap() sparse warnings in setup.c Linn Crosetto

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=CAE9FiQUyGH94SAz_g3RqciB275sK_QEHSogiex5O9GNRSaAj1A@mail.gmail.com \
    --to=yinghai@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jacob.shin@amd.com \
    --cc=linn@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mtk.manpages@gmail.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=penberg@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@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 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).