From 6e42c527d7c22f0749b2c8466e249020f761e619 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Wed, 9 Nov 2022 18:06:11 +0000 Subject: [PATCH] zdump: pv_process_pglist: convert assertions into errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Corrupted dumps might have invalid page states. Therefore, let's convert the assertions into errors. Fixes: 8fa1b5a00b9c ("zdump: dfi: add support to read Protected Virtualization dumps") Signed-off-by: Marc Hartmayer Reviewed-by: Steffen Eiden Signed-off-by: Jan Höppner --- zdump/pv_utils.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/zdump/pv_utils.c b/zdump/pv_utils.c index 3c287689..43616534 100644 --- a/zdump/pv_utils.c +++ b/zdump/pv_utils.c @@ -608,14 +608,26 @@ ssize_t pv_process_pglist(pv_crypto_ctx_t *ctx, BIO *output, return -1; } } - g_assert(!(page_state & ~PV_ZERO_PAGE)); + if (page_state & ~PV_ZERO_PAGE) { + g_set_error(error, ZDUMP_PV_UTILS_ERROR, + ZDUMP_ERR_PGLIST_INVAL_STATE, + _("Invalid page state. page-idx: %#lx, state: %#lx"), + page_idx, page_state); + return -1; + } continue; } if (page_state & PV_SHARED_PAGE) { /* shared pages are not encrypted */ input = ctx->input; - g_assert(!(page_state & ~PV_SHARED_PAGE)); + if (page_state & ~PV_SHARED_PAGE) { + g_set_error(error, ZDUMP_PV_UTILS_ERROR, + ZDUMP_ERR_PGLIST_INVAL_STATE, + _("Invalid page state. page-idx: %#lx, state: %#lx"), + page_idx, page_state); + return -1; + } } else if (page_state & PV_ENCRYPTED_PAGE) { input = ctx->filter; calculate_tweak(tweak_comp, ctx->nonce, &ctx->tweak_scratch); @@ -624,7 +636,13 @@ ssize_t pv_process_pglist(pv_crypto_ctx_t *ctx, BIO *output, if (update_tweak(ctx, error) < 0) return -1; - g_assert(!(page_state & ~PV_ENCRYPTED_PAGE)); + if (page_state & ~PV_ENCRYPTED_PAGE) { + g_set_error(error, ZDUMP_PV_UTILS_ERROR, + ZDUMP_ERR_PGLIST_INVAL_STATE, + _("Invalid page state. page-idx: %#lx, state: %#lx"), + page_idx, page_state); + return -1; + } } else { g_set_error(error, ZDUMP_PV_UTILS_ERROR, ZDUMP_ERR_PGLIST_INVAL_STATE, _("Invalid page state. page-idx: %#lx, state: %#lx"), page_idx,