lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGdbjmKO-XDmm-0kw0xm=58TFYdK8t6Yp8OfXCrXVAwWEh3m-A@mail.gmail.com>
Date: Fri, 2 Feb 2024 16:11:37 -0800
From: Kevin Loughlin <kevinloughlin@...gle.com>
To: Ard Biesheuvel <ardb@...nel.org>
Cc: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>, Thomas Gleixner <tglx@...utronix.de>, 
	Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>, 
	Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org, 
	Nick Desaulniers <ndesaulniers@...gle.com>, Justin Stitt <justinstitt@...gle.com>, 
	Tom Lendacky <thomas.lendacky@....com>, Pankaj Gupta <pankaj.gupta@....com>, 
	Hou Wenlong <houwenlong.hwl@...group.com>, Dionna Glaze <dionnaglaze@...gle.com>, 
	Brijesh Singh <brijesh.singh@....com>, Michael Roth <michael.roth@....com>, 
	linux-kernel@...r.kernel.org, llvm@...ts.linux.dev, 
	linux-coco@...ts.linux.dev, Ashish Kalra <ashish.kalra@....com>, 
	Andi Kleen <ak@...ux.intel.com>, Adam Dunlap <acdunlap@...gle.com>, 
	Peter Gonda <pgonda@...gle.com>, Jacob Xu <jacobhxu@...gle.com>, 
	Sidharth Telang <sidtelang@...gle.com>
Subject: Re: [PATCH v3 1/2] x86/sev: enforce RIP-relative accesses in early
 SEV/SME code

On Fri, Feb 2, 2024 at 2:47 PM Ard Biesheuvel <ardb@...nel.org> wrote:
>
> On Fri, 2 Feb 2024 at 23:00, Kevin Loughlin <kevinloughlin@...gle.com> wrote:
> >
> > On Wed, Jan 31, 2024 at 12:20 AM Kirill A. Shutemov
> > <kirill.shutemov@...ux.intel.com> wrote:
> > >
> > > On Tue, Jan 30, 2024 at 10:08:44PM +0000, Kevin Loughlin wrote:
> > > > diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h
> > > > index 359ada486fa9..b65e66ee79c4 100644
> > > > --- a/arch/x86/include/asm/mem_encrypt.h
> > > > +++ b/arch/x86/include/asm/mem_encrypt.h
> > > > @@ -17,6 +17,20 @@
> > > >
> > > >  #include <asm/bootparam.h>
> > > >
> > > > +/*
> > > > + * Like the address operator "&", evaluates to the address of a LHS variable
> > > > + * "var", but also enforces the use of RIP-relative logic. This macro can be
> > > > + * used to safely access global data variables prior to kernel relocation.
> > > > + */
> > > > +#define RIP_RELATIVE_ADDR(var)               \
> > > > +({                                   \
> > > > +     void *rip_rel_ptr;              \
> > > > +     asm ("lea "#var"(%%rip), %0"    \
> > > > +             : "=r" (rip_rel_ptr)    \
> > > > +             : "p" (&var));          \
> > > > +     rip_rel_ptr;                    \
> > > > +})
> > > > +
> > >
> > > I don't think it is the right place for the macro. The next patch uses for
> > > things unrelated to memory encryption.
> >
> > You're right; with the cleanup, I agree it becomes more general. We
> > can move it to arch/x86/include/asm/asm.h.
> >
> > >
> > > > @@ -239,14 +244,14 @@ unsigned long __head __startup_64(unsigned long physaddr,
> > > >        */
> > > >
> > > >       next_pgt_ptr = fixup_pointer(&next_early_pgt, physaddr);
> > > > -     pud = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr);
> > > > -     pmd = fixup_pointer(early_dynamic_pgts[(*next_pgt_ptr)++], physaddr);
> > > > +     early_dynamic_pgts_ptr = fixup_pointer(early_dynamic_pgts, physaddr);
> > > > +     pud = (pudval_t *) early_dynamic_pgts_ptr[(*next_pgt_ptr)++];
> > > > +     pmd = (pmdval_t *) early_dynamic_pgts_ptr[(*next_pgt_ptr)++];
> > > >
> > >
> > > This change doesn't belong to this patch. Maybe move it into the next
> > > patch and combine with removing fixup_pointer().
> >
> > I'll put it in a separate commit even preceding this one, as it's
> > actually a bug in the existing fixup pointer logic that I noticed when
> > transitioning to the use of the RIP-relative macro. Specifically,
> > early_dynamic_pgts is a global variable just like next_early_pgt and
> > thus also needs to be fixed up to guarantee the correct address is
> > used across toolchains.
>
> No, this is not a bug.
>
> early_dynamic_pgts is a two dimensional array
>
> extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES][PTRS_PER_PMD];
>
> and so this expression
>
> early_dynamic_pgts[(*next_pgt_ptr)++]
>
> produces the kernel virtual address of one of the top level elements,
> which itself is an array, and so this can be fixed up as usual.
> IOW, the [] operation does not result in pointer dereference here,
> only in pointer arithmetic.

Ah, yes, you're right. Thanks for the correction! I will just drop it then.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