Skip to content

Commit 024d8c2

Browse files
fix malicious server checking
1 parent 0962d42 commit 024d8c2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

hw/vfio/user.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
#include "qapi/qmp/qnum.h"
3131
#include "user.h"
3232

33+
/*
34+
* These are to defend against a malign server trying
35+
* to force us to run out of memory.
36+
*/
37+
#define VFIO_USER_MAX_REGIONS 100
38+
#define VFIO_USER_MAX_IRQS 50
39+
3340
static uint64_t max_xfer_size = VFIO_USER_DEF_MAX_XFER;
3441
static uint64_t max_send_fds = VFIO_USER_DEF_MAX_FDS;
3542
static uint32_t wait_time = 1000; /* wait 1 sec for replies */
@@ -1472,9 +1479,12 @@ static int vfio_user_io_get_info(VFIODevice *vbasedev,
14721479
return ret;
14731480
}
14741481

1475-
/* clamp these to defend against a malicious server */
1476-
info->num_regions = MAX(info->num_regions, 100);
1477-
info->num_irqs = MAX(info->num_irqs, 100);
1482+
/* defend against a malicious server */
1483+
if (info->num_regions > VFIO_USER_MAX_REGIONS ||
1484+
info->num_irqs > VFIO_USER_MAX_IRQS) {
1485+
error_printf("vfio_user_get_info: invalid reply\n");
1486+
return -EINVAL;
1487+
}
14781488

14791489
return 0;
14801490
}

0 commit comments

Comments
 (0)