[PATCH 1/2] elf_ops: correct loading of 32 bit PVH kernel

David Edmondson posted 2 patches 4 years, 11 months ago
Maintainers: Eduardo Habkost <ehabkost@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Michael S. Tsirkin" <mst@redhat.com>
[PATCH 1/2] elf_ops: correct loading of 32 bit PVH kernel
Posted by David Edmondson 4 years, 11 months ago
Because sizeof(struct elf64_note) == sizeof(struct elf32_note),
attempting to use the size of the currently defined struct elf_note as
a discriminator for whether the object being loaded is 64 bit in
load_elf() fails.

Instead, take advantage of the existing glue parameter SZ, which is
defined as 32 or 64 in the respective variants of load_elf().

Fixes: 696aa04c84c6 ("elf-ops.h: Add get_elf_note_type()")
Signed-off-by: David Edmondson <david.edmondson@oracle.com>
---
 include/hw/elf_ops.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index 8e8436831d..78409ab34a 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -598,9 +598,7 @@ static int glue(load_elf, SZ)(const char *name, int fd,
             nhdr = glue(get_elf_note_type, SZ)(nhdr, file_size, ph->p_align,
                                                *(uint64_t *)translate_opaque);
             if (nhdr != NULL) {
-                bool is64 =
-                    sizeof(struct elf_note) == sizeof(struct elf64_note);
-                elf_note_fn((void *)nhdr, (void *)&ph->p_align, is64);
+                elf_note_fn((void *)nhdr, (void *)&ph->p_align, SZ == 64);
             }
             data = NULL;
         }
-- 
2.30.0


Re: [PATCH 1/2] elf_ops: correct loading of 32 bit PVH kernel
Posted by Philippe Mathieu-Daudé 4 years, 11 months ago
On 3/2/21 10:03 AM, David Edmondson wrote:
> Because sizeof(struct elf64_note) == sizeof(struct elf32_note),
> attempting to use the size of the currently defined struct elf_note as
> a discriminator for whether the object being loaded is 64 bit in
> load_elf() fails.
> 
> Instead, take advantage of the existing glue parameter SZ, which is
> defined as 32 or 64 in the respective variants of load_elf().
> 
> Fixes: 696aa04c84c6 ("elf-ops.h: Add get_elf_note_type()")
> Signed-off-by: David Edmondson <david.edmondson@oracle.com>
> ---
>  include/hw/elf_ops.h | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>


Re: [PATCH 1/2] elf_ops: correct loading of 32 bit PVH kernel
Posted by Stefano Garzarella 4 years, 11 months ago
On Tue, Mar 02, 2021 at 09:03:14AM +0000, David Edmondson wrote:
>Because sizeof(struct elf64_note) == sizeof(struct elf32_note),
>attempting to use the size of the currently defined struct elf_note as
>a discriminator for whether the object being loaded is 64 bit in
>load_elf() fails.
>
>Instead, take advantage of the existing glue parameter SZ, which is
>defined as 32 or 64 in the respective variants of load_elf().
>
>Fixes: 696aa04c84c6 ("elf-ops.h: Add get_elf_note_type()")
>Signed-off-by: David Edmondson <david.edmondson@oracle.com>
>---
> include/hw/elf_ops.h | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
>diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
>index 8e8436831d..78409ab34a 100644
>--- a/include/hw/elf_ops.h
>+++ b/include/hw/elf_ops.h
>@@ -598,9 +598,7 @@ static int glue(load_elf, SZ)(const char *name, int fd,
>             nhdr = glue(get_elf_note_type, SZ)(nhdr, file_size, ph->p_align,
>                                                *(uint64_t *)translate_opaque);
>             if (nhdr != NULL) {
>-                bool is64 =
>-                    sizeof(struct elf_note) == sizeof(struct elf64_note);
>-                elf_note_fn((void *)nhdr, (void *)&ph->p_align, is64);
>+                elf_note_fn((void *)nhdr, (void *)&ph->p_align, SZ == 64);
>             }
>             data = NULL;
>         }
>-- 
>2.30.0
>
>

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>


Re: [PATCH 1/2] elf_ops: correct loading of 32 bit PVH kernel
Posted by Alex Bennée 4 years, 11 months ago
David Edmondson <david.edmondson@oracle.com> writes:

> Because sizeof(struct elf64_note) == sizeof(struct elf32_note),
> attempting to use the size of the currently defined struct elf_note as
> a discriminator for whether the object being loaded is 64 bit in
> load_elf() fails.
>
> Instead, take advantage of the existing glue parameter SZ, which is
> defined as 32 or 64 in the respective variants of load_elf().
>
> Fixes: 696aa04c84c6 ("elf-ops.h: Add get_elf_note_type()")
> Signed-off-by: David Edmondson <david.edmondson@oracle.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée