print error when reading with unsupported compression

Resolves: bz2069200
Upstream: github.com/makedumpfile/makedumpfile.git
Conflicts: goto out_error --> return FALSE
	   due to missing 64b5b29 ("[PATCH 03/15] remove variable length
	   array in readpage_kdump_compressed()")

commit 5035c0821f07da3badda645cd0064d4b80e1667d
Author: Philipp Rudo <prudo@redhat.com>
Date:   Mon Mar 14 17:04:32 2022 +0100

    [PATCH] print error when reading with unsupported compression

    Currently makedumpfile only checks if the required compression algorithm
    was enabled during build when compressing a dump but not when reading
    from one. This can lead to situations where, one version of makedumpfile
    creates the dump using a compression algorithm an other version of
    makedumpfile doesn't support. When the second version now tries to, e.g.
    extract the dmesg from the dump it will fail with an error similar to

      # makedumpfile --dump-dmesg vmcore dmesg.txt
      __vtop4_x86_64: Can't get a valid pgd.
      readmem: Can't convert a virtual address(ffffffff92e18284) to physical address.
      readmem: type_addr: 0, addr:ffffffff92e18284, size:390
      check_release: Can't get the address of system_utsname.

      makedumpfile Failed.

    That's because readpage_kdump_compressed{_parallel} does not return
    with an error if the page it is trying to read is compressed with an
    unsupported compression algorithm. Thus readmem copies random data from
    the (uninitialized) cachebuf to its caller and thus causing the error
    above.

    Fix this by checking if the required compression algorithm is supported
    in readpage_kdump_compressed{_parallel} and print a proper error message
    if it isn't.

    Reported-by: Dave Wysochanski <dwysocha@redhat.com>
    Signed-off-by: Philipp Rudo <prudo@redhat.com>
    Reviewed-and-tested-by: Dave Wysochanski <dwysocha@redhat.com>
    Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>

Signed-off-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
Philipp Rudo 2022-03-28 18:13:48 +02:00
parent fb25c11f79
commit 7620d676de
2 changed files with 152 additions and 0 deletions

View File

@ -0,0 +1,150 @@
commit 5035c0821f07da3badda645cd0064d4b80e1667d
Author: Philipp Rudo <prudo@redhat.com>
Date: Mon Mar 14 17:04:32 2022 +0100
[PATCH] print error when reading with unsupported compression
Currently makedumpfile only checks if the required compression algorithm
was enabled during build when compressing a dump but not when reading
from one. This can lead to situations where, one version of makedumpfile
creates the dump using a compression algorithm an other version of
makedumpfile doesn't support. When the second version now tries to, e.g.
extract the dmesg from the dump it will fail with an error similar to
# makedumpfile --dump-dmesg vmcore dmesg.txt
__vtop4_x86_64: Can't get a valid pgd.
readmem: Can't convert a virtual address(ffffffff92e18284) to physical address.
readmem: type_addr: 0, addr:ffffffff92e18284, size:390
check_release: Can't get the address of system_utsname.
makedumpfile Failed.
That's because readpage_kdump_compressed{_parallel} does not return
with an error if the page it is trying to read is compressed with an
unsupported compression algorithm. Thus readmem copies random data from
the (uninitialized) cachebuf to its caller and thus causing the error
above.
Fix this by checking if the required compression algorithm is supported
in readpage_kdump_compressed{_parallel} and print a proper error message
if it isn't.
Reported-by: Dave Wysochanski <dwysocha@redhat.com>
Signed-off-by: Philipp Rudo <prudo@redhat.com>
Reviewed-and-tested-by: Dave Wysochanski <dwysocha@redhat.com>
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
diff --git a/makedumpfile-1.7.0/makedumpfile.c b/makedumpfile-1.7.0/makedumpfile.c
index 2b94446b8f2ad513da060e15821544ae32e1a2c6..14556db15627617cb394bba85bb7ebec6b35fb34 100644
--- a/makedumpfile-1.7.0/makedumpfile.c
+++ b/makedumpfile-1.7.0/makedumpfile.c
@@ -865,9 +865,13 @@ readpage_kdump_compressed(unsigned long long paddr, void *bufptr)
ERRMSG("Uncompress failed: %d\n", ret);
return FALSE;
}
+ } else if ((pd.flags & DUMP_DH_COMPRESSED_LZO)) {
#ifdef USELZO
- } else if (info->flag_lzo_support
- && (pd.flags & DUMP_DH_COMPRESSED_LZO)) {
+ if (!info->flag_lzo_support) {
+ ERRMSG("lzo compression unsupported\n");
+ return FALSE;
+ }
+
retlen = info->page_size;
ret = lzo1x_decompress_safe((unsigned char *)buf, pd.size,
(unsigned char *)bufptr, &retlen,
@@ -876,9 +880,13 @@ readpage_kdump_compressed(unsigned long long paddr, void *bufptr)
ERRMSG("Uncompress failed: %d\n", ret);
return FALSE;
}
+#else
+ ERRMSG("lzo compression unsupported\n");
+ ERRMSG("Try `make USELZO=on` when building.\n");
+ return FALSE;
#endif
-#ifdef USESNAPPY
} else if ((pd.flags & DUMP_DH_COMPRESSED_SNAPPY)) {
+#ifdef USESNAPPY
ret = snappy_uncompressed_length(buf, pd.size, (size_t *)&retlen);
if (ret != SNAPPY_OK) {
@@ -891,14 +899,22 @@ readpage_kdump_compressed(unsigned long long paddr, void *bufptr)
ERRMSG("Uncompress failed: %d\n", ret);
return FALSE;
}
+#else
+ ERRMSG("snappy compression unsupported\n");
+ ERRMSG("Try `make USESNAPPY=on` when building.\n");
+ return FALSE;
#endif
-#ifdef USEZSTD
} else if ((pd.flags & DUMP_DH_COMPRESSED_ZSTD)) {
+#ifdef USEZSTD
ret = ZSTD_decompress(bufptr, info->page_size, buf, pd.size);
if (ZSTD_isError(ret) || (ret != info->page_size)) {
ERRMSG("Uncompress failed: %d\n", ret);
return FALSE;
}
+#else
+ ERRMSG("zstd compression unsupported\n");
+ ERRMSG("Try `make USEZSTD=on` when building.\n");
+ return FALSE;
#endif
}
@@ -964,9 +980,13 @@ readpage_kdump_compressed_parallel(int fd_memory, unsigned long long paddr,
ERRMSG("Uncompress failed: %d\n", ret);
return FALSE;
}
+ } else if ((pd.flags & DUMP_DH_COMPRESSED_LZO)) {
#ifdef USELZO
- } else if (info->flag_lzo_support
- && (pd.flags & DUMP_DH_COMPRESSED_LZO)) {
+ if (!info->flag_lzo_support) {
+ ERRMSG("lzo compression unsupported\n");
+ return FALSE;
+ }
+
retlen = info->page_size;
ret = lzo1x_decompress_safe((unsigned char *)buf, pd.size,
(unsigned char *)bufptr, &retlen,
@@ -975,9 +995,13 @@ readpage_kdump_compressed_parallel(int fd_memory, unsigned long long paddr,
ERRMSG("Uncompress failed: %d\n", ret);
return FALSE;
}
+#else
+ ERRMSG("lzo compression unsupported\n");
+ ERRMSG("Try `make USELZO=on` when building.\n");
+ return FALSE;
#endif
-#ifdef USESNAPPY
} else if ((pd.flags & DUMP_DH_COMPRESSED_SNAPPY)) {
+#ifdef USESNAPPY
ret = snappy_uncompressed_length(buf, pd.size, (size_t *)&retlen);
if (ret != SNAPPY_OK) {
@@ -990,14 +1014,22 @@ readpage_kdump_compressed_parallel(int fd_memory, unsigned long long paddr,
ERRMSG("Uncompress failed: %d\n", ret);
return FALSE;
}
+#else
+ ERRMSG("snappy compression unsupported\n");
+ ERRMSG("Try `make USESNAPPY=on` when building.\n");
+ return FALSE;
#endif
-#ifdef USEZSTD
} else if ((pd.flags & DUMP_DH_COMPRESSED_ZSTD)) {
+#ifdef USEZSTD
ret = ZSTD_decompress(bufptr, info->page_size, buf, pd.size);
if (ZSTD_isError(ret) || (ret != info->page_size)) {
ERRMSG("Uncompress failed: %d\n", ret);
return FALSE;
}
+#else
+ ERRMSG("zstd compression unsupported\n");
+ ERRMSG("Try `make USEZSTD=on` when building.\n");
+ return FALSE;
#endif
}

View File

@ -116,6 +116,7 @@ Patch602: ./kexec-tools-2.0.23-makedumpfile-sadump-kaslr-fix-failure-of-calculat
Patch603: ./kexec-tools-2.0.23-01-_PATCH_v2_1_3_add_generic_cycle_detection.patch
Patch604: ./kexec-tools-2.0.23-02-_PATCH_v2_2_3_use_pointer_arithmetics_for_dump_dmesg.patch
Patch605: ./kexec-tools-2.0.23-03-_PATCH_v2_3_3_use_cycle_detection_when_parsing_the_prink_log_buf.patch
Patch606: ./kexec-tools-2.0.23-04-_PATCH_print_error_when_reading_with_unsupported_compression.patch
%description
kexec-tools provides /sbin/kexec binary that facilitates a new
@ -136,6 +137,7 @@ tar -z -x -v -f %{SOURCE19}
%patch603 -p1
%patch604 -p1
%patch605 -p1
%patch606 -p1
%ifarch ppc
%define archdef ARCH=ppc