[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] libelf: improve PVH elfnote parsing


  • To: Juergen Gross <jgross@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Fri, 21 May 2021 11:37:47 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wWwnRSBxKZqHRNCT6g9seyV9Rg0Xk/a5GNpEqkZ4XLk=; b=T9i184bPVQMWKv10sbA7anmfDEbEzACmq/NCPF9jIwcrm8rNSrCE5RxRcDtvK2PB22+pdMYKQ1DO+BmLf68hHgT5yweV+iY/l9N5ff9XHVASKoaFFaHdTMhSNM2tcvjFSg04soAYPyGUK10jsQr4/8rgD4Tjec9+0aQtriF96JWNmcf5hzfeNtz9QlgybRXvhVvnYz+P2rT4ptnQhKHietZxS05R1PuqVy4Hm6pWUiTRrm6ni1+NUzPyR5Jq/mY0oV3b1VHC0mGcqL/Bw24sMG2pSTlPZ5wQo/Cip+Xyzv+BMujFcYojj3U4K/RwEZE/nr/DCechDoURs2xojahTzQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=doF0lzzlCpRNUGpy/rYm02zwxcb7rY2AVACd5Say7edAwbRoxVlTNiykRpI1ILal2T/tzcVmU6K6UFPpGBrh7ohrnNM9y5wKIerlzDhLLQwhw0H6r9tYqKW8fllWh+AMhPLTdsBAk/ZbWtieotdHwpQhjINBg7wCDPGUOOwgNVOjI+rx1mFwvts8vfVYceP367T+5g8vrrj0fkClxf9zgq1dS6Xo9T+NvjQVssJ+5VnpyXnVfyQwGRS27+U2nXxz7hDqKlN7nZ+5zueEMDavugoDozm9TLXASUHe3wqsUFoftUxFyHGyarceyPG0+YI9hQPgdqaNi01Es37Nknc07g==
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Jan Beulich <jbeulich@xxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Ian Jackson" <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, "Julien Grall" <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Fri, 21 May 2021 09:38:07 +0000
  • Ironport-data: A9a23:+fRLRqAZKNJwVRVW/wPjw5YqxClBgxIJ4kV8jS/XYbTApG8ihjQCm 2IeCzvQM/+CN2X2LYsiO9m29xgH65aGzYU1QQY4rX1jcSlH+JHPbTi7wuYcHM8wwunrFh8PA xA2M4GYRCwMZiaH4EjratANlFEkvU2ybuOU5NXsZ2YhH2eIdA970Ug6w7Ng09Y26TSEK1jlV e3a8pW31GCNg1aYAkpMg05UgEoy1BhakGpwUm0WPZinjneH/5UmJMt3yZWKB2n5WuFp8tuSH I4v+l0bElTxpH/BAvv9+lryn9ZjrrT6ZWBigVIOM0Sub4QrSoXfHc/XOdJFAXq7hQllkPhzz vZ0hcCtTT0rHfLvhL4GUhdkCS5xaPguFL/veRBTsOSWxkzCNXDt3+9vHAc9OohwFuRfWD8Us 6ZCcXZUM0DF3bveLLGTE4GAguw5K8bmJsUHs2xIxjDFF/c2B5vERs0m4PcEgGxq15ETQp4yY eJIVD5kdSjKWSRGP1kRC5gzxvX4nyLwJmgwRFW9+vNsvjm7IBZK+LriKt3OYfSRWN5Y2E2fo wru/W70HxUbP9y30iee/zSngeqntTP2XsceGaO18tZugUaP3SoDBRsOT1y5rPKlzEmkVLp3K lMW0jojq7Ao806mRcW7WAe3yFabujYMVtwWFPc1gCmP167V7g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OOEBcE4n8YQzDnK3bJo5tPjnKu0Kn3p5/x+z2TPO+nG4+vXA/i9O VPQisO5PibBX7YnlBwslovsxg268IkF2tjqTDyAtEbc5KM/mR/fS/j8+owBziwfYg0aR8N4SAK isKrdLJHa8z8Kew0DFBADv5DkSVyipuBiWvY5dqMagNZqEKGbBwKXjUe/UlfbQ51lGbANE0Hgf xOk9kXn9t5WXB2O958CwcfIVWK8mOK9piyBclL4opPcbWhpG5X9etbS4LjlemmJMfwfu0c67LG PWQ=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Fri, May 21, 2021 at 07:26:21AM +0200, Juergen Gross wrote:
> On 20.05.21 11:28, Jan Beulich wrote:
> > On 20.05.2021 11:27, Roger Pau Monné wrote:
> > > On Wed, May 19, 2021 at 12:34:19PM +0200, Jan Beulich wrote:
> > > > On 18.05.2021 16:47, Roger Pau Monne wrote:
> > > > > @@ -425,8 +425,11 @@ static elf_errorstatus 
> > > > > elf_xen_addr_calc_check(struct elf_binary *elf,
> > > > >           return -1;
> > > > >       }
> > > > > -    /* Initial guess for virt_base is 0 if it is not explicitly 
> > > > > defined. */
> > > > > -    if ( parms->virt_base == UNSET_ADDR )
> > > > > +    /*
> > > > > +     * Initial guess for virt_base is 0 if it is not explicitly 
> > > > > defined in the
> > > > > +     * PV case. For PVH virt_base is forced to 0 because paging is 
> > > > > disabled.
> > > > > +     */
> > > > > +    if ( parms->virt_base == UNSET_ADDR || hvm )
> > > > >       {
> > > > >           parms->virt_base = 0;
> > > > >           elf_msg(elf, "ELF: VIRT_BASE unset, using %#" PRIx64 "\n",
> > > > 
> > > > This message is wrong now if hvm is true but parms->virt_base != 
> > > > UNSET_ADDR.
> > > > Best perhaps is to avoid emitting the message altogether when hvm is 
> > > > true.
> > > > (Since you'll be touching it anyway, perhaps a good opportunity
> > > > to do
> away
> > > > with passing parms->virt_base to elf_msg(), and instead simply use a 
> > > > literal
> > > > zero.)
> > > > 
> > > > > @@ -441,8 +444,10 @@ static elf_errorstatus 
> > > > > elf_xen_addr_calc_check(struct elf_binary *elf,
> > > > >        *
> > > > >        * If we are using the modern ELF notes interface then the 
> > > > > default
> > > > >        * is 0.
> > > > > +     *
> > > > > +     * For PVH this is forced to 0, as it's already a
> > > > > legacy option
> for PV.
> > > > >        */
> > > > > -    if ( parms->elf_paddr_offset == UNSET_ADDR )
> > > > > +    if ( parms->elf_paddr_offset == UNSET_ADDR || hvm )
> > > > >       {
> > > > >           if ( parms->elf_note_start )
> > > > 
> > > > Don't you want "|| hvm" here as well, or alternatively suppress the
> > > > fallback to the __xen_guest section in the PVH case (near the end of
> > > > elf_xen_parse())?
> > > 
> > > The legacy __xen_guest section doesn't support PHYS32_ENTRY, so yes,
> > > that part could be completely skipped when called from an HVM
> > > container.
> > > 
> > > I think I will fix that in another patch though if you are OK, as
> > > it's not strictly related to the calculation fixes done here.
> > 
> > That's fine; it wants to be a prereq to the one here then, though,
> > I think.
> 
> Would it be possible to add some comment to xen/include/public/elfnote.h
> Indicating which elfnotes are evaluated for which guest types,

For PVH after this patch the only mandatory note should be
PHYS32_ENTRY. BSD_SYMTAB is also parsed if found on that case.

> including
> a hint which elfnotes _have_ been evaluated before this series?

Before this patch mostly all PV notes are parsed, and you have to
manage to get suitable values set so that:

    if ( (parms->virt_kstart > parms->virt_kend) ||
         (parms->virt_entry < parms->virt_kstart) ||
         (parms->virt_entry > parms->virt_kend) ||
         (parms->virt_base > parms->virt_kstart) )
    {
        elf_err(elf, "ERROR: ELF start or entries are out of bounds\n");
        return -1;
    }

Doesn't trigger. That can be done by setting virt_entry or the native
elf entry point to a value that satisfies the condition. Or by setting
a suitable offset in VIRT_BASE to a value that matches the offset
added to the native entry point in the ELF header.

I can try to write this up, albeit I think it can get messy. Not sure
what's the best approach here regarding recommended settings to
satisfy old Xen versions.

Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.