Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/rth/tags/pull-rng-20190522' int…
Browse files Browse the repository at this point in the history
…o staging

Introduce qemu_guest_getrandom.
Use qemu_guest_getrandom in aspeed, nrf51, bcm2835, exynos4210 rng devices.
Use qemu_guest_getrandom in target/ppc darn instruction.
Support ARMv8.5-RNG extension.
Support x86 RDRAND extension.

Acked-by: Daniel P. Berrangé <berrange@redhat.com>
Acked-by: Laurent Vivier <laurent@vivier.eu>

# gpg: Signature made Wed 22 May 2019 19:36:43 BST
# gpg:                using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F
# gpg:                issuer "richard.henderson@linaro.org"
# gpg: Good signature from "Richard Henderson <richard.henderson@linaro.org>" [full]
# Primary key fingerprint: 7A48 1E78 868B 4DB6 A85A  05C0 64DF 38E8 AF7E 215F

* remotes/rth/tags/pull-rng-20190522: (25 commits)
  target/i386: Implement CPUID_EXT_RDRAND
  target/ppc: Use qemu_guest_getrandom for DARN
  target/ppc: Use gen_io_start/end around DARN
  target/arm: Implement ARMv8.5-RNG
  target/arm: Put all PAC keys into a structure
  hw/misc/exynos4210_rng: Use qemu_guest_getrandom
  hw/misc/bcm2835_rng: Use qemu_guest_getrandom_nofail
  hw/misc/nrf51_rng: Use qemu_guest_getrandom_nofail
  aspeed/scu: Use qemu_guest_getrandom_nofail
  linux-user: Remove srand call
  linux-user/aarch64: Use qemu_guest_getrandom for PAUTH keys
  linux-user: Use qemu_guest_getrandom_nofail for AT_RANDOM
  linux-user: Call qcrypto_init if not using -seed
  linux-user: Initialize pseudo-random seeds for all guest cpus
  cpus: Initialize pseudo-random seeds for all guest cpus
  util: Add qemu_guest_getrandom and associated routines
  ui/vnc: Use gcrypto_random_bytes for start_auth_vnc
  ui/vnc: Split out authentication_failed
  crypto: Change the qcrypto_random_bytes buffer type to void*
  crypto: Use getrandom for qcrypto_random_bytes
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed May 23, 2019
2 parents c4600d5 + 369fd5c commit d418238
Show file tree
Hide file tree
Showing 36 changed files with 610 additions and 256 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ dummy := $(call unnest-vars,, \
block-obj-y \
block-obj-m \
crypto-obj-y \
crypto-aes-obj-y \
crypto-user-obj-y \
qom-obj-y \
io-obj-y \
common-obj-y \
Expand Down Expand Up @@ -487,7 +487,7 @@ subdir-slirp: .git-submodule-status
$(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp BUILD_DIR="$(BUILD_DIR)/slirp" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(LDFLAGS)")

$(SUBDIR_RULES): libqemuutil.a $(common-obj-y) \
$(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY))
$(qom-obj-y) $(crypto-user-obj-$(CONFIG_USER_ONLY))

ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS))
# Only keep -O and -g cflags
Expand Down
2 changes: 1 addition & 1 deletion Makefile.objs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ block-obj-m = block/
# crypto-obj-y is code used by both qemu system emulation and qemu-img

crypto-obj-y = crypto/
crypto-aes-obj-y = crypto/
crypto-user-obj-y = crypto/

#######################################################################
# qom-obj-y is code used by both qemu system emulation and qemu-img
Expand Down
4 changes: 2 additions & 2 deletions Makefile.target
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ dummy := $(call unnest-vars,.., \
block-obj-m \
chardev-obj-y \
crypto-obj-y \
crypto-aes-obj-y \
crypto-user-obj-y \
qom-obj-y \
io-obj-y \
common-obj-y \
Expand All @@ -189,7 +189,7 @@ all-obj-y += $(common-obj-y)
all-obj-y += $(qom-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y)
all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y)
all-obj-$(CONFIG_USER_ONLY) += $(crypto-user-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)

Expand Down
87 changes: 58 additions & 29 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -2784,17 +2784,23 @@ fi
# GNUTLS probe

