[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Crash-utility] add support for incomplete elf dump file



Hello Dave,

On 10/22/2014 09:49 PM, Dave Anderson wrote:

Hello Wenjian,

First -- please send patches as email attachments.  Even if I cut-and-paste your
patch from the crash-utility archives (which normally works), there are
still no tabs in your patch.

Appreciate your suggestion.

Now, with respect to the patch, it's not clear to me what would happen if you
make no changes to check_dumpfile_size()?

It seems to me that a read error would occur regardless whether you change
the PT_LOAD-related contents or not.

If no changes are made:

   If a readmem() of a truncated page is attempted, read_netdump() would
   calculate an offset based upon the original PT_LOAD contents, but then
   the subsequent read() would fail, and would return a READ_ERROR.

If your patch is applied:

   If a readmem() of a truncated page is attempted, read_netdump() would not
   be able to calculate an offset, and would return a READ_ERROR.

What's the difference?  Why even bother making the changes?

If my patch is applied:
	If a readmem() of a truncated page is attempted,

	(pls->zero_fill && (paddr >= pls->phys_end) && (paddr < pls->zero_fill))
	
	,this will be right. So read_netdump() will fill bufptr with zero and
	return cnt.

In my patch, information of PT_LOAD segment is modified, so that the segment will
not go beyond the file size. And use zero to replace the lost part.

Previously, we intend to do this work in makedumpfile by modifying the PT_LOAD
header of the ELF dump file. But kumagai atsushi thought it's not good to make the
irreversible change. So we think do it in crash maybe a better choice.

I also don't understand what the difference between "truncated" and "incomplete"
is?  Why did you separate the messages into two?

At first, I thought the difference is the incomplete flag.
Now, I think it's not necessary to distinguish them.


Anyway, I had already created a patch in preparation for the changes to
makedumpfile for ELF and compressed kdump vmcores.  The patch will apply
to the current github master branch.  Please apply it alone, and tell me
what happens.

The patch can show the incomplete information, but will be interrupted by the
READ_ERROR (we don't change the PT_LOAD headers in makedumpfile any more).


Thanks
Zhou Wenjian

diff --git a/netdump.c b/netdump.c
index abc85e0..ef2c839 100644
--- a/netdump.c
+++ b/netdump.c
@@ -488,6 +488,10 @@ check_dumpfile_size(char *file)
 	if (stat64(file, &stat) < 0)
 		return;
 
+	Elf64_Phdr *load64 = nd->load64;
+	Elf32_Phdr *load32 = nd->load32;
+	unsigned int e_flag = (NULL == nd->elf64) ? (nd->elf32)->e_flags : (nd->elf64)->e_flags;
+	int status = e_flag & DUMP_ELF_INCOMPLETE;
 	for (i = 0; i < nd->num_pt_load_segments; i++) {
 		pls = &nd->pt_load_segments[i];
 
@@ -495,16 +499,35 @@ check_dumpfile_size(char *file)
 			(pls->phys_end - pls->phys_start);
 
 		if (segment_end > stat.st_size) {
-			error(WARNING, "%s: may be truncated or incomplete\n"
-				"         PT_LOAD p_offset: %lld\n"
-				"                 p_filesz: %lld\n"
-				"           bytes required: %lld\n"
-				"            dumpfile size: %lld\n\n",
-				file, pls->file_offset, 
-				pls->phys_end - pls->phys_start,  
-				segment_end, stat.st_size);
-			return;
+			if (!status){
+				error(WARNING, "%s: may be truncated or incomplete\n"
+					"         PT_LOAD p_offset: %lld\n"
+					"                 p_filesz: %lld\n"
+					"           bytes required: %lld\n"
+					"            dumpfile size: %lld\n\n",
+					file, pls->file_offset,
+					pls->phys_end - pls->phys_start,
+					segment_end, stat.st_size);
+				return;
+			}
+	                if (pls->file_offset > stat.st_size){
+				pls->file_offset = 0;
+				pls->phys_start = 0;
+				pls->phys_end = 0;
+			}
+			else {
+				if (NULL == load32)
+					load64->p_filesz = stat.st_size - pls->file_offset;
+				else
+					load32->p_filesz = stat.st_size - pls->file_offset;
+				pls->zero_fill = pls->phys_end;
+				pls->phys_end = stat.st_size - pls->file_offset + pls->phys_start;
+			}
 		}
+		if (NULL == load32)
+			load64++;
+		else
+			load32++;
 	}
 }
 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]