Skip to contentSkip to conversation

makedumpfile: make reserve_diskspace do nothing for flattened format

PATCH In review Jiri Bohac 3 participants 3 messages Jun 19, 2024 – Aug 6, 2024

Subsystems (2)
lore
Share & tools
lore

Jiri Bohac

author
#0 lore raw

PATCH 1/1 makedumpfile: make reserve_diskspace do nothing for flattened format

makedumpfile: make reserve_diskspace do nothing for flattened format

reserve_diskspace() is called by write_elf_header() to make sure there is always space to write the program header, even if writing other data fails because of ENOSPC.

This is harmful when writing the flattened format to STDOUT for two reasons:

First, it actually wastes disk space, because first the block of zeroes is sent to STDOUT by reserve_diskspace() and then the actual program header is sent, meant to overwrite the zeroes when the flattened format is rearranged.

Second, the algorithm used to read flattened format directly by the crash program does not cope with the flattened file containing two chunks meant for the same offset. It uses a binary search on a sorted array of flat_data headers to find the data in the flat file. It may return the zeroed chunk written by reserve_diskspace() near the beginning of the file instead of the actual ELF header located near the end of the flattened file.

Fixes e39216fce9f73759509ec158e39c289e6c211125 ("Make the incomplete dumpfile generated by ENOSPC error analyzable.")
---
 makedumpfile.c | 3 +++
 1 file changed, 3 insertions(+)
makedumpfile.c +3 -0
index cadc596..9624c3f 100644
@@ -5206,6 +5206,9 @@ reserve_diskspace(int fd, off_t start_offset, off_t end_offset, char *file_name)
 
 	int ret = FALSE;
 
+	if (info->flag_flatten)
+		return TRUE;
+
 	assert(start_offset < end_offset);
 	buf_size = end_offset - start_offset;
 
Signature · 11 lines
2.43.0

-- 
Jiri Bohac <[email protected]>
SUSE Labs, Prague, Czechia


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

Hi Jiri,

sorry for the long delay.

Quoted 12 lines · Jiri Bohac

makedumpfile: make reserve_diskspace do nothing for flattened format

reserve_diskspace() is called by write_elf_header() to make sure there is always space to write the program header, even if writing other data fails because of ENOSPC.

This is harmful when writing the flattened format to STDOUT for two reasons:

First, it actually wastes disk space, because first the block of zeroes is sent to STDOUT by reserve_diskspace() and then the actual program header is sent, meant to overwrite the zeroes when the flattened format is rearranged.

Quoted 6 lines

Second, the algorithm used to read flattened format directly by the crash program does not cope with the flattened file containing two chunks meant for the same offset. It uses a binary search on a sorted array of flat_data headers to find the data in the flat file. It may return the zeroed chunk written by reserve_diskspace() near the beginning of the file instead of the actual ELF header located near the end of the flattened file.

Thank you for the patch, I found a vmcore that reproduced the issue:

$ makedumpfile -FEd 31 vmcore > dump.FEd31
$ crash vmlinux dump.FEd31
...
realloc: No such file or directory
cannot realloc resized ELF header buffer
$

and the patch fixed this, so

(Masa will apply the patch, please wait for a while.)

Thanks,
Kazu

Quoted 13 lines
Fixes e39216fce9f73759509ec158e39c289e6c211125 ("Make the incomplete dumpfile generated by ENOSPC error analyzable.")
---
  makedumpfile.c | 3 +++
  1 file changed, 3 insertions(+)
makedumpfile.c +0 -0
index cadc596..9624c3f 100644

makedumpfile.c reserve_diskspace(int fd, off_t start_offset, off_t end_offset, char *file_name) · line 5214

Quoted 9 lines
makedumpfile.c +3 -0
@@ -5206,6 +5206,9 @@ reserve_diskspace(int fd, off_t start_offset, off_t end_offset, char *file_name)
 
  	int ret = FALSE;
 
+	if (info->flag_flatten)
+		return TRUE;
+
  	assert(start_offset < end_offset);
  	buf_size = end_offset - start_offset;
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw
Quoted 55 lines · HAGIO KAZUHITO(萩尾 一仁)

Hi Jiri,

sorry for the long delay.

Quoted 12 lines · Jiri Bohac

makedumpfile: make reserve_diskspace do nothing for flattened format

reserve_diskspace() is called by write_elf_header() to make sure there is always space to write the program header, even if writing other data fails because of ENOSPC.

This is harmful when writing the flattened format to STDOUT for two reasons:

First, it actually wastes disk space, because first the block of zeroes is sent to STDOUT by reserve_diskspace() and then the actual program header is sent, meant to overwrite the zeroes when the flattened format is rearranged.

Quoted 6 lines

Second, the algorithm used to read flattened format directly by the crash program does not cope with the flattened file containing two chunks meant for the same offset. It uses a binary search on a sorted array of flat_data headers to find the data in the flat file. It may return the zeroed chunk written by reserve_diskspace() near the beginning of the file instead of the actual ELF header located near the end of the flattened file.

Thank you for the patch, I found a vmcore that reproduced the issue:

$ makedumpfile -FEd 31 vmcore > dump.FEd31
$ crash vmlinux dump.FEd31
...
realloc: No such file or directory
cannot realloc resized ELF header buffer
$

and the patch fixed this, so

(Masa will apply the patch, please wait for a while.)

Thanks,
Kazu

Quoted 13 lines
Fixes e39216fce9f73759509ec158e39c289e6c211125 ("Make the incomplete dumpfile generated by ENOSPC error analyzable.")
---
   makedumpfile.c | 3 +++
   1 file changed, 3 insertions(+)
makedumpfile.c +0 -0
index cadc596..9624c3f 100644
@@ -5206,6 +5206,9 @@ reserve_diskspace(int fd, off_t start_offset, off_t end_offset, char *file_name)
 
Quoted 8 lines

makedumpfile.c reserve_diskspace(int fd, off_t start_offset, off_t end_offset, char *file_name) · line 5214

Quoted 8 lines
makedumpfile.c +3 -0
   	int ret = FALSE;
 
+	if (info->flag_flatten)
+		return TRUE;
+
   	assert(start_offset < end_offset);
   	buf_size = end_offset - start_offset;
 

Thank you, Jiri, for the patch. Sorry for the late apply the patch.

https://github.com/makedumpfile/makedumpfile/commit/c76301277552b95b613ffe9d5a211d01df73bd79

Thanks,
Masa
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec