dump: Fix writing of ELF section
PATCH 1/1 dump: Fix writing of ELF section
In write_elf_section() we set the 'shdr' pointer to point to local structures shdr32 or shdr64, which we fill in to be written out to the ELF dump. Unfortunately the address we pass to fd_write_vmcore() has a spurious '&' operator, so instead of writing out the section header we write out the literal pointer value followed by whatever is on the stack after the 'shdr' local variable.
Pass the correct address into fd_write_vmcore().
---
I have not tested this because I can't reproduce the conditions under which we try to actually use write_elf_section() (they must be rare, because currently we produce a bogus ELF file for this code path). In dump_init() s->list.num must be at least UINT16_MAX-1, which I think means it has to be a paging-enabled dump and the guest's page table must be extremely fragmented ?
--- dump/dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
dump/dump.c +1 -1
@@ -364,7 +364,7 @@ static void write_elf_section(DumpState *s, int type, Error **errp) shdr = &shdr64; } - ret =fd_write_vmcore (&shdr, shdr_size, s); + ret =fd_write_vmcore (shdr, shdr_size, s);if (ret <0 ) {error_setg_errno (errp, -ret,"dump: failed to write section header table" );
Signature · 1 line
2.20.1
Quoted 28 lines · Peter Maydell
In
write_elf_section()we set the 'shdr' pointer to point to local structures shdr32 or shdr64, which we fill in to be written out to the ELF dump. Unfortunately the address we pass tofd_write_vmcore()has a spurious '&' operator, so instead of writing out the section header we write out the literal pointer value followed by whatever is on the stack after the 'shdr' local variable.Pass the correct address into
fd_write_vmcore().Signed-off-by Peter Maydell <[email protected]>---
I have not tested this because I can't reproduce the conditions under which we try to actually usewrite_elf_section()(they must be rare, because currently we produce a bogus ELF file for this code path). Indump_init()s->list.nummust be at least UINT16_MAX-1, which I think means it has to be a paging-enabled dump and the guest's page table must be extremely fragmented ?--- dump/dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)dump/dump.c +0
-0
dump/dump.c static void write_elf_section(DumpState *s, int type, Error **errp) · line 370
Quoted 8 lines
dump/dump.c +1
-1@@ -364,7 +364,7 @@ static void write_elf_section(DumpState *s, int type, Error **errp) shdr = &shdr64; } - ret =fd_write_vmcore (&shdr, shdr_size, s); + ret =fd_write_vmcore (shdr, shdr_size, s);if (ret <0 ) {error_setg_errno (errp, -ret,"dump: failed to write section header table" );
Just realized this probably merits
Cc: [email protected]
thanks
-- PMM
Hi
Quoted 11 lines · Peter Maydell
In
write_elf_section()we set the 'shdr' pointer to point to local structures shdr32 or shdr64, which we fill in to be written out to the ELF dump. Unfortunately the address we pass tofd_write_vmcore()has a spurious '&' operator, so instead of writing out the section header we write out the literal pointer value followed by whatever is on the stack after the 'shdr' local variable.Pass the correct address into
fd_write_vmcore().Signed-off-by Peter Maydell <[email protected]>
Quoted 8 lines
---
I have not tested this because I can't reproduce the conditions under which we try to actually usewrite_elf_section()(they must be rare, because currently we produce a bogus ELF file for this code path). Indump_init()s->list.nummust be at least UINT16_MAX-1, which I think means it has to be a paging-enabled dump and the guest's page table must be extremely fragmented ?
yeah, I can't help either without spending more time playing with it, but the fix looks good nonetheless.
Quoted 20 lines
--- dump/dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)dump/dump.c +1
-2@@ -364,7 +364,7 @@ static void write_elf_section(DumpState *s, int type, Error **errp) shdr = &shdr64; } - ret =fd_write_vmcore (&shdr, shdr_size, s); + ret =fd_write_vmcore (shdr, shdr_size, s);if (ret <0 ) {error_setg_errno (errp, -ret,"dump: failed to write section header table" ); --2.20.1
Quoted 12 lines · Marc-André Lureau
Hi
Quoted 8 lines · Peter Maydell
In
write_elf_section()we set the 'shdr' pointer to point to local structures shdr32 or shdr64, which we fill in to be written out to the ELF dump. Unfortunately the address we pass tofd_write_vmcore()has a spurious '&' operator, so instead of writing out the section header we write out the literal pointer value followed by whatever is on the stack after the 'shdr' local variable.
Quoted 5 lines
Quoted 3 lines
Pass the correct address into
fd_write_vmcore().Signed-off-by Peter Maydell <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>
Thanks for the review; since nobody else has picked the patch up I'll put it in via target-arm.next just for convenience.
-- PMM
Quoted 6 lines · Peter Maydell
In
write_elf_section()we set the 'shdr' pointer to point to local structures shdr32 or shdr64, which we fill in to be written out to the ELF dump. Unfortunately the address we pass tofd_write_vmcore()has a spurious '&' operator, so instead of writing out the section header we write out the literal pointer value followed by whatever is on the stack after the 'shdr' local variable.
How did you notice this? While reviewing around?
Quoted 30 lines
Pass the correct address into
fd_write_vmcore().Signed-off-by Peter Maydell <[email protected]>---
I have not tested this because I can't reproduce the conditions under which we try to actually usewrite_elf_section()(they must be rare, because currently we produce a bogus ELF file for this code path). Indump_init()s->list.nummust be at least UINT16_MAX-1, which I think means it has to be a paging-enabled dump and the guest's page table must be extremely fragmented ?--- dump/dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)dump/dump.c +1
-1@@ -364,7 +364,7 @@ static void write_elf_section(DumpState *s, int type, Error **errp) shdr = &shdr64; } - ret =fd_write_vmcore (&shdr, shdr_size, s); + ret =fd_write_vmcore (shdr, shdr_size, s);if (ret <0 ) {error_setg_errno (errp, -ret,"dump: failed to write section header table" );
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Peter Maydell
In
write_elf_section()we set the 'shdr' pointer to point to local structures shdr32 or shdr64, which we fill in to be written out to the ELF dump. Unfortunately the address we pass tofd_write_vmcore()has a spurious '&' operator, so instead of writing out the section header we write out the literal pointer value followed by whatever is on the stack after the 'shdr' local variable.How did you notice this? While reviewing around?
Coverity, but I forgot to quote the CID in the commit message.
-- PMM
I forgot to cc qemu-stable, so doing that now (I've also added the
Cc: tag to the commit message for when I send this in the target-arm pullreq today); for the record, the Coverity id is CID 1421970 (also added to the commit message).
thanks
-- PMM
Quoted 39 lines · Peter Maydell
In
write_elf_section()we set the 'shdr' pointer to point to local structures shdr32 or shdr64, which we fill in to be written out to the ELF dump. Unfortunately the address we pass tofd_write_vmcore()has a spurious '&' operator, so instead of writing out the section header we write out the literal pointer value followed by whatever is on the stack after the 'shdr' local variable.Pass the correct address into
fd_write_vmcore().Signed-off-by Peter Maydell <[email protected]>---
I have not tested this because I can't reproduce the conditions under which we try to actually usewrite_elf_section()(they must be rare, because currently we produce a bogus ELF file for this code path). Indump_init()s->list.nummust be at least UINT16_MAX-1, which I think means it has to be a paging-enabled dump and the guest's page table must be extremely fragmented ?--- dump/dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)dump/dump.c +1
-2@@ -364,7 +364,7 @@ static void write_elf_section(DumpState *s, int type, Error **errp) shdr = &shdr64; } - ret =fd_write_vmcore (&shdr, shdr_size, s); + ret =fd_write_vmcore (shdr, shdr_size, s);if (ret <0 ) {error_setg_errno (errp, -ret,"dump: failed to write section header table" ); --2.20.1