if test "$gnutls" != "no"; then
pass="no"
if $pkg_config --exists "gnutls >= 3.1.18"; then
gnutls_cflags=$($pkg_config --cflags gnutls)
gnutls_libs=$($pkg_config --libs gnutls)
libs_softmmu="$gnutls_libs $libs_softmmu"
libs_tools="$gnutls_libs $libs_tools"
QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags"
gnutls="yes"
elif test "$gnutls" = "yes"; then
# Packaging for the static libraries is not always correct.
# At least ubuntu 18.04 ships only shared libraries.
write_c_skeleton
if compile_prog "" "$gnutls_libs" ; then
LIBS="$gnutls_libs $LIBS"
QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags"
pass="yes"
fi
fi
if test "$pass" = "no" && test "$gnutls" = "yes"; then
feature_not_found "gnutls" "Install gnutls devel >= 3.1.18"
else
gnutls="no"
gnutls="$pass"
fi
fi

Expand Down Expand Up @@ -2849,43 +2855,52 @@ has_libgcrypt() {


if test "$nettle" != "no"; then
pass="no"
if $pkg_config --exists "nettle >= 2.7.1"; then
nettle_cflags=$($pkg_config --cflags nettle)
nettle_libs=$($pkg_config --libs nettle)
nettle_version=$($pkg_config --modversion nettle)
libs_softmmu="$nettle_libs $libs_softmmu"
libs_tools="$nettle_libs $libs_tools"
QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags"
nettle="yes"

if test -z "$gcrypt"; then
gcrypt="no"
# Link test to make sure the given libraries work (e.g for static).
write_c_skeleton
if compile_prog "" "$nettle_libs" ; then
LIBS="$nettle_libs $LIBS"
QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags"
if test -z "$gcrypt"; then
gcrypt="no"
fi
pass="yes"
fi
fi
if test "$pass" = "no" && test "$nettle" = "yes"; then
feature_not_found "nettle" "Install nettle devel >= 2.7.1"
else
if test "$nettle" = "yes"; then
feature_not_found "nettle" "Install nettle devel >= 2.7.1"
else
nettle="no"
fi
nettle="$pass"
fi
fi

if test "$gcrypt" != "no"; then
pass="no"
if has_libgcrypt; then
gcrypt_cflags=$(libgcrypt-config --cflags)
gcrypt_libs=$(libgcrypt-config --libs)
# Debian has remove -lgpg-error from libgcrypt-config
# Debian has removed -lgpg-error from libgcrypt-config
# as it "spreads unnecessary dependencies" which in
# turn breaks static builds...
if test "$static" = "yes"
then
gcrypt_libs="$gcrypt_libs -lgpg-error"
fi
libs_softmmu="$gcrypt_libs $libs_softmmu"
libs_tools="$gcrypt_libs $libs_tools"
QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags"
gcrypt="yes"

# Link test to make sure the given libraries work (e.g for static).
write_c_skeleton
if compile_prog "" "$gcrypt_libs" ; then
LIBS="$gcrypt_libs $LIBS"
QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags"
pass="yes"
fi
fi
if test "$pass" = "yes"; then
gcrypt="yes"
cat > $TMPC << EOF
#include <gcrypt.h>
int main(void) {
Expand All @@ -2898,12 +2913,10 @@ EOF
if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then
gcrypt_hmac=yes
fi
elif test "$gcrypt" = "yes"; then
feature_not_found "gcrypt" "Install gcrypt devel >= 1.5.0"
else
if test "$gcrypt" = "yes"; then
feature_not_found "gcrypt" "Install gcrypt devel >= 1.5.0"
else
gcrypt="no"
fi
gcrypt="no"
fi
fi

Expand Down Expand Up @@ -5802,6 +5815,20 @@ if compile_prog "" "" ; then
have_utmpx=yes
fi

##########################################
# check for getrandom()

have_getrandom=no
cat > $TMPC << EOF
#include <sys/random.h>
int main(void) {
return getrandom(0, 0, GRND_NONBLOCK);
}
EOF
if compile_prog "" "" ; then
have_getrandom=yes
fi

##########################################
# checks for sanitizers

Expand Down Expand Up @@ -7191,7 +7218,9 @@ fi
if test "$have_utmpx" = "yes" ; then
echo "HAVE_UTMPX=y" >> $config_host_mak
fi

if test "$have_getrandom" = "yes" ; then
echo "CONFIG_GETRANDOM=y" >> $config_host_mak
fi
if test "$ivshmem" = "yes" ; then
echo "CONFIG_IVSHMEM=y" >> $config_host_mak
fi
Expand Down
9 changes: 9 additions & 0 deletions cpus.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "qemu/option.h"
#include "qemu/bitmap.h"
#include "qemu/seqlock.h"
#include "qemu/guest-random.h"
#include "tcg.h"
#include "hw/nmi.h"
#include "sysemu/replay.h"
Expand Down Expand Up @@ -1276,6 +1277,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
/* signal CPU creation */
cpu->created = true;
qemu_cond_signal(&qemu_cpu_cond);
qemu_guest_random_seed_thread_part2(cpu->random_seed);

do {
if (cpu_can_run(cpu)) {
Expand Down Expand Up @@ -1319,6 +1321,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg)
/* signal CPU creation */
cpu->created = true;
qemu_cond_signal(&qemu_cpu_cond);
qemu_guest_random_seed_thread_part2(cpu->random_seed);

do {
qemu_mutex_unlock_iothread();
Expand Down Expand Up @@ -1478,6 +1481,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg)
cpu->created = true;
cpu->can_do_io = 1;
qemu_cond_signal(&qemu_cpu_cond);
qemu_guest_random_seed_thread_part2(cpu->random_seed);

/* wait for initial kick-off after machine start */
while (first_cpu->stopped) {
Expand Down Expand Up @@ -1592,6 +1596,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg)

hax_init_vcpu(cpu);
qemu_cond_signal(&qemu_cpu_cond);
qemu_guest_random_seed_thread_part2(cpu->random_seed);

do {
if (cpu_can_run(cpu)) {
Expand Down Expand Up @@ -1631,6 +1636,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg)
/* signal CPU creation */
cpu->created = true;
qemu_cond_signal(&qemu_cpu_cond);
qemu_guest_random_seed_thread_part2(cpu->random_seed);

do {
if (cpu_can_run(cpu)) {
Expand Down Expand Up @@ -1671,6 +1677,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg)
/* signal CPU creation */
cpu->created = true;
qemu_cond_signal(&qemu_cpu_cond);
qemu_guest_random_seed_thread_part2(cpu->random_seed);

do {
if (cpu_can_run(cpu)) {
Expand Down Expand Up @@ -1724,6 +1731,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
cpu->can_do_io = 1;
current_cpu = cpu;
qemu_cond_signal(&qemu_cpu_cond);
qemu_guest_random_seed_thread_part2(cpu->random_seed);

/* process any pending work */
cpu->exit_request = 1;
Expand Down Expand Up @@ -2071,6 +2079,7 @@ void qemu_init_vcpu(CPUState *cpu)
cpu->nr_cores = smp_cores;
cpu->nr_threads = smp_threads;
cpu->stopped = true;
cpu->random_seed = qemu_guest_random_seed_thread_part1();

if (!cpu->as) {
/* If the target cpu hasn't set up any address spaces itself,
Expand Down
11 changes: 6 additions & 5 deletions crypto/Makefile.objs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ crypto-obj-y += tlscredspsk.o
crypto-obj-y += tlscredsx509.o
crypto-obj-y += tlssession.o
crypto-obj-y += secret.o
crypto-obj-$(CONFIG_GCRYPT) += random-gcrypt.o
crypto-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o
crypto-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o
crypto-rng-obj-$(CONFIG_GCRYPT) += random-gcrypt.o
crypto-rng-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o
crypto-rng-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o
crypto-obj-y += $(crypto-rng-obj-y)
crypto-obj-y += pbkdf.o
crypto-obj-$(CONFIG_NETTLE) += pbkdf-nettle.o
crypto-obj-$(if $(CONFIG_NETTLE),n,$(CONFIG_GCRYPT)) += pbkdf-gcrypt.o
Expand All @@ -35,7 +36,7 @@ crypto-obj-y += block.o
crypto-obj-y += block-qcow.o
crypto-obj-y += block-luks.o

# Let the userspace emulators avoid linking gnutls/etc
crypto-aes-obj-y = aes.o
# Let the userspace emulators avoid linking stuff they won't use.
crypto-user-obj-y = aes.o $(crypto-rng-obj-y) init.o

stub-obj-y += pbkdf-stub.o
2 changes: 1 addition & 1 deletion crypto/random-gcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <gcrypt.h>

int qcrypto_random_bytes(uint8_t *buf,
int qcrypto_random_bytes(void *buf,
size_t buflen,
Error **errp G_GNUC_UNUSED)
{
Expand Down
2 changes: 1 addition & 1 deletion crypto/random-gnutls.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <gnutls/gnutls.h>
#include <gnutls/crypto.h>

int qcrypto_random_bytes(uint8_t *buf,
int qcrypto_random_bytes(void *buf,
size_t buflen,
Error **errp)
{
Expand Down
Loading

0 comments on commit d418238

Please sign in to comment.