From patchwork Thu Mar 14 04:55:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160285 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15073109jad; Wed, 13 Mar 2019 21:58:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJzLOHFBWKLpPUmnjz3P12Apa2NHxKKpfEjD2Ry0QAdgDy/X0Bhxpf6N253B+O/h1bWKi9 X-Received: by 2002:a25:3746:: with SMTP id e67mr39719261yba.42.1552539514526; Wed, 13 Mar 2019 21:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539514; cv=none; d=google.com; s=arc-20160816; b=0JYzVb/Cf9eFm9Xi7JXLjJXyLiyYc2dY3dh4kMMXkggfb0ed5KnWMySpOPZ2MiTaYL sY2YabJny7XFX6EbrNXNVj0u5R3GLPEt8Xec3jBLD2cTi/ELmzFpUNSkuGyRrkxZFgdz vckGSLp69hesafLS5JzcvEvQLhnzmD0feFurlveS8EaU5Djz9yllfgwlBF7H/+GVdzkA A9YNsK7+p81TGaNvvdMfUaMWhyqimV6mVwRAvN+vcg+Gw4Ly4uFZwD9VbYJabtxdDe6g eHYKtEKhpltQKb3ix385Vox6j9GAq3XW8bNdDJkuwvbjBbUsv/AeGRztxDNL5fr8J8CJ Um6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=tUK9oRvbFsnUe/XftR8H/1QGMXmsiHbTr53Gr78dYsM=; b=zFToQmO3bA/z51mtEwo610IVQaNGZeWPvYcefl/vM+XQ+u4j+c25cPoYl2nF3Oh9uw 95BaWY0T/30i05KpCTt3jrYRkHUS+m0WmHKOScaqw3XJAzy0qHU35USUk4A8jrFYyxur dGZ3kEnBM57V9DMfzMWuAmCRJz68B+QgCltnrutO1mj8N0QHzw3MJ/ytfNSyHcOG+BYj 75iacdwV7qppI+ihxiiKatKEvtk4Zr3H7WACPBBXgFpncYJqCepUptJypkeHiT5M5jqc 6jb2UCtjQYcyhPOpMXowjuckJlG3hZN5rLekEImYYEPeOPqLY2pRMBaALghijBbRoN4S EAug== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CiLVoRHO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g11si7359320ybg.260.2019.03.13.21.58.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 21:58:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CiLVoRHO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IRt-0006ke-Qt for patch@linaro.org; Thu, 14 Mar 2019 00:58:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IOz-0004T8-SA for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IOy-0007LU-Gy for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:33 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:32869) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IOy-0007Kz-59 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:32 -0400 Received: by mail-pf1-x430.google.com with SMTP id i19so3023203pfd.0 for ; Wed, 13 Mar 2019 21:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tUK9oRvbFsnUe/XftR8H/1QGMXmsiHbTr53Gr78dYsM=; b=CiLVoRHOPwRZTMKjEt2LPqU3kpul2VCoQJ5J1bfYWdkY2q2r2gvUNe7BoHOC2sRukT ohtCoiFUtb3FMXDFxK8C3o6w513aMc7kQRnTnVACNOw/kTKipyFT7gIRnmhfHuwwZ6Zq lw++yqUwtvXWdbSNwJcKoCgqDD7auqIep6CkDgtuaeD12Lpqh8FcZegYBiipasLnxrZK ktDiyDiGUVmmWCw/+3LI6Um/pvMTkhzunezR6Rbs9xmIrpv5347MQ0DA6daBu64+P6UE 3QuH1zJxJ0XqoqFTS7QIqXNAQ9CTNqueWjWInDehVvyRn2LBhmR6njQmUuQjzge7esqH ykeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tUK9oRvbFsnUe/XftR8H/1QGMXmsiHbTr53Gr78dYsM=; b=cT0CfP/rT6C56Ksen6cFBD5xj70ZtFzU1qdc8wmZnEAJ8Ux5KeSKTdk6s2QMogneTj T8AV2md7GihIjcLaIOWNnEPkxifHhAcAj7aQSB/flW3A31TgNa9yPpeUFf1nldeeNzw7 SlHpTX2w1Up8XO+XR0acJwtazfvB0x6nvwZvmIs3yM8UJ2D8h3H5kdZ4pU8pNks0hYPv rwe80CK23B7LDtw4MtkVBq72v2ws9Lvq+vSsd4iPTJE5j47464FI38IzKf/iU7AG8Dd5 5vgyuOyXRHBVVOYTyvFF3Sip2Vmyv3YXJyfZGB46XNKDDg68vvDo6ki1sdTFIb6Imh6I JhrQ== X-Gm-Message-State: APjAAAX79yDw7bsLmI+SqChrfowoVDnDddgevLTdLI64n9CByM6XO3he 9HW0rHmyiY14FlUf0D0/5I4wRzzmFSw= X-Received: by 2002:a17:902:b687:: with SMTP id c7mr2139563pls.270.1552539330604; Wed, 13 Mar 2019 21:55:30 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:13 -0700 Message-Id: <20190314045526.13342-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::430 Subject: [Qemu-devel] [PATCH v2 01/14] crypto: Merge crypto-obj-y into libqemuutil.a X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We will shortly need this in the user-only binaries, so drop the split into system and tools binaries. This also means that crypto-aes-obj-y can be merged back into crypto-obj-y. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- Makefile | 12 +++++------- Makefile.objs | 8 ++------ Makefile.target | 4 ---- configure | 9 +++------ crypto/Makefile.objs | 5 +---- 5 files changed, 11 insertions(+), 27 deletions(-) -- 2.17.1 diff --git a/Makefile b/Makefile index abd78a9826..a85f33f47e 100644 --- a/Makefile +++ b/Makefile @@ -405,7 +405,6 @@ dummy := $(call unnest-vars,, \ block-obj-y \ block-obj-m \ crypto-obj-y \ - crypto-aes-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -441,7 +440,6 @@ SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES)) $(SOFTMMU_SUBDIR_RULES): $(authz-obj-y) $(SOFTMMU_SUBDIR_RULES): $(block-obj-y) -$(SOFTMMU_SUBDIR_RULES): $(crypto-obj-y) $(SOFTMMU_SUBDIR_RULES): $(io-obj-y) $(SOFTMMU_SUBDIR_RULES): config-all-devices.mak @@ -496,7 +494,7 @@ Makefile: $(version-obj-y) ###################################################################### # Build libraries -libqemuutil.a: $(util-obj-y) $(trace-obj-y) $(stub-obj-y) +libqemuutil.a: $(util-obj-y) $(trace-obj-y) $(stub-obj-y) $(crypto-obj-y) libvhost-user.a: $(libvhost-user-obj-y) $(util-obj-y) $(stub-obj-y) ###################################################################### @@ -505,9 +503,9 @@ COMMON_LDADDS = libqemuutil.a qemu-img.o: qemu-img-cmds.h -qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) @@ -518,7 +516,7 @@ qemu-edid$(EXESUF): qemu-edid.o hw/display/edid-generate.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap -scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(authz-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(authz-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) ifdef CONFIG_MPATH scsi/qemu-pr-helper$(EXESUF): LIBS += -ludev -lmultipath -lmpathpersist endif diff --git a/Makefile.objs b/Makefile.objs index 72debbf5c5..23950a37af 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -3,6 +3,8 @@ stub-obj-y = stubs/ util/ crypto/ util-obj-y = util/ qobject/ qapi/ +crypto-obj-y = crypto/ + chardev-obj-y = chardev/ ####################################################################### @@ -21,12 +23,6 @@ block-obj-$(CONFIG_REPLICATION) += replication.o 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/ - ####################################################################### # qom-obj-y is code used by both qemu system emulation and qemu-img diff --git a/Makefile.target b/Makefile.target index d8048aab8f..8840d70b57 100644 --- a/Makefile.target +++ b/Makefile.target @@ -181,8 +181,6 @@ dummy := $(call unnest-vars,.., \ block-obj-y \ block-obj-m \ chardev-obj-y \ - crypto-obj-y \ - crypto-aes-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -191,8 +189,6 @@ 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_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y) ifdef CONFIG_SOFTMMU diff --git a/configure b/configure index abe453f8fd..8992b3aade 100755 --- a/configure +++ b/configure @@ -2771,8 +2771,7 @@ if test "$gnutls" != "no"; then 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" + LIBS="$gnutls_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" gnutls="yes" elif test "$gnutls" = "yes"; then @@ -2837,8 +2836,7 @@ if test "$nettle" != "no"; 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" + LIBS="$nettle_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags" nettle="yes" @@ -2865,8 +2863,7 @@ if test "$gcrypt" != "no"; then then gcrypt_libs="$gcrypt_libs -lgpg-error" fi - libs_softmmu="$gcrypt_libs $libs_softmmu" - libs_tools="$gcrypt_libs $libs_tools" + LIBS="$gcrypt_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags" gcrypt="yes" diff --git a/crypto/Makefile.objs b/crypto/Makefile.objs index 256c9aca1f..a291bc5b9a 100644 --- a/crypto/Makefile.objs +++ b/crypto/Makefile.objs @@ -34,8 +34,5 @@ crypto-obj-y += xts.o 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 - +crypto-obj-y += aes.o stub-obj-y += pbkdf-stub.o From patchwork Thu Mar 14 04:55:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160289 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15075238jad; Wed, 13 Mar 2019 22:01:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqy560fqABFcFmtn+W92oQZxyZ43ayg7po0qRcdq3Aatut/yW+g30HYvM8D7WSuzM3WyU+Y/ X-Received: by 2002:a0d:ffc5:: with SMTP id p188mr27301279ywf.40.1552539701884; Wed, 13 Mar 2019 22:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539701; cv=none; d=google.com; s=arc-20160816; b=JWTUJHhWuY49C6IyNCwbdBRfNrAIEi8j+ChRxIWnfeSTO00GkTRVmEwXRyvwmyLxoa QjP++tpnyMz9VDs5RZCa3MTWvDr+IEWzJ2bcpxqoE1ULcDamIu/ByLOq3bT2bBszwMlq oVn/2ICnZtR8ukltUSzH5i/8mmZ5yqDufJcmUCMhRkoIRUm8PmnIRdfjvQJAFml67toe Cs8MsXY1qgTkqh5rkfH8hPCSBpbLSDLE3YjyHSFqJH/n1hQVyAf8DYFf1V/N4Aika0OX 60fBsUfXKkJEuPLTtkidQBv1ZiSTimjB5GCq4lp91zkyKUcMUFkH6zwanjqDK+RCNNIF gqcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=+ojpjwybhRjnluxW5GelrvS+BsZOt4ZCH9VZc7CqjKY=; b=zJSjKaJwA6GHbMyr9ypxWh4fckxbehn4+6o2sUkN4WcgpHrnKdInQIe1HzkaIdmX64 0/+LseqkEXH3ioSQ6RqXLXiW5o7ckPdoy1hqTVKJc072xe7Fiqwh4ScXMFrzU6bJQR3N KPHy4gJoGl81IHNZvGSleCp1rw7v/r53T25anHWR4aunfhbarnYeTg/w5eJwVuBij0na UZGu1raS38M4d1jP3abva5WvmEjg3DB03zyoTuqPmeYt5eZFoN2WAy0fYjv6kFqb8l2K tBeMNyTF6/PT5cYdKemql2ZhNh5Tfih7X0hDtYVxUXF3Kg7qrV/i30eGSB86oMgkBgEO eBSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=haMytNTz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d65si7664976ywa.142.2019.03.13.22.01.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 22:01:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=haMytNTz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IUv-0000qn-Cc for patch@linaro.org; Thu, 14 Mar 2019 01:01:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56107) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IP0-0004T9-GA for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IOz-0007MC-HS for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:34 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:43537) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IOz-0007LY-A7 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:33 -0400 Received: by mail-pf1-x42c.google.com with SMTP id q17so2992547pfh.10 for ; Wed, 13 Mar 2019 21:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+ojpjwybhRjnluxW5GelrvS+BsZOt4ZCH9VZc7CqjKY=; b=haMytNTzrA4eecoTkONX/2FM+ki13f/+RQNYDtUCAwDAOj+dNzsNYqP5od6nlBk0SZ d87QVrepShFEiQaSlL/pcQx1kPdGkTAbKKAMDXe78wo9m11ElHWjlMFh71rb8rFHwOWy ryRowXkqF7DdUuEImcF7XizVbl/kKkdrG9uERvOQca9gaWaQlHqjhVJ6UdY3f/WgtxDC vDcd2AXn8MjzKrTrevLGfGDedMHHW86i/kRr5/7UzDv0Q3JxbYBc1kOPsQmqCcTU7aTf RHWdEEHU183/VPG/DtOmDhRAjGoCGYa4VAGRFkAe8xOl/zclmy3FcO8r74omZ7dWWMuw XQKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+ojpjwybhRjnluxW5GelrvS+BsZOt4ZCH9VZc7CqjKY=; b=W1pUseQu3xrBZ2zjh4J36JxglYZWxV/2RYNmzscIPsBVQmOgTt/9HuWCVFRh+NzxB/ x8UUnGVjFc9bfiztoh5BKuhawJp2/yAHgNdY1ufZ9WiqGVqIpuoCggmw8qghUc09r5w/ IFbdakb4tUUNmy5c4X+QiHin064SHBI5PnzYXcwE6zHG2IukSTtnmbz2+ZZSQdo3/7CQ qhP52FHyDj+34PKZgodyi8Nw6hteTHX554jyz8tHYGV19LSs2RPhG3ROOUIAApg8AGjI HLYae3Dqhu88A0vbH8aXTixxFlllr7N6Ye8OGJrduFKxhu6rI8koxGTWuIdlUsaAmFZ9 fJ8w== X-Gm-Message-State: APjAAAXo93M+McynPy6nDHFWlXlHIRawLxLi9Mmx15wpmDBgkkneCGEU g3fx5D8OeMwoL6LxKoHoIbJsRDGgf9w= X-Received: by 2002:a17:902:7592:: with SMTP id j18mr23278850pll.300.1552539331785; Wed, 13 Mar 2019 21:55:31 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:14 -0700 Message-Id: <20190314045526.13342-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::42c Subject: [Qemu-devel] [PATCH v2 02/14] crypto: Reverse code blocks in random-platform.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use #ifdef _WIN32 instead of #ifndef _WIN32. This will make other tests easier to sequence. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) -- 2.17.1 Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 7541b4cae7..f995fc0ef1 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -32,7 +32,14 @@ static int fd; /* a file handle to either /dev/urandom or /dev/random */ int qcrypto_random_init(Error **errp) { -#ifndef _WIN32 +#ifdef _WIN32 + if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, + CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { + error_setg_win32(errp, GetLastError(), + "Unable to create cryptographic provider"); + return -1; + } +#else /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ fd = open("/dev/urandom", O_RDONLY); @@ -44,15 +51,7 @@ int qcrypto_random_init(Error **errp) error_setg(errp, "No /dev/urandom or /dev/random found"); return -1; } -#else - if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, - CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { - error_setg_win32(errp, GetLastError(), - "Unable to create cryptographic provider"); - return -1; - } #endif - return 0; } @@ -60,7 +59,15 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, size_t buflen G_GNUC_UNUSED, Error **errp) { -#ifndef _WIN32 +#ifdef _WIN32 + if (!CryptGenRandom(hCryptProv, buflen, buf)) { + error_setg_win32(errp, GetLastError(), + "Unable to read random bytes"); + return -1; + } + + return 0; +#else int ret = -1; int got; @@ -82,13 +89,5 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, ret = 0; cleanup: return ret; -#else - if (!CryptGenRandom(hCryptProv, buflen, buf)) { - error_setg_win32(errp, GetLastError(), - "Unable to read random bytes"); - return -1; - } - - return 0; #endif } From patchwork Thu Mar 14 04:55:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160287 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15073287jad; Wed, 13 Mar 2019 21:58:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyALyy5UaBdT7HYqnZHxDLa+/00PMTMsW7K5ilCMJ1E1OLCL9AZPuMselkZRwVEjVKw5pJS X-Received: by 2002:a81:2042:: with SMTP id g63mr15922365ywg.208.1552539534879; Wed, 13 Mar 2019 21:58:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539534; cv=none; d=google.com; s=arc-20160816; b=LBGTt3sX1ORKCj6V1kg8WgVcTKnOUnwD840usqzP4x7lYnuzUFjzxhMVajhfo06JDN ASVHUk0o4EyITpIkns2iNGCjcvyvjZKS/JymQH+yr2BpebRP5hy0WDTUv69kmITHdJpx JzJ8br2gKqKQApFWF/I+1cO+JwezPiM1I0QYRHufkohPjeBibSvMRq0Pg89zSoOnC28S p3raDvmExfDytezOR4zf16V4tWJP8HHdjRiUVsXndiwNOyPS8ePWkfPZt5JdzAop3biG JS6r8PL8S97QDkd4Qhp0pFmaVjPLi3Vh/rDdgHHYkO9CjpFraCHdtRmzAnRTu5mvijUQ OoAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=+xqsi/guaYA7D3YHKOREkAPcowZW/n5ISz+HVCnkFiA=; b=DAAhQix1IzQMX/jleYK1lG2ki6iZ63uRVq+f3Ay6zsaQbpJGeAAAPktwPLOQXa9zbC srRxNdiAMU0Mfn9kjbKxLbbIaHLXPqMe4KsL9Sa51RdsO9mMrYD/4yUXHdsBW/14VZq9 VorL1SHzgwmw9o90BZL0M+y7a23bmIsfF7KcfuTiF9Lu8M2VveybnjeLULAJKo5Zz5F2 t7oDfoJBmqlsgreAQO/iD+2uqvggXoubAgvz/r12HhxZrgK98CXH7TTiQZMdKEOjSsK9 Wfblmqb6B/w+zh5oTPRBv397/cbU9GOEZKsaNQbYDe3J+/VRRw2+K5mBAoCuawL7gXJM GGFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DieBk48w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f16si7813498ybn.24.2019.03.13.21.58.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 21:58:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DieBk48w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4ISE-0006h4-CC for patch@linaro.org; Thu, 14 Mar 2019 00:58:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IP1-0004U1-KQ for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IP0-0007Mh-In for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:35 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:39623) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IP0-0007MI-Ac for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:34 -0400 Received: by mail-pg1-x542.google.com with SMTP id h8so3146838pgp.6 for ; Wed, 13 Mar 2019 21:55:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+xqsi/guaYA7D3YHKOREkAPcowZW/n5ISz+HVCnkFiA=; b=DieBk48wUTWAq2D11D/aTKBJN0ycVlMybg+DqjwRZnIXmXQGCfHkr+B86ZfFeFs6oe t+qEzKCR8WSjVnoFhEeJbHRlgZBEDggiOfFXwFn0p/5gIGJd5xjNlHZJMW0yvbXvP4rC YR9jC9lXG1zca+vUfxiGeSmFfXBSkVcjwPIep/blWJB6f9XyIpoYwUoS6LjBLtkflBbp 9Uu8DxqmkZG9Idy3eJ2hadiVpvMQkJPtgJU36joHnImRPgHGcU4FTmuv8Kc+VWhwR4fA 0Fn10+OYdLLHrpiTpVFg/Ye2IhtegG3DugPIVwa71b55OoTy4WhyIG8v89dKGCHCTKoB 4t4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+xqsi/guaYA7D3YHKOREkAPcowZW/n5ISz+HVCnkFiA=; b=WfPQ2zEREOeX38doepNTQHch8GR9IUDYveq396VZc2hB3KOqnGgbkT0Qf8GKibjVEP SBWKpe63EyYEUBnQ77mMQ3n+9PurOht3xZZXcvuL3VKHxx0bkzGdO3jPpjmwboXploh3 LLl3/PGQWJ55YPQSUpoC4mBU1h+0Mla5441QIiA/Uaz3mxWahxwiBSmoZwGVicjnL2Vw /Y1AHXESbCE8XaZnRDwiGV7PAjEHbvDBE72urUVHM2CdlM+O2tccPFF6sdQvG32JZSlM XXc6qtTVhIu4Bw9SnRvxcZYp+lNzld+/NQzU7aNCbdhA5BxwKviN5kRCjXkdIQpOEAad UHBw== X-Gm-Message-State: APjAAAUNj/pGEcO8ASTHd81Ujy54S2rhmW5V5/4HzbS825esYxG91TSo 3Jc6qkOi+5eQ8xaB75YE4hWNvG6XgtE= X-Received: by 2002:a17:902:29ca:: with SMTP id h68mr5189804plb.297.1552539332912; Wed, 13 Mar 2019 21:55:32 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:15 -0700 Message-Id: <20190314045526.13342-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v2 03/14] crypto: Do not fail for EINTR during qcrypto_random_bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We can always get EINTR for read; /dev/urandom is no exception. Clean up return paths and avoid unnecessary goto. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) -- 2.17.1 Reviewed-by: Daniel P. Berrangé diff --git a/crypto/random-platform.c b/crypto/random-platform.c index f995fc0ef1..0866f216dc 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -65,29 +65,22 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, "Unable to read random bytes"); return -1; } - - return 0; #else - int ret = -1; - int got; - while (buflen > 0) { - got = read(fd, buf, buflen); - if (got < 0) { - error_setg_errno(errp, errno, - "Unable to read random bytes"); - goto cleanup; - } else if (!got) { - error_setg(errp, - "Unexpected EOF reading random bytes"); - goto cleanup; + ssize_t got = read(fd, buf, buflen); + if (unlikely(got <= 0)) { + if (got == 0) { + error_setg(errp, "Unexpected EOF reading random bytes"); + return -1; + } else if (errno != EINTR) { + error_setg_errno(errp, errno, "Unable to read random bytes"); + return -1; + } + } else { + buflen -= got; + buf += got; } - buflen -= got; - buf += got; } - - ret = 0; - cleanup: - return ret; #endif + return 0; } From patchwork Thu Mar 14 04:55:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160291 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15077508jad; Wed, 13 Mar 2019 22:04:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMEL0YGNzg/TC1xDy1Y1VlXpZ1TLvvfCdGyfdGT9Mnrlp0QTDAohxexYrfgaZGDQ7EEC+R X-Received: by 2002:a81:4bce:: with SMTP id y197mr13867632ywa.204.1552539863583; Wed, 13 Mar 2019 22:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539863; cv=none; d=google.com; s=arc-20160816; b=wAtp7lEVqkT+iCyEj/OQt7s+sOZD59U1eFRWXqxVE8doGwSKzvIJ1zybXvjIsZW44y 9IAbI5alMXoFLNHtTatqfTLRSxOdgOsX4xF6XYGOvqoNCrnFoqM7cdf1DbVN5rwQgn37 s7PjzWoZ0SwfoNeXKXjNxqqoDeUhGJtly527iB1gioHN3aGaY6S5QrBndRKZTGcswsH7 n4lpABTT504pFBq8JgO4Ee9gXFy0uInn/vAjeTfMLAdMZdynEgrr5Ba+XQPd9d6WwEo8 nMyp51gt8NOnjSsQ/IycEh5cdgrov09hhJSUwAywCuKyEgr/gj0bIPYJM9VxhSLMEPgF +x1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=NWEt74dwLia08E5ia2X/lyc1UBZ3BVl9ogK5yim+NNU=; b=m4MjD7hKtvey4ZukA8cvfI5amlPztSswdlXhBjnbHwQyoBXo7eJluIlp+R4kAKdkdr j93ZGTu2WOqnLMUkxlFtvnK9Wgffa2tnePTJa7PPC8F9gPFM+s5l1eLLHRf9OjwzcjDq /IMIjVRSw9NfP/sJif5+Fhf6rXaAr7qsyGJZkHgsizmHgnLiixFZcyWdgcVWt/jAd1dO w+B/0ylNqrAOrgJXmWCE/kZGzm8hp6TE5HigMMzdHwfs825SLsgrL2yqS+OJBVl4p5wi vwrC8zWbzDiAPD/V8hhccJ7Kp0jwhLFBSZElyFbdpKe+Ddq5hjtu4O7U/EEpMOcYQWfB qtRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ubpItWhA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x14si8373955ywj.463.2019.03.13.22.04.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 22:04:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ubpItWhA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IXX-0002dC-3N for patch@linaro.org; Thu, 14 Mar 2019 01:04:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56134) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IP2-0004UI-2T for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IP1-0007NB-CE for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:36 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:33574) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IP1-0007Mn-48 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:35 -0400 Received: by mail-pg1-x542.google.com with SMTP id h11so3168713pgl.0 for ; Wed, 13 Mar 2019 21:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NWEt74dwLia08E5ia2X/lyc1UBZ3BVl9ogK5yim+NNU=; b=ubpItWhA6lntjTUhGvP0EaDAhbCkORRernTV0grnO8NABPGSYaPzqJEIhTJWroQT5b Y2qXKPP4CkjNubOtgLHvJtbFE4cAfWKeCoan87M3TmObJ504bSKI1ozZHTGvx2QbGswJ 7vNFr4T7DzkRCP0VAJfXZB+xGCdIm9j4CMDEpgQRjC60T6o27o+Yb23J6C99mvFMkOo8 ufztjVvIjdVRZKzcOGdsn72hxaK2jQ+H5D5eG1BtZAd6Qq4S1MwOcbHWtzBiHQjap9fN 79Dz6MFVxbnKqEXZ+4m0YFZTVFUPaBi+NUT0oCA+X1xZtpzcLTKKGVA18ZWp79rFXPYO Siww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NWEt74dwLia08E5ia2X/lyc1UBZ3BVl9ogK5yim+NNU=; b=r8h7QcyFrzo8GCLc1vm4zvSO9S7azM0uVhDZoQPIXHswoKl+h6x36l0THzATifexr7 dXybKKSX/hvL7YvF805fN6udot5QxDd4Y79HVveghfpEUh3reH+WtO8ZmfO5RLlz7N+m OmQbqZBhvz5K5g1hx8SPUu5XCMlq43Vu/vs1bBMcQEksjANrmW1+6xSRD5YsZZ75dTLh 5DQ9FWGsZ12gwkXEbsT9PV+iZcLrdT/VwPcRbrc3mnHDg7YH50AxAOcRuZruARvSF3N1 862RCDOcQ4zvvcuDIugkUzdGfSJqWcviX82bNh8C8Uw0ypC3ULqHe4/0I60BC5bAYSQE qNmA== X-Gm-Message-State: APjAAAUJswwrd+eoanRlD6DZcMtZSlLC1ngsMg9ezZd4OSx/sWh8m85k YV4h4SYXXGyEzRd+XscmPVPPJRcjvaQ= X-Received: by 2002:a17:902:765:: with SMTP id 92mr48236470pli.95.1552539333922; Wed, 13 Mar 2019 21:55:33 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:16 -0700 Message-Id: <20190314045526.13342-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v2 04/14] crypto: Use O_CLOEXEC in qcrypto_random_init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Avoids leaking the /dev/urandom fd into any child processes. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 Reviewed-by: Daniel P. Berrangé diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 0866f216dc..8bfce99a65 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -42,9 +42,9 @@ int qcrypto_random_init(Error **errp) #else /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ - fd = open("/dev/urandom", O_RDONLY); + fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); if (fd == -1 && errno == ENOENT) { - fd = open("/dev/random", O_RDONLY); + fd = open("/dev/random", O_RDONLY | O_CLOEXEC); } if (fd < 0) { From patchwork Thu Mar 14 04:55:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160292 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15077594jad; Wed, 13 Mar 2019 22:04:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFmBtc3orlgPsiPDyr/lEfTPyisou/N4nHSEp5UqhXHdzWV/m2hF9kIRFhDnR/VVgdRxPF X-Received: by 2002:a0d:dbd2:: with SMTP id d201mr37549584ywe.484.1552539872207; Wed, 13 Mar 2019 22:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539872; cv=none; d=google.com; s=arc-20160816; b=k7JedxlHStzBTEradLKXmLpxeS6ZBiJJPEh3bRsLNL9YdOAIN/+a3O1jAWhQEM9slv L/ymYmsWnGxfsAgWqSie9N4I3mAudGf5GTwPfdpIcwBTR6MqB33JOEoC36NmKWM+ttex 13PhAXEyWwTUfeqKYQL23HjY2MvqIJrrMQgK0vlE3M19ktJuiqItWS4MjhfkZVpqXQoO g8Y7N3P285HDlWlOx4xQL0hTH3Ttmb5SvEuUpvgeDSI9CteNHyg+hRdhOo2NFwz23YeQ ffnOswHA4xtx7geUhouGN979jwPmcIxGqUFc2eQHfvSj7qffsvhSI+AUEGjXnfUZrEMD D9ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=CoYKWtcbjnkf8ec29DwDvyGtEftw+7AvJg2LPmquNfI=; b=ZVaD6pCqcewmVK/m6r2eBnzYWqlhyUpp/kxW6ND+pJyLOylWdeAWV9aRpR8v7EJRSu 7NFgucaBH4vDc344IzbOEv/NK4TaB12M3kQ28vJmCmA9p4WNNA0dACRzEKuiMvRCILeS fYV876Glj9Sp088ZvEAkzC6OEiMkeNPn0bq56C85idrU/7NSdXRBBXsOq7BzGaMShoZP xXhcsKqhiDblIsy+RyDkWVa+/15fNqRJ6Knj+d+rd+nBdl68FhXu0onFcmd0E5FYim1D lLMgglw1v1LYFYamNaLTxjCR8prqxlss0B/3ihk7+HmaOwf7rZmymooBQThweAS+A/+Q rDbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wxlZzNoJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 206si7890454ywo.44.2019.03.13.22.04.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 22:04:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wxlZzNoJ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IXf-0002nV-N3 for patch@linaro.org; Thu, 14 Mar 2019 01:04:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IP3-0004Vq-J9 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IP2-0007Ns-K8 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:37 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:35829) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IP2-0007NO-CJ for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:36 -0400 Received: by mail-pf1-x432.google.com with SMTP id j5so3019677pfa.2 for ; Wed, 13 Mar 2019 21:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CoYKWtcbjnkf8ec29DwDvyGtEftw+7AvJg2LPmquNfI=; b=wxlZzNoJBsCaR2oNNS1aUsFy7iv2g/iyxGCts959DJO0xVRFNZC8o5GQb9UJfWbqgL KJhZsSFYl07vr4oriN2AphT2WuTHqzaSbSt+N1tpd1OhqTXK6vIh0djo1CvPOIeVBOwV PqtmVo9bcVDeruzoUx06+GH9r5JaUfgkxFpUR7K4aeifyMCWyHBSDJ0w0TIgDSiJUlEG UMQb57RPVVcG5TnHNBrS1+fOLCbnu87JowSPTzGCeuK8xosTilw6z7L5yLDTdm76hKzE snFgOoi61dQJh5pLaE0aqzDSGH5xjeK0iYucFxH4v7WiHb0FSBB4Of3yfM92AIjxlGr4 6tvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CoYKWtcbjnkf8ec29DwDvyGtEftw+7AvJg2LPmquNfI=; b=IDhbWgTfx+AupL1zigsn/0X2u8ihP54lWu8z1RcSCZVr6+q+7PLWGY4Kw5NEegHknT SlOk4mHWBvnJOnBaa5c0eCz+Zn06/WZcmddieLR8xYq/1lKCyLnorinDVgA88Cv+saNf VhiP+rTNQCG6Qw/XqooMTWQ/sO4ZD3yt844ik53hklER7x+IO61O7GspjLkl3LxmaBte dCoOaLn4clG68bOvoD5oa15urFLVH3hPbCYc3v1Qd2W7YZY54zNUWM0icyLFs7W09qjL nJdb4IT1J/r47Fq+6BkG0mYn3nIquWaypvxk7j9h6cllGdA/5297v/JEAYIWYc5upx2D jtKQ== X-Gm-Message-State: APjAAAXiSnU0q/ixB3FW0DKF52K+Stbjy/MzdZzUJai/w55tDK/Uvb+M tf2WWhaskkNRM9TwSsWKJIjAgDZdrY4= X-Received: by 2002:a63:4c13:: with SMTP id z19mr17730178pga.71.1552539334932; Wed, 13 Mar 2019 21:55:34 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:17 -0700 Message-Id: <20190314045526.13342-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::432 Subject: [Qemu-devel] [PATCH v2 05/14] crypto: Use getrandom for qcrypto_random_bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Prefer it to direct use of /dev/urandom. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 21 +++++++++++++++++++++ configure | 18 +++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 8bfce99a65..bdaa8fbbfb 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -26,6 +26,8 @@ #ifdef _WIN32 #include static HCRYPTPROV hCryptProv; +#elif defined(CONFIG_GETRANDOM) +#include #else static int fd; /* a file handle to either /dev/urandom or /dev/random */ #endif @@ -39,6 +41,12 @@ int qcrypto_random_init(Error **errp) "Unable to create cryptographic provider"); return -1; } +#elif defined(CONFIG_GETRANDOM) + errno = 0; + if (getrandom(NULL, 0, 0) < 0 && errno == ENOSYS) { + error_setg_errno(errp, errno, "getrandom"); + return -1; + } #else /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ @@ -65,6 +73,19 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, "Unable to read random bytes"); return -1; } +#elif defined(CONFIG_GETRANDOM) + while (buflen > 0) { + ssize_t got = getrandom(buf, buflen, 0); + if (unlikely(got < 0)) { + if (errno != EINTR) { + error_setg_errno(errp, errno, "getrandom"); + return -1; + } + } else { + buflen -= got; + buf += got; + } + } #else while (buflen > 0) { ssize_t got = read(fd, buf, buflen); diff --git a/configure b/configure index 8992b3aade..6a32284d26 100755 --- a/configure +++ b/configure @@ -5783,6 +5783,20 @@ if compile_prog "" "" ; then have_utmpx=yes fi +########################################## +# check for getrandom() + +have_getrandom=no +cat > $TMPC << EOF +#include +int main(void) { + return getrandom(0, 0, GRND_NONBLOCK); +} +EOF +if compile_prog "" "" ; then + have_getrandom=yes +fi + ########################################## # checks for sanitizers @@ -7170,7 +7184,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 From patchwork Thu Mar 14 04:55:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160296 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15079378jad; Wed, 13 Mar 2019 22:07:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTk+Y/YvnV1sThUWD4oip1kmnMeo1Uo6Wv/Qhc4PEgpgPsdV7E5ZOvmPjA1KgmAOCJe5WQ X-Received: by 2002:a81:65c2:: with SMTP id z185mr37198787ywb.430.1552540027984; Wed, 13 Mar 2019 22:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552540027; cv=none; d=google.com; s=arc-20160816; b=zWFbUAqegy4LB5cJZISeLbx/PpZG1x5yzG9JmssOH1Hfjl7DNmBYR4OfDfqJ+m1N9i Wn+PmJAb8grFAOFnxonIr3Brfgyby3vZnyQS8Vs/Mq7+NSPlxklwZbbZGgLY3Bj02Yox N1cM8XMcBCK3Q+DokOt0wcF4MwjK80hM9F36VMZWFGz3ke03FwkwrM/NXgf70UEyzBys WxcKNWWWxX8SLccUznFcAeBzXkNnyCh75i7FAiiUepOIIiGy737XM7a7uwXGnDpRMRRU +eKMWLMVEHS4NqkfifapXT72YTr7xadFQcqq3zMZ6vf3U2ndrEGxOEcdQe1hfVECfp2L xVpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=gqAwyLmZC+r281Bx+Ixa5zHetQPvXenm/6ftztHIm1Y=; b=U9dd5xyts2H5U9yJCtlFmJAMKGReUk91jMFpYlMivOInyq1kZGX1XfaAiWY8Vfio1G f/jCZTN7tGuMl/P2X9wRrn59HoIVOAWWu3FZKdkketFvr2TtmdicMCy5+/x2Zb9XL1cb ucn+MGzFmOJLT+7+SkvXaj9kwGq0fRGgHVkszyWGpOFcADGsfxG+v8NHZhgB8WJ5F4DH jMwll+Spfw75T76F3aMIZXU6Fpkei8J7/CfBJAZ7zZcJT4uz5Fe2mTli51YvFw0AMTn8 JBRndhCEZNA7f/xYvD4bCAw8doQsQ6yIm1LUeX+65HsE6mFZecZSsJo8jW5SsjmdZsOV HkuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sXHw1scq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s189si8006518ywe.132.2019.03.13.22.07.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 22:07:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sXHw1scq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:57000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IaB-0004ZG-CQ for patch@linaro.org; Thu, 14 Mar 2019 01:07:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IP9-0004Yr-Re for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IP8-0007Qc-HL for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:43 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:34719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IP8-0007Q6-7n for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:42 -0400 Received: by mail-pf1-x442.google.com with SMTP id v64so3017716pfb.1 for ; Wed, 13 Mar 2019 21:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gqAwyLmZC+r281Bx+Ixa5zHetQPvXenm/6ftztHIm1Y=; b=sXHw1scqL7CUZNZV1rqroSCFf1Sx7Bsx8zwGvUXl0FjRYv55YIEq7jqFxANqR+Q6pK +xymAI/7SZsGEWWVbI6Baqp6LiTvy/VdjoAzR+A3kWNKxyJq7vtI2Se3VrhN72id/J3u I9LPQoTwTh1LCQZkfN+qYial2jqe8g4V6TKSrnqF7KREawYtV7hhqkX0b/ah3fpnXePw HoU5PNBTIk4EitSLmb5GlBtqPbzTTec54164ey6K0Mm+4i4ENGTcwVutWwSlOpjyUige 4HnQykDqLFdIi1ZHp+YY11Pu1xTGTfd70v0D0iaU78UFZEB5i/HixDipcd7xH9RIusTK Ibgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gqAwyLmZC+r281Bx+Ixa5zHetQPvXenm/6ftztHIm1Y=; b=tuxDkEYJS3yWSkfx8bKygf1ZTMcVQGpYDu0aKg/wCiLWNXd7PxY6MhvX9q2nAlwAcU CT+vfee6lK63a6zfbrpjhDVERnscGerEr4ql8yyGtwLrxhgzZj/Rdz9vHboeco/WtqiT IpSQl+zfukcnIjAxVuvgUGlNGUX8LvpX/xd6e6FP89xNntlcI6Oag3+bH0ZzkWma+2yX wjaU3+Ar366OeqdObJWdqjU/P44XoxLFzCO8vP1v8VJ0XwrxqIDdlPulEIiZ7rsYgseb r2UMNwPPMdvSQ3692QSUDlVNuZqDufpJrSC3zH9Oot6xgf9KfRjhoUhldF/d/G3pe1v0 VOEg== X-Gm-Message-State: APjAAAXQaiAhHjkEklPNKE2SRbw2NMSc6bpk3L8AzmZsKe1NgHWrlYt0 WC2YKQgp0QJYoPkj0IRTyutaJ+4f1Lk= X-Received: by 2002:a65:5cc7:: with SMTP id b7mr43655937pgt.396.1552539336134; Wed, 13 Mar 2019 21:55:36 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:18 -0700 Message-Id: <20190314045526.13342-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v2 06/14] crypto: Change the qcrypto_random_bytes buffer type to void* X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Using uint8_t* merely requires useless casts for use with other types to be filled with randomness. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- include/crypto/random.h | 2 +- crypto/random-gcrypt.c | 2 +- crypto/random-gnutls.c | 2 +- crypto/random-platform.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) -- 2.17.1 Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé diff --git a/include/crypto/random.h b/include/crypto/random.h index 8764ca0562..fde592904e 100644 --- a/include/crypto/random.h +++ b/include/crypto/random.h @@ -34,7 +34,7 @@ * * Returns 0 on success, -1 on error */ -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp); diff --git a/crypto/random-gcrypt.c b/crypto/random-gcrypt.c index 9f1c9ee60e..7aea4ac81f 100644 --- a/crypto/random-gcrypt.c +++ b/crypto/random-gcrypt.c @@ -24,7 +24,7 @@ #include -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp G_GNUC_UNUSED) { diff --git a/crypto/random-gnutls.c b/crypto/random-gnutls.c index 445fd6a30b..ed6c9ca12f 100644 --- a/crypto/random-gnutls.c +++ b/crypto/random-gnutls.c @@ -26,7 +26,7 @@ #include #include -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp) { diff --git a/crypto/random-platform.c b/crypto/random-platform.c index bdaa8fbbfb..51c219701d 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -63,8 +63,8 @@ int qcrypto_random_init(Error **errp) return 0; } -int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, - size_t buflen G_GNUC_UNUSED, +int qcrypto_random_bytes(void *buf, + size_t buflen, Error **errp) { #ifdef _WIN32 From patchwork Thu Mar 14 04:55:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160288 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15073413jad; Wed, 13 Mar 2019 21:59:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhBePrPneplkBAU078P3djtvmObauI1fVtGO0Na20APXixy/JeylqPFrE5f4ir3UjM200r X-Received: by 2002:a25:34d3:: with SMTP id b202mr40239944yba.188.1552539550414; Wed, 13 Mar 2019 21:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539550; cv=none; d=google.com; s=arc-20160816; b=SPV8yFpBNFTkGtX6dlaetrMv1ayynH/KLIwdKvfb8Jw8sO9dcA5ubVerxenjsvw4vl 56Iao9GQ9j6F44Qc4CL4hs0KgfHBvZYPVu8CF6t19z8bSasO+9zXqAgENxlMVELBeFUe kTuglblYlfzKj3FhNS7eVGO9n508oyZJ/jDSlhV3bo9UlPwTaVNMg+97ZfwHn1Bi+Mgf S6+MKPc56W09l3f7CsW9RxmXXLpTmudGG333kjlNAoVCGaYAygV3JJmVM2GqMdNM2mau 0HPNolqUXqWKma3PnhGCJVhw582P7wmfySLuqPDmltS6f+CAIcq55U3bou37IM2uv1/f rpWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=xzvOFE0efPIbOrrniJr0rCF+lgmieAStNQzr5aCVccg=; b=DhkeCUKv6CrjAZI1l7nQwBQx9ZTPd4wTk9romm2byr5CucomiKvvCGWFQxjZLAnzm6 l/By41oMlZd43nneVvhnoqbXmOmNUKN7x2oN9g65DYmu4L/i+71bI5HGsEmXJh9tTNBT Ryjm3Do70MVyBd7ZoE3gSMDNR3y27jWB8IxbbA1BZCSjqV3Z9NTOCSnKiRIrxB6umsGh Z09EaNk0rH9BiT0UIe09ysMdjgHsfy7UzKvAyquI8knSQ4sTtKgU8nE1RV7eyJERVLav RGIoHk7IjYlwsOWF4YDvylF/cHT+TWdAux0TeSBsLopAnT5KeHbNcDtXCfiwS6FSRT9I FcJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UHIxX9Lk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k10si8167319ybb.486.2019.03.13.21.59.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 21:59:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UHIxX9Lk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56871 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4ISS-0006tG-Bs for patch@linaro.org; Thu, 14 Mar 2019 00:59:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IP5-0004XY-Dm for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IP4-0007Of-KW for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:39 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:39624) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IP4-0007OM-Ca for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:38 -0400 Received: by mail-pg1-x542.google.com with SMTP id h8so3146945pgp.6 for ; Wed, 13 Mar 2019 21:55:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xzvOFE0efPIbOrrniJr0rCF+lgmieAStNQzr5aCVccg=; b=UHIxX9LkHu52su0CP7YXy10UbQPtFne/AoPEa0HbGCTzkshD7J4YnENOOIwXy30ljo W/+qs+JmMbx7MB34v1u2ujGukCDED0VUEExv8XwMUMOegmTUn3vIYuzrCH5Q0dFBE/mR EdTPABSolCLVQ1HMWYs9uaVkxaf0QsjMysiFODn2eQGTda57+HaV/5uNqY5bbv/LkuEv r9cCGpX0AmFUPQ5yVoJY5G9vCavxmnnT35Iw2cFhK74gPnz39eehQ/RBSP1u3XQd1wkO UUbRXpJgcNAapGwgjyaQ9gRcXbfQiJFOyQyR5OTUSQLsqccZNXtDlsGf77VUqmyHGFdL NmOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xzvOFE0efPIbOrrniJr0rCF+lgmieAStNQzr5aCVccg=; b=DB9EIcrt57L6GB9c9/bGbDqpkstrBYB3fIMRCnNkI8GnMRhOB/Sv7TuYAwtZnpsLPz bkWn8RFvOi0y6GTwSnUDURzBUt+qkorwKPPX+1hpGAF+ETgusjUKBnsbjHKf8UyQBSCD hC342s6//wWF7i0yoBv9E5WQYxPKjvjcyf0d03JbkjZiKW3Bwtoq6HNK74OT3WOTgm5d Jwmo98mXvUvG6pplZXeQlZG4rxjJH6dKQi5lRGFdMQAf38DVPZ+pYxopUr3fe1AyDvlS HO5iVApw0rR9OF3Dv9ecFEUksJZouef1MpDrKOT3Ofb2g0V67mPSzdcEt8GuMIHEOvkF FjTw== X-Gm-Message-State: APjAAAV2dnHR7ssxQxtWa3fJPHsxO7py+OFhh7Ccuvez7RmubUnj9t8i Ib+bShnpBjlqZkEMDlyfFhE2Kh2xyEU= X-Received: by 2002:a63:ef05:: with SMTP id u5mr43563817pgh.177.1552539337152; Wed, 13 Mar 2019 21:55:37 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:19 -0700 Message-Id: <20190314045526.13342-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v2 07/14] ui/vnc: Use qcrypto_random_bytes for make_challenge X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand, plus some useless floating point arithmetic. Cc: Gerd Hoffmann Signed-off-by: Richard Henderson --- v2: Use qcrypto_random_bytes, not qemu_getrandom, as there is no need for deterministic results for this interface. --- ui/vnc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) -- 2.17.1 Reviewed-by: Gerd Hoffmann diff --git a/ui/vnc.c b/ui/vnc.c index 1871422e1d..9fa586dfa0 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -43,6 +43,7 @@ #include "crypto/hash.h" #include "crypto/tlscredsanon.h" #include "crypto/tlscredsx509.h" +#include "crypto/random.h" #include "qom/object_interfaces.h" #include "qemu/cutils.h" #include "io/dns-resolver.h" @@ -2537,12 +2538,7 @@ void start_client_init(VncState *vs) static void make_challenge(VncState *vs) { - int i; - - srand(time(NULL)+getpid()+getpid()*987654+rand()); - - for (i = 0 ; i < sizeof(vs->challenge) ; i++) - vs->challenge[i] = (int) (256.0*rand()/(RAND_MAX+1.0)); + qcrypto_random_bytes(vs->challenge, sizeof(vs->challenge), &error_fatal); } static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) From patchwork Thu Mar 14 04:55:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160293 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15077703jad; Wed, 13 Mar 2019 22:04:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjRjOvdRGIJi6K6Ein+RiOUE62QsdkmjomSM4/b3q9Phz7zT1SyTHRGxeEe/HWahniKeLg X-Received: by 2002:a25:a285:: with SMTP id c5mr24645857ybi.140.1552539882669; Wed, 13 Mar 2019 22:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539882; cv=none; d=google.com; s=arc-20160816; b=Q18ZVvhTXe9nd8FrhO8c4BE9a69wXDgNqzqHC2WNMXBdkgurGBzc6jb9LLvbeZCe/q euxDZFoceBVNWNxMmAfHSubr9xEc2AvHRRgxDbrG8qpsxTzT34rN6dnfZRp/104Skid6 M7f9eMrgGSoszzPwsdit12JV55sQxK6unD6sfbhIK7KBG7ZaA7PVu7ZaTNhi6rxBIxyC 5MkPEmP6fQEyITM0dCNoea5XbWwwkST+CpcYPSMguVdw6LPcDLkAsVQs6Ml2MCp2fmdm SY31ha+PfxxzrBz10BK5mVSvBL/lq3+GYMfRWfcx52Qvwda+28Q1QVtuFhE//pjFagZy rPOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=r/9fu8oUAgIeYStikSu5RD4Xo7mI5WjXjD4LSh4V41I=; b=IiHukV/rbNR8urVZaFrvXZkp31YhK1sDB7XGvRUhOMsMnoKM7k7gA5/A8BbIyVGqXg uRN1TtisfbXHbbLvNwbttbrQwve3S3RrLOs0kYIMOc57ad6Z2OZtrxVGvo/wVFZ62c+A SZzh/kp5bJD/4NECZtqualUdBJ2dJEoI5rgfH26eYMe/sswbP/s8IgAmr7UlZdXk0iKA L9O09PfduxcybmL/ZiBMmuyYCqwieaKCTUkxalET3xsKqLo7gNEft7e2rNLCef8BdlvU kjAyOiil9bswMZW1II3Y8Ett6vbYuz19Xfp+ccae9dptkuyU7YpSxYoqRt1WDqiBYT0W FpNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tiddGgJB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 7si7981192ybc.200.2019.03.13.22.04.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 22:04:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tiddGgJB; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IXq-0002rn-6B for patch@linaro.org; Thu, 14 Mar 2019 01:04:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IP8-0004Xe-E5 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IP6-0007PF-9D for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:42 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:36605) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IP5-0007Ou-Ta for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:40 -0400 Received: by mail-pf1-x441.google.com with SMTP id n22so3014169pfa.3 for ; Wed, 13 Mar 2019 21:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=r/9fu8oUAgIeYStikSu5RD4Xo7mI5WjXjD4LSh4V41I=; b=tiddGgJBgeKZrs3fcr94TxtqQkLDjLqGH4nZMKQ5yEuNlrNVt8BeK6Cwkp/grX4FSn pSq+cvp8/6lanki/w+tinpJMF8t0/W6Gy94y2gtqynw8oHBU+v2KcQOyALZohG/A5gFj HFvS85elwcIZ0gH2g+teATPn+VX47qT1kEcdMR7TedsLFv//VVE91iw/F7chxUiN+Hle xg3vm0OHRQFLLkH0aIcDkaINA9mLQfzrMsMneXKlo3CJKEzKD813AIYClMfG4pCov+YM LyvF4qobPDGBSOSvF2ajThrZrvvJqlQbBBT1UEYP9p6YyrNoaeN1QIPRBBuRvoTEUNp9 VKCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=r/9fu8oUAgIeYStikSu5RD4Xo7mI5WjXjD4LSh4V41I=; b=stYP670uQIpeyMZpa0ZuA/ZUdye0qg8fC8+wXMSix4QOVofNKo7DrWbhiDWOkQkon6 xwWTHXiIeo5YgVolpUO/B7gTxktm8aZ0qaM/MYTDto6l+/UGvXBMKAcq4aZ4+c2Q0p6h VTotl75D4N5YJkisX7/LwFt35NOI9rjac4CaJY8uCmhB0Y4+Tc2lYkzC5yyZ3Kyc3+2d baPhagDy5r5+TTSdqAWnU7NRtNNBtdbeHeiMeFUNf1Ng22dDUv2W2uXcUOuuo3Oi1qrk oICkycZL7TbafxREgoDbMPXSI5EQkmzX+I+0lGhtQO7bqN7Ja3wG+Gc8q4+MJ9ve5nZh fVvg== X-Gm-Message-State: APjAAAUEc3P0k6hGJqeIU/mV4vAhOx0QOjhuLpUbw2HbBoXA2HwTlDcI 5lQgxMlG+UGKBa8zG9DP6OSrtpba2IA= X-Received: by 2002:a63:4287:: with SMTP id p129mr25071919pga.84.1552539338273; Wed, 13 Mar 2019 21:55:38 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:20 -0700 Message-Id: <20190314045526.13342-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 Subject: [Qemu-devel] [PATCH v2 08/14] util: Add qemu_getrandom and support functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Initialize the system from system and linux-user arguments. Propagate deterministic seeds when creating new cpu threads. Signed-off-by: Richard Henderson --- include/qemu/random.h | 58 +++++++++++++++++++++++++++++++++++ include/qom/cpu.h | 1 + cpus.c | 9 ++++++ linux-user/main.c | 21 ++++++------- linux-user/syscall.c | 3 ++ util/random.c | 71 +++++++++++++++++++++++++++++++++++++++++++ vl.c | 4 +++ qemu-options.hx | 10 ++++++ util/Makefile.objs | 1 + 9 files changed, 167 insertions(+), 11 deletions(-) create mode 100644 include/qemu/random.h create mode 100644 util/random.c -- 2.17.1 diff --git a/include/qemu/random.h b/include/qemu/random.h new file mode 100644 index 0000000000..9d88008288 --- /dev/null +++ b/include/qemu/random.h @@ -0,0 +1,58 @@ +/* + * QEMU random functions + * + * Copyright 2019 Linaro, Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + */ + +#ifndef QEMU_RANDOM_H +#define QEMU_RANDOM_H + +/** + * qemu_seedrandom_main(const char *optarg, Error **errp) + * @optarg: a non-NULL pointer to a C string + * @errp: an Error handler + * + * The @optarg value is that which accompanies the -seed argument. + * This forces qemu_getrandom into deterministic mode. + */ +void qemu_seedrandom_main(const char *optarg, Error **errp); + +/** + * qemu_seedrandom_thread_part1(void) + * + * If qemu_getrandom is in deterministic mode, returns an + * independant seed for the new thread. Otherwise returns 0. + */ +uint64_t qemu_seedrandom_thread_part1(void); + +/** + * qemu_seedrandom_thread_part2(uint64_t seed) + * @seed: a value for the new thread. + * + * If qemu_getrandom is in deterministic mode, this stores an + * independant seed for the new thread. Otherwise a no-op. + */ +void qemu_seedrandom_thread_part2(uint64_t seed); + +/** + * qemu_getrandom(void *buf, size_t len, bool nonblock) + * @buf: a buffer of bytes to be written + * @len: the number of bytes in @buf + * @nonblock: do not delay if the entropy pool is low + * + * Fills len bytes in buf with random data. If nonblock is false, + * this may require a delay while the entropy pool fills. Returns + * true if the call is successful, but the only non-successful case + * is when nonblock is true. + * + * The value of len must be <= 256, so that the BSD getentropy(3) + * function can be used to implement this. + */ +bool qemu_getrandom(void *buf, size_t len, bool nonblock); + +#endif /* QEMU_RANDOM_H */ diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 1d6099e5d4..343cc6d51e 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -372,6 +372,7 @@ struct CPUState { int singlestep_enabled; int64_t icount_budget; int64_t icount_extra; + uint64_t random_seed; sigjmp_buf jmp_env; QemuMutex work_mutex; diff --git a/cpus.c b/cpus.c index e83f72b48b..b5d3f46220 100644 --- a/cpus.c +++ b/cpus.c @@ -49,6 +49,7 @@ #include "qemu/option.h" #include "qemu/bitmap.h" #include "qemu/seqlock.h" +#include "qemu/random.h" #include "tcg.h" #include "hw/nmi.h" #include "sysemu/replay.h" @@ -1275,6 +1276,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_seedrandom_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1318,6 +1320,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_seedrandom_thread_part2(cpu->random_seed); do { qemu_mutex_unlock_iothread(); @@ -1477,6 +1480,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_seedrandom_thread_part2(cpu->random_seed); /* wait for initial kick-off after machine start */ while (first_cpu->stopped) { @@ -1591,6 +1595,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg) hax_init_vcpu(cpu); qemu_cond_signal(&qemu_cpu_cond); + qemu_seedrandom_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1630,6 +1635,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_seedrandom_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1670,6 +1676,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_seedrandom_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1723,6 +1730,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_seedrandom_thread_part2(cpu->random_seed); /* process any pending work */ cpu->exit_request = 1; @@ -2070,6 +2078,7 @@ void qemu_init_vcpu(CPUState *cpu) cpu->nr_cores = smp_cores; cpu->nr_threads = smp_threads; cpu->stopped = true; + cpu->random_seed = qemu_seedrandom_thread_part1(); if (!cpu->as) { /* If the target cpu hasn't set up any address spaces itself, diff --git a/linux-user/main.c b/linux-user/main.c index a0aba9cb1e..9682e81610 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -33,6 +33,7 @@ #include "tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h" +#include "qemu/random.h" #include "elf.h" #include "trace/control.h" #include "target_elf.h" @@ -47,6 +48,7 @@ static int gdbstub_port; static envlist_t *envlist; static const char *cpu_model; static const char *cpu_type; +static const char *seed_optarg; unsigned long mmap_min_addr; unsigned long guest_base; int have_guest_base; @@ -289,15 +291,9 @@ static void handle_arg_pagesize(const char *arg) } } -static void handle_arg_randseed(const char *arg) +static void handle_arg_seed(const char *arg) { - unsigned long long seed; - - if (parse_uint_full(arg, &seed, 0) != 0 || seed > UINT_MAX) { - fprintf(stderr, "Invalid seed number: %s\n", arg); - exit(EXIT_FAILURE); - } - srand(seed); + seed_optarg = arg; } static void handle_arg_gdb(const char *arg) @@ -432,7 +428,7 @@ static const struct qemu_argument arg_table[] = { "", "run in singlestep mode"}, {"strace", "QEMU_STRACE", false, handle_arg_strace, "", "log system calls"}, - {"seed", "QEMU_RAND_SEED", true, handle_arg_randseed, + {"seed", "QEMU_RAND_SEED", true, handle_arg_seed, "", "Seed for pseudo-random number generator"}, {"trace", "QEMU_TRACE", true, handle_arg_trace, "", "[[enable=]][,events=][,file=]"}, @@ -687,8 +683,11 @@ int main(int argc, char **argv, char **envp) do_strace = 1; } - if (getenv("QEMU_RAND_SEED")) { - handle_arg_randseed(getenv("QEMU_RAND_SEED")); + if (seed_optarg == NULL) { + seed_optarg = getenv("QEMU_RAND_SEED"); + } + if (seed_optarg != NULL) { + qemu_seedrandom_main(seed_optarg, &error_fatal); } target_environ = envlist_to_environ(envlist, NULL); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 208fd1813d..18d98f5a08 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -110,6 +110,7 @@ #include "uname.h" #include "qemu.h" +#include "qemu/random.h" #include "fd-trans.h" #ifndef CLONE_IO @@ -5448,6 +5449,7 @@ static void *clone_func(void *arg) put_user_u32(info->tid, info->child_tidptr); if (info->parent_tidptr) put_user_u32(info->tid, info->parent_tidptr); + qemu_seedrandom_thread_part2(cpu->random_seed); /* Enable signals. */ sigprocmask(SIG_SETMASK, &info->sigmask, NULL); /* Signal to the parent that we're ready. */ @@ -5534,6 +5536,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, initializing, so temporarily block all signals. */ sigfillset(&sigmask); sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); + cpu->random_seed = qemu_seedrandom_thread_part1(); /* If this is our first additional thread, we need to ensure we * generate code for parallel execution and flush old translations. diff --git a/util/random.c b/util/random.c new file mode 100644 index 0000000000..467c987a66 --- /dev/null +++ b/util/random.c @@ -0,0 +1,71 @@ +/* + * QEMU random functions + * + * Copyright 2019 Linaro, Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/cutils.h" +#include "qapi/error.h" +#include "qemu/random.h" + +static __thread GRand *thread_rand; + +/* Deterministic implementation using Glib's Mersenne Twister. */ +bool qemu_getrandom(void *buf, size_t len, bool nonblock) +{ + GRand *rand; + size_t i; + uint32_t x; + + g_assert(len <= 256); + + rand = thread_rand; + if (unlikely(rand == NULL)) { + /* Thread not initialized for a cpu, or main w/o -seed. */ + thread_rand = rand = g_rand_new(); + } + + for (i = 0; i + 4 <= len; i += 4) { + x = g_rand_int(rand); + __builtin_memcpy(buf + i, &x, 4); + } + if (i < len) { + x = g_rand_int(rand); + __builtin_memcpy(buf + i, &x, i - len); + } + + return true; +} + +uint64_t qemu_seedrandom_thread_part1(void) +{ + uint64_t ret; + qemu_getrandom(&ret, sizeof(ret), false); + return ret; +} + +void qemu_seedrandom_thread_part2(uint64_t seed) +{ + g_assert(thread_rand == NULL); + thread_rand = g_rand_new_with_seed_array((const guint32 *)&seed, + sizeof(seed) / sizeof(guint32)); +} + +void qemu_seedrandom_main(const char *optarg, Error **errp) +{ + unsigned long long seed; + if (parse_uint_full(optarg, &seed, 0)) { + error_setg(errp, "Invalid seed number: %s", optarg); + } else { + g_assert(thread_rand != NULL); + g_rand_set_seed_array(thread_rand, (const guint32 *)&seed, + sizeof(seed) / sizeof(guint32)); + } +} diff --git a/vl.c b/vl.c index c1d5484e12..0438b72f95 100644 --- a/vl.c +++ b/vl.c @@ -128,6 +128,7 @@ int main(int argc, char **argv) #include "qapi/qapi-commands-ui.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" +#include "qemu/random.h" #define MAX_VIRTIO_CONSOLES 1 @@ -3330,6 +3331,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_DFILTER: qemu_set_dfilter_ranges(optarg, &error_fatal); break; + case QEMU_OPTION_seed: + qemu_seedrandom_main(optarg, &error_fatal); + break; case QEMU_OPTION_s: add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); break; diff --git a/qemu-options.hx b/qemu-options.hx index 08749a3391..ed70de67d8 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3601,6 +3601,16 @@ the 0x200 sized block starting at 0xffffffc000080000 and another 0x1000 sized block starting at 0xffffffc00005f000. ETEXI +DEF("seed", HAS_ARG, QEMU_OPTION_seed, \ + "-seed number seed the pseudo-random number generator\n", + QEMU_ARCH_ALL) +STEXI +@item -seed @var{number} +@findex -seed +Force qemu to use a deterministic pseudo-random number generator, +seeded with @var{number}. +ETEXI + DEF("L", HAS_ARG, QEMU_OPTION_L, \ "-L path set the directory for the BIOS, VGA BIOS and keymaps\n", QEMU_ARCH_ALL) diff --git a/util/Makefile.objs b/util/Makefile.objs index 835fcd69e2..bc7405c535 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -53,5 +53,6 @@ util-obj-y += iova-tree.o util-obj-$(CONFIG_INOTIFY1) += filemonitor-inotify.o util-obj-$(CONFIG_LINUX) += vfio-helpers.o util-obj-$(CONFIG_OPENGL) += drm.o +util-obj-y += random.o stub-obj-y += filemonitor-stub.o From patchwork Thu Mar 14 04:55:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160295 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15079277jad; Wed, 13 Mar 2019 22:07:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIu/gV8hdY2uhnd3sq43PDwrBJBNMb0yMKGMEvx/iUDSl/cMbrSqi8zy1XXG9nectK0sy+ X-Received: by 2002:a81:2f8c:: with SMTP id v134mr35129361ywv.438.1552540020017; Wed, 13 Mar 2019 22:07:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552540020; cv=none; d=google.com; s=arc-20160816; b=gpgEEO+lpOlQDDcyG6kMWvQ2uKrYfc+a175eYQ3Vt9ufXn41CqFK+0Mj9qzdAeCbsk vTFwjscMkELdCDDx6E1DskHKNjYG4H8J/7oTKQAsUV2jHOENg+PglqvEvsPEcb696AZx 3hnMep1uMXyQvyyEF6Fc0kt+z0R1H/wO6TDGvECAKuydKEly+5culwm5CGDL0mGvjEEo MTXirb3mMFmhogSDdqaCT51GwGXZhAmyKTPYEB1nRSyHHZPC4hWrLp/YZHQIYZzm5EYH 7boEd9huGky5Cst6ksE7UDvsHd/DHfii1ylJztWNR89g3v7uiZJUbgcGes1Rqucl0QP3 o1YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=lNgGBV08JdM/4W0wwa/93vZ9B93Qd3ysUi2+GHmW4Nw=; b=rVthWoiKvZgGlwLRq14zFpe9gzA6TGSZGhW10iNJuvzwCdx/NH8NnO5vQId7+Tl6Eo qY7daJpikqd0oGkcRFijsll3W/sNnVoEXLowEcizvoRcaa44duc0ekqeGzmLwDp9+Cj9 qYHmpNGtpm8JTi7lS1BTZMCI7OFVWAjMJcZxGcMdBvWPgaPa9Xz4jBkg6MQFQ8A2S4RR 1oQ0vGEXP3P0QlekuN6fE9M7+WGtV9HIwMVxEhoda5deDa/Lv7wE0Mo0cM5dqHZS8uLg ZCOcImFSM/Ek0W7S96w6dIdURrkPwN8LGWiKAAmiTBSa0ejI3B2VLF5gRI8TXkmBWX7x QVdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oUdSXLr8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d18si7941315ywh.325.2019.03.13.22.06.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 22:07:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oUdSXLr8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56996 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4Ia3-0004T8-Dx for patch@linaro.org; Thu, 14 Mar 2019 01:06:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IP7-0004Xa-UQ for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IP6-0007Pe-Uh for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:41 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:36607) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IP6-0007P7-LM for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:40 -0400 Received: by mail-pf1-x443.google.com with SMTP id n22so3014183pfa.3 for ; Wed, 13 Mar 2019 21:55:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=lNgGBV08JdM/4W0wwa/93vZ9B93Qd3ysUi2+GHmW4Nw=; b=oUdSXLr8DU3aAxbrYw44qUpudvkfAguGWrANmDdab3A332d1YcqICcAAFlfdibhhh9 LsE1I9fbIXgbW5n4U3jMoJU/Dsm3F+e+XwXnKdSpMtzhQB8ZfyYP+jyWTwre6a5TPkpB OZm0TCfYaO2JmhKWQz3FvfPBx1Ha5PkfLlxCg5fJaai2eEaQo7yPZpo+apEmT7X/Vh7b 1QR9SBzpsmBciUpr1voYaH1Jw6LBI5yN6+Rg5K7YFafnpTAEA3VApW674fQR+DBxsStB Jy/74Gv5eulY6KgN89MJKhVv8up3nLXdSqfsTuvmPexgEM1hKUbWDnzyGjedBst5cPZg jWUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=lNgGBV08JdM/4W0wwa/93vZ9B93Qd3ysUi2+GHmW4Nw=; b=JItUy4/JSsxjXkN/pKVfFJ8i5lc3Jp0JSqME7OLM1giEETTpLIybt5UVDeEUf5oPDB IbEGtp2sJXtb6fYP9WnoUmD1Rq2bF2BSoI0kDRdwJbWUIVl2FmkA7BVYqz3QaXc5Klpn CU/Ra+dYH4GvHzs9jqB8ePfZGWra6EbXj/FKwB+ba7rtSAPzDnVZUel2gcKrkw4s8Cce xtqnDCAWekouyoekcfBDrvt9eGQ2wQJ3nOnp1qFiobumfNvVVvhYWpeuEipbubS/zbeP 6WA0LLRapqi4DA3XkfGO69mA8EKGFPY6qq2OLUGMRHt3bUNsveWALNj1ZolqyeJYDHWt riEQ== X-Gm-Message-State: APjAAAXpA0mLHCThsoNxAUfnIJb7tuKk61lc7rYcjJLExL2Spfz6C/WG TpP8ZXbSYwVRgb94W8DZxJPzEDnmW9k= X-Received: by 2002:a17:902:1025:: with SMTP id b34mr50271080pla.306.1552539339274; Wed, 13 Mar 2019 21:55:39 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:21 -0700 Message-Id: <20190314045526.13342-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v2 09/14] util: Use qcrypto_random_bytes for qemu_getrandom X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" When not requesting deterministic bytes, use our existing crypto. Signed-off-by: Richard Henderson --- util/random.c | 61 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 13 deletions(-) -- 2.17.1 diff --git a/util/random.c b/util/random.c index 467c987a66..c2628ace80 100644 --- a/util/random.c +++ b/util/random.c @@ -14,19 +14,20 @@ #include "qemu/cutils.h" #include "qapi/error.h" #include "qemu/random.h" +#include "crypto/random.h" + static __thread GRand *thread_rand; +static bool deterministic; + /* Deterministic implementation using Glib's Mersenne Twister. */ -bool qemu_getrandom(void *buf, size_t len, bool nonblock) +static bool do_glib(void *buf, size_t len, bool nonblock) { - GRand *rand; + GRand *rand = thread_rand; size_t i; uint32_t x; - g_assert(len <= 256); - - rand = thread_rand; if (unlikely(rand == NULL)) { /* Thread not initialized for a cpu, or main w/o -seed. */ thread_rand = rand = g_rand_new(); @@ -44,18 +45,53 @@ bool qemu_getrandom(void *buf, size_t len, bool nonblock) return true; } +/* Non-deterministic implementation using crypto routines. */ +static bool do_qcrypt(void *buf, size_t len, bool nonblock) +{ + if (nonblock) { + /* + * ??? This is not non-blocking; report failure as "would block". + * That said, what does "failure" really mean, and can we in fact + * reasonably recover from it? + */ + if (qcrypto_random_bytes(buf, len, NULL) < 0) { + return false; + } + } else { + int ret = qcrypto_random_bytes(buf, len, &error_fatal); + g_assert(ret == 0); + } + return true; +} + +bool qemu_getrandom(void *buf, size_t len, bool nonblock) +{ + g_assert(len <= 256); + if (unlikely(deterministic)) { + return do_glib(buf, len, nonblock); + } else { + return do_qcrypt(buf, len, nonblock); + } +} + uint64_t qemu_seedrandom_thread_part1(void) { - uint64_t ret; - qemu_getrandom(&ret, sizeof(ret), false); - return ret; + if (deterministic) { + uint64_t ret; + do_glib(&ret, sizeof(ret), false); + return ret; + } + return 0; } void qemu_seedrandom_thread_part2(uint64_t seed) { g_assert(thread_rand == NULL); - thread_rand = g_rand_new_with_seed_array((const guint32 *)&seed, - sizeof(seed) / sizeof(guint32)); + if (deterministic) { + thread_rand = + g_rand_new_with_seed_array((const guint32 *)&seed, + sizeof(seed) / sizeof(guint32)); + } } void qemu_seedrandom_main(const char *optarg, Error **errp) @@ -64,8 +100,7 @@ void qemu_seedrandom_main(const char *optarg, Error **errp) if (parse_uint_full(optarg, &seed, 0)) { error_setg(errp, "Invalid seed number: %s", optarg); } else { - g_assert(thread_rand != NULL); - g_rand_set_seed_array(thread_rand, (const guint32 *)&seed, - sizeof(seed) / sizeof(guint32)); + deterministic = true; + qemu_seedrandom_thread_part2(seed); } } From patchwork Thu Mar 14 04:55:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160283 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15071875jad; Wed, 13 Mar 2019 21:56:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzR3EtQbAEMelg7XzlZ/FPoU0kisXA1gM+UP2RLGvnA65zaMAOxLrCumvbgUc4Qk9mV72fs X-Received: by 2002:a81:27d5:: with SMTP id n204mr36718371ywn.495.1552539372387; Wed, 13 Mar 2019 21:56:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539372; cv=none; d=google.com; s=arc-20160816; b=02XmnE/qnJBU1b5qLmCS/GUXzc79nGvXVOpdYbefXctOtNM3U1JXrVIyrVeznq4CRp Ev9sLexz7487AM4s4CgUYCWa6m/VxsBrTpKszHOx4LMKax3CuB6RNoTGdPWO+CLQbDfi 5ZGrBCKuKY+286/lJQwh00oxxeDFhH1x3BDSRva2RVH6yAtR10lXZk0BNab+bvzrncY5 8GtC2crvaNHgNhJdoHM8riMJ8ucZeaWI7xsyDYf03AcU9NsKXIvV2OcXC1HELyabpxjW R2RSVi6D5MdQo81n5c8vElbghpZZI1xlL8zR4dlHIbkXBztKbtyVeKmy/H7zxZWRAuEv 0TuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=uKRTrj7re9FbweA0AMluPgstQhCPOuLpPcbNF1yhnjs=; b=AT1owMGX919SnrJmLuV3QyYia+GfG0yhP3lyqcrVybMUsu9yRL+DF7CICngTqwxsa2 JQELBbAS8WVOfeEBP/xRj15PVmaFf4oPwVklhbP0pOE5Q46nGxXUWervMNdDvSj4RuWM M/FgX8AvPO8woBY2EWlYLMqtoPb3D83IxTCqUf2Mgb7m91WcXFupx8Edlt7e8TD0jgKV CVYMCMkH33hj/pxkNSNuj+r5uMW++cE2kg9vvyvaOdbWxYxdOHLjZO3BsZtYjWEPzj2c aOZsE0vNkd/W0h29oAEsl8UhOtFENKV+rJMj5cWOi+H+lHF2MQAylC3NPSjS1vfmXtbT UYww== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kPQEdaey; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i3si8011027ybb.306.2019.03.13.21.56.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 21:56:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kPQEdaey; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IPb-0004Zh-Qs for patch@linaro.org; Thu, 14 Mar 2019 00:56:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IP8-0004Xy-TE for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IP7-0007QG-Vr for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:42 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:44666) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IP7-0007Pm-P2 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:41 -0400 Received: by mail-pf1-x42a.google.com with SMTP id a3so2989284pff.11 for ; Wed, 13 Mar 2019 21:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uKRTrj7re9FbweA0AMluPgstQhCPOuLpPcbNF1yhnjs=; b=kPQEdaeyrSqiNfbRxn5VfepzkyUJd/QvhzcxHsKiFJ0q7pySPJaRBweYa8MYKFQ8xe N12ydlM9dMXAfunuIF1I1gIeLx4eAr+Yr4Y5woXzHYDymUfEM+oeWzr1duEMPyaP7Xmt OrLruxC8PoX5mst3+mFhqOOK3YlRxU3RLsCMVSRM4gp27Wwpn+qSKsl7uYcfe3Zn5yJL SWnlrMZdSqOy5nsJPpWrN6nktJRblRRok28Z8MIIgdQfCE20RtKjD8JrZ75FbDIMRgVh tucZ9d+/4xs2d5/iRElKWzNbriX5OGrWu6FjlYyyNu0vvyntWglIdhfDyfuUZnh4X8oN QnAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uKRTrj7re9FbweA0AMluPgstQhCPOuLpPcbNF1yhnjs=; b=H2tBmzPsJf07EMxiMIDezwJZs3TbCuP9ZP9r+3EuzDmF/84QVeYVeOfWN6kw8Tp+on 127k66vBNs/WPM5oI0NJTPQaaqIKQUbh94zbu0aDsP3pGd3EnI5UZFlhyYAFd7JhD+pr /ri/vRtikDc/Gjy5nAK3g4IiM2dY1m3/tRUJ4exCNvN6x9hoL8RNSGfdur9I3pYTN5Gl pBlOHxBS8oM/u1wsOig04kGnpnFP3ezXaYxcgZumSEuK4OMmtTqckNcheId4MY7bXkdR 3cYrv7LlqWoOj3ZpbDwHCff3AENs8i7mEKl84NAkYoRvLuqs/C+9cmr66KJ3vAqJX0KW /9qw== X-Gm-Message-State: APjAAAV8GXHRYeuIG0isCw4ON2HKIxjOV83S9WabIpdAeg9jV4rjQTFy 2jRYMRGm/u7VhCC2hWT0Pj1NxIo063M= X-Received: by 2002:a62:5249:: with SMTP id g70mr47305454pfb.115.1552539340534; Wed, 13 Mar 2019 21:55:40 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:22 -0700 Message-Id: <20190314045526.13342-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::42a Subject: [Qemu-devel] [PATCH v2 10/14] linux-user: Call qcrypto_init if not using -seed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is required before using qcrypto_random_bytes by way of qemu_getrandom. Cc: Laurent Vivier Signed-off-by: Richard Henderson --- linux-user/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index 9682e81610..192bf759b8 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -38,6 +38,7 @@ #include "trace/control.h" #include "target_elf.h" #include "cpu_loop-common.h" +#include "crypto/init.h" char *exec_path; @@ -688,6 +689,13 @@ int main(int argc, char **argv, char **envp) } if (seed_optarg != NULL) { qemu_seedrandom_main(seed_optarg, &error_fatal); + } else { + /* ??? This assumes qcrypto is only used by qemu_getrandom. */ + Error *err = NULL; + if (qcrypto_init(&err) < 0) { + error_reportf_err(err, "cannot initialize crypto: "); + exit(1); + } } target_environ = envlist_to_environ(envlist, NULL); From patchwork Thu Mar 14 04:55:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160286 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15073230jad; Wed, 13 Mar 2019 21:58:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwpfQ8ok5AhJ8wipuuRm0mfeVeGhhq5XkXHMhy7ojGNcEvPn4oI/sdxo58rtFCacZhC0Tb X-Received: by 2002:a81:3a05:: with SMTP id h5mr37502204ywa.282.1552539528202; Wed, 13 Mar 2019 21:58:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539528; cv=none; d=google.com; s=arc-20160816; b=teN085ZYNYPS8cuBVhCSluRtj+svmVxePd/t7tQirEsGFftPZxGx/8C/VCSAv/4okI Yuu7jPAWpg0Gac6g1yGkPOC8tNqTFhMTe0kYIjdkGSIU1kw2SqX3d4E3I/x4MyIQOlsZ UEmUsaoJs67jVIy2C74Ed75XispaTXWRndyOKAIym1Y68MIuNWjUZuFAMDBFcvoana0t CimFLu5BLMHhBV7yvZ5k0EHyBQvwOwt0atNPARInZveRbn97M4llxOa1SWSOxl0noemL jYKWyxzcxDkICSwo1Jau0i2atx/kXb3FoUQ0ORyiTyaTsR2i89kdTCDQGXn7FIQN8tK7 ItqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=7Mh6mMTXzeuIMplceTqZz4BZtZM4Cu0MqRNCaV8ItN4=; b=YUXHzIy4BAJpwlxSrg+GGH2hGnFJ9iUAW4Ag3ss4Bf/riAV0MmWn6g5hlccwsSzhzG EKVkiDi+aFFNsszPZicSjR/XFwnTJt1NIy9/JzZMcRAUXeeC5GaMsf1lko/QjPuA2FIl Gle1C4CdBTbmvMN52bWIEJhxfCO+7F4gNp9IX+JiMjPRndtZZlOoQYbJHu4kdQ4n9yOD hidTSiAy1XO3RBQKstxsRW+RxPZMwkhLmBBgiZFvHcigdYeCZVpspe/4Llkcze8vgP14 WvPRoTtioXjS1WFeXXVyVpLFZYNcLFASgb3QsiZmZKezxm5YZbudcuOkOGLdGzlXlDwd uVcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rj57aJww; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h40si8748882ywk.242.2019.03.13.21.58.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 21:58:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rj57aJww; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IS7-0006to-LC for patch@linaro.org; Thu, 14 Mar 2019 00:58:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IPA-0004Zt-NL for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IP9-0007RL-KW for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:44 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:36581) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IP9-0007Ql-Ao for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:43 -0400 Received: by mail-pg1-x541.google.com with SMTP id r124so3161708pgr.3 for ; Wed, 13 Mar 2019 21:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7Mh6mMTXzeuIMplceTqZz4BZtZM4Cu0MqRNCaV8ItN4=; b=rj57aJwwtIkxSgELXPiehqfcI1fnaiXOaMjjBonNnXTHPJKJuIpZB5JIUMWAAJJYWB nLdCl/l5RDw5I2bNbmvi232YoTZQMhhbnsaOgXQotte8Mef+TRzRWW+bpJyRA3BR/++5 fjcui8J0B3eIljV/ZmeQC6xVAqh95SGTkaBxFfHFBPLclbpDZcujphNt0SvKcaM1cShs pqpPXIFDNujB1ffb3xy9g3v648LAWKogtQZd2icHvPLlu0uzOW37d+p3EE+hbFowYY3z GRqgQCOnOARy0ceFrpPzO33yDig80vmRUmdO44E25rlvAS63/M+JQIOauEvTbAk/Jszq 93Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7Mh6mMTXzeuIMplceTqZz4BZtZM4Cu0MqRNCaV8ItN4=; b=rlqdqATCZycr1FdumsTWTvP51cwKn3JXqW6xwjWgIYIfvM38lRlWBGXQOSlfwHDwSx 90pAtx4oUe0CTRJRk030RszEYnHjCPSU9UAXjDG0Lxh2LF7+yAlqR59j9UTZcSVATar1 +25l1SSwUdEh2dw0V85ZXlpYd8y8PDfNlBoyJnmByap1KSL9R3cRSQbXg0gIRXmRjQoT AVFe0BKcYwOfVt7iG0Dj+/k6dnKz86Dq1ODSH7wCsKBERITpJtFPRhbICsm2P18aq3IS 2BvrjvsulWo6ASQPWiu34mTVrPoJ5eumfDwhSQ+s3IS/ILquqVAj6IhrS1nqS2jkAi5q PRyQ== X-Gm-Message-State: APjAAAU33eIDVBwe0r8j3JhOK9kL1nUzOMbMIuS2dz93m988HSclHphj FjY63VKDu83WvqS1krAtolonWwDgBBE= X-Received: by 2002:a17:902:6a4:: with SMTP id 33mr49539107plh.140.1552539341816; Wed, 13 Mar 2019 21:55:41 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:23 -0700 Message-Id: <20190314045526.13342-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH v2 11/14] linux-user: Use qemu_getrandom for AT_RANDOM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand * 16. Cc: Laurent Vivier Signed-off-by: Richard Henderson --- linux-user/elfload.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) -- 2.17.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c1a26021f8..f33bf4fb85 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -7,6 +7,7 @@ #include "qemu.h" #include "disas/disas.h" #include "qemu/path.h" +#include "qemu/random.h" #ifdef _ARCH_PPC64 #undef ARCH_DLINFO @@ -1883,12 +1884,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } /* - * Generate 16 random bytes for userspace PRNG seeding (not - * cryptically secure but it's not the aim of QEMU). + * Generate 16 random bytes for userspace PRNG seeding. */ - for (i = 0; i < 16; i++) { - k_rand_bytes[i] = rand(); - } + qemu_getrandom(k_rand_bytes, sizeof(k_rand_bytes), false); if (STACK_GROWS_DOWN) { sp -= 16; u_rand_bytes = sp; From patchwork Thu Mar 14 04:55:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160294 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15077997jad; Wed, 13 Mar 2019 22:05:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvkROB5vWoXORCurbSI1C7o4dz2PDSjBGpfsD0mUeZG4VfvQzf1bbvrhh7ScwY+HPBgJQb X-Received: by 2002:a25:9101:: with SMTP id v1mr40395576ybl.20.1552539908371; Wed, 13 Mar 2019 22:05:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539908; cv=none; d=google.com; s=arc-20160816; b=ItXPFv5vnb/nz0PBmfIdyC/yvhLCmsP+G6lHf9OOll35Jf60Tr19db+uUY76d8SNy7 +0o/e7mbIgQWbsVvzhOEQEbsYeodY1tgl2YGnsHepC6i+QLPxO9Pbt2GgLEWpMTTl7K1 pMx0uWYJEieR4EGLpAPPV0IbOO8FseFjNfUVF1956yxFpntUoWbXCxUtnVAfdZjyBbl6 moviAhC8GHzOMdeV8uq1mWfZLVzG95PhfprN9CvOiEWWia+ZiuIoJMYr+8ivnBkoyXKp fgOUrB9z8/XgVngJchJQyj4dkgUajtcodI/ELE6gFHk4X/gDoHhwjU5UsdBMLcEefUjU bq9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=I39zQahYJfO4v9BtHWnWSXDEM3G+gAshBbiSOHHVUzY=; b=sYOokG1M0zCKG1eaIvM5rBG2ukTfnrO3FFIcyUrazrYU+N/clqHnwTw+Q6a+4JTdJx SS+qOu1AFIFZlss+b5TbA2ntRXjf/OoA8cTQgTa6rUGXJGpyK/Npix8abph/pqnOIND/ xuPF8r35q/BmD6LoOku0IrMlVrm0mpMpLc7GTAY1HM3thg4L2P0QPrwJEiesaCGRQaFC DIiV9mGxw+CBw89LT79/WiqENOOJv3h900LzkJ0r3tF+KJ5lz79BTeDu4skvRTeASwy8 +cvxxKF6sofOiwe73bSx3lBNXAwpUb+l6+GLopyAOhM5kVQ2Aye9AOmyX2ziSQY8i+ak pptA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=c4zxkyFc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 123si8063178yws.279.2019.03.13.22.05.08 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 22:05:08 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=c4zxkyFc; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IYF-0002uu-Tp for patch@linaro.org; Thu, 14 Mar 2019 01:05:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IPB-0004ak-F9 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IPA-0007Rt-GH for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:45 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:33575) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IPA-0007RP-7D for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:44 -0400 Received: by mail-pg1-x542.google.com with SMTP id h11so3168991pgl.0 for ; Wed, 13 Mar 2019 21:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=I39zQahYJfO4v9BtHWnWSXDEM3G+gAshBbiSOHHVUzY=; b=c4zxkyFcR1EPcjyQUpS85K+hU1gkfAYx9NGMRqQyEC1y1uwU0Ao9Y5MVCSLZorrX6O +gcPAGlmHwsjYSzuEBZDM4A/CzZOdz8a8EPMdoCEYE1TntJsxoFyYLdlwe2aSrPGnFeW PQm8iNoCQpi+MQCFtWNMTvGnSKiRFCnktTjohAOCV3fTgdoMcW1qLbbHYSvkofJyXM1V 1JlJac2v6WluNjf1ywbdMOOCHhlnCOy/HrrOVeAGihrvbxOB1ISB6aZiXeLtmU66bxdc pPXGNUb8TGdlxn+8BL6zOCzxcoYWdW4dQjFASgfLqEROmtmzYMUlqKJ33OaUAjOXixIP q5VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=I39zQahYJfO4v9BtHWnWSXDEM3G+gAshBbiSOHHVUzY=; b=D1mNJttzGOc2eZIjSPZZe+8wMwqtZP1jtlrxYNDblv5R6bo6QF+hTpqDHhM/hdEliM S81XDjJL8fFT31gPGIl0e3tiAikQzrLFUciJwN6vOsY0hfvOBGT45vrUIT5pSCgZTEpj WZVfjNJuEsPqi1w8/vH7L8RnS4g+nerQRcvTJn7zMNgPF+a86kNBosHoaiGW73zNuLdW orn3eXncDDKEbjGkifGzCotRU0HVOlWV78Dv07MNj8UV4Ua+rUdhqYWVuDOrL2UPx9+m IiqEe5ZltzH/b22ahnHC0YQrH7HEKtm74YZvX8kae/yTiTng1UAUyep3m8c9ytd6VUe4 Mp0A== X-Gm-Message-State: APjAAAX2Z/oZ74GBpATaA9/HWWHMfi4KukK6Wj9Cmc2SXUx4WLCyoKQL rn2gpVyLNwkaMh9f5sOTgUootIEtzHo= X-Received: by 2002:a17:902:6b47:: with SMTP id g7mr50367586plt.100.1552539342964; Wed, 13 Mar 2019 21:55:42 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:24 -0700 Message-Id: <20190314045526.13342-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v2 12/14] linux-user/aarch64: Use qemu_getrandom for arm_init_pauth_key X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand * 3. Cc: Laurent Vivier Cc: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/aarch64/cpu_loop.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) -- 2.17.1 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index d75fd9d3e2..ad30cab52d 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "qemu/random.h" #define get_user_code_u32(x, gaddr, env) \ ({ abi_long __r = get_user_u32((x), (gaddr)); \ @@ -147,22 +148,9 @@ void cpu_loop(CPUARMState *env) } } -static uint64_t arm_rand64(void) -{ - int shift = 64 - clz64(RAND_MAX); - int i, n = 64 / shift + (64 % shift != 0); - uint64_t ret = 0; - - for (i = 0; i < n; i++) { - ret = (ret << shift) | rand(); - } - return ret; -} - void arm_init_pauth_key(ARMPACKey *key) { - key->lo = arm_rand64(); - key->hi = arm_rand64(); + qemu_getrandom(key, sizeof(*key), false); } void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) From patchwork Thu Mar 14 04:55:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160290 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15075480jad; Wed, 13 Mar 2019 22:01:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdmN3flzg8oGpiZLf1VeMoDbjqRFNDFlooTKBghs0VYvU2KyV+0ynHv8cnp6rY3L4HtBT9 X-Received: by 2002:a25:bd88:: with SMTP id f8mr20086596ybh.373.1552539715872; Wed, 13 Mar 2019 22:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552539715; cv=none; d=google.com; s=arc-20160816; b=LHz2YcdqQwZDWuiE708yJNfUmZV9aeImkOZDBl7pUvxTKxYBVoW7Z8VW5pfBalbDt8 nMpuTZqmnaw5iUNYzGErmGGeTYy5MlB8TQxzmhC8W1mcVSuaRWdlfOB+i0wOJTb9+pdY X5ajEp6nH6yQWfPAM1fTnK0nzYVpBqmgw1qH7CGLyiW+qhvMZ1/huLpGJLnoAPMozm6G aFhSq7eJ94XMM/lccbYDkfgRoA4vXWlfTSNdXnXor4T7c6c33QYEzllxpw0paWhhr2Ru 8I+9sc4Ua2m+c4K1CtGBjwsuZIi8aNN/mXAB1bJsDFIPvu9Z+hwtjoV6mJLpC+GTEY4G Poeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=8NCeH4mjwYfJB5pPXQkyOvXvcMzBKrxe6uKuMt36S8E=; b=J+BCBOsjynzukATV4t/K6BmKks3C9ZdtQxauf8MfK4dGpCrl63iF17Tmc0iLDaJ7DE 86U+FKyGnhGkcb/GIZixGQT3mAJwRdsXwCpzItcHc334gI6S5mCLcJaZSn8ZURyyiYbv 9C1zm2esaCZ9n8XKValDVOf4bbvCgMaJ11V15Mzvr/nnQFUWRNVyDDFfpeESsNb0twUM PN4LZT0YvX9zXpQ1CAM6zpUppJTJCJhkHph7bpRWEGQyU19OFIsr6BNk1TqFSMZ2Ypt7 h+JknyrO50XDRxgCQFwWbNzS2uNSrFHJ/bq0i2KsUR8bt1o1iEtEKll7Dzm5gAPsMC/S bf6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fKhq2bvA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n10si7521327ybp.335.2019.03.13.22.01.55 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 22:01:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fKhq2bvA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:56930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IV9-0000yc-8F for patch@linaro.org; Thu, 14 Mar 2019 01:01:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56258) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IPC-0004c3-Hx for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IPB-0007SW-Nz for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:46 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:36102) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IPB-0007S7-FO for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:45 -0400 Received: by mail-pg1-x531.google.com with SMTP id r124so3161765pgr.3 for ; Wed, 13 Mar 2019 21:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8NCeH4mjwYfJB5pPXQkyOvXvcMzBKrxe6uKuMt36S8E=; b=fKhq2bvAt/ogmagCdTjpNnfEc9KW2VKKfMz2MkFu996x1m5jxRGxZYv2i0dTOm8lFN hlL55MoOkDwu/fS8pnK/eNa56af6GEcK8O+rGdSLMM4UGzqDkMqF34Fe8jRiKhRSOFHR TYUqxLD7H7VD45S634mn6If08yCFO/myRthYwY3fnq/DklSHYAB4k583gDE/uTwFLLWN XKJ+SEogE1VHrEjnQKDhi0U1jyjJ7pWVuV0JlRXWH733jl38n5qpUOSm2QprPUngdusX Dj9c6CVIgwF8Oy2dBLBy+7iQFsHiFYp6o8cQqH19yZlEXVmT2d7+Eg4nkqnYF+4j1c33 +P4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8NCeH4mjwYfJB5pPXQkyOvXvcMzBKrxe6uKuMt36S8E=; b=r69ATG8xxMYUrNV3LcXt2g7FnrNO67FWdyFIz8w6soYy6siLJCDK7mhz3nncZ7nS8m g2itx5sKdnVTV88M9dLgev2dZ2ZI2qjgdMeQrYCBWzANfwpcqestzqP1C91VkYa2U2eh xBy36Qsztk5aioJyHR+8jaAIeR6kaAN9t3Z7LjR9eI+FEunLLEAEJk/j18Bi2PDyCGPt H24qmfNst0Nmx5JoWuLBbx3tc5pgwGHZOC7Zz24r1N10zuAG88+CP2q586DvQSoKnVCC 2Tpxp26zLUNkeycuiQNPGOV8cMJSXjOqxOyrM6Jwe7YPrnJpqfm0CaB+o1WqPCIL26DS cnwg== X-Gm-Message-State: APjAAAV39xzToJtZ/cm1o8vZXvrbjrmjQeYgkFb6WpExXdJAR2yMF2TW cFwtHOQ+7bZTkPaXyq8ETDTyNPS1rsU= X-Received: by 2002:aa7:86c6:: with SMTP id h6mr43724387pfo.236.1552539344071; Wed, 13 Mar 2019 21:55:44 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:25 -0700 Message-Id: <20190314045526.13342-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::531 Subject: [Qemu-devel] [PATCH v2 13/14] linux-user: Remove srand call X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We no longer use rand() within linux-user. Cc: Laurent Vivier Signed-off-by: Richard Henderson --- linux-user/main.c | 2 -- 1 file changed, 2 deletions(-) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index 192bf759b8..11a37f7f9b 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -621,8 +621,6 @@ int main(int argc, char **argv, char **envp) cpu_model = NULL; - srand(time(NULL)); - qemu_add_opts(&qemu_trace_opts); optind = parse_args(argc, argv); From patchwork Thu Mar 14 04:55:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160297 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp15080476jad; Wed, 13 Mar 2019 22:08:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyV0RQTq3/TaG8KjM0rOJd9JMTW0u0Viw9dQuFpRteL5+q40kx7jgp611zYMgOBJP0VqBbi X-Received: by 2002:a0d:f747:: with SMTP id h68mr23785890ywf.235.1552540126197; Wed, 13 Mar 2019 22:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552540126; cv=none; d=google.com; s=arc-20160816; b=zrV2IA9XIBUv4Fm7wjld1Ts/wUtonzTNLtrIT7NkpnUlBA1FXY9Zsj1t7W5UYJom1t rXP803fne3wjW/FzgZzNWp5mBCQy6CmsSW72DQ6Mkn/xOpQS0JLHPl0Z3w584eMGEKjL QU/6i56tbpWSNP5wohS1y7jCx54Qg6uhs1c+CH9/oAM9OAbQUaqfRCTW5gr45gM9nqJZ w0ORlHSBKuNP3jXNR+NKDQV4m8ow8Yb+3ISa9fWOunkQcIQbJh2B02LzMg/0wb19nbZP oB+E1FlEUB1yE5Pp15yYc1zaglOCth++57YCccLjS3rUNeiJv7YgXYuu5ZL9f0B0K0xs b0OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=D2d2Ekku2Ab6AUXv8SytBYGltSiFV/Xsi168amKsjOE=; b=JmIxcZET82bfbzwyqhIc3xQyfWIXblvJG3yxs6Bue69TNm7aDWumT6k899hVJ3fa4P DJGiQxeWTPxJ/UftVTlx8WNCkRvxzlRs9mKP9f5pBqNjV0knc/1u3TLyVhwpfExKk0Yt ZmAE4ty+WE0hsKjQO/ktRDrG5Zs2kfCyewNzFrrjXpiWOs1/DgTozbuA1ebt2C8EAEeV FZ5sWk+M8K3TnaaHLEUGNHBwxdXylOiIsZCQCgbECbykh8HDrFykeAsPFy9rFwWkjvCp t1qdXqbLUdb8wNKaNp3knUVdyu2H465O4zTl5UbVzuWCUdwx0M9JOq9PHldDWsGMt6Mr xHJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yyCFqKgD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 185si7741377ybq.202.2019.03.13.22.08.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Mar 2019 22:08:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yyCFqKgD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:57018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4Ibl-0005PV-P1 for patch@linaro.org; Thu, 14 Mar 2019 01:08:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4IPE-0004dq-3D for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4IPD-0007TD-5c for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:48 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:39626) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4IPC-0007So-Ud for qemu-devel@nongnu.org; Thu, 14 Mar 2019 00:55:47 -0400 Received: by mail-pg1-x543.google.com with SMTP id h8so3147164pgp.6 for ; Wed, 13 Mar 2019 21:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D2d2Ekku2Ab6AUXv8SytBYGltSiFV/Xsi168amKsjOE=; b=yyCFqKgDQcZ1MLF523Ew4u4hiLNiypQ8G1l3Uio54ryK3c+7oUtSzRQYWPDVopI389 XxUK7Ef16TrbGKqtwbYfBKiOxL6CNyc+wJ07AIh3wfiFrayUlZBu5oM6I8DHd6W4kl31 fI7AxCrqZY4FF2M+ZyclWjmkgOoupMYaTmJf0g5tzVzaz/JgMuaPlWFMzIJSsSc9ur27 IP6K1ZZjOpxqAgdrJDMx20IH2qZrKT9EdC84Ewufcw6rS57yD5pPevVb0jpdZ0J/ZRZz CxBBG/FA5pQENfawm/e1FLSdw5AgdWnukc2xNZYQXfHy6yCsTu2I2v5qWBXu6FuLafbt easQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=D2d2Ekku2Ab6AUXv8SytBYGltSiFV/Xsi168amKsjOE=; b=Fq/tMw3tm19/InSDDqFc+R5Nt+iJI58iM9CPLHjtUlDkCtDAhsvSiCYslPN7jpur0x coAw2OJy0rUNVL5ny0Q45E/j/h3J+CI7KA0GXAK7xQaRgiCUTajt36eWgfcyAjBpjhsv az9i4S7J4zjJT4IizrKoF43cNfRfKXHqIcgICVE9oapNk71FuetkIF853MvXvEMFMmwd sOESLTZOWZ/H35bF5T/dna3x1lxtb7dDVdlQ6m0vEl2sy8wSJ4MB/enkazn+sjKhYNq0 EE9ZsLZjYHK8/DrHeydUMsZ2rBC5bdRWI/wPcPE65vBuyWiC0bhQGWMjZ2F0VdypZwOz vSeA== X-Gm-Message-State: APjAAAW70v2aoUD2akn5SwtnS6tuq0yRFPUH0kL2NT8ILyGLVKBd4Zni 8wpkY5EFS43Z1568GXaQN7gZRv9qUfg= X-Received: by 2002:aa7:81c5:: with SMTP id c5mr48659905pfn.217.1552539345105; Wed, 13 Mar 2019 21:55:45 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d9sm16185027pgq.6.2019.03.13.21.55.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Mar 2019 21:55:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 13 Mar 2019 21:55:26 -0700 Message-Id: <20190314045526.13342-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190314045526.13342-1-richard.henderson@linaro.org> References: <20190314045526.13342-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH v2 14/14] target/arm: Implement ARMv8.5-RNG X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Cc: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 5 +++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) -- 2.17.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 5f23c62132..aaa9e02e78 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3441,6 +3441,11 @@ static inline bool isar_feature_aa64_condm_5(const ARMISARegisters *id) return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TS) >= 2; } +static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RNDR) != 0; +} + static inline bool isar_feature_aa64_jscvt(const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, JSCVT) != 0; diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 228906f267..835f73cceb 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -310,6 +310,7 @@ static void aarch64_max_initfn(Object *obj) t = FIELD_DP64(t, ID_AA64ISAR0, DP, 1); t = FIELD_DP64(t, ID_AA64ISAR0, FHM, 1); t = FIELD_DP64(t, ID_AA64ISAR0, TS, 2); /* v8.5-CondM */ + t = FIELD_DP64(t, ID_AA64ISAR0, RNDR, 1); cpu->isar.id_aa64isar0 = t; t = cpu->isar.id_aa64isar1; diff --git a/target/arm/helper.c b/target/arm/helper.c index 2607d39ad1..3fe7dc8719 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -20,6 +20,7 @@ #include "fpu/softfloat.h" #include "qemu/range.h" #include "qapi/qapi-commands-target.h" +#include "qemu/random.h" #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ @@ -5717,6 +5718,34 @@ static const ARMCPRegInfo pauth_reginfo[] = { .fieldoffset = offsetof(CPUARMState, apib_key.hi) }, REGINFO_SENTINEL }; + +static uint64_t rndr_readfn(CPUARMState *env, const ARMCPRegInfo *ri) +{ + uint64_t ret; + + /* Success sets NZCV = 0000. */ + env->NF = env->CF = env->VF = 0, env->ZF = 1; + if (likely(qemu_getrandom(&ret, sizeof(ret), true))) { + return ret; + } + + /* Failure sets Z = 1 and returns 0. */ + env->ZF = 0; + return 0; +} + +/* We do not support re-seeding, so the two registers operate the same. */ +static const ARMCPRegInfo rndr_reginfo[] = { + { .name = "RNDR", .state = ARM_CP_STATE_AA64, + .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END, + .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 0, + .access = PL0_R, .readfn = rndr_readfn }, + { .name = "RNDRRS", .state = ARM_CP_STATE_AA64, + .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END, + .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 1, + .access = PL0_R, .readfn = rndr_readfn }, + REGINFO_SENTINEL +}; #endif static CPAccessResult access_predinv(CPUARMState *env, const ARMCPRegInfo *ri, @@ -6661,6 +6690,9 @@ void register_cp_regs_for_features(ARMCPU *cpu) if (cpu_isar_feature(aa64_pauth, cpu)) { define_arm_cp_regs(cpu, pauth_reginfo); } + if (cpu_isar_feature(aa64_rndr, cpu)) { + define_arm_cp_regs(cpu, rndr_reginfo); + } #endif /*