mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-23 14:07:42 +00:00
dm: cleanup 'assert' for guest software loading module
cleanup 'assert' to avoid possible vulnerabilities. Tracked-On: #3252 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
This commit is contained in:
parent
0e046c7a0a
commit
ec626482d2
@ -121,7 +121,7 @@ acrn_parse_bootargs(char *arg)
|
|||||||
with_bootargs = 1;
|
with_bootargs = 1;
|
||||||
printf("SW_LOAD: get bootargs %s\n", bootargs);
|
printf("SW_LOAD: get bootargs %s\n", bootargs);
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,8 +222,6 @@ acrn_create_e820_table(struct vmctx *ctx, struct e820_entry *e820)
|
|||||||
uint32_t removed = 0, k;
|
uint32_t removed = 0, k;
|
||||||
|
|
||||||
memcpy(e820, e820_default_entries, sizeof(e820_default_entries));
|
memcpy(e820, e820_default_entries, sizeof(e820_default_entries));
|
||||||
|
|
||||||
assert(ctx->lowmem > e820[LOWRAM_E820_ENTRY].baseaddr);
|
|
||||||
e820[LOWRAM_E820_ENTRY].length = ctx->lowmem -
|
e820[LOWRAM_E820_ENTRY].length = ctx->lowmem -
|
||||||
e820[LOWRAM_E820_ENTRY].baseaddr;
|
e820[LOWRAM_E820_ENTRY].baseaddr;
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <elf.h>
|
#include <elf.h>
|
||||||
|
|
||||||
@ -95,19 +94,19 @@ struct multiboot_info {
|
|||||||
int
|
int
|
||||||
acrn_parse_elf(char *arg)
|
acrn_parse_elf(char *arg)
|
||||||
{
|
{
|
||||||
|
int err = -1;
|
||||||
size_t len = strnlen(arg, STR_LEN);
|
size_t len = strnlen(arg, STR_LEN);
|
||||||
size_t elfsz;
|
size_t elfsz;
|
||||||
|
|
||||||
if (len < STR_LEN) {
|
if (len < STR_LEN) {
|
||||||
strncpy(elf_path, arg, len + 1);
|
strncpy(elf_path, arg, len + 1);
|
||||||
assert(check_image(elf_path, 0, &elfsz) == 0);
|
if (check_image(elf_path, 0, &elfsz) == 0) {
|
||||||
|
|
||||||
elf_file_name = elf_path;
|
elf_file_name = elf_path;
|
||||||
|
|
||||||
printf("SW_LOAD: get elf path %s\n", elf_path);
|
printf("SW_LOAD: get elf path %s\n", elf_path);
|
||||||
return 0;
|
err = 0;
|
||||||
} else
|
}
|
||||||
return -1;
|
}
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int load_elf32(struct vmctx *ctx, FILE *fp, void *buf)
|
static int load_elf32(struct vmctx *ctx, FILE *fp, void *buf)
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "dm.h"
|
#include "dm.h"
|
||||||
#include "vmmapi.h"
|
#include "vmmapi.h"
|
||||||
@ -72,20 +71,19 @@ ovmf_image_size(void)
|
|||||||
int
|
int
|
||||||
acrn_parse_ovmf(char *arg)
|
acrn_parse_ovmf(char *arg)
|
||||||
{
|
{
|
||||||
int error;
|
int error = -1;
|
||||||
size_t len = strnlen(arg, STR_LEN);
|
size_t len = strnlen(arg, STR_LEN);
|
||||||
|
|
||||||
if (len < STR_LEN) {
|
if (len < STR_LEN) {
|
||||||
strncpy(ovmf_path, arg, len + 1);
|
strncpy(ovmf_path, arg, len + 1);
|
||||||
error = check_image(ovmf_path, 2 * MB, &ovmf_size);
|
if (check_image(ovmf_path, 2 * MB, &ovmf_size) == 0) {
|
||||||
assert(!error);
|
|
||||||
|
|
||||||
ovmf_file_name = ovmf_path;
|
ovmf_file_name = ovmf_path;
|
||||||
printf("SW_LOAD: get ovmf path %s, size 0x%lx\n",
|
printf("SW_LOAD: get ovmf path %s, size 0x%lx\n",
|
||||||
ovmf_path, ovmf_size);
|
ovmf_path, ovmf_size);
|
||||||
return 0;
|
error = 0;
|
||||||
} else
|
}
|
||||||
return -1;
|
}
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -149,7 +147,8 @@ acrn_sw_load_ovmf(struct vmctx *ctx)
|
|||||||
e820 = paddr_guest2host(ctx, OVMF_E820_BASE,
|
e820 = paddr_guest2host(ctx, OVMF_E820_BASE,
|
||||||
e820_default_entries[LOWRAM_E820_ENTRY].baseaddr -
|
e820_default_entries[LOWRAM_E820_ENTRY].baseaddr -
|
||||||
OVMF_E820_BASE);
|
OVMF_E820_BASE);
|
||||||
assert(e820 != NULL);
|
if (e820 == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
strncpy(e820->signature, "820", sizeof(e820->signature));
|
strncpy(e820->signature, "820", sizeof(e820->signature));
|
||||||
e820->nentries = acrn_create_e820_table(ctx, e820->map);
|
e820->nentries = acrn_create_e820_table(ctx, e820->map);
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "dm.h"
|
#include "dm.h"
|
||||||
@ -125,21 +124,19 @@ vsbl_set_bdf(int bnum, int snum, int fnum)
|
|||||||
int
|
int
|
||||||
acrn_parse_guest_part_info(char *arg)
|
acrn_parse_guest_part_info(char *arg)
|
||||||
{
|
{
|
||||||
int error;
|
int error = -1;
|
||||||
size_t len = strnlen(arg, STR_LEN);
|
size_t len = strnlen(arg, STR_LEN);
|
||||||
|
|
||||||
if (len < STR_LEN) {
|
if (len < STR_LEN) {
|
||||||
strncpy(guest_part_info_path, arg, len + 1);
|
strncpy(guest_part_info_path, arg, len + 1);
|
||||||
error = check_image(guest_part_info_path, 0, &guest_part_info_size);
|
if (check_image(guest_part_info_path, 0, &guest_part_info_size) == 0) {
|
||||||
assert(!error);
|
|
||||||
|
|
||||||
with_guest_part_info = true;
|
with_guest_part_info = true;
|
||||||
|
|
||||||
printf("SW_LOAD: get partition blob path %s\n",
|
printf("SW_LOAD: get partition blob path %s\n",
|
||||||
guest_part_info_path);
|
guest_part_info_path);
|
||||||
return 0;
|
error = 0;
|
||||||
} else
|
}
|
||||||
return -1;
|
}
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -194,21 +191,18 @@ acrn_prepare_guest_part_info(struct vmctx *ctx)
|
|||||||
int
|
int
|
||||||
acrn_parse_vsbl(char *arg)
|
acrn_parse_vsbl(char *arg)
|
||||||
{
|
{
|
||||||
int error;
|
int error = -1;
|
||||||
size_t len = strnlen(arg, STR_LEN);
|
size_t len = strnlen(arg, STR_LEN);
|
||||||
|
|
||||||
if (len < STR_LEN) {
|
if (len < STR_LEN) {
|
||||||
strncpy(vsbl_path, arg, len + 1);
|
strncpy(vsbl_path, arg, len + 1);
|
||||||
error = check_image(vsbl_path, 8 * MB, &vsbl_size);
|
if (check_image(vsbl_path, 8 * MB, &vsbl_size) == 0) {
|
||||||
assert(!error);
|
|
||||||
|
|
||||||
vsbl_file_name = vsbl_path;
|
vsbl_file_name = vsbl_path;
|
||||||
|
printf("SW_LOAD: get vsbl path %s\n", vsbl_path);
|
||||||
printf("SW_LOAD: get vsbl path %s\n",
|
error = 0;
|
||||||
vsbl_path);
|
}
|
||||||
return 0;
|
}
|
||||||
} else
|
return error;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
Reference in New Issue
Block a user