From e6eef9b67267fba407eb59e1e3010a94e6b4fda5 Mon Sep 17 00:00:00 2001 From: Yonghua Huang Date: Mon, 17 Jun 2019 18:46:50 +0800 Subject: [PATCH] dm: refine 'assert' usage in pm.c and acpi.c 'assert' usage cleanup to avoid possible software vulnerabilities Tracked-On: #3252 Signed-off-by: Yonghua Huang Reviewed-by: Shuo A Liu --- devicemodel/arch/x86/pm.c | 19 +++++-------------- devicemodel/hw/platform/acpi/acpi.c | 5 ++--- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/devicemodel/arch/x86/pm.c b/devicemodel/arch/x86/pm.c index d9ad99adf..878733aa4 100644 --- a/devicemodel/arch/x86/pm.c +++ b/devicemodel/arch/x86/pm.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -69,7 +68,6 @@ static int reset_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) { - int error; static uint8_t reset_control; if (bytes != 1) @@ -81,14 +79,12 @@ reset_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, if (*eax & 0x8) { fprintf(stderr, "full reset\r\n"); - error = vm_suspend(ctx, VM_SUSPEND_FULL_RESET); - assert(error ==0 || errno == EALREADY); + vm_suspend(ctx, VM_SUSPEND_FULL_RESET); mevent_notify(); reset_control = 0; } else if (*eax & 0x4) { fprintf(stderr, "system reset\r\n"); - error = vm_suspend(ctx, VM_SUSPEND_SYSTEM_RESET); - assert(error ==0 || errno == EALREADY); + vm_suspend(ctx, VM_SUSPEND_SYSTEM_RESET); mevent_notify(); } } @@ -279,8 +275,6 @@ static int pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) { - int error; - if (bytes != 2) return -1; if (in) @@ -300,13 +294,11 @@ pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, */ if (*eax & VIRTUAL_PM1A_SLP_EN) { if ((pm1_control & VIRTUAL_PM1A_SLP_TYP) >> 10 == 5) { - error = vm_suspend(ctx, VM_SUSPEND_POWEROFF); - assert(error == 0 || errno == EALREADY); + vm_suspend(ctx, VM_SUSPEND_POWEROFF); } if ((pm1_control & VIRTUAL_PM1A_SLP_TYP) >> 10 == 3) { - error = vm_suspend(ctx, VM_SUSPEND_SUSPEND); - assert(error == 0 || errno == EALREADY); + vm_suspend(ctx, VM_SUSPEND_SUSPEND); } } } @@ -452,8 +444,7 @@ static int smi_cmd_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) { - assert(!in); - if (bytes != 1) + if (in || (bytes != 1)) return -1; pthread_mutex_lock(&pm_lock); diff --git a/devicemodel/hw/platform/acpi/acpi.c b/devicemodel/hw/platform/acpi/acpi.c index c133982c9..cec1d30cc 100644 --- a/devicemodel/hw/platform/acpi/acpi.c +++ b/devicemodel/hw/platform/acpi/acpi.c @@ -857,14 +857,13 @@ void dsdt_indent(int levels) { dsdt_indent_level += levels; - assert(dsdt_indent_level >= 0); } void dsdt_unindent(int levels) { - assert(dsdt_indent_level >= levels); - dsdt_indent_level -= levels; + if (dsdt_indent_level >= levels) + dsdt_indent_level -= levels; } void