libelf: don't attempt to parse __xen_guest for PVH

The legacy __xen_guest section doesn't support the PHYS32_ENTRY
elfnote, so it's pointless to attempt to parse the elfnotes from that
section when called from an hvm container.

Pass an hvm boolean parameter to the elf note parsing routine, so that
the respective parsing can be suppressed in case libelf is dealing with
an hvm container.

Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Roger Pau Monné authored and Jan Beulich committed 2021-05-28 09:13:32 +02:00
1 parent 8c90dbb999
commit dec25a2cd1
7 files changed
+13 -12

No files matched your search

+2 -1
View File
@@ -17,7 +17,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
return -1;
elf_parse_binary(elf);
elf_xen_parse(elf, &parms);
elf_xen_parse(elf, &parms, false);
elf_xen_parse(elf, &parms, true);
return 0;
}
+4 -2
View File
@@ -135,7 +135,8 @@ static elf_negerrnoval xc_dom_probe_elf_kernel(struct xc_dom_image *dom)
* or else we might be trying to load a plain ELF.
*/
elf_parse_binary(&elf);
rc = elf_xen_parse(&elf, dom->parms);
rc = elf_xen_parse(&elf, dom->parms,
dom->container_type == XC_DOM_HVM_CONTAINER);
if ( rc != 0 )
return rc;
@@ -166,7 +167,8 @@ static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom)
/* parse binary and get xen meta info */
elf_parse_binary(elf);
if ( elf_xen_parse(elf, dom->parms) != 0 )
if ( elf_xen_parse(elf, dom->parms,
dom->container_type == XC_DOM_HVM_CONTAINER) != 0 )
{
rc = -EINVAL;
goto out;
+1 -1
View File
@@ -73,7 +73,7 @@ static elf_negerrnoval xc_dom_probe_hvm_kernel(struct xc_dom_image *dom)
* else we might be trying to load a PV kernel.
*/
elf_parse_binary(&elf);
rc = elf_xen_parse(&elf, dom->parms);
rc = elf_xen_parse(&elf, dom->parms, true);
if ( rc == 0 )
return -EINVAL;
+1 -1
View File
@@ -561,7 +561,7 @@ static int __init pvh_load_kernel(struct domain *d, const module_t *image,
elf_set_verbose(&elf);
#endif
elf_parse_binary(&elf);
if ( (rc = elf_xen_parse(&elf, &parms)) != 0 )
if ( (rc = elf_xen_parse(&elf, &parms, true)) != 0 )
{
printk("Unable to parse kernel for ELFNOTES\n");
return rc;
+1 -1
View File
@@ -353,7 +353,7 @@ int __init dom0_construct_pv(struct domain *d,
elf_set_verbose(&elf);
elf_parse_binary(&elf);
if ( (rc = elf_xen_parse(&elf, &parms)) != 0 )
if ( (rc = elf_xen_parse(&elf, &parms, false)) != 0 )
goto out;
/* compatibility check */
+3 -5
View File
@@ -499,7 +499,7 @@ static elf_errorstatus elf_xen_addr_calc_check(struct elf_binary *elf,
/* glue it all together ... */
elf_errorstatus elf_xen_parse(struct elf_binary *elf,
struct elf_dom_parms *parms)
struct elf_dom_parms *parms, bool hvm)
{
ELF_HANDLE_DECL(elf_shdr) shdr;
ELF_HANDLE_DECL(elf_phdr) phdr;
@@ -577,10 +577,8 @@ elf_errorstatus elf_xen_parse(struct elf_binary *elf,
}
/*
* Finally fall back to the __xen_guest section.
*/
if ( xen_elfnotes == 0 )
/* Finally fall back to the __xen_guest section for PV guests only. */
if ( xen_elfnotes == 0 && !hvm )
{
shdr = elf_shdr_by_name(elf, "__xen_guest");
if ( ELF_HANDLE_VALID(shdr) )
+1 -1
View File
@@ -454,7 +454,7 @@ int elf_xen_parse_note(struct elf_binary *elf,
int elf_xen_parse_guest_info(struct elf_binary *elf,
struct elf_dom_parms *parms);
int elf_xen_parse(struct elf_binary *elf,
struct elf_dom_parms *parms);
struct elf_dom_parms *parms, bool hvm);
static inline void *elf_memcpy_unchecked(void *dest, const void *src, size_t n)
{ return memcpy(dest, src, n); }
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.