Commit 17b0128a authored by Jason A. Donenfeld's avatar Jason A. Donenfeld

wireguard: selftests: use maximum cpu features and allow rng seeding

By forcing the maximum CPU that QEMU has available, we expose additional
capabilities, such as the RNDR instruction, which increases test
coverage. This then allows the CI to skip the fake seeding step in some
cases. Also enable STRICT_KERNEL_RWX to catch issues related to early
jump labels when the RNG is initialized at boot.
Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
parent e052a478
...@@ -64,8 +64,8 @@ QEMU_VPORT_RESULT := virtio-serial-device ...@@ -64,8 +64,8 @@ QEMU_VPORT_RESULT := virtio-serial-device
ifeq ($(HOST_ARCH),$(ARCH)) ifeq ($(HOST_ARCH),$(ARCH))
QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
else else
QEMU_MACHINE := -cpu cortex-a53 -machine virt QEMU_MACHINE := -cpu max -machine virt
CFLAGS += -march=armv8-a -mtune=cortex-a53 CFLAGS += -march=armv8-a
endif endif
else ifeq ($(ARCH),aarch64_be) else ifeq ($(ARCH),aarch64_be)
CHOST := aarch64_be-linux-musl CHOST := aarch64_be-linux-musl
...@@ -76,8 +76,8 @@ QEMU_VPORT_RESULT := virtio-serial-device ...@@ -76,8 +76,8 @@ QEMU_VPORT_RESULT := virtio-serial-device
ifeq ($(HOST_ARCH),$(ARCH)) ifeq ($(HOST_ARCH),$(ARCH))
QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
else else
QEMU_MACHINE := -cpu cortex-a53 -machine virt QEMU_MACHINE := -cpu max -machine virt
CFLAGS += -march=armv8-a -mtune=cortex-a53 CFLAGS += -march=armv8-a
endif endif
else ifeq ($(ARCH),arm) else ifeq ($(ARCH),arm)
CHOST := arm-linux-musleabi CHOST := arm-linux-musleabi
...@@ -88,8 +88,8 @@ QEMU_VPORT_RESULT := virtio-serial-device ...@@ -88,8 +88,8 @@ QEMU_VPORT_RESULT := virtio-serial-device
ifeq ($(HOST_ARCH),$(ARCH)) ifeq ($(HOST_ARCH),$(ARCH))
QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
else else
QEMU_MACHINE := -cpu cortex-a15 -machine virt QEMU_MACHINE := -cpu max -machine virt
CFLAGS += -march=armv7-a -mtune=cortex-a15 -mabi=aapcs-linux CFLAGS += -march=armv7-a -mabi=aapcs-linux
endif endif
else ifeq ($(ARCH),armeb) else ifeq ($(ARCH),armeb)
CHOST := armeb-linux-musleabi CHOST := armeb-linux-musleabi
...@@ -100,8 +100,8 @@ QEMU_VPORT_RESULT := virtio-serial-device ...@@ -100,8 +100,8 @@ QEMU_VPORT_RESULT := virtio-serial-device
ifeq ($(HOST_ARCH),$(ARCH)) ifeq ($(HOST_ARCH),$(ARCH))
QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm QEMU_MACHINE := -cpu host -machine virt,gic_version=host,accel=kvm
else else
QEMU_MACHINE := -cpu cortex-a15 -machine virt QEMU_MACHINE := -cpu max -machine virt
CFLAGS += -march=armv7-a -mabi=aapcs-linux # We don't pass -mtune=cortex-a15 due to a compiler bug on big endian. CFLAGS += -march=armv7-a -mabi=aapcs-linux
LDFLAGS += -Wl,--be8 LDFLAGS += -Wl,--be8
endif endif
else ifeq ($(ARCH),x86_64) else ifeq ($(ARCH),x86_64)
...@@ -112,8 +112,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage ...@@ -112,8 +112,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage
ifeq ($(HOST_ARCH),$(ARCH)) ifeq ($(HOST_ARCH),$(ARCH))
QEMU_MACHINE := -cpu host -machine q35,accel=kvm QEMU_MACHINE := -cpu host -machine q35,accel=kvm
else else
QEMU_MACHINE := -cpu Skylake-Server -machine q35 QEMU_MACHINE := -cpu max -machine q35
CFLAGS += -march=skylake-avx512
endif endif
else ifeq ($(ARCH),i686) else ifeq ($(ARCH),i686)
CHOST := i686-linux-musl CHOST := i686-linux-musl
...@@ -123,8 +122,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage ...@@ -123,8 +122,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/arch/x86/boot/bzImage
ifeq ($(subst x86_64,i686,$(HOST_ARCH)),$(ARCH)) ifeq ($(subst x86_64,i686,$(HOST_ARCH)),$(ARCH))
QEMU_MACHINE := -cpu host -machine q35,accel=kvm QEMU_MACHINE := -cpu host -machine q35,accel=kvm
else else
QEMU_MACHINE := -cpu coreduo -machine q35 QEMU_MACHINE := -cpu max -machine q35
CFLAGS += -march=prescott
endif endif
else ifeq ($(ARCH),mips64) else ifeq ($(ARCH),mips64)
CHOST := mips64-linux-musl CHOST := mips64-linux-musl
...@@ -182,7 +180,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux ...@@ -182,7 +180,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
ifeq ($(HOST_ARCH),$(ARCH)) ifeq ($(HOST_ARCH),$(ARCH))
QEMU_MACHINE := -cpu host,accel=kvm -machine pseries QEMU_MACHINE := -cpu host,accel=kvm -machine pseries
else else
QEMU_MACHINE := -machine pseries QEMU_MACHINE := -machine pseries -device spapr-rng,rng=rng -object rng-random,id=rng
endif endif
else ifeq ($(ARCH),powerpc64le) else ifeq ($(ARCH),powerpc64le)
CHOST := powerpc64le-linux-musl CHOST := powerpc64le-linux-musl
...@@ -192,7 +190,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux ...@@ -192,7 +190,7 @@ KERNEL_BZIMAGE := $(KERNEL_BUILD_PATH)/vmlinux
ifeq ($(HOST_ARCH),$(ARCH)) ifeq ($(HOST_ARCH),$(ARCH))
QEMU_MACHINE := -cpu host,accel=kvm -machine pseries QEMU_MACHINE := -cpu host,accel=kvm -machine pseries
else else
QEMU_MACHINE := -machine pseries QEMU_MACHINE := -machine pseries -device spapr-rng,rng=rng -object rng-random,id=rng
endif endif
else ifeq ($(ARCH),powerpc) else ifeq ($(ARCH),powerpc)
CHOST := powerpc-linux-musl CHOST := powerpc-linux-musl
...@@ -247,7 +245,7 @@ QEMU_VPORT_RESULT := virtio-serial-ccw ...@@ -247,7 +245,7 @@ QEMU_VPORT_RESULT := virtio-serial-ccw
ifeq ($(HOST_ARCH),$(ARCH)) ifeq ($(HOST_ARCH),$(ARCH))
QEMU_MACHINE := -cpu host,accel=kvm -machine s390-ccw-virtio -append $(KERNEL_CMDLINE) QEMU_MACHINE := -cpu host,accel=kvm -machine s390-ccw-virtio -append $(KERNEL_CMDLINE)
else else
QEMU_MACHINE := -machine s390-ccw-virtio -append $(KERNEL_CMDLINE) QEMU_MACHINE := -cpu max -machine s390-ccw-virtio -append $(KERNEL_CMDLINE)
endif endif
else else
$(error I only build: x86_64, i686, arm, armeb, aarch64, aarch64_be, mips, mipsel, mips64, mips64el, powerpc64, powerpc64le, powerpc, m68k, riscv64, riscv32, s390x) $(error I only build: x86_64, i686, arm, armeb, aarch64, aarch64_be, mips, mipsel, mips64, mips64el, powerpc64, powerpc64le, powerpc, m68k, riscv64, riscv32, s390x)
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#include <sys/sendfile.h> #include <sys/sendfile.h>
#include <sys/sysmacros.h> #include <sys/sysmacros.h>
#include <sys/random.h>
#include <linux/random.h> #include <linux/random.h>
#include <linux/version.h> #include <linux/version.h>
...@@ -58,6 +59,8 @@ static void seed_rng(void) ...@@ -58,6 +59,8 @@ static void seed_rng(void)
{ {
int bits = 256, fd; int bits = 256, fd;
if (!getrandom(NULL, 0, GRND_NONBLOCK))
return;
pretty_message("[+] Fake seeding RNG..."); pretty_message("[+] Fake seeding RNG...");
fd = open("/dev/random", O_WRONLY); fd = open("/dev/random", O_WRONLY);
if (fd < 0) if (fd < 0)
......
...@@ -31,6 +31,7 @@ CONFIG_TTY=y ...@@ -31,6 +31,7 @@ CONFIG_TTY=y
CONFIG_BINFMT_ELF=y CONFIG_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y CONFIG_BINFMT_SCRIPT=y
CONFIG_VDSO=y CONFIG_VDSO=y
CONFIG_STRICT_KERNEL_RWX=y
CONFIG_VIRTUALIZATION=y CONFIG_VIRTUALIZATION=y
CONFIG_HYPERVISOR_GUEST=y CONFIG_HYPERVISOR_GUEST=y
CONFIG_PARAVIRT=y CONFIG_PARAVIRT=y
...@@ -65,6 +66,8 @@ CONFIG_PROC_FS=y ...@@ -65,6 +66,8 @@ CONFIG_PROC_FS=y
CONFIG_PROC_SYSCTL=y CONFIG_PROC_SYSCTL=y
CONFIG_SYSFS=y CONFIG_SYSFS=y
CONFIG_TMPFS=y CONFIG_TMPFS=y
CONFIG_RANDOM_TRUST_CPU=y
CONFIG_RANDOM_TRUST_BOOTLOADER=y
CONFIG_CONSOLE_LOGLEVEL_DEFAULT=15 CONFIG_CONSOLE_LOGLEVEL_DEFAULT=15
CONFIG_LOG_BUF_SHIFT=18 CONFIG_LOG_BUF_SHIFT=18
CONFIG_PRINTK_TIME=y CONFIG_PRINTK_TIME=y
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment