linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: catalin.marinas@arm.com (Catalin Marinas)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/3] arm64: efi: Ensure efi_create_mapping() does not map overlapping regions
Date: Mon, 6 Jun 2016 18:42:08 +0100	[thread overview]
Message-ID: <20160606174207.GH29910@e104818-lin.cambridge.arm.com> (raw)
In-Reply-To: <20160606170950.GD29910@e104818-lin.cambridge.arm.com>

On Mon, Jun 06, 2016 at 06:09:50PM +0100, Catalin Marinas wrote:
> On Mon, Jun 06, 2016 at 11:43:01AM +0200, Ard Biesheuvel wrote:
> > On 31 May 2016 at 17:14, Catalin Marinas <catalin.marinas@arm.com> wrote:
> > > diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
> > > index 78f52488f9ff..0d5753c31c7f 100644
> > > --- a/arch/arm64/kernel/efi.c
> > > +++ b/arch/arm64/kernel/efi.c
> > > @@ -62,10 +62,26 @@ struct screen_info screen_info __section(.data);
> > >  int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
> > >  {
> > >         pteval_t prot_val = create_mapping_protection(md);
> > > +       phys_addr_t length = md->num_pages << EFI_PAGE_SHIFT;
> > > +       efi_memory_desc_t *next = md;
> > >
> > > -       create_pgd_mapping(mm, md->phys_addr, md->virt_addr,
> > > -                          md->num_pages << EFI_PAGE_SHIFT,
> > > -                          __pgprot(prot_val | PTE_NG));
> > > +       /*
> > > +        * Search for the next EFI runtime map and check for any overlap with
> > > +        * the current map when aligned to PAGE_SIZE. In such case, defer
> > > +        * mapping the end of the current range until the next
> > > +        * efi_create_mapping() call.
> > > +        */
> > > +       for_each_efi_memory_desc_continue(next) {
> > > +               if (!(next->attribute & EFI_MEMORY_RUNTIME))
> > > +                       continue;
> > > +               if (next->phys_addr < PAGE_ALIGN(md->phys_addr + length))
> > > +                       length -= (md->phys_addr + length) & ~PAGE_MASK;
> > 
> > This looks fishy. We could have more than two runtime regions sharing
> > a 64 KB page frame, for instance, and the middle regions will have
> > unaligned start and end addresses, and sizes smaller than 64 KB. This
> > subtraction may wrap in that case, producing a bogus length.
> 
> I don't think I get it. This subtraction is meant to reduce the length
> of the current md so that it is page aligned, deferring the mapping of
> the last page to the next efi_create_mapping() call. Note that there is
> a "break" just after the hunk you quoted, so we only care about the next
> runtime map.

I think I get it now. If the md we are currently mapping is within a
64KB page *and* phys_addr unaligned, length can wrap through 0. I will
update the patch.

-- 
Catalin

  parent reply	other threads:[~2016-06-06 17:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-31 15:14 [PATCH 0/3] arm64: Avoid overlapping EFI regions Catalin Marinas
2016-05-31 15:14 ` [PATCH 1/3] efi: Introduce *_continue efi_memory_desc iterators Catalin Marinas
2016-06-01 10:34   ` Mark Rutland
2016-06-01 10:43     ` Catalin Marinas
2016-06-02 14:36       ` Matt Fleming
2016-06-02 16:29         ` Catalin Marinas
2016-06-02 16:31           ` Jeremy Linton
2016-06-02 17:11             ` Catalin Marinas
2016-06-02 17:15               ` Jeremy Linton
2016-06-03 20:43               ` Matt Fleming
2016-05-31 15:14 ` [PATCH 2/3] arm64: efi: Ensure efi_create_mapping() does not map overlapping regions Catalin Marinas
2016-06-02 14:52   ` Matt Fleming
2016-06-02 16:56     ` Catalin Marinas
2016-06-03 20:56       ` Matt Fleming
2016-06-06  9:43   ` Ard Biesheuvel
2016-06-06 17:09     ` Catalin Marinas
2016-06-06 17:26       ` Ard Biesheuvel
2016-06-06 17:42       ` Catalin Marinas [this message]
2016-06-06 21:18         ` Ard Biesheuvel
2016-06-28 16:05           ` Catalin Marinas
2016-06-28 16:12             ` Ard Biesheuvel
2016-06-29  9:39               ` Catalin Marinas
2016-06-29 10:03                 ` Ard Biesheuvel
2016-06-29 10:50                   ` Catalin Marinas
2016-06-29 11:03                     ` Ard Biesheuvel
2016-06-29 12:03                       ` Catalin Marinas
2016-05-31 15:14 ` [PATCH 3/3] arm64: mm: Remove split_p*d() functions Catalin Marinas

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=20160606174207.GH29910@e104818-lin.cambridge.arm.com \
    --to=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.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).