Add function check_kdump_headers() that validates page descriptor
table. This function is intended to be called when
--validate_kdump_headers command-line option is specified.
While the function name says checking kdump headers, current
implementation checks only page descriptor table. This is to keep the
implementation simple in the first discussion. The implementation can
later be extended if necessary.
Also the current implementation covers only a single dump file in the
header version 6 or later. Split dump files and other header version
are going to be covered in later versions of this patch set.
---
diskdump.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/diskdump.c b/diskdump.c
index 2d2cf97..5084b0d 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -93,6 +93,7 @@ static char *vmcoreinfo_read_string(const char *);
static void diskdump_get_osrelease(void);
static int valid_note_address(unsigned char *);
static int sanity_check_page_desc(page_desc_t *);
+static void check_kdump_headers(void);
/* For split dumpfile */
static struct diskdump_data **dd_list = NULL;
@@ -3145,3 +3146,39 @@ static int sanity_check_page_desc(page_desc_t *pd)
(pd->size < dd->block_size && pd->flags &
(DUMP_DH_COMPRESSED_ZLIB|DUMP_DH_COMPRESSED_LZO|DUMP_DH_COMPRESSED_SNAPPY|DUMP_DH_COMPRESSED_ZSTD)))
&&
pd->page_flags == 0;
}
+
+static void check_kdump_headers(void)
+{
+ ulong pfn, desc_pos;
+ off_t seek_offset;
+ page_desc_t pd;
+ int valid, ret;
+
+ if (CRASHDEBUG(1))
+ error(INFO, "pfn offset size flags page_flags\n");
+
+ for (pfn = 0;
+ pfn < dd->sub_header_kdump->max_mapnr_64;
+ pfn++) {
+ if (!page_is_dumpable(pfn))
+ continue;
+
+ desc_pos = pfn_to_pos(pfn);
+ seek_offset = dd->data_offset
+ + (off_t)(desc_pos - 1)*sizeof(page_desc_t);
+ ret = read_pd(dd->dfd, seek_offset, &pd);
+ if (ret)
+ return;
+
+ if (!sanity_check_page_desc(&pd)) {
+ if (CRASHDEBUG(1))
+ error(INFO,
+ "%lu %lu %u %08x %016lx\n",
+ pfn,
+ pd.offset,
+ pd.size,
+ pd.flags,
+ pd.page_flags);
+ }
+ }
+}
--
2.43.1