summaryrefslogtreecommitdiffstats
path: root/usr.sbin/vmd/vmd.c
diff options
context:
space:
mode:
authorreyk <reyk@openbsd.org>2018-10-15 10:35:41 +0000
committerreyk <reyk@openbsd.org>2018-10-15 10:35:41 +0000
commit75cf143ab306db172df3f037074fa6bca7aca85c (patch)
tree495d476dd936f64bb43add35bc3002b6e9dc7849 /usr.sbin/vmd/vmd.c
parentOmit HSTS headers over unencrypted connections, per RFC 6797. (diff)
downloadwireguard-openbsd-75cf143ab306db172df3f037074fa6bca7aca85c.tar.xz
wireguard-openbsd-75cf143ab306db172df3f037074fa6bca7aca85c.zip
Prevent VM reboot loops by rate-limiting the interval a VM can reboot.
This looping has been experienced by people who run VMs with a broken kernel or boot loader that trigger a very fast reboot loop (triple fault) of a VM that ends up using a lot of CPU and resources on the host. Some fixes in vmm(4) and vmd(8) helped to avoid such conditions but it can still occur if something is wrong in the guest VM itself. If the VM restarts after less than VM_START_RATE_SEC (6) seconds, we increment the limit counter. After VM_START_RATE_LIMIT (3) of suchs fast reboots the VM is stopped. There are only very few people who intentionally want to reboot-loop a VM very quickly (many times within a second); mostly for fuzzing. They will have to recompile and adjust the stated #defines in the code as we don't have a config option to disable it. OK mlarkin@
Diffstat (limited to 'usr.sbin/vmd/vmd.c')
-rw-r--r--usr.sbin/vmd/vmd.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c
index 057b67770c9..8053b02620f 100644
--- a/usr.sbin/vmd/vmd.c
+++ b/usr.sbin/vmd/vmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmd.c,v 1.103 2018/10/08 16:32:01 reyk Exp $ */
+/* $OpenBSD: vmd.c,v 1.104 2018/10/15 10:35:41 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -1921,3 +1921,14 @@ prefixlen2mask(uint8_t prefixlen)
return (htonl(0xffffffff << (32 - prefixlen)));
}
+
+void
+getmonotime(struct timeval *tv)
+{
+ struct timespec ts;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ts))
+ fatal("clock_gettime");
+
+ TIMESPEC_TO_TIMEVAL(tv, &ts);
+}