Add function sanity_check_page_desc(). This sanity checks an given entry of page descriptor table based on the conditions that are expected to hold in each filed, i.e.: - offset must be smaller than a file size of dump file. - size must not be 0 and equal to or smaller than a block size. - If size is equal to a block size, it means the page is not compressed and so flags must be 0. - If size is smaller than a block size, it means the page is compressed and so flags must hold any of compression flags. - page_flags must constantly be 0 because this field is unused. This will be later used to validate a single entry of page descriptor table when it is read in cache_page() and to validate a whole part of page descriptor table when --validate_kdump_headers command-line option is specified. --- diskdump.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/diskdump.c b/diskdump.c index a495120..2d2cf97 100644 --- a/diskdump.c +++ b/diskdump.c @@ -92,6 +92,7 @@ static void dump_note_offsets(FILE *); 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 *); /* For split dumpfile */ static struct diskdump_data **dd_list = NULL; @@ -3134,3 +3135,13 @@ out: FREEBUF(zram_buf); return len; } + +static int sanity_check_page_desc(page_desc_t *pd) +{ + return pd->offset < dd->stat.st_size && + pd->size && + pd->size <= dd->block_size && + ((pd->size == dd->block_size && pd->flags == 0) || + (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; +} -- 2.43.1 -- Crash-utility mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxxxxxx https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/ Contribution Guidelines: https://github.com/crash-utility/crash/wiki