dm: refine 'assert' in hugetlb.c and mem.c
cleanup 'assert' usage to avoid possible software 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
65d7d83b1c
commit
885d503a60
|
@ -36,7 +36,6 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "vmmapi.h"
|
#include "vmmapi.h"
|
||||||
|
|
||||||
|
@ -267,7 +266,6 @@ static int mmap_hugetlbfs(struct vmctx *ctx, size_t offset,
|
||||||
pg_size = hugetlb_priv[level].pg_size;
|
pg_size = hugetlb_priv[level].pg_size;
|
||||||
|
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
assert((offset & (pg_size - 1)) == 0);
|
|
||||||
ret = mmap_hugetlbfs_from_level(ctx, level, len, offset, skip);
|
ret = mmap_hugetlbfs_from_level(ctx, level, len, offset, skip);
|
||||||
|
|
||||||
if (ret < 0 && level > HUGETLB_LV1) {
|
if (ret < 0 && level > HUGETLB_LV1) {
|
||||||
|
@ -297,7 +295,6 @@ static void get_lowmem_param(struct hugetlb_info *htlb,
|
||||||
static size_t adj_lowmem_param(struct hugetlb_info *htlb,
|
static size_t adj_lowmem_param(struct hugetlb_info *htlb,
|
||||||
struct hugetlb_info *htlb_prev, int adj_size)
|
struct hugetlb_info *htlb_prev, int adj_size)
|
||||||
{
|
{
|
||||||
assert(htlb->lowmem >= adj_size);
|
|
||||||
htlb->lowmem -= adj_size;
|
htlb->lowmem -= adj_size;
|
||||||
htlb_prev->lowmem += adj_size;
|
htlb_prev->lowmem += adj_size;
|
||||||
|
|
||||||
|
@ -314,7 +311,6 @@ static void get_highmem_param(struct hugetlb_info *htlb,
|
||||||
static size_t adj_highmem_param(struct hugetlb_info *htlb,
|
static size_t adj_highmem_param(struct hugetlb_info *htlb,
|
||||||
struct hugetlb_info *htlb_prev, int adj_size)
|
struct hugetlb_info *htlb_prev, int adj_size)
|
||||||
{
|
{
|
||||||
assert(htlb->highmem >= adj_size);
|
|
||||||
htlb->highmem -= adj_size;
|
htlb->highmem -= adj_size;
|
||||||
htlb_prev->highmem += adj_size;
|
htlb_prev->highmem += adj_size;
|
||||||
|
|
||||||
|
@ -331,7 +327,6 @@ static void get_biosmem_param(struct hugetlb_info *htlb,
|
||||||
static size_t adj_biosmem_param(struct hugetlb_info *htlb,
|
static size_t adj_biosmem_param(struct hugetlb_info *htlb,
|
||||||
struct hugetlb_info *htlb_prev, int adj_size)
|
struct hugetlb_info *htlb_prev, int adj_size)
|
||||||
{
|
{
|
||||||
assert(htlb->biosmem >= adj_size);
|
|
||||||
htlb->biosmem -= adj_size;
|
htlb->biosmem -= adj_size;
|
||||||
htlb_prev->biosmem += adj_size;
|
htlb_prev->biosmem += adj_size;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
|
@ -178,7 +177,8 @@ emulate_mem(struct vmctx *ctx, struct mmio_request *mmio_req)
|
||||||
|
|
||||||
pthread_rwlock_unlock(&mmio_rwlock);
|
pthread_rwlock_unlock(&mmio_rwlock);
|
||||||
|
|
||||||
assert(entry != NULL);
|
if (entry == NULL)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
if (mmio_req->direction == REQUEST_READ)
|
if (mmio_req->direction == REQUEST_READ)
|
||||||
err = mem_read(ctx, 0, paddr, (uint64_t *)&mmio_req->value,
|
err = mem_read(ctx, 0, paddr, (uint64_t *)&mmio_req->value,
|
||||||
|
@ -238,11 +238,11 @@ unregister_mem_int(struct mmio_rb_tree *rbt, struct mem_range *memp)
|
||||||
err = mmio_rb_lookup(rbt, memp->base, &entry);
|
err = mmio_rb_lookup(rbt, memp->base, &entry);
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
mr = &entry->mr_param;
|
mr = &entry->mr_param;
|
||||||
if (strncmp(mr->name, memp->name, MEMNAMESZ)) {
|
if (strncmp(mr->name, memp->name, MEMNAMESZ)
|
||||||
|
|| (mr->base != memp->base) || (mr->size != memp->size)
|
||||||
|
|| ((mr->flags & MEM_F_IMMUTABLE) != 0)) {
|
||||||
err = -1;
|
err = -1;
|
||||||
} else {
|
} else {
|
||||||
assert(mr->base == memp->base && mr->size == memp->size);
|
|
||||||
assert((mr->flags & MEM_F_IMMUTABLE) == 0);
|
|
||||||
RB_REMOVE(mmio_rb_tree, rbt, entry);
|
RB_REMOVE(mmio_rb_tree, rbt, entry);
|
||||||
|
|
||||||
/* flush Per-VM cache */
|
/* flush Per-VM cache */
|
||||||
|
|
Loading…
Reference in New Issue