xen: look for Xen notes in section headers too
PATCH 1/1 xen: look for Xen notes in section headers too
Mirror behaviour of elf loader in libxc: first look for Xen notes in PT_NOTE segment, then in SHT_NOTE section and only then fallback to a section with __xen_guest name.
This fixes loading PV kernels that Xen note have outside of PT_NOTE. While this may be result of a buggy linker script, loading such kernel directly works fine, so make it work with grub too. Specifically, this applies to binaries built from Unikraft.
--- grub-core/loader/i386/xen_fileXX.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
grub-core/loader/i386/xen_fileXX.c +15 -0
@@ -344,6 +344,21 @@ grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) s = (Elf_Shdr *) ((char *) s0 + elf->ehdr.ehdrXX.e_shstrndx * shentsize); stroff = s->sh_offset; +for (s = s0; s < (Elf_Shdr *) ((char *) s0 + shnum * shentsize); + s = (Elf_Shdr *) ((char *) s + shentsize)) + { +if (s->sh_type ==SHT_NOTE ) { + err =parse_note (elf, xi, s->sh_offset, s->sh_size); +if (err) + goto cleanup; + } + } + +if (xi->has_note) { + err =GRUB_ERR_NONE ; + goto cleanup; + } +for (s = s0; s < (Elf_Shdr *) ((char *) s0 + shnum * shentsize); s = (Elf_Shdr *) ((char *) s + shentsize)) {
Signature · 1 line
2.17.2
Quoted 9 lines · Marek Marczykowski-Górecki
Mirror behaviour of elf loader in libxc: first look for Xen notes in
PT_NOTEsegment, then inSHT_NOTEsection and only then fallback to a section with__xen_guestname.
This fixes loading PV kernels that Xen note have outside ofPT_NOTE. While this may be result of a buggy linker script, loading such kernel directly works fine, so make it work with grub too. Specifically, this applies to binaries built from Unikraft.Signed-off-by Marek Marczykowski-Górecki <[email protected]>
I treat this as a fix, so, Reviewed-by: Daniel Kiper <[email protected]>
However, ...
Quoted 9 lines
--- grub-core/loader/i386/xen_fileXX.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)grub-core/loader/i386/xen_fileXX.c +0
-0
grub-core/loader/i386/xen_fileXX.c grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) · line 350
Quoted 7 lines
grub-core/loader/i386/xen_fileXX.c +4
-0@@ -344,6 +344,21 @@ grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) s = (Elf_Shdr *) ((char *) s0 + elf->ehdr.ehdrXX.e_shstrndx * shentsize); stroff = s->sh_offset; +for (s = s0; s < (Elf_Shdr *) ((char *) s0 + shnum * shentsize); + s = (Elf_Shdr *) ((char *) s + shentsize)) + { +if (s->sh_type ==SHT_NOTE ) {
Curly bracket is in wrong place...
grub-core/loader/i386/xen_fileXX.c grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) · line 354
Quoted 4 lines
grub-core/loader/i386/xen_fileXX.c +4
-0+ err =parse_note (elf, xi, s->sh_offset, s->sh_size); +if (err) + goto cleanup; + }
... and this is also in wrong place.
grub-core/loader/i386/xen_fileXX.c grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) · line 360
Quoted 6 lines
grub-core/loader/i386/xen_fileXX.c +6
-0+ } + +if (xi->has_note) { + err =GRUB_ERR_NONE ; + goto cleanup; + }
Ditto. Next time please double check that you have correct formatting. Now I will fix it before the push. If there are no objections then it will happen at the beginning of next week.
Daniel
Quoted 48 lines · Daniel Kiper
Quoted 9 lines · Marek Marczykowski-Górecki
Mirror behaviour of elf loader in libxc: first look for Xen notes in
PT_NOTEsegment, then inSHT_NOTEsection and only then fallback to a section with__xen_guestname.
This fixes loading PV kernels that Xen note have outside ofPT_NOTE. While this may be result of a buggy linker script, loading such kernel directly works fine, so make it work with grub too. Specifically, this applies to binaries built from Unikraft.Signed-off-by Marek Marczykowski-Górecki <[email protected]>I treat this as a fix, so, Reviewed-by: Daniel Kiper <[email protected]>
However, ...
Quoted 9 lines
--- grub-core/loader/i386/xen_fileXX.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)grub-core/loader/i386/xen_fileXX.c +0
-0grub-core/loader/i386/xen_fileXX.c grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) · line 350
Quoted 7 lines
grub-core/loader/i386/xen_fileXX.c +4
-0@@ -344,6 +344,21 @@ grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) s = (Elf_Shdr *) ((char *) s0 + elf->ehdr.ehdrXX.e_shstrndx * shentsize); stroff = s->sh_offset; +for (s = s0; s < (Elf_Shdr *) ((char *) s0 + shnum * shentsize); + s = (Elf_Shdr *) ((char *) s + shentsize)) + { +if (s->sh_type ==SHT_NOTE ) {Curly bracket is in wrong place...
grub-core/loader/i386/xen_fileXX.c grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) · line 354
Quoted 4 lines
grub-core/loader/i386/xen_fileXX.c +4
-0+ err =parse_note (elf, xi, s->sh_offset, s->sh_size); +if (err) + goto cleanup; + }... and this is also in wrong place.
grub-core/loader/i386/xen_fileXX.c grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) · line 360
Quoted 6 lines
grub-core/loader/i386/xen_fileXX.c +6
-0+ } + +if (xi->has_note) { + err =GRUB_ERR_NONE ; + goto cleanup; + }
Quoted 3 lines
Ditto. Next time please double check that you have correct formatting. Now I will fix it before the push. If there are no objections then it will happen at the beginning of next week.
Thanks. This code style is very different than any other project I contribute to...
Anyway, there is a comment earlier in this function:
/* FIXME: check note. */
Is it about this very issue and now can be removed?
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
Quoted 49 lines · Marek Marczykowski-Górecki
Quoted 48 lines · Daniel Kiper
Quoted 9 lines · Marek Marczykowski-Górecki
Mirror behaviour of elf loader in libxc: first look for Xen notes in
PT_NOTEsegment, then inSHT_NOTEsection and only then fallback to a section with__xen_guestname.
This fixes loading PV kernels that Xen note have outside ofPT_NOTE. While this may be result of a buggy linker script, loading such kernel directly works fine, so make it work with grub too. Specifically, this applies to binaries built from Unikraft.Signed-off-by Marek Marczykowski-Górecki <[email protected]>I treat this as a fix, so, Reviewed-by: Daniel Kiper <[email protected]>
However, ...
Quoted 9 lines
--- grub-core/loader/i386/xen_fileXX.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)grub-core/loader/i386/xen_fileXX.c +0
-0grub-core/loader/i386/xen_fileXX.c grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) · line 350
Quoted 7 lines
grub-core/loader/i386/xen_fileXX.c +4
-0@@ -344,6 +344,21 @@ grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) s = (Elf_Shdr *) ((char *) s0 + elf->ehdr.ehdrXX.e_shstrndx * shentsize); stroff = s->sh_offset; +for (s = s0; s < (Elf_Shdr *) ((char *) s0 + shnum * shentsize); + s = (Elf_Shdr *) ((char *) s + shentsize)) + { +if (s->sh_type ==SHT_NOTE ) {Curly bracket is in wrong place...
grub-core/loader/i386/xen_fileXX.c grub_xen_get_infoXX (grub_elf_t elf, struct grub_xen_file_info *xi) · line 354
Quoted 4 lines
grub-core/loader/i386/xen_fileXX.c +4
-0+ err =parse_note (elf, xi, s->sh_offset, s->sh_size); +if (err) + goto cleanup; + }... and this is also in wrong place.
Quoted 6 lines
grub-core/loader/i386/xen_fileXX.c +6
-0+ } + +if (xi->has_note) { + err =GRUB_ERR_NONE ; + goto cleanup; + }
Quoted 6 lines
Quoted 3 lines
Ditto. Next time please double check that you have correct formatting. Now I will fix it before the push. If there are no objections then it will happen at the beginning of next week.
Thanks. This code style is very different than any other project I contribute to...
Yeah, I know how it works.
Quoted 5 lines
Anyway, there is a comment earlier in this function:
/* FIXME: check note. */Is it about this very issue and now can be removed?
Hmmm... I am not sure. I am not the author of this comment. I think that I would leave it as is if we are not sure.
Daniel