From bdad106ad1037600440e59c2462a457f3615e9d4 Mon Sep 17 00:00:00 2001 From: Boris Mittelberg Date: Mon, 24 Oct 2022 17:21:32 -0700 Subject: panic output: remove assert Remove assert to avoid nested panic while getting panic info. Truncate panic data to maximal supported size. BRANCH=none BUG=b:254485444 TEST=./twister -p native_posix -p unit_testing --coverage Signed-off-by: Boris Mittelberg Change-Id: Ibcf3c0244b159578b6c51c80eec23453522059df Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3975601 Reviewed-by: Ricardo Quesada Code-Coverage: Zoss (cherry picked from commit 0a031be7f2ca6b9f11f0085cb22960d7780ee4a4) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4329105 Reviewed-by: Daisuke Nojiri Reviewed-by: caveh jalali --- common/panic_output.c | 14 +++++++++++--- include/panic.h | 2 ++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/common/panic_output.c b/common/panic_output.c index e6b48a375d..06b2b7e51e 100644 --- a/common/panic_output.c +++ b/common/panic_output.c @@ -229,10 +229,18 @@ DECLARE_CONSOLE_COMMAND(panicinfo, command_panicinfo, int host_command_panic_info(struct host_cmd_handler_args *args) { + uint32_t pdata_size = pdata_ptr->struct_size; + if (pdata_ptr->magic == PANIC_DATA_MAGIC) { - ASSERT(pdata_ptr->struct_size <= args->response_max); - memcpy(args->response, pdata_ptr, pdata_ptr->struct_size); - args->response_size = pdata_ptr->struct_size; + if (pdata_size > args->response_max) { + panic_printf("Panic data size %d is too " + "large, truncating to %d\n", + pdata_size, args->response_max); + pdata_size = args->response_max; + pdata_ptr->flags |= PANIC_DATA_FLAG_TRUNCATED; + } + memcpy(args->response, pdata_ptr, pdata_size); + args->response_size = pdata_size; /* Data has now been returned */ pdata_ptr->flags |= PANIC_DATA_FLAG_OLD_HOSTCMD; diff --git a/include/panic.h b/include/panic.h index 8a689c4b23..f3910b70ca 100644 --- a/include/panic.h +++ b/include/panic.h @@ -81,6 +81,8 @@ enum panic_arch { #define PANIC_DATA_FLAG_OLD_HOSTCMD (1 << 2) /* Already reported via host event */ #define PANIC_DATA_FLAG_OLD_HOSTEVENT (1 << 3) +/* The data was truncated to fit panic info host cmd */ +#define PANIC_DATA_FLAG_TRUNCATED (1 << 4) /** * Write a string to the panic reporting device -- cgit v1.2.1