From patchwork Mon May 6 17:33:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 529181398 for ; Mon, 6 May 2019 17:35:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37F90287A0 for ; Mon, 6 May 2019 17:35:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29B7B28844; Mon, 6 May 2019 17:35:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9DBD0287A0 for ; Mon, 6 May 2019 17:35:33 +0000 (UTC) Received: from localhost ([127.0.0.1]:59924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhWW-0002Qr-Vi for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:35:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhV5-0000xO-1B for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV2-0001EU-VC for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:02 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:46467) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV0-0001CZ-W6 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:33:59 -0400 Received: by mail-pl1-x631.google.com with SMTP id bi2so6693377plb.13 for ; Mon, 06 May 2019 10:33:58 -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=3IcDqOxNxFpx6A0tMNvu47gM3lLo8oZJFxC0ZgDmPNI=; b=oKjjQI7XVRe+sFhrMIATJOL1VyUY+fzx97cMBhwu57e9IPvhP/GSvaazc9Td3vfuEq WzCBcx1EBJXNwmeAkEmX4FSZq8F606fSiynWx4V5g22ZSdG+n/7Z5VwbkSQjH4jtnoCa mvMyDQmv/spUO+bejio3bvbJo3ilzQgkZuJJlUPRwT98ubZzZRY7CJ0dIDZi05MjXW5m xzbxVbl++L1EvLlAglY7Jw0DGGFFFfjnfEJrKBeLbKY6Oikt3oujCBkrwKNTqWX07uOZ k2A6uWHAb69W7UdtXBTHEEJp+dHAupyu9WvvRIajrj7GmN1S+z3bWzXt40sKDkHWXEk2 WGNQ== 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=3IcDqOxNxFpx6A0tMNvu47gM3lLo8oZJFxC0ZgDmPNI=; b=SceXMgQ7JRHlq160tbrN15DlQ4drdp8aMsqgngvK9saoCVP6DCvneHvtaqKgIkgyob /X7hE8Ny6Vf/w+2K5mqeGZT74XLsOnQ6YByh2Gmr5W3fJtaLuGuGGpBqqO9nr/HByWw4 GU3yuVGb5KqsdZlR9n4D0mq5vDn7D3tGuqASB5htAiOmb0RtyEf/raEN1f5S52/suIU6 8IFkO3C0Q4e26t10/JGuuevl+jcXlNX7ov8t92/4dfsdXzHUKK2Snx6wQO5H1TxjMsGU gQlfE+jORkNWWn3/jDiYl7aWUzF0+J7c5UW+dicrG1b99P2jwSrDuT2C0caHDOyB43Jy PTNg== X-Gm-Message-State: APjAAAW/k+C+FfrIrZdjYsUzsPnnFCcvzj1LV6Z4E90twIaAuBXrjZai ZUkHikAuazJ/t/3+2j6zHQyxSRIUmJE= X-Google-Smtp-Source: APXvYqxHRF9Jaw5bKlHjuKKlvJAckzuGgmhoyML4DNok2H30Fas9aGJuWefEMh9zpNq9vDHNwrghwg== X-Received: by 2002:a17:902:5982:: with SMTP id p2mr1790959pli.197.1557164036766; Mon, 06 May 2019 10:33:56 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.33.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:33:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:30 -0700 Message-Id: <20190506173353.32206-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::631 Subject: [Qemu-devel] [PATCH v4 01/24] configure: Link test before auto-enabling gnutls 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP At least ubuntu 18.04 does not package static gnutls libraries. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- configure | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/configure b/configure index 5b183c2e39..daadfe9ad4 100755 --- a/configure +++ b/configure @@ -2784,17 +2784,24 @@ fi # GNUTLS probe if test "$gnutls" != "no"; then + pass="no" if $pkg_config --exists "gnutls >= 3.1.18"; then gnutls_cflags=$($pkg_config --cflags gnutls) gnutls_libs=$($pkg_config --libs gnutls) - libs_softmmu="$gnutls_libs $libs_softmmu" - libs_tools="$gnutls_libs $libs_tools" - QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" - gnutls="yes" - elif test "$gnutls" = "yes"; then + # Packaging for the static libraries is not always correct. + # At least ubuntu 18.04 ships only shared libraries. + write_c_skeleton + if compile_prog "" "$gnutls_libs" ; then + libs_softmmu="$gnutls_libs $libs_softmmu" + libs_tools="$gnutls_libs $libs_tools" + QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" + pass="yes" + fi + fi + if test "$pass" = "no" && test "$gnutls" = "yes"; then feature_not_found "gnutls" "Install gnutls devel >= 3.1.18" else - gnutls="no" + gnutls="$pass" fi fi From patchwork Mon May 6 17:33:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931691 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A1181515 for ; Mon, 6 May 2019 17:38:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60B2420453 for ; Mon, 6 May 2019 17:38:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 554AA28844; Mon, 6 May 2019 17:38:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ACC5020453 for ; Mon, 6 May 2019 17:38:42 +0000 (UTC) Received: from localhost ([127.0.0.1]:59950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhZZ-0005Zs-U7 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:38:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhV9-00010s-4F for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV5-0001Fd-1o for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:07 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:33542) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV3-0001DM-1r for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:02 -0400 Received: by mail-pg1-x544.google.com with SMTP id h17so818186pgv.0 for ; Mon, 06 May 2019 10:33:59 -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=1xjlqRXirnP5LswdNxna6nzxrI47MTAcF912r95XRb0=; b=t2CugovX1/haMwIVga+gft4+pIDnMUVLUxgHoAcFivygQl7rP7iJdl0OToTNIGpeFn 7To872ySiLXWAWqNo1+AOauzny9sG6PeWH/oVUN/WtGCFx+hQX92YAWGurVodnj1Xpix PT9k0iPbueuPPwQGdexmLOf54fv8Z0Aerny3yCnZBoRRmYS92tpmD16kPk1nTIjkT9Lg Xw/LF1aLnBXnVYKS8pL6AdN7qr9H6GpdxSe1BmrxyB8N/zWMPAuojjNvBN8vitHbdFfd ztF4xbtIraMejUc57UPwaLaKx70MXmSwv7rJjTSyiq5MYD7jLjuUv2Rt/iV4fK/OumO6 TKuQ== 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=1xjlqRXirnP5LswdNxna6nzxrI47MTAcF912r95XRb0=; b=uCUhJr4GyGR+uCznGsMxjHJEAdsPB2chM9LczMYdsvQBU0jScwqcb9697PuynwIxrL vHuf9jKg8vZ/IO7W2ktXD38hMgrXNFJ3GDxvVugPPntuMPzBPepvIAFUfV2yOGDCiFDz FTaxUZo0YjLDOvEFBz8JpYsryCDOEw9eHZT/IRglYRj3KZktHTZOO5IXuc/7QjXCXm/5 asSOZgSyuU3P/73FaoowZomS3hWMAF+L6rdlxfQ9kYSAdxDyjhbXYerqe1pvFDEsNizg QdcYas6f5gKmOc+6+Rtm9LHAbvqgdgq7Hb0fwy0zwwsOMk1yYGWSjstlS1RtWUKthkSJ Epvw== X-Gm-Message-State: APjAAAUyMCqIQWkORC79/tArasBon56u4szzkS7seiJ0zuPHjQdfrGtm kFib/8pPGLtcM9uI+p7sInCPd1StKFM= X-Google-Smtp-Source: APXvYqxUNv0EtdkYk1eKEFDDs7MDu27pX8Iqcxn9NznkZPUHj4+XXChdWm2b7roedBude7fnVwJPXw== X-Received: by 2002:aa7:8b12:: with SMTP id f18mr34787998pfd.178.1557164037998; Mon, 06 May 2019 10:33:57 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.33.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:33:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:31 -0700 Message-Id: <20190506173353.32206-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::544 Subject: [Qemu-devel] [PATCH v4 02/24] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) diff --git a/Makefile b/Makefile index d372493042..09c8591805 100644 --- a/Makefile +++ b/Makefile @@ -410,7 +410,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 \ @@ -446,7 +445,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 $(SOFTMMU_SUBDIR_RULES): $(edk2-decompressed) @@ -502,7 +500,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) ###################################################################### @@ -511,9 +509,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) @@ -524,7 +522,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 cf065de5ed..0ce429c1af 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 ae02495951..ce02924ffb 100644 --- a/Makefile.target +++ b/Makefile.target @@ -179,8 +179,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 \ @@ -189,8 +187,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 daadfe9ad4..0099e85a03 100755 --- a/configure +++ b/configure @@ -2792,8 +2792,7 @@ if test "$gnutls" != "no"; then # At least ubuntu 18.04 ships only shared libraries. write_c_skeleton if compile_prog "" "$gnutls_libs" ; then - libs_softmmu="$gnutls_libs $libs_softmmu" - libs_tools="$gnutls_libs $libs_tools" + LIBS="$gnutls_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" pass="yes" fi @@ -2860,8 +2859,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" @@ -2888,8 +2886,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 Mon May 6 17:33:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCC2D1398 for ; Mon, 6 May 2019 17:35:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2948287A0 for ; Mon, 6 May 2019 17:35:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B705228844; Mon, 6 May 2019 17:35:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5AAD1287A0 for ; Mon, 6 May 2019 17:35:43 +0000 (UTC) Received: from localhost ([127.0.0.1]:59926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhWg-0002Y6-Hw for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:35:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhV9-00010o-3N for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV5-0001Fm-2Y for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:05 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:40440) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV3-0001Dv-2O for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:02 -0400 Received: by mail-pl1-x644.google.com with SMTP id b3so6706946plr.7 for ; Mon, 06 May 2019 10:34:00 -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:mime-version :content-transfer-encoding; bh=O1PQbxI86I2bI4Y4HCTdo78SLn5JqRTP/j+lnThrZ4M=; b=QlAFgO6bdhjojlKOog/QcrhXghb0rPMOgocTzc6WOYuB9M9c9XWFW5GG7hObkuqCht pBpqklm8CjGR79JFXs0OJlutcc1ViafuuU5LGZNKxVSjPlW+ow3qAZqePYbdOSXJ2LaZ oOy+Ig55KCJhAvOhbuVgWvjPrGhR+AxEe3ma0ockDfm3hgssTi3poJXuG385cSYsLZId +S5M0SuH0w7Gn2JnJmlBLliWl9P70nBbYTtmW4oZHCs5ivlfiXjK1D25tMjpKaJY+B6a iJBA3d2zv91M+nHBuTewjMNGnZTRY/GcCO9Gb1A6A0ToGiBTsr6LXRORaRqj6t5GmygW HyLA== 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:mime-version:content-transfer-encoding; bh=O1PQbxI86I2bI4Y4HCTdo78SLn5JqRTP/j+lnThrZ4M=; b=n/0E/1oTSLfjKR4eoF3sf/KmCV4DtGqKxtrE+oqUvl2LDlmU39/eSWfGe0d9zv6UrQ NypLreU0eBKSnq1C+CJ1+1Cp+amMUk8bsc+iVxOCRmxY4xmxAxZSjkIMRnaHvkAEiH30 8I7fUdl5TGObSEvxxw0E5I0fUkWilgOWYhWlo80KNG/JoFLsUaqq4CkfrEnIw3CWZi1+ 58R9AQODRG/+9eBrqDWRyx84FV8OFIfxhUuGmUzkMAZSLFpHJgzqlS86aUzOHD5W7unS 6H4BzDsTUJUCz8HOXLY/Avd0z08MfRRspOWICp+Kly3D6bQHtP+srvvn2G1NWVG2Old2 F+Hg== X-Gm-Message-State: APjAAAUO/p7hwfgTHiuUSg+uq3BAMMbue03uvmuH1tYSPd933cjn7k+G OjHpk70Sdo82YoKIpUWE5mjmAieATys= X-Google-Smtp-Source: APXvYqze7WdOEl63SvFyvueS7l2jIOZw+VLFgZ/GaAvxAb9CDb726Xd5HnDC2ADAsS/BaFTNOtoHtQ== X-Received: by 2002:a17:902:e612:: with SMTP id cm18mr10597325plb.255.1557164039170; Mon, 06 May 2019 10:33:59 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.33.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:33:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:32 -0700 Message-Id: <20190506173353.32206-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::644 Subject: [Qemu-devel] [PATCH v4 03/24] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use #ifdef _WIN32 instead of #ifndef _WIN32. This will make other tests easier to sequence. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- crypto/random-platform.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) 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 Mon May 6 17:33:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 31D3B1515 for ; Mon, 6 May 2019 17:40:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17B6826E4F for ; Mon, 6 May 2019 17:40:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B0E128880; Mon, 6 May 2019 17:40:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A870B26E4F for ; Mon, 6 May 2019 17:40:53 +0000 (UTC) Received: from localhost ([127.0.0.1]:59999 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhbg-0007Pb-VS for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:40:53 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVA-00011n-5x for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV9-0001IE-3l for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:33274) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV5-0001Ee-03 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:04 -0400 Received: by mail-pf1-x443.google.com with SMTP id z28so7145429pfk.0 for ; Mon, 06 May 2019 10:34:01 -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:mime-version :content-transfer-encoding; bh=SxHcSgvXH46Lcz+sBihH+DQ9BaQG6plA/B5ZKvOuxJA=; b=pkil7NXwQ0LqaEBzco3zRNKPlgnZYoK7PI32QoHcMkfhprBVa99RoQqn/KxfbNUL6f RzNppNhYONng6jOice7MGDn2zEVZHhdecPTJSWaMIKKLHAH2vamr9OdQ8PvekzWNkR20 /5q+jzRDAzNwpQB3YnfEcbJ4BZxtGIO3pSSu/RPY3MxaLfbkF6ZEQo0nhHc+YjQLcHDN i9fXAcPn/IJOMT5DuRTDMP/EY2DYx2Lm6H0WeDlgBLG3DUN+h9aj4u+4il7mWeSVrVwF 7R4JBa0ynT2c7RW151zD6hJnZmrqnMsjlmlTVzdb7vCpoEy6dQ44Bz90jc8c6ZZ93gSo S5Bw== 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:mime-version:content-transfer-encoding; bh=SxHcSgvXH46Lcz+sBihH+DQ9BaQG6plA/B5ZKvOuxJA=; b=cMS6Tbr4oiVKNJ56B7PzqlVYh9ooEgFOFq0PlUBPEzwBwFKqb/pBVM3woy6wkLbjOg UaEFdCSH0i3MZFS8qaJwOOvTWvs12/r6u29vfV2R0ETb2jcifRCtz/sQTKsjkFTo1fcQ u0rB7Ahu6pnI4hrRHXC1SYRiKoFQQsxKUCiDop6oUYC02qXt05xhiNXOqeGn0a3Yuhuw w9wLdWaoE1xclv/42hrbpZa1k1wFthL2ziL87nc/ZXZDW8Y27Pj7Wx1Vlw1sRDHzAbuG fca+wQXJcdKZxJ4DgxwBjKAKI2SmlyNQNljHiHuY/c5AHrvGevzqoG8b2LwnwCOr9ALQ WyCA== X-Gm-Message-State: APjAAAXcBHo4lzwkyNNwwTEmCFkxMfBPFXieFuUkLAGrFouQ2nCBFy/O sFr96i+oRoLSYt+PmBqGO71pOfoQu9Y= X-Google-Smtp-Source: APXvYqxb38FwDYIByAhdPO3V7+E9BOFbTlDNsKardpoR4xNDU1CQ9HmBOON6QzU6O+evYqmrodPW7Q== X-Received: by 2002:a63:4a5a:: with SMTP id j26mr32302687pgl.361.1557164040520; Mon, 06 May 2019 10:34:00 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.33.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:33:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:33 -0700 Message-Id: <20190506173353.32206-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::443 Subject: [Qemu-devel] [PATCH v4 04/24] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We can always get EINTR for read; /dev/urandom is no exception. Rearrange the order of tests for likelihood; allow degenerate buflen==0 case to perform a no-op zero-length read. This means that the normal success path is a straight line with a single test for success. Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- v3: Rearrage the read loop again. --- crypto/random-platform.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/crypto/random-platform.c b/crypto/random-platform.c index f995fc0ef1..260b64564d 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -65,29 +65,23 @@ 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; + while (1) { + ssize_t got = read(fd, buf, buflen); + if (likely(got == buflen)) { + return 0; + } + if (got > 0) { + buflen -= got; + buf += got; + } else 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; } - buflen -= got; - buf += got; } - - ret = 0; - cleanup: - return ret; #endif + return 0; } From patchwork Mon May 6 17:33:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37EF11575 for ; Mon, 6 May 2019 17:37:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13D14287B3 for ; Mon, 6 May 2019 17:37:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0851128880; Mon, 6 May 2019 17:37:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B0181287B3 for ; Mon, 6 May 2019 17:37:56 +0000 (UTC) Received: from localhost ([127.0.0.1]:59944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhYq-0004zJ-2D for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:37:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVA-00011h-3o for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV9-0001IK-48 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:45552) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV5-0001FC-1S for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:05 -0400 Received: by mail-pl1-x643.google.com with SMTP id a5so1769815pls.12 for ; Mon, 06 May 2019 10:34:02 -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:mime-version :content-transfer-encoding; bh=urHRlG6kBlVfKAPWfqk7nsWOPo9eNvxapFP6SXeaD3k=; b=eyRaLYBIqxXVktyb+HTVaFGi3HFWopEiTqw34tPLVew1SYdIBU21YUVtW/WEm9ut+B IhBNdLflZ7JCc/fEIuhZeMkZaOR3xYlMf4pzAea064cyJHX52nU29X4qJ0SfKmNsRBNY 4NMXrhVuTeGaQqctYnS9nUdcpFsffTKt7eUfgksBdv4FgYgvQoiZSHNJAE5wzJF8ldUi XQQILtxuLr3gnvwpr9xdp+2hY0T41/U7lJnC8aOZR6Th+Ew55T7+bDzPWe0OxpI1zNLp NFXQFGSZ9rt0GwSpz0430BPaIcnN64yQncwg/z+sfKWc5Pepy95baFCb4fm5ccPljbz/ nqMg== 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:mime-version:content-transfer-encoding; bh=urHRlG6kBlVfKAPWfqk7nsWOPo9eNvxapFP6SXeaD3k=; b=I1IOskZRvtXoNPDC3Zvz4qNlkNUTwQb7M4uNKUknCGaeIWq3i62SdJgBwa9zsYEfkU /VCVldbq+RtOdRPhBTyOKNiPZESqkVOc9toQ/3E8snPaL7Hej6pfhlTqWKn+jOP8Uxuu bnVzK3VZJq04fTTmX3QEgNhpQ/QwWrZeg6hIh3izwpeUcYuszZ4kGP4Z1wugSpcZLnoB 8gY/Bvu1xQsLTIznPAmLkzzIDLOGfJHCGApfEd7jOyngHocme+jwFtMCds287TG5883K YMxXhOv8YFao9XSenwy9seHocFLFzVtpGLKPr16uTMezsgJlQPlntUuirbFTO8NgYzeD mK0g== X-Gm-Message-State: APjAAAVX52uATh6ztZDbXAs3QAvk7feqBjC3+nk27iv8lkalPg4EB6Hx c+nAk7B4bMw9Ya2N9yAt7Xq5oIpWADo= X-Google-Smtp-Source: APXvYqykmfos0aQervz+k3Tp9yWC6q2mHow0P7dJhR1NExhbCiVWLsHoxH/0QSC8ntdBJ+AGpscGUQ== X-Received: by 2002:a17:902:bd92:: with SMTP id q18mr33896137pls.136.1557164041616; Mon, 06 May 2019 10:34:01 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:34 -0700 Message-Id: <20190506173353.32206-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::643 Subject: [Qemu-devel] [PATCH v4 05/24] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Avoids leaking the /dev/urandom fd into any child processes. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- crypto/random-platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 260b64564d..6df40744c7 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 Mon May 6 17:33:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E63C91575 for ; Mon, 6 May 2019 17:41:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD10B26E4F for ; Mon, 6 May 2019 17:41:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE51628880; Mon, 6 May 2019 17:41:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 56CFD26E4F for ; Mon, 6 May 2019 17:41:26 +0000 (UTC) Received: from localhost ([127.0.0.1]:60001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhcD-0007xN-Iv for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:41:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVA-00012F-HW for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV9-0001J2-DJ for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:42676) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV9-0001G2-2p for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:07 -0400 Received: by mail-pf1-x442.google.com with SMTP id 13so6821932pfw.9 for ; Mon, 06 May 2019 10:34:04 -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:mime-version :content-transfer-encoding; bh=esNllaMlu2hXfZ1dTWICAYQAatBfGQUsBlaS7ORBn8s=; b=CblyidrERYrSmUe/QNFM9pDuBnu2GOQWyCiYAJ1ahITmWOQMAhWl8z7DQQRlvnJ0EU iQemffNZvxh+sMsxlE6gU319NQvPhxI6oscrfJUe4pNu2e+bK/NvsNlGUezBzggClEPn pe/4qhwwvD8iklYbL3/0FUF6IEfMr7Lpner8Bx/vy6FQ3Lytt6kXQf7O9Qi2gTvVN79A meIXfSOl12vtTjO6Fz3sdZV/1ixL1av8QT7hkZp+62QsQfZHSvby54HrNZ4KdUhbSeZ6 CwPg2ih+X4WtuFSVZMqsZMbLIgd4PUna/4y1w4DppjzNoTtR1UBCvGHjbMknd6Bodat8 V9qQ== 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:mime-version:content-transfer-encoding; bh=esNllaMlu2hXfZ1dTWICAYQAatBfGQUsBlaS7ORBn8s=; b=CronMq5aCkp8InOU6uCBh/JYUc39zxocrF2JYgjXhq8elGN1dfJVyzEFrGf/piHqDD Eowx7durjiFH7njyCgOqJ1M6cnA07Wpl4mGGUVlAUUqkrNa46dw5/n6b00VKlvwWI26u nN+hBjxFlegfhLxLM7OYGh0TLbQjunjv8Qnj6p7a1bJJXzMomnpVz5CUW9iTyheizrdH Q4RWY6lThwcqUNIJ8UsKLdruAEOOBNZpqtc8k9En1HxyRq3ZhZyzV8OqVYAPGhmCkph6 P/KuaSn7/KwBWSTB1tUvO0OiWCW9sludWCq6y3OBnc/Ep3s7T6M4PJs5uZqpt4JjuzaD LgpA== X-Gm-Message-State: APjAAAWgcTo4nUaLYMeevjzBc8i4g5qLQThbINOEBQrKdBrRNhmVa2hu eRMx0XK1f4EJX7g///JImWI8MYpJ4jk= X-Google-Smtp-Source: APXvYqx2zBnIPkrcZTd/X7kPwVF1Uam32KEGdsXQbw7bcAPz4yiBgJ4i9fkQRAl0RGprh1v+K+mtZw== X-Received: by 2002:a63:e048:: with SMTP id n8mr33581286pgj.41.1557164042881; Mon, 06 May 2019 10:34:02 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:35 -0700 Message-Id: <20190506173353.32206-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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 v4 06/24] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Prefer it to direct use of /dev/urandom. Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- v3: If getrandom is not present, fall back on /dev/(u)random. --- crypto/random-platform.c | 37 ++++++++++++++++++++++++++++++++----- configure | 18 +++++++++++++++++- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 6df40744c7..cb3ca1bc09 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -27,7 +27,11 @@ #include static HCRYPTPROV hCryptProv; #else -static int fd; /* a file handle to either /dev/urandom or /dev/random */ +# ifdef CONFIG_GETRANDOM +# include +# endif +/* This is -1 for getrandom(), or a file handle for /dev/{u,}random. */ +static int fd; #endif int qcrypto_random_init(Error **errp) @@ -40,15 +44,20 @@ int qcrypto_random_init(Error **errp) return -1; } #else - /* TBD perhaps also add support for BSD getentropy / Linux - * getrandom syscalls directly */ +# ifdef CONFIG_GETRANDOM + if (getrandom(NULL, 0, 0) == 0) { + /* Use getrandom() */ + fd = -1; + return 0; + } + /* Fall through to /dev/urandom case. */ +# endif fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); if (fd == -1 && errno == ENOENT) { fd = open("/dev/random", O_RDONLY | O_CLOEXEC); } - if (fd < 0) { - error_setg(errp, "No /dev/urandom or /dev/random found"); + error_setg_errno(errp, errno, "No /dev/urandom or /dev/random"); return -1; } #endif @@ -66,6 +75,24 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, return -1; } #else +# ifdef CONFIG_GETRANDOM + if (likely(fd < 0)) { + while (1) { + ssize_t got = getrandom(buf, buflen, 0); + if (likely(got == buflen)) { + return 0; + } + if (got >= 0) { + buflen -= got; + buf += got; + } else if (errno != EINTR) { + error_setg_errno(errp, errno, "getrandom"); + return -1; + } + } + } + /* Fall through to /dev/urandom case. */ +# endif while (1) { ssize_t got = read(fd, buf, buflen); if (likely(got == buflen)) { diff --git a/configure b/configure index 0099e85a03..5138a1a45c 100755 --- a/configure +++ b/configure @@ -5806,6 +5806,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 @@ -7193,7 +7207,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 Mon May 6 17:33:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D23B1515 for ; Mon, 6 May 2019 17:38:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 334BB20453 for ; Mon, 6 May 2019 17:38:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27D8428844; Mon, 6 May 2019 17:38:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C63ED20453 for ; Mon, 6 May 2019 17:38:37 +0000 (UTC) Received: from localhost ([127.0.0.1]:59948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhZV-0005Ud-2j for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:38:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVA-00012B-GK for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV9-0001J7-Ds for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:41747) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV9-0001Ge-4C for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:07 -0400 Received: by mail-pf1-x441.google.com with SMTP id l132so2178005pfc.8 for ; Mon, 06 May 2019 10:34:05 -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:mime-version :content-transfer-encoding; bh=Jdxoq0cd07u7NwCDIf4s8w4ApIde8s71XHdZkh2CqpM=; b=mV1tPHz45dpuWrSvod7+7lKaee7aXsf5FBPuk2C13AMjacbAK6WA/YKpDSEqFPWP0o v3kfjGtFfB1LGynKc+uRc16OzXhdbxJRfFXxkOwXQykOBnqG5giiF89cO2OlV4XoNjpo 8Yv1dgWeSFeUVOU0PoIeWGjTpeAbwuwcGMNtlvyUJe9IsvAFDva9gz5LUqnJnJRJhpPT 2Oa8zeRLAYfmRJzCJTmSCsStXNWL1jBECLmMhlIrMGFgBSRW/aTUWJlZ/+GqI+gjbxZT U4lhxqzrQv+c/K3m69/+0OiJd06mhizauRz1WYqJaF6Zrg+979Bnb0WZ+gx0psMmDVre otcQ== 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:mime-version:content-transfer-encoding; bh=Jdxoq0cd07u7NwCDIf4s8w4ApIde8s71XHdZkh2CqpM=; b=dXAhbJRAbVgo3D8Sabr2sd7de/kDFlAjN7doi2xF/lAJgeiyX5RQDCXftChcWsR9IZ 4/AV6SSs4sCH3W89GAmI5KTipW6tCQbHo8AJPre/nbSHqc1mevw2249LeZ8A/xATsF1P q0D/uoONBhO1VEJTl/2VFcvVrX/X+yYika++Ad9Tjj9NXqfhiox+sAiqxmKJrBGe/cW1 qBkTxsSgPAIjUt3JXbWzW7aJpJ/JmizJJXMFzmswTVVuxiZid0lx69Mx3LIyI65J3+jq zCWlZf5tiZFYcuMY2fuxlBbKkcebISy4QuyS+0/fpm3cMICLUFIVv/TCj+0jDZTMH2AP 8rPw== X-Gm-Message-State: APjAAAUdA4eoSVJ5q6xXw4JPCWkXi8mCRFogoAzFg6X3wijh8b1DAmxX Re3YzD8Sx1Ar6ws4OH6eA/vWsp0BvAY= X-Google-Smtp-Source: APXvYqyN2IMfHi0RoEekQO+Xg8qYmDltmFTD+aJuSbvcbxpIZh4SPn9IXYVjXABkgOfYGBR571UDdw== X-Received: by 2002:a63:2c4c:: with SMTP id s73mr33490534pgs.42.1557164044062; Mon, 06 May 2019 10:34:04 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:36 -0700 Message-Id: <20190506173353.32206-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::441 Subject: [Qemu-devel] [PATCH v4 07/24] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Using uint8_t* merely requires useless casts for use with other types to be filled with randomness. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- 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(-) 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 cb3ca1bc09..66624106fe 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -64,8 +64,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 Mon May 6 17:33:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D83821515 for ; Mon, 6 May 2019 17:41:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF61B26E4F for ; Mon, 6 May 2019 17:41:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B353728880; Mon, 6 May 2019 17:41:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 563A626E4F for ; Mon, 6 May 2019 17:41:29 +0000 (UTC) Received: from localhost ([127.0.0.1]:60003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhcG-00082b-MM for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:41:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVB-00012t-5m for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVA-0001Jj-3J for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:33275) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV9-0001Hu-C3 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:07 -0400 Received: by mail-pf1-x444.google.com with SMTP id z28so7145546pfk.0 for ; Mon, 06 May 2019 10:34:07 -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:mime-version :content-transfer-encoding; bh=jYAIQMfujH1Yj8GqMNdb9ZgzR2B+8AW7wjG3BA673NY=; b=mLk6dAg1QsjNbOm4DQ60Gu/71PfAo5s0UVcwGKOTIgmRy1yEjAWDGZj+ixu4KPy0LV wyk29yKHH9c2inXYUpr1O/VdFBEKgC3fNmFRchbiYAGm2sxwRkUWW7IyoJqfHObtjbxr pXTa4TmOykFdfDb8tU/evt1Bx3m3YiddcZu2uKeZTj2HMRCR8FADxOEq4p4fsdeewNS1 2T5Fx+hnst+1TYvyT5NNBFUpqu/QcXRCPmtnNw8tbmvLaK5Ennp2Xs5xxMTMyW3TeotE xOrjEW55mv+bAQaw4Ar93r+DmotWmAQwULfyizrE4YQIWz5TQXQuk4pUcmCcc5SD7cx9 etcw== 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:mime-version:content-transfer-encoding; bh=jYAIQMfujH1Yj8GqMNdb9ZgzR2B+8AW7wjG3BA673NY=; b=bNgl0Egww3oOTKM/KhzhxYObZi5FGTRmrcmmIS4wsfje/x4GJRB05IlyBNXsbCxLCn kVHQcNHtdvFsFGoKB4U6rRPIDF1V0HlXw4Kl/H1M93QDEVnlHOXVLsYi7NCcSKlcekHg dkQ0rAbQstf8TJKrQVWnWHzSO9grD5W/wbeM/ojKMId+eqyDt8N2POjzBPYlYx4plyQA jcTOLtsv+WGSY1EeoAMY0zlw8tJ0Phe5nn7DKcIGJKgfmkROz9FSooXUgrF/VXZSTKXx vryyw4BjdBdq2t9aV4g7umXYizUb53VX92bnlHFRJcQi6Em262iqtSBrNzLVTsD8hHgA skzw== X-Gm-Message-State: APjAAAVZKlSfzClSECsQcK6krDrweLvZQpFNPrR5v9a73l3h9QVJCp3k 6HlpYPNxei3rz0lgwdwmhN1tPgufPiQ= X-Google-Smtp-Source: APXvYqxQZ1IKaxZBuHkfybCA3CqzzRwMM4OX0wz2Xxms7FspnjE8O0L0/u6U2QmaxmypXmzAVBKQFQ== X-Received: by 2002:a62:1b8a:: with SMTP id b132mr34709412pfb.19.1557164045886; Mon, 06 May 2019 10:34:05 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:37 -0700 Message-Id: <20190506173353.32206-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::444 Subject: [Qemu-devel] [PATCH v4 08/24] ui/vnc: Split out authentication_failed 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP There were 3 copies of this code, one of which used the wrong data size for the failure indicator. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- ui/vnc.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 1871422e1d..785edf3af1 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2535,6 +2535,18 @@ void start_client_init(VncState *vs) vnc_read_when(vs, protocol_client_init, 1); } +static void authentication_failed(VncState *vs) +{ + vnc_write_u32(vs, 1); /* Reject auth */ + if (vs->minor >= 8) { + static const char err[] = "Authentication failed"; + vnc_write_u32(vs, sizeof(err)); + vnc_write(vs, err, sizeof(err)); + } + vnc_flush(vs); + vnc_client_error(vs); +} + static void make_challenge(VncState *vs) { int i; @@ -2609,14 +2621,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) return 0; reject: - vnc_write_u32(vs, 1); /* Reject auth */ - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_flush(vs); - vnc_client_error(vs); + authentication_failed(vs); qcrypto_cipher_free(cipher); return 0; } @@ -2638,13 +2643,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) * must pick the one we sent. Verify this */ if (data[0] != vs->auth) { /* Reject auth */ trace_vnc_auth_reject(vs, vs->auth, (int)data[0]); - vnc_write_u32(vs, 1); - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_client_error(vs); + authentication_failed(vs); } else { /* Accept requested auth */ trace_vnc_auth_start(vs, vs->auth); switch (vs->auth) { @@ -2673,13 +2672,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) default: /* Should not be possible, but just in case */ trace_vnc_auth_fail(vs, vs->auth, "Unhandled auth method", ""); - vnc_write_u8(vs, 1); - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_client_error(vs); + authentication_failed(vs); } } return 0; From patchwork Mon May 6 17:33:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 709691398 for ; Mon, 6 May 2019 17:35:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56EBC287B3 for ; Mon, 6 May 2019 17:35:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B87C2887A; Mon, 6 May 2019 17:35:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E42BD287B3 for ; Mon, 6 May 2019 17:35:44 +0000 (UTC) Received: from localhost ([127.0.0.1]:59928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhWi-0002cm-7u for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:35:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVB-00013I-KB for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVA-0001KR-H5 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:45882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVA-0001JI-91 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: by mail-pg1-x543.google.com with SMTP id i21so6781675pgi.12 for ; Mon, 06 May 2019 10:34:08 -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:mime-version :content-transfer-encoding; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=n8q6IHGmbXLkHiw8TrdDI1Qnr0lkZsTs2wkjYQ3BIKve8qI7/ZptgDyrOOpXbZqimF bg8lDUZih+BLgc6jPoUEZ4Wvh0OVv4yCrIw576Y77P1avSmPj+EaZE+oZrvX4ZpBFVIW HLSOIwoVVV73ExFEhfBmtvfHRDu7wto23KWyqk+9mKAPkbwMkEMZ3jNr9qdfGoMjZWYH YgY8I7PkCuldJjHS0beqsCh+b0mzwAbtvYxuRzv4nx7g5uAwUztMKEcoB7uFHXSfMahe x20bh5Yksyy4z36/l6gqCgYj7jF3B38aO7nPlF+PAcr8/uSLqLdhhjZ9md6o1fK9IN+7 S/wg== 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:mime-version:content-transfer-encoding; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=iTXkZfSg9fLlKzQvr/xozElndTn1EJVKGLW/JnmSe0Be6oUsQVH5RoHnnaLCcD1lqU A02hMfEQK99+rHdCNa7I3pZrgiZrydzrkHYVrHXZi/DGP6BUwyodIViBOuzdwwpHEazB nmmN7jSRw4MQCLpIF3svO1njvfotVF1jYnFYWKd+lLsnQdmhrE9k5dUENK+2nBw72nG2 QF7TE6Tr2v7gQ0PymtmFbJcehIhA9W0ilk+OsjU7T3HNALQM3bwKNxg1vtAVZAR4Zudc cHIzageKMdPM9AIldP7GQNo8otGhAZqEySyV3LwhtEKYtopEpJeQxYPFiyHw9PHANgju LV+w== X-Gm-Message-State: APjAAAXyJkCOGo42RV9/15DRfldhxV+ZuONqUt2OfME9tMt1JP6jQSOO 536CxmA7uYWAYEhySBUfeipqKq4Fxgc= X-Google-Smtp-Source: APXvYqwW0BSLyL38Gb8oOdJIlLZkSaG9WDUw8vYV3mkxgX16KAH4xczs268OROz4KLY1pQv8NmpT+Q== X-Received: by 2002:a65:5241:: with SMTP id q1mr12586526pgp.298.1557164047018; Mon, 06 May 2019 10:34:07 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:38 -0700 Message-Id: <20190506173353.32206-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::543 Subject: [Qemu-devel] [PATCH v4 09/24] ui/vnc: Use gcrypto_random_bytes for start_auth_vnc 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use a better interface for random numbers than rand(). Fail gracefully if for some reason we cannot use the crypto system. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- v2: Use qcrypto_random_bytes, not qemu_getrandom, as there is no need for deterministic results for this interface. v3: Fail gracefully in the event qcrypto_random_bytes fails. --- ui/vnc.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 785edf3af1..d83f4a6ff9 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" @@ -2547,16 +2548,6 @@ static void authentication_failed(VncState *vs) vnc_client_error(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)); -} - static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) { unsigned char response[VNC_AUTH_CHALLENGE_SIZE]; @@ -2628,7 +2619,16 @@ reject: void start_auth_vnc(VncState *vs) { - make_challenge(vs); + Error *err = NULL; + + if (qcrypto_random_bytes(vs->challenge, sizeof(vs->challenge), &err)) { + trace_vnc_auth_fail(vs, vs->auth, "cannot get random bytes", + error_get_pretty(err)); + error_free(err); + authentication_failed(vs); + return; + } + /* Send client a 'random' challenge */ vnc_write(vs, vs->challenge, sizeof(vs->challenge)); vnc_flush(vs); From patchwork Mon May 6 17:33:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C9E41515 for ; Mon, 6 May 2019 17:44:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3539E26E4F for ; Mon, 6 May 2019 17:44:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2950628880; Mon, 6 May 2019 17:44:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 21EB626E4F for ; Mon, 6 May 2019 17:44:12 +0000 (UTC) Received: from localhost ([127.0.0.1]:60027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhet-0002B4-FG for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:44:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVE-00016R-U4 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVB-0001LM-MI for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:12 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:36746) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVB-0001Kp-E7 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: by mail-pg1-x533.google.com with SMTP id 85so6797447pgc.3 for ; Mon, 06 May 2019 10:34:09 -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:mime-version :content-transfer-encoding; bh=lbaopiF28XTSe0kOgA43uLo7FEzHh7vNLBWI3VxuLJg=; b=yHrF05c493lMI8Ycww/BdgbvwfwJzJL5/wDqNnvOANcNr7P16SfM4ZjBV2sWr7/88s zVcxZGB6bK1EN+NT6V7Brj2A9qpWDeX+kCgoCSEyTtyLsgUMcPpWkRayX8bZeVoSke+x TnX8ktXtmpSacFwJYp2rhRn3X/kITXHTKRSOxZbNfNqcL4h9rWBxoeJ2XlkLZDYSPC28 TA86sZVN1Ku25AmdK1dYjzYLSZGk+UisA7C4DRFGuAqJzlq5ywFs+WSDh+QUUl7c7OKz njDSrjusjlM55A+ONe6V3c8qFxQMM2EcgPGCUymS7NV3Ok+vx4RV+OqSzAygDpqKnCOe BALg== 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:mime-version:content-transfer-encoding; bh=lbaopiF28XTSe0kOgA43uLo7FEzHh7vNLBWI3VxuLJg=; b=cgNWJNzXLFbdaMk39hHh0kurklsqSIEKVzJ+iJaufFQNC/cX5rLm+HjI1+L08U7mIX /l/1OlnfjrJJpTSe9fyuwNLfQjpLS5vIJ0PtyjoGYEQvkjYqUlnAE0rCBwbAkx/PPA2h BIfgCY//G7KNG9Vmes7WlfHt7z+rh4tDkkj+EEYGR12c3K8x4Evg3l4Lp17Ta5rrtjCN wh9iaEmggktat7Zuw9GgfRRNld27l6FlEd5Uo6ajQh05iAiJnRz/v1M+VQ/Gu32pTvxA 0VU8Vo0KDtohA5S6kPoSVP6iPs0Js36Cfnr0OgZ6eAvJDh0IX58TYQgqP3qHgRA1q6lD XCAQ== X-Gm-Message-State: APjAAAU7JXYuewPUxNxSIy+xx7MuTmP8f1pkdGVAH7Q+95N05aBzrzgr ry6/Yf+AL2/Zv4Ob9TrKoqG55NGeAt0= X-Google-Smtp-Source: APXvYqyrTW/k7r5/751BY/ZTsictQZbHuKTbQIQC6o2pSclEWdrBjvRdjFQwVhAw5M1zhEdQhMxkKw== X-Received: by 2002:a65:66d2:: with SMTP id c18mr3106926pgw.427.1557164048174; Mon, 06 May 2019 10:34:08 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:39 -0700 Message-Id: <20190506173353.32206-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::533 Subject: [Qemu-devel] [PATCH v4 10/24] util: Add qemu_guest_getrandom and associated routines 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This routine is intended to produce high-quality random numbers to the guest. Normally, such numbers are crypto quality from the host, but a command-line option can force the use of a fully deterministic sequence for use while debugging. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- include/qemu/guest-random.h | 68 +++++++++++++++++++++++++++ util/guest-random.c | 93 +++++++++++++++++++++++++++++++++++++ util/Makefile.objs | 1 + 3 files changed, 162 insertions(+) create mode 100644 include/qemu/guest-random.h create mode 100644 util/guest-random.c diff --git a/include/qemu/guest-random.h b/include/qemu/guest-random.h new file mode 100644 index 0000000000..09ff9c2236 --- /dev/null +++ b/include/qemu/guest-random.h @@ -0,0 +1,68 @@ +/* + * QEMU guest-visible 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_GUEST_RANDOM_H +#define QEMU_GUEST_RANDOM_H + +/** + * qemu_guest_random_seed_main(const char *optarg, Error **errp) + * @optarg: a non-NULL pointer to a C string + * @errp: an error indicator + * + * The @optarg value is that which accompanies the -seed argument. + * This forces qemu_guest_getrandom into deterministic mode. + * + * Returns 0 on success, < 0 on failure while setting *errp. + */ +int qemu_guest_random_seed_main(const char *optarg, Error **errp); + +/** + * qemu_guest_random_seed_thread_part1(void) + * + * If qemu_getrandom is in deterministic mode, returns an + * independent seed for the new thread. Otherwise returns 0. + */ +uint64_t qemu_guest_random_seed_thread_part1(void); + +/** + * qemu_guest_random_seed_thread_part2(uint64_t seed) + * @seed: a value for the new thread. + * + * If qemu_guest_getrandom is in deterministic mode, this stores an + * independent seed for the new thread. Otherwise a no-op. + */ +void qemu_guest_random_seed_thread_part2(uint64_t seed); + +/** + * qemu_guest_getrandom(void *buf, size_t len, Error **errp) + * @buf: a buffer of bytes to be written + * @len: the number of bytes in @buf + * @errp: an error indicator + * + * Fills len bytes in buf with random data. This should only be used + * for data presented to the guest. Host-side crypto services should + * use qcrypto_random_bytes. + * + * Returns 0 on success, < 0 on failure while setting *errp. + */ +int qemu_guest_getrandom(void *buf, size_t len, Error **errp); + +/** + * qemu_guest_getrandom_nofail(void *buf, size_t len) + * @buf: a buffer of bytes to be written + * @len: the number of bytes in @buf + * + * Like qemu_guest_getrandom, but will assert for failure. + * Use this when there is no reasonable recovery. + */ +void qemu_guest_getrandom_nofail(void *buf, size_t len); + +#endif /* QEMU_GUEST_RANDOM_H */ diff --git a/util/guest-random.c b/util/guest-random.c new file mode 100644 index 0000000000..e8124a3cad --- /dev/null +++ b/util/guest-random.c @@ -0,0 +1,93 @@ +/* + * QEMU guest-visible 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/guest-random.h" +#include "crypto/random.h" + + +static __thread GRand *thread_rand; +static bool deterministic; + + +static int glib_random_bytes(void *buf, size_t len) +{ + GRand *rand = thread_rand; + size_t i; + uint32_t x; + + 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 0; +} + +int qemu_guest_getrandom(void *buf, size_t len, Error **errp) +{ + if (unlikely(deterministic)) { + /* Deterministic implementation using Glib's Mersenne Twister. */ + return glib_random_bytes(buf, len); + } else { + /* Non-deterministic implementation using crypto routines. */ + return qcrypto_random_bytes(buf, len, errp); + } +} + +void qemu_guest_getrandom_nofail(void *buf, size_t len) +{ + qemu_guest_getrandom(buf, len, &error_fatal); +} + +uint64_t qemu_guest_random_seed_thread_part1(void) +{ + if (deterministic) { + uint64_t ret; + glib_random_bytes(&ret, sizeof(ret)); + return ret; + } + return 0; +} + +void qemu_guest_random_seed_thread_part2(uint64_t seed) +{ + g_assert(thread_rand == NULL); + if (deterministic) { + thread_rand = + g_rand_new_with_seed_array((const guint32 *)&seed, + sizeof(seed) / sizeof(guint32)); + } +} + +int qemu_guest_random_seed_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); + return -1; + } else { + deterministic = true; + qemu_guest_random_seed_thread_part2(seed); + return 0; + } +} diff --git a/util/Makefile.objs b/util/Makefile.objs index 9206878dec..c27a923dbe 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -54,5 +54,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 += guest-random.o stub-obj-y += filemonitor-stub.o From patchwork Mon May 6 17:33:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D88191575 for ; Mon, 6 May 2019 17:44:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C16BB28880 for ; Mon, 6 May 2019 17:44:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2C442887B; Mon, 6 May 2019 17:44:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 28A822887B for ; Mon, 6 May 2019 17:44:08 +0000 (UTC) Received: from localhost ([127.0.0.1]:60025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhep-00027S-AR for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:44:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVG-00018g-PU for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVF-0001On-6c for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:14 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:45881) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVE-0001Ln-Vs for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:13 -0400 Received: by mail-pg1-x541.google.com with SMTP id i21so6781728pgi.12 for ; Mon, 06 May 2019 10:34:10 -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:mime-version :content-transfer-encoding; bh=J+zhFbaacEoUzexA1I0BDxycgRD6FbkODujZaWxzKG4=; b=t2G1W0uYDa4lW1lyiUP/+916G5cnH0fvYVtJHpWaKgtjj79q9QieSkhcIEQrkmOtOq p4rROWn3YYVqwBWIRo5PD223/6NAU1iCuqpktZ92QNXCkcO3WFTh2dlOZCg+r2jtSh+c by6kN0hiDudH/FBzvgbCZvWCH2/SUcKCBdwgs1/wTQbmSdlGJqXbiOXHiiStuHA17WHr wx8YmTy4WbHZ4Q720A3DjWUwNEOUmWacppchbxulTMVmGKGB4kUa8sEtLZMBmJZngaDk R6eYjIXxYVzLe6dZSsWT6dGge6dPkvwxl+D6cT/wZ+h+2k+7h9Nt3ys1iUpwMrJ1dPtb G9fQ== 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:mime-version:content-transfer-encoding; bh=J+zhFbaacEoUzexA1I0BDxycgRD6FbkODujZaWxzKG4=; b=t6QQ9R2HncoYzYGIpZP6nKZBJ/G62YitQdjUxHrg2U/jMvu2vJbbZOYKIgtFLzyX9s sHLxNYrfUcfAylXHB4HIN0b/pLs99snLsYLPNYCls4Yi4UVNW/7zmilDPBOdZOnZPUW2 d34sxismIruIh31Ri5auXnBbBYx7IqxCNbe+cplcFVEuXbEO5nfynMS1+673ie062RdX lhd7pfV7Qaj1gtLGfMkMtI41hfk9ZTXdmsRhGTQ8xtkH6EdhW2aF67ZHzvv8bXJsFNtW 1TYlS3nBNtKitXMrYzgT6eCIl7jyyqstiS2fKKFriIPj/0lE6aR0w/31x+L4d8E4GDHv ftaw== X-Gm-Message-State: APjAAAUki8Uze8nln5NgaVnCqNzqIPd/JzLrZi5bTdKiTLFeJGI+Xj0/ CSr/XcOv7qz6H3vAAUFcFcTXG77mD14= X-Google-Smtp-Source: APXvYqz0r2c29JCQPUt56BguSqVBmBLA7SARc414dLtnTe/zrwOan0TZraEMLQ3sZmIJZ6mJ6HVxeQ== X-Received: by 2002:a63:d949:: with SMTP id e9mr8476264pgj.437.1557164049399; Mon, 06 May 2019 10:34:09 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:40 -0700 Message-Id: <20190506173353.32206-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::541 Subject: [Qemu-devel] [PATCH v4 11/24] cpus: Initialize pseudo-random seeds for all guest cpus 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When the -seed option is given, call qemu_guest_random_seed_main, putting the subsystem into deterministic mode. Pass derived seeds to each cpu created; which is a no-op unless the subsystem is in deterministic mode. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- include/qom/cpu.h | 1 + cpus.c | 9 +++++++++ vl.c | 4 ++++ qemu-options.hx | 10 ++++++++++ 4 files changed, 24 insertions(+) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 08abcbd3fe..9793ec39bc 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -369,6 +369,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 e58e7ab0f6..ffc57119ca 100644 --- a/cpus.c +++ b/cpus.c @@ -50,6 +50,7 @@ #include "qemu/option.h" #include "qemu/bitmap.h" #include "qemu/seqlock.h" +#include "qemu/guest-random.h" #include "tcg.h" #include "hw/nmi.h" #include "sysemu/replay.h" @@ -1276,6 +1277,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1319,6 +1321,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { qemu_mutex_unlock_iothread(); @@ -1478,6 +1481,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) cpu->created = true; cpu->can_do_io = 1; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* wait for initial kick-off after machine start */ while (first_cpu->stopped) { @@ -1592,6 +1596,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg) hax_init_vcpu(cpu); qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1631,6 +1636,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1671,6 +1677,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1724,6 +1731,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) cpu->can_do_io = 1; current_cpu = cpu; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* process any pending work */ cpu->exit_request = 1; @@ -2071,6 +2079,7 @@ void qemu_init_vcpu(CPUState *cpu) cpu->nr_cores = smp_cores; cpu->nr_threads = smp_threads; cpu->stopped = true; + cpu->random_seed = qemu_guest_random_seed_thread_part1(); if (!cpu->as) { /* If the target cpu hasn't set up any address spaces itself, diff --git a/vl.c b/vl.c index d9fea0a119..d847b3ebad 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/guest-random.h" #define MAX_VIRTIO_CONSOLES 1 @@ -3319,6 +3320,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_guest_random_seed_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 51802cbb26..0191ef8b1e 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 the guest to use a deterministic pseudo-random number generator, seeded +with @var{number}. This does not affect crypto routines within the host. +ETEXI + DEF("L", HAS_ARG, QEMU_OPTION_L, \ "-L path set the directory for the BIOS, VGA BIOS and keymaps\n", QEMU_ARCH_ALL) From patchwork Mon May 6 17:33:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 10C931575 for ; Mon, 6 May 2019 17:41:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDB4F26E4F for ; Mon, 6 May 2019 17:41:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1BA728880; Mon, 6 May 2019 17:41:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 62D8F26E4F for ; Mon, 6 May 2019 17:41:37 +0000 (UTC) Received: from localhost ([127.0.0.1]:60005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhcO-0008A7-Mn for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:41:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVG-00018h-PG for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVF-0001Ou-70 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:14 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:40440) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVF-0001N1-07 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:13 -0400 Received: by mail-pl1-x642.google.com with SMTP id b3so6707168plr.7 for ; Mon, 06 May 2019 10:34:11 -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=Fj9NAT+dC/44CVxKQ9vRk+R9FLW3wBp4fXibMqKhPs0=; b=NS4nASxHHKXLy0BIyjl1W6Y0jZRvqItBP8DTW46Iu6scDsjW7PAngMCDENbFU3Pe8O inOUA56K/FjJPK2G7scK7/3cibtebx4f8qqd1HcMKifsbavxb88zgn6WIYna/qGOVlVb 9zPiUg0XYrSgtHOUyXTX1gNx1066/e//ZkquhlBzDlfIeot4G8LnZxin9T1mCIWG5GC2 x3LlzYf9gV67QqaZGFADNFu4KnP4wXAwoqhwim/AScSTO1ViKKbzAMdepSVqokzVEC95 iniHUQbcoPeARExpqyaWn5oF2LgtJA1hvjgcx57hxiqN5w+x0iE52WlhoUOEq6BY/AKi 3AMA== 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=Fj9NAT+dC/44CVxKQ9vRk+R9FLW3wBp4fXibMqKhPs0=; b=C4iKdFnnvclX6ARMZxUXVPGMHv5arO2PuZoXt1LZqfitanINcWMVPDbHv2oyLC5t4/ siNfIaupJTF/NrfYonRqar1ARmD7Y+UotfekzjxdBHw5PVAkIdVXsqZ3p3DXNSmBWmv2 R1CpWmrep2X6QVKfmX2vc9ZYoStVHsICIBq/0hOGd5XCzJUcmJ72rPZ9y0vjwuA+fP4f 5GN0V7zZhbEyFh+20kLrESMLpLjp70lhBdk78+Uu9C9qt+UqnFruBuvE58rlKYyYkths kKxfaK8DF2zMtExi+/z0zC4Rlu8DJqV/jI35dKH04s5as73kMI2szfMQ8yPaLLe4YACe TIJw== X-Gm-Message-State: APjAAAVOC3qaXZBofbVO3P4xdZCYynAab5biR0TqcMRetIGPHBXJavHN ppVQd044bNT5qYMmWIkCR5FnsMRkURk= X-Google-Smtp-Source: APXvYqywU81fOTPUcQt1dPvolfLqpFHy5DDdt5DJAG8N+/Mbb8l8MxOcHu2y/TqH8/ISEUXkSb6Rrg== X-Received: by 2002:a17:902:4624:: with SMTP id o33mr33953868pld.191.1557164050651; Mon, 06 May 2019 10:34:10 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:41 -0700 Message-Id: <20190506173353.32206-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::642 Subject: [Qemu-devel] [PATCH v4 12/24] linux-user: Initialize pseudo-random seeds for all guest cpus 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When the -seed option is given, call qemu_guest_random_seed_main, putting the subsystem into deterministic mode. Pass derived seeds to each cpu created during clone; which is a no-op unless the subsystem is in deterministic mode. Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 21 ++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 3d2230320b..7dfb202e5d 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -34,6 +34,7 @@ #include "tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h" +#include "qemu/guest-random.h" #include "elf.h" #include "trace/control.h" #include "target_elf.h" @@ -48,6 +49,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; @@ -290,15 +292,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) @@ -433,7 +429,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=]"}, @@ -689,8 +685,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_guest_random_seed_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 96cd4bf86d..ce377b2fc1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -110,6 +110,7 @@ #include "uname.h" #include "qemu.h" +#include "qemu/guest-random.h" #include "fd-trans.h" #ifndef CLONE_IO @@ -5441,6 +5442,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_guest_random_seed_thread_part2(cpu->random_seed); /* Enable signals. */ sigprocmask(SIG_SETMASK, &info->sigmask, NULL); /* Signal to the parent that we're ready. */ @@ -5527,6 +5529,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_guest_random_seed_thread_part1(); /* If this is our first additional thread, we need to ensure we * generate code for parallel execution and flush old translations. From patchwork Mon May 6 17:33:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD620912 for ; Mon, 6 May 2019 17:47:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7FAF28843 for ; Mon, 6 May 2019 17:47:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C1EA28880; Mon, 6 May 2019 17:47:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4C41228843 for ; Mon, 6 May 2019 17:47:17 +0000 (UTC) Received: from localhost ([127.0.0.1]:60082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhhs-0004q1-Ji for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:47:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVK-0001Cy-Gr for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVI-0001R5-Mq for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:36747) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVG-0001OO-Ph for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:16 -0400 Received: by mail-pg1-x534.google.com with SMTP id 85so6797515pgc.3 for ; Mon, 06 May 2019 10:34:13 -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=HH/L9mt26ecHO3SVHPhMrOoX9weRmZOQf65hlibBofo=; b=x3XXvdHgCk4PbDzhb99ICvZWxdjsdUNjfjS4HLi+oUzM+5m1Wz9OBa6cvk9mq117H8 n4Lv98wqzKAEFhQGhNysVaOKZvBNAUNaOeVlWh/i8IGVEeWHt8Bb8osvCTy1N7CNvDDF iyvVHwvNtbmDQYuIUelAsdxG9c29VvOM+jxeT9BMnzcGs3s8FS9YBdrsUYiEcdULAOl3 o+a+4MWmqoNJZP6zFrg/oMRanxDMEHQbdgTWpFI8XakuShJzyQ/p1dI9+YWfnlrcZwJk ud8eDaZn1Jse4HM5jRgYaVPiY5Mn8p2F2rPkukqMoubFksOSbHvxUwIHX+O6rCRLRM6K Dswg== 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=HH/L9mt26ecHO3SVHPhMrOoX9weRmZOQf65hlibBofo=; b=pPgtOxq2tQWn7osvtT466FflQtZPn1A7V+AEJZ+M1ziVyNxlOHbShZY3dReWz2GH59 F4KFMdrhhIxa4wcyL3hXHriuc6soqk8fBjC4dGZtLceWtcfgJBicgnnqbV0rDx9M1pqg e2GedNg6htA/0aFq4aE1Tl++W4qumE8PThBxuj/EkQtJYztQerXDoELBZCwX6DuPHmUc VGaRa13GuLfsj5/24IQ2XAjQ3Xh1YTDbe0gr5Q/8R1z+WxNCOJ9pg/pI3dGlj+eczm2k qN+hj/7k6EkbwLr06aYPnC7yfyuQL7lPlo743jlxHMEwPns1LnkqoyudSJLRWpMqkVjk BVWg== X-Gm-Message-State: APjAAAUmXb3ySMMM8ce75UJ+WlahHt8KUOPDVwQ4Dr+CfBpSnBskv/kg /Zl1R38RgAwOWEeze3p2hMOJs2bHFjU= X-Google-Smtp-Source: APXvYqyUQ04TYTkVEvfpjfS4bwVXNFWCaFQk94Qk7/8Nbuf3peYAGFpR/I5fga276x7+7dQhqTfC5w== X-Received: by 2002:a65:6496:: with SMTP id e22mr33710784pgv.249.1557164051833; Mon, 06 May 2019 10:34:11 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:42 -0700 Message-Id: <20190506173353.32206-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::534 Subject: [Qemu-devel] [PATCH v4 13/24] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- linux-user/main.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 7dfb202e5d..e05aebe4e1 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -39,6 +39,7 @@ #include "trace/control.h" #include "target_elf.h" #include "cpu_loop-common.h" +#include "crypto/init.h" char *exec_path; @@ -688,8 +689,18 @@ int main(int argc, char **argv, char **envp) if (seed_optarg == NULL) { seed_optarg = getenv("QEMU_RAND_SEED"); } - if (seed_optarg != NULL) { - qemu_guest_random_seed_main(seed_optarg, &error_fatal); + { + Error *err = NULL; + if (seed_optarg != NULL) { + qemu_guest_random_seed_main(seed_optarg, &err); + } else { + /* ??? Assumes qcrypto is only used by qemu_guest_getrandom. */ + qcrypto_init(&err); + } + if (err) { + error_reportf_err(err, "cannot initialize crypto: "); + exit(1); + } } target_environ = envlist_to_environ(envlist, NULL); From patchwork Mon May 6 17:33:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9527C912 for ; Mon, 6 May 2019 17:47:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F36428843 for ; Mon, 6 May 2019 17:47:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70EB628880; Mon, 6 May 2019 17:47:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1FC6E28843 for ; Mon, 6 May 2019 17:47:14 +0000 (UTC) Received: from localhost ([127.0.0.1]:60080 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhhp-0004lU-E0 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:47:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVK-0001Cz-Gs for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVI-0001Qp-Lf for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:37276) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVG-0001P9-Ol for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:15 -0400 Received: by mail-pg1-x544.google.com with SMTP id e6so6799970pgc.4 for ; Mon, 06 May 2019 10:34:13 -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=6ZLSvDsE417cQFXtdznOdElqMvcAzRRA3vqOLnZRXkY=; b=E32KfjgMlH1BNZqxvEe87rzW5aXT1ryTedZZsN1NoTPRj8Lo5MKTENOVYjBnYfpgQg vI74qDBQ6nv8qxXXDbvERkYtVaZ31P3Cl+Vt6tGex/nFUQ+UT6Po1dw5GesRWry95Jko ofBkUgbvbqwLTajEGDRqWgdm7ymFIk14MvdVu0+eL8V/oluZMMi+wDHw3c8/RUzCAfYX 8lwUbS1f42yaO7pdTL9RuljvwMIUuAYI7+aZco1eMucsi4JO9ixoowwuz7SctYK2frWy 3tIAOI8kS8r/4C6ZvmE/9DeGVwIkTOTM9mC+Pxe4xUPs5YBoEcixmRz6as2LTlM/95Zn wR5g== 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=6ZLSvDsE417cQFXtdznOdElqMvcAzRRA3vqOLnZRXkY=; b=CZ1Q8NW9hb6hL9Ri+DI6z4szHgEZTFRuqEI4X22qxudm8sbGY7XdVWeEeHkE1R4lvi hKoCISA7xjfjuHSSOE1jjeOuIYPpmUV5YcH8ZVJ+UkA+luDbPGFR1ugrB0AI3/WDDJzp nFUNuOX+obeQM6dDl92NEvboPb7eiqHS2SGndylMp4BWXF5xTscLqyKNZv8oNne/HDtc Bw0gfC6YNh/EcnMZMSJXTEbRm/lWALIpt0v36zWSytVmeklhPxNHKEDwsblutzZ6E2Ic z4hPSt4kFM0W15KjbRM3I4tLPYdKuXkoABoiqvQMQU+mBLfQu8+7YCZNgkhZhKjOUvxO 9wYQ== X-Gm-Message-State: APjAAAXuc/jZfwI9HNurogvIjpkdA1Pjiv+zhs0yrHdvvU0HM3r8xHXA HrCvCkjHmJAaWh6hTFPtH3AUhNiVAnM= X-Google-Smtp-Source: APXvYqxjmnCwkhzAnroSW6y7utolcv6REpaPfJYXYJy1DNDYwVvAcmW4VV1vMfiStn4wWS8C5FW+xQ== X-Received: by 2002:a62:5a42:: with SMTP id o63mr36429284pfb.170.1557164052846; Mon, 06 May 2019 10:34:12 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:43 -0700 Message-Id: <20190506173353.32206-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::544 Subject: [Qemu-devel] [PATCH v4 14/24] linux-user: Use qemu_guest_getrandom_nofail 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use a better interface for random numbers than rand * 16. Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- linux-user/elfload.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c1a26021f8..e673f7ea55 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/guest-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_guest_getrandom_nofail(k_rand_bytes, sizeof(k_rand_bytes)); if (STACK_GROWS_DOWN) { sp -= 16; u_rand_bytes = sp; From patchwork Mon May 6 17:33:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A0FA912 for ; Mon, 6 May 2019 17:50:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86A782888D for ; Mon, 6 May 2019 17:50:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B3B528864; Mon, 6 May 2019 17:50:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 379D228880 for ; Mon, 6 May 2019 17:50:18 +0000 (UTC) Received: from localhost ([127.0.0.1]:60148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhko-0007AX-BR for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:50:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVO-0001F2-0G for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVK-0001SS-Ho for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:20 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:46569) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVI-0001Pg-LI for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: by mail-pf1-x42f.google.com with SMTP id j11so7111844pff.13 for ; Mon, 06 May 2019 10:34:15 -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=XGj6206fsdJxol+0Im+/ya3c6hhRI8KMqoTGs4TcX0E=; b=Hck4bxZS5lN1BVH0JeCN8+AIj+HAHE6FayH8F6hePk6Qw1lfF8V7mKFyn58QNGu7gy EpIQBnLb6TLsUEatCYigkrtbK45Y0EIaCp1alybwgBBCr07U/cfCVq/PvvbARBJIO134 uHgLRXsRaHWc6g977fBaP3z/8PnYxD/RZNGi/eynnEjHP66cff4GwSdivixRJyeXgYDC RABXB28gDF0yjCKhD5X6o4+4KyzI7YlfDXEzBLqIoylhYSAh0JaQFHPf5OHiJtLPAM6t GA3ruEeUqEiokd5aQ3A/wW+0wRl4bORI50RyjtM0H1o4la8uxjrN0fHRanwMh9OTC95r 07rw== 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=XGj6206fsdJxol+0Im+/ya3c6hhRI8KMqoTGs4TcX0E=; b=S1R2FzDbgYTRO+plzWO3fvOgdHOIkyCosMXz2JqgJWkcXOmvOVX4+8yk0BuGXrGA8z XQpab8gitZU1QfAX3zrHteidMR6c4714SBF5squLHFoHjwRz1vWtr0KksBcJ1qdFmGcX tu7Y+LGGNMF1mGWrOQpol6gsphRZxWK5QVfI82W2bArC65EolmLDvjD9h1ZEbuzTT4Rq hE3P8pEiFUtfgjgVVuNpyW8lKjBgpErowGpDtXwH+N1bDNCtq/gsFnACyI8bOCxl0AVB gM0zrF7h9uB2TXFyG0Qx0cR1HNRAfWv62UTkINsnZebdk9yHcvUNEMb+5KMzN0jVpsNQ nkrA== X-Gm-Message-State: APjAAAXHI+nB3xvgnIgFA4FNfOpxa+TK/P2AY9oH9Pkl0RAdsrjDUmgH Hko6pT6WyMSFildxf5H5Rj4cEisz/aQ= X-Google-Smtp-Source: APXvYqxrkbJWZTmKixPaFwodOjOz48WJuxQ2x7z/1n5yW/3TAWooJE5IRIIrbyWLrjWgMr/fvIZ5tA== X-Received: by 2002:a63:1d02:: with SMTP id d2mr7013533pgd.26.1557164054000; Mon, 06 May 2019 10:34:14 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:44 -0700 Message-Id: <20190506173353.32206-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::42f Subject: [Qemu-devel] [PATCH v4 15/24] linux-user/aarch64: Use qemu_guest_getrandom for PAUTH keys 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use a better interface for random numbers than rand() * 3. Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- linux-user/aarch64/target_syscall.h | 2 -- linux-user/aarch64/cpu_loop.c | 29 ++++++--------------------- linux-user/syscall.c | 31 ++++++++++++++++++++++++----- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h index b595e5da82..995e475c73 100644 --- a/linux-user/aarch64/target_syscall.h +++ b/linux-user/aarch64/target_syscall.h @@ -29,6 +29,4 @@ struct target_pt_regs { # define TARGET_PR_PAC_APDBKEY (1 << 3) # define TARGET_PR_PAC_APGAKEY (1 << 4) -void arm_init_pauth_key(ARMPACKey *key); - #endif /* AARCH64_TARGET_SYSCALL_H */ diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index d75fd9d3e2..cedad39ca0 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/guest-random.h" #define get_user_code_u32(x, gaddr, env) \ ({ abi_long __r = get_user_u32((x), (gaddr)); \ @@ -147,24 +148,6 @@ 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(); -} - void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { ARMCPU *cpu = arm_env_get_cpu(env); @@ -192,11 +175,11 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) #endif if (cpu_isar_feature(aa64_pauth, cpu)) { - arm_init_pauth_key(&env->apia_key); - arm_init_pauth_key(&env->apib_key); - arm_init_pauth_key(&env->apda_key); - arm_init_pauth_key(&env->apdb_key); - arm_init_pauth_key(&env->apga_key); + qemu_guest_getrandom_nofail(&env->apia_key, sizeof(ARMPACKey)); + qemu_guest_getrandom_nofail(&env->apib_key, sizeof(ARMPACKey)); + qemu_guest_getrandom_nofail(&env->apda_key, sizeof(ARMPACKey)); + qemu_guest_getrandom_nofail(&env->apdb_key, sizeof(ARMPACKey)); + qemu_guest_getrandom_nofail(&env->apga_key, sizeof(ARMPACKey)); } ts->stack_base = info->start_stack; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ce377b2fc1..b73d1d9f65 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -111,6 +111,7 @@ #include "qemu.h" #include "qemu/guest-random.h" +#include "qapi/error.h" #include "fd-trans.h" #ifndef CLONE_IO @@ -9724,25 +9725,45 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, int all = (TARGET_PR_PAC_APIAKEY | TARGET_PR_PAC_APIBKEY | TARGET_PR_PAC_APDAKEY | TARGET_PR_PAC_APDBKEY | TARGET_PR_PAC_APGAKEY); + int ret = 0; + Error *err = NULL; + if (arg2 == 0) { arg2 = all; } else if (arg2 & ~all) { return -TARGET_EINVAL; } if (arg2 & TARGET_PR_PAC_APIAKEY) { - arm_init_pauth_key(&env->apia_key); + ret |= qemu_guest_getrandom(&env->apia_key, + sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APIBKEY) { - arm_init_pauth_key(&env->apib_key); + ret |= qemu_guest_getrandom(&env->apib_key, + sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APDAKEY) { - arm_init_pauth_key(&env->apda_key); + ret |= qemu_guest_getrandom(&env->apda_key, + sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APDBKEY) { - arm_init_pauth_key(&env->apdb_key); + ret |= qemu_guest_getrandom(&env->apdb_key, + sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APGAKEY) { - arm_init_pauth_key(&env->apga_key); + ret |= qemu_guest_getrandom(&env->apga_key, + sizeof(ARMPACKey), &err); + } + if (ret != 0) { + /* + * Some unknown failure in the crypto. The best + * we can do is log it and fail the syscall. + * The real syscall cannot fail this way. + */ + qemu_log_mask(LOG_UNIMP, + "PR_PAC_RESET_KEYS: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -TARGET_EIO; } return 0; } From patchwork Mon May 6 17:33:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931703 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF98C1575 for ; Mon, 6 May 2019 17:43:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98D7526E4F for ; Mon, 6 May 2019 17:43:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C33D28880; Mon, 6 May 2019 17:43:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4388C26E4F for ; Mon, 6 May 2019 17:43:40 +0000 (UTC) Received: from localhost ([127.0.0.1]:60023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNheN-0001ip-AH for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:43:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVO-0001Ey-07 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVK-0001SO-HZ for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:20 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:41751) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVI-0001QJ-LW for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: by mail-pf1-x444.google.com with SMTP id l132so2178234pfc.8 for ; Mon, 06 May 2019 10:34:16 -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=eiE9fqe9KMXKwTkJClxb0B2B9ssy/VKRiWp6bsH/0U0=; b=sK6KxzCNzNFZFFS5hBP6i9IqgAut+jrnX9Azs97fkmeWcNbvdyHnS+KSS1jSUX4bij x9wop2iwo3pTvk9yCrAaL2NncN6cjXJtPhkKEaDwWJJT/I9AKcf7N3+LEasky95cyzPw fiddB8n9QZyfgkT8pXBk5ZRRKPR4IIGdYgSM64luPmO5jc9fiUK57eoUKqArtPslpPo3 6UKxJ71IkqdFyuqic/UiUJYtRHGytAbJ/1qcEMnA8fZ+I6QxTd31GvdoeOipUHA9NlhU Nlmdn1BguZGgKaBS2WpBjT9sOurvC1A2SVs7tOeitcwZl6pUrwb/RnpGX7ggFu/LtXg4 u66A== 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=eiE9fqe9KMXKwTkJClxb0B2B9ssy/VKRiWp6bsH/0U0=; b=HZPFvVJuWcBTfiJWNm1Q3nOeI5QUIPXP6/F0Rts1Wul6vwJ0UuD/kEE2dFdL3oEA6b G+PYXYbDcMPV7h1GR/AgoTedwVpaF1Kl+8D0hfqfi3wZY+UslGOwqUTwnIAZdAPHDRK0 lMEi6YiTdyAVEQTjmkH620ynvyvFQvonJCOfI/IEy3i+ImsVU66wGP1wITysM6aCYzkM 5Q2EfJJL4u0diuNoxloHNRpWJwuFLKlC08kvFVjggsFl3sTJrSzS8HZx1siqvLOUgoB7 0lr2735oDRYsZ1HhRIhmbhOwbkl0GR310cmvG6tVRWHNvrIRDtJRP2YuHlW3bnvcWWrQ FiUA== X-Gm-Message-State: APjAAAUdXkBHhoR4oItMSzTeSzOGbyMSbsYU1w+jbZBu4IDyjHqFfddd vm9Nuq3wOiPJkgwHQfAmGX5f4a7DKQs= X-Google-Smtp-Source: APXvYqyaCILbO54ajmpct6Vrf74iGV9DDBxkA/uasGdP3elG2AR6L6rw7n9Jnv2xpwhwHGzUXEx3bQ== X-Received: by 2002:a62:5286:: with SMTP id g128mr34058692pfb.226.1557164055105; Mon, 06 May 2019 10:34:15 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:45 -0700 Message-Id: <20190506173353.32206-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::444 Subject: [Qemu-devel] [PATCH v4 16/24] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We no longer use rand() within linux-user. Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index e05aebe4e1..5d1c6a115b 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -623,8 +623,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 Mon May 6 17:33:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B0B261575 for ; Mon, 6 May 2019 17:46:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97C7028843 for ; Mon, 6 May 2019 17:46:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BEC228880; Mon, 6 May 2019 17:46:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1AEDA28843 for ; Mon, 6 May 2019 17:46:37 +0000 (UTC) Received: from localhost ([127.0.0.1]:60078 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhhE-0004Ep-Cb for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:46:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVO-0001F1-0I for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVK-0001St-P7 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:20 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:42678) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVK-0001RD-HR for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: by mail-pf1-x443.google.com with SMTP id 13so6822231pfw.9 for ; Mon, 06 May 2019 10:34:17 -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=PvlwPcZPY/FWFYh3k49LzzqKgqvSGwd1QF+0Yp8Ixq4=; b=FtmpCYW2i5ojok4k2vEbCXHVQi8yP6K+LoxD05vBTGP6vq75Rr8lHdm28xNtI1ZI0u a0G9OW/fI7O5IQuKSpA3guGEmMDdUH21sF11J4eRhjs76Yrp55Roy25FjdjbYRv0CWo5 JFo8CizPG2FVHATM80gGMAmsFljmdbsAhXj9NON++vRlBEBYmkvrfP/XOCUp3cBZpTD1 GcX4okn94qath5pIaWbNh7r09RU+zJj8m23PaCQpKDpFEzrRGw71AjjBSnje0eXiEdvC 773e4TxrfZR5ltJqobbxmuSo3we4hj1v6IlxPLzKEp9qxVW0YO6p6s7G9BkfyaLIBT08 muAw== 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=PvlwPcZPY/FWFYh3k49LzzqKgqvSGwd1QF+0Yp8Ixq4=; b=o2BWax92tK7qkT120zorgOalvVrKxDe6ls/Uzi6+rGxveGuZ+umA/Wsbr6zbUWcfEy nSlBmR5NXvSm0jR8hoG2MHQkXzQcpNEtOUtzNBXI/C13qb8cDREYmz6B0YfsBV1qfXyv QzZph5eLil0MHAZJtujBN9TlQC9d+dXrGImX/SXZ59/VWGO7YYPxcldQlNFwQXEjOW00 oh1pX8ec3PaX6vyZs5IEiTpveMJd+V5ug1aQqQp7fZx3NsPJOD5X+xporRoZyTWoUPKb NBAcUBMN+6SWeHYamMC63BZjx399dh9qkU3o6aHVSvTLFAKp/l1ikrleCMb4k8lHI4Fd n6dw== X-Gm-Message-State: APjAAAXYYkRcPkDER5Mwtgtr0iIDlgcAnO5rlWuaWyEs1tkGn0k35j8l U5SGCpv7uxQkFuRu61AuCq7IdQJb5OQ= X-Google-Smtp-Source: APXvYqwyglYmLflS5AuzZ7Q0XBNsgS9lDw//MGo0iw6KzYXydZvhXu2jG6uUb9t27DyHW17B3tee8A== X-Received: by 2002:aa7:8243:: with SMTP id e3mr2434449pfn.213.1557164056133; Mon, 06 May 2019 10:34:16 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:46 -0700 Message-Id: <20190506173353.32206-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::443 Subject: [Qemu-devel] [PATCH v4 17/24] aspeed/scu: Use qemu_guest_getrandom_nofail 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: Andrew Jeffery , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Use the *_nofail routine instead of rolling our own error handling locally. Cc: qemu-arm@nongnu.org Cc: Andrew Jeffery Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Reviewed-by: Joel Stanley Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- hw/misc/aspeed_scu.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c index c8217740ef..ab1e18ed4b 100644 --- a/hw/misc/aspeed_scu.c +++ b/hw/misc/aspeed_scu.c @@ -16,7 +16,7 @@ #include "qapi/visitor.h" #include "qemu/bitops.h" #include "qemu/log.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "trace.h" #define TO_REG(offset) ((offset) >> 2) @@ -157,14 +157,8 @@ static const uint32_t ast2500_a1_resets[ASPEED_SCU_NR_REGS] = { static uint32_t aspeed_scu_get_random(void) { - Error *err = NULL; uint32_t num; - - if (qcrypto_random_bytes((uint8_t *)&num, sizeof(num), &err)) { - error_report_err(err); - exit(1); - } - + qemu_guest_getrandom_nofail(&num, sizeof(num)); return num; } From patchwork Mon May 6 17:33:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5FCAD1575 for ; Mon, 6 May 2019 17:49:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4ABDF2887B for ; Mon, 6 May 2019 17:49:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B36628882; Mon, 6 May 2019 17:49:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C6D112887B for ; Mon, 6 May 2019 17:49:45 +0000 (UTC) Received: from localhost ([127.0.0.1]:60110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhkG-0006kX-T1 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:49:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVO-0001Ez-07 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVK-0001T4-Pe for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:20 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:37703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVK-0001Ry-Ia for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: by mail-pl1-x641.google.com with SMTP id z8so6722983pln.4 for ; Mon, 06 May 2019 10:34:18 -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=N99BQlBfn/0a0vkPsRVGBD0Y+fTNw9UH381I+mLvorI=; b=Dg5+08ulJwFtevhdXETSihRnqYW53GxvjPzw9ZR3Qx6fNBXqDsUz+BEg2OG4QoUPe8 vkoX4Cs3zdwrbURmxP7Z5gDG9uvSpuYLcAl2mt1cL2BfZWIJDouEdvI3YxOExef4pqDP m5dU93hcjaSZu/r5Rq/WnMWTNMIyIDCMaIuzmiHaojzodxuIcuUpU7QSkftKg1DT8hcJ mNvgznnAm2labFfkUIS9R/KqaLXyETesGAqL8i2q5hn4GBphmnJHBn+SMNi+9FgWyjKF xqr9Jb/vVNb6XzFDBMUBx5vJA2Xli40KCjRhl+BZdwcIDuCapR5tZ76B1tHpCOrESQ/I 5vfw== 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=N99BQlBfn/0a0vkPsRVGBD0Y+fTNw9UH381I+mLvorI=; b=fK0tgBJuWWwyf2phhUO24LUVeIorSMZ7OJc491yH5Rle2HYkYqzTM+HE/+UeT3Z0gx J9tUWbFqhe0bmpImswdDt9jcq2xZEwnDeGajJJH7crgIrvGwVFe2SnfSX+WY5SM1p5YX AEf8iZw8ZklrjgQEc0UpzWtbOUv9JfQ0dkqCb8SXmepYaoe1MDElzYWxf0TYJOzwTMUL vcS2J6NP7GEb52l4JPLZeoeXSJRoVBZHPCe6SK6HFmEmCwsRjh+Fg2Jq44wUP+nKFyOC pG1SN5Hwy42FOEBaSKGlYoULVA+8UaWq1Oc6onUg1UFD+a/zFtqqKLMMTBNGH9qnsa2b NzAw== X-Gm-Message-State: APjAAAXdjyTU1cxZ+PIsDJNYI3Ffw0Oou3ue8oi+bNfABRTcBSiOdoy6 2OH+2ucw9Yoidcpap/rfMvj6LIvfpH4= X-Google-Smtp-Source: APXvYqwyoYJRvKtAqAdVjtdNgDRMJYwzjNa1PM170md8pV5ss2e/e7CItTFdt+H+ZpZn0Ez2vVS2GQ== X-Received: by 2002:a17:902:76c5:: with SMTP id j5mr34356896plt.337.1557164057250; Mon, 06 May 2019 10:34:17 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:47 -0700 Message-Id: <20190506173353.32206-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::641 Subject: [Qemu-devel] [PATCH v4 18/24] hw/misc/nrf51_rng: Use qemu_guest_getrandom_nofail 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: qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Use the *_nofail routine instead of error_abort directly. Cc: qemu-arm@nongnu.org Reviewed-by: Joel Stanley Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- hw/misc/nrf51_rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/misc/nrf51_rng.c b/hw/misc/nrf51_rng.c index d188f044f4..3400e90a9b 100644 --- a/hw/misc/nrf51_rng.c +++ b/hw/misc/nrf51_rng.c @@ -14,7 +14,7 @@ #include "qapi/error.h" #include "hw/arm/nrf51.h" #include "hw/misc/nrf51_rng.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" static void update_irq(NRF51RNGState *s) { @@ -145,7 +145,7 @@ static void nrf51_rng_timer_expire(void *opaque) { NRF51RNGState *s = NRF51_RNG(opaque); - qcrypto_random_bytes(&s->value, 1, &error_abort); + qemu_guest_getrandom_nofail(&s->value, 1); s->event_valrdy = 1; qemu_set_irq(s->eep_valrdy, 1); From patchwork Mon May 6 17:33:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 649D092A for ; Mon, 6 May 2019 17:52:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50B8528882 for ; Mon, 6 May 2019 17:52:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44D1C28898; Mon, 6 May 2019 17:52:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D84D5288A6 for ; Mon, 6 May 2019 17:52:23 +0000 (UTC) Received: from localhost ([127.0.0.1]:60166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhmp-0000WL-2O for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:52:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVQ-0001HV-Aj for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVO-0001XD-Dw for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:24 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:45199) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVM-0001TN-NK for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:22 -0400 Received: by mail-pf1-x42d.google.com with SMTP id e24so7118995pfi.12 for ; Mon, 06 May 2019 10:34:19 -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=2div2YVLjVe7DwdMLbNY+nkm3nkpzeNz5eXH0qLyY8k=; b=HO/a2KJObdqAqpfzLvR4kxvp/QT1f95D5xt+K0LIV2VzAmNoQrgm2U+Nb2uCf6ok6p yN33eYIsJXEMa86FMzwRDP162tq0K7ekCNjWz9cOGIOkeG/onWyEg4nEJGAXrkw460tS NOSp1OhPx2HiQ9GQAkxvRiGX4f+tuL5IXORfBo1QJ+G4iJR+U3OivNRjq9vrDvSriY8v dLij5r9lDV1F5g6q7TqaGK/4pGnx/duV/MfxhsjPjcXBmgD7RKOPbeUaIj154olp8win XrtNK5cif//1qeYt0l/YvCjKD4GRFKh7boWflcS9pGWDkuwDHwYfRu+GwoFgVdmC1L8e adNA== 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=2div2YVLjVe7DwdMLbNY+nkm3nkpzeNz5eXH0qLyY8k=; b=qHVUzgOwFrAI3mn0sqI9OYd6ipCYN/3EtlKtjYBK9g1a5pAS5e/bnf543tYzjp1daP jVx6Co1aOlKZz4KUnWFkf7DZgq2ZSuxvIDED1goildRYioadkXZNryU4Ha7XgTyR7gtC mvq2QCjgT+zDHQBG7oXO/e3QTv89GbP1AYyKl8t/p1tNA2bO12crSdWsjv41rBfwifyc cllYLDqBqMAhSlEBlSkud+aNPteiH+djKJ9mz0RIA0BF9pT1Hb2eLsQlhSi/bmdIeJoE 0IrlkuL182G/5gqJCQknXuUJrjzBlkOJevJQq1sW0T8tSI/z6dD88RdPTQrn9QfmChVO E6wg== X-Gm-Message-State: APjAAAUUYVYo/rjOg+kJFCYwrHrO3617Y4RAIa69UBfrngp7NOykif+q q5uYn9XSksGDB5Dz5Q8D68fL+NPA86Q= X-Google-Smtp-Source: APXvYqzzli0KoGVRT5t4y83bYT4UU6lSAu6qWL/0KRlflxZW1u9UItZx484N034yxLjY4I8PBsVGIA== X-Received: by 2002:a62:2703:: with SMTP id n3mr10803121pfn.199.1557164058577; Mon, 06 May 2019 10:34:18 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:48 -0700 Message-Id: <20190506173353.32206-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::42d Subject: [Qemu-devel] [PATCH v4 19/24] hw/misc/bcm2835_rng: Use qemu_guest_getrandom_nofail 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: qemu-arm@nongnu.org, Andrew Baumann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Use the *_nofail routine instead of rolling our own error handling locally. Cc: qemu-arm@nongnu.org Cc: Andrew Baumann Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- hw/misc/bcm2835_rng.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/hw/misc/bcm2835_rng.c b/hw/misc/bcm2835_rng.c index 4d62143b24..fe59c868f5 100644 --- a/hw/misc/bcm2835_rng.c +++ b/hw/misc/bcm2835_rng.c @@ -9,30 +9,26 @@ #include "qemu/osdep.h" #include "qemu/log.h" -#include "qapi/error.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "hw/misc/bcm2835_rng.h" static uint32_t get_random_bytes(void) { uint32_t res; - Error *err = NULL; - if (qcrypto_random_bytes((uint8_t *)&res, sizeof(res), &err) < 0) { - /* On failure we don't want to return the guest a non-random - * value in case they're really using it for cryptographic - * purposes, so the best we can do is die here. - * This shouldn't happen unless something's broken. - * In theory we could implement this device's full FIFO - * and interrupt semantics and then just stop filling the - * FIFO. That's a lot of work, though, so we assume any - * errors are systematic problems and trust that if we didn't - * fail as the guest inited then we won't fail later on - * mid-run. - */ - error_report_err(err); - exit(1); - } + /* + * On failure we don't want to return the guest a non-random + * value in case they're really using it for cryptographic + * purposes, so the best we can do is die here. + * This shouldn't happen unless something's broken. + * In theory we could implement this device's full FIFO + * and interrupt semantics and then just stop filling the + * FIFO. That's a lot of work, though, so we assume any + * errors are systematic problems and trust that if we didn't + * fail as the guest inited then we won't fail later on + * mid-run. + */ + qemu_guest_getrandom_nofail(&res, sizeof(res)); return res; } From patchwork Mon May 6 17:33:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5320692A for ; Mon, 6 May 2019 17:52:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 417A92876B for ; Mon, 6 May 2019 17:52:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35AF7287EA; Mon, 6 May 2019 17:52:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D4B852876B for ; Mon, 6 May 2019 17:52:51 +0000 (UTC) Received: from localhost ([127.0.0.1]:60168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhnH-0000t9-45 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:52:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVS-0001Lo-6v for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVQ-0001ZM-BT for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:26 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:39619) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVO-0001Uh-Cf for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:23 -0400 Received: by mail-pg1-x544.google.com with SMTP id w22so5482385pgi.6 for ; Mon, 06 May 2019 10:34:20 -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=WkMgXREw0aoSQxhQGI3jtOyJDuRA2/EcPM5PhnT27hg=; b=M0lQsOCDnQ1jXB8oOlUdFWQEnQl2GKBcG39v9z7yxfTA5yax80UsmGLJL3XbgGwRIZ w8RJlHAQ+ehS6e7VcrU2IsXp+KANuR7/iwP+VM7eBCxb8meC1VxMltyitzx7SzJSURXB DGQ5EC3fnwwcmYznShqkqR/yg6BzPaEQ/6GBcRCBPo46g8zOui0qUU6qqeB7ZAqfrPXh fJS+HIVgnBy55567Zj7eJvPEHlLg/tjyAnB3ndc9hC4scZhErZmcpqtLnYs1mCIWagY4 clTC+PnhZ5/8tS9DSZg0TRAnlj2cFe22ajUUea5otUju4fD5s2PThdjBIe4zBwyBSs98 T+Pw== 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=WkMgXREw0aoSQxhQGI3jtOyJDuRA2/EcPM5PhnT27hg=; b=hSElmU8AHGFTwkK6Q9lM7jrNlzJXFolzf+O9FiI2ITk5g17O9KBCkj7eplVzVQHGxE lsQZy1VZ/5HakDufIw54mTcjWup/40IU16Kx+ISx1xS+ak/rpEoc/gyLJRozgCVHDBfB bgG3Ho7y/j9LWPbPxnP18792JY/jV5q2zfokpwxdYiPBo/b7dm8vm9XLv2iO+ruyeeFF ubWlVrYgJSseqh/RhyQ79SJlb0KsMXxMVNKQO+Lu89kmIEbi56vaLkQDHAnqVj/MRnvv TYEv5rNec0ztXH65SFiO5ne4btQUzKJtncWGqsYJP6LgzGGBE62rTVNmSgk/ZwmBMK93 ZEhg== X-Gm-Message-State: APjAAAW8R7Ojs2b3j9oCEUD6W6ihyUOP7RlM0LFRahB0Ic4uiWnTR+ri 8LmXcoC8yj9m82ov5JONocO89bGQkOs= X-Google-Smtp-Source: APXvYqyXHcsDzKyF1c7ndIZgJ0pe1liHklZJNJ7QN29FvqVqUq3UWp7M+reKS9BDdFGPE8wZoczZcw== X-Received: by 2002:a62:5915:: with SMTP id n21mr34013649pfb.180.1557164059592; Mon, 06 May 2019 10:34:19 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:49 -0700 Message-Id: <20190506173353.32206-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::544 Subject: [Qemu-devel] [PATCH v4 20/24] hw/misc/exynos4210_rng: Use qemu_guest_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: , Cc: Igor Mitsyanko , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Cc: qemu-arm@nongnu.org Cc: Igor Mitsyanko Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- hw/misc/exynos4210_rng.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/hw/misc/exynos4210_rng.c b/hw/misc/exynos4210_rng.c index 4ecbebd2d7..0e70ffb404 100644 --- a/hw/misc/exynos4210_rng.c +++ b/hw/misc/exynos4210_rng.c @@ -18,10 +18,10 @@ */ #include "qemu/osdep.h" -#include "crypto/random.h" #include "hw/sysbus.h" #include "qapi/error.h" #include "qemu/log.h" +#include "qemu/guest-random.h" #define DEBUG_EXYNOS_RNG 0 @@ -109,7 +109,6 @@ static void exynos4210_rng_set_seed(Exynos4210RngState *s, unsigned int i, static void exynos4210_rng_run_engine(Exynos4210RngState *s) { Error *err = NULL; - int ret; /* Seed set? */ if ((s->reg_status & EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE) == 0) { @@ -127,13 +126,11 @@ static void exynos4210_rng_run_engine(Exynos4210RngState *s) } /* Get randoms */ - ret = qcrypto_random_bytes((uint8_t *)s->randr_value, - sizeof(s->randr_value), &err); - if (!ret) { + if (qemu_guest_getrandom(s->randr_value, sizeof(s->randr_value), &err)) { + error_report_err(err); + } else { /* Notify that PRNG is ready */ s->reg_status |= EXYNOS4210_RNG_STATUS_PRNG_DONE; - } else { - error_report_err(err); } out: From patchwork Mon May 6 17:33:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6FE6F1575 for ; Mon, 6 May 2019 17:44:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 586612887B for ; Mon, 6 May 2019 17:44:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C8E028882; Mon, 6 May 2019 17:44:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 751BE2887B for ; Mon, 6 May 2019 17:44:21 +0000 (UTC) Received: from localhost ([127.0.0.1]:60029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhf2-0002JB-Op for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:44:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVU-0001O8-6C for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVS-0001bj-7p for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:28 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:34688) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVQ-0001WQ-9S for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:25 -0400 Received: by mail-pg1-x541.google.com with SMTP id c13so6806405pgt.1 for ; Mon, 06 May 2019 10:34:22 -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:mime-version :content-transfer-encoding; bh=G/LPrgJph2n0xWoB68vwNP1sqZ2D7Ndofy8Ou9toiJU=; b=YJoMSrBOLQi8prawBoxDvEKjN3YKYVPmoPjPR89Li6b2Y76kuJeYFSrp74rYSEYtcP gEe9bdA85TOOEn8okOJ3YOwG7OXTOOwAFrPg+p6EwwmHkCJTvXYTVwPCuiDMLH+ghsjx bfZ/r2N8gb6hOntpg7l/20DFJXFlcoz4lseKrkvtDlaLdPalgbjK1sFONV8Pdm9yFHfY tALj3qydYFOODDsPHdw7gY2qbs1UeSBsG7un5SP98Mj1kIBAxkT2kU0nJQHYfqXoJ1dS KJIRbDmab6zw0fgyPVZkvlHqtXXbr1VhuEnJKRFz0hi1QByQRj/jJrMvBBlLniQmh6sw bx8A== 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:mime-version:content-transfer-encoding; bh=G/LPrgJph2n0xWoB68vwNP1sqZ2D7Ndofy8Ou9toiJU=; b=i1bGrEJIZt+gGyfDqMYGR4l9duPdpS3uw4jV3F+2oGqXPe0kUzjr13of7jJ3XrdnU0 p3Ti+RydoaFx7tB9BtItIy5iruK7pTVHY7Td4I64aVjEqM8etonx+n8f3KeUJkd2m022 GzM/cTrBDfb02zoQuxB3AChO7xsx6Tf7vu8Mgp0TvzdUHrA3wpnWBgHA5gtWlY6to/IG 6UDc2Xb0I09EST2SgrOtUf8L+GBoLjYA3FG9bXeb/9rkNtKZI5YKBbFyxAaPLPf0kqwV N74VdOUiKaviwZM4MOaU6KIX5bu6+88qNkKQ4MAyXKkUTvCG+9e1zBisk1HeHDEsbl5X JhyA== X-Gm-Message-State: APjAAAWLRYjGeAU4ZPPtw+bQ8yEn8pBn1ixiJ6pqoziIIzF8G4yBbSkq WCW8TP/DEdV6F0M+x4JVkS8iHuPoukE= X-Google-Smtp-Source: APXvYqxP0Yj19KXWu8jH6mnsC1PzhLSN8wrz+at6ysiKcORFdwAC/DEBJ0E3ft5c4ep0uxAYAaHRhQ== X-Received: by 2002:a63:c104:: with SMTP id w4mr33151579pgf.409.1557164060772; Mon, 06 May 2019 10:34:20 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:50 -0700 Message-Id: <20190506173353.32206-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::541 Subject: [Qemu-devel] [PATCH v4 21/24] target/arm: Put all PAC keys into a structure 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This allows us to use a single syscall to initialize them all. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- target/arm/cpu.h | 12 +++++++----- linux-user/aarch64/cpu_loop.c | 6 +----- linux-user/syscall.c | 10 +++++----- target/arm/helper.c | 20 ++++++++++---------- target/arm/pauth_helper.c | 18 +++++++++--------- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 22bc6e00ab..9448a76186 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -636,11 +636,13 @@ typedef struct CPUARMState { } iwmmxt; #ifdef TARGET_AARCH64 - ARMPACKey apia_key; - ARMPACKey apib_key; - ARMPACKey apda_key; - ARMPACKey apdb_key; - ARMPACKey apga_key; + struct { + ARMPACKey apia; + ARMPACKey apib; + ARMPACKey apda; + ARMPACKey apdb; + ARMPACKey apga; + } keys; #endif #if defined(CONFIG_USER_ONLY) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index cedad39ca0..2f2f63e3e8 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -175,11 +175,7 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) #endif if (cpu_isar_feature(aa64_pauth, cpu)) { - qemu_guest_getrandom_nofail(&env->apia_key, sizeof(ARMPACKey)); - qemu_guest_getrandom_nofail(&env->apib_key, sizeof(ARMPACKey)); - qemu_guest_getrandom_nofail(&env->apda_key, sizeof(ARMPACKey)); - qemu_guest_getrandom_nofail(&env->apdb_key, sizeof(ARMPACKey)); - qemu_guest_getrandom_nofail(&env->apga_key, sizeof(ARMPACKey)); + qemu_guest_getrandom_nofail(&env->keys, sizeof(env->keys)); } ts->stack_base = info->start_stack; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b73d1d9f65..3c26f6f9d4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9734,23 +9734,23 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, return -TARGET_EINVAL; } if (arg2 & TARGET_PR_PAC_APIAKEY) { - ret |= qemu_guest_getrandom(&env->apia_key, + ret |= qemu_guest_getrandom(&env->keys.apia, sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APIBKEY) { - ret |= qemu_guest_getrandom(&env->apib_key, + ret |= qemu_guest_getrandom(&env->keys.apib, sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APDAKEY) { - ret |= qemu_guest_getrandom(&env->apda_key, + ret |= qemu_guest_getrandom(&env->keys.apda, sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APDBKEY) { - ret |= qemu_guest_getrandom(&env->apdb_key, + ret |= qemu_guest_getrandom(&env->keys.apdb, sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APGAKEY) { - ret |= qemu_guest_getrandom(&env->apga_key, + ret |= qemu_guest_getrandom(&env->keys.apga, sizeof(ARMPACKey), &err); } if (ret != 0) { diff --git a/target/arm/helper.c b/target/arm/helper.c index 81a92ab491..658a5a9822 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5683,43 +5683,43 @@ static const ARMCPRegInfo pauth_reginfo[] = { { .name = "APDAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apda_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apda.lo) }, { .name = "APDAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apda_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apda.hi) }, { .name = "APDBKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 2, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apdb_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apdb.lo) }, { .name = "APDBKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 3, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apdb_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apdb.hi) }, { .name = "APGAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 3, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apga_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apga.lo) }, { .name = "APGAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 3, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apga_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apga.hi) }, { .name = "APIAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apia_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apia.lo) }, { .name = "APIAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apia_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apia.hi) }, { .name = "APIBKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 2, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apib_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apib.lo) }, { .name = "APIBKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 3, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apib_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apib.hi) }, REGINFO_SENTINEL }; #endif diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c index d750f96edf..7f30ae7395 100644 --- a/target/arm/pauth_helper.c +++ b/target/arm/pauth_helper.c @@ -403,7 +403,7 @@ uint64_t HELPER(pacia)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apia_key, false); + return pauth_addpac(env, x, y, &env->keys.apia, false); } uint64_t HELPER(pacib)(CPUARMState *env, uint64_t x, uint64_t y) @@ -413,7 +413,7 @@ uint64_t HELPER(pacib)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apib_key, false); + return pauth_addpac(env, x, y, &env->keys.apib, false); } uint64_t HELPER(pacda)(CPUARMState *env, uint64_t x, uint64_t y) @@ -423,7 +423,7 @@ uint64_t HELPER(pacda)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apda_key, true); + return pauth_addpac(env, x, y, &env->keys.apda, true); } uint64_t HELPER(pacdb)(CPUARMState *env, uint64_t x, uint64_t y) @@ -433,7 +433,7 @@ uint64_t HELPER(pacdb)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apdb_key, true); + return pauth_addpac(env, x, y, &env->keys.apdb, true); } uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) @@ -441,7 +441,7 @@ uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) uint64_t pac; pauth_check_trap(env, arm_current_el(env), GETPC()); - pac = pauth_computepac(x, y, env->apga_key); + pac = pauth_computepac(x, y, env->keys.apga); return pac & 0xffffffff00000000ull; } @@ -453,7 +453,7 @@ uint64_t HELPER(autia)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apia_key, false, 0); + return pauth_auth(env, x, y, &env->keys.apia, false, 0); } uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) @@ -463,7 +463,7 @@ uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apib_key, false, 1); + return pauth_auth(env, x, y, &env->keys.apib, false, 1); } uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) @@ -473,7 +473,7 @@ uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apda_key, true, 0); + return pauth_auth(env, x, y, &env->keys.apda, true, 0); } uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) @@ -483,7 +483,7 @@ uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apdb_key, true, 1); + return pauth_auth(env, x, y, &env->keys.apdb, true, 1); } uint64_t HELPER(xpaci)(CPUARMState *env, uint64_t a) From patchwork Mon May 6 17:33:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CB87912 for ; Mon, 6 May 2019 17:47:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2715128843 for ; Mon, 6 May 2019 17:47:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B37928880; Mon, 6 May 2019 17:47:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 91EEB28843 for ; Mon, 6 May 2019 17:47:28 +0000 (UTC) Received: from localhost ([127.0.0.1]:60084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhi3-00052L-RP for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:47:27 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVV-0001P3-4Z for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVS-0001bn-7o for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:29 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:33544) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVQ-0001Y1-C7 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:25 -0400 Received: by mail-pg1-x542.google.com with SMTP id h17so818712pgv.0 for ; Mon, 06 May 2019 10:34:23 -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=C88Ei/VihHBAOteN7bDmsYhjQHUxDozERJjKlZZiWa8=; b=sHvcnbl3E2ZWklsiprgp0xlEK/K7eAg6GixcuLtR3Tp/kBdNtfHYZsgPBZ+R3hSlfs qwvWwpIMH3mzRoU4wVKCaeW5d4UO+pd1ZCa+Yzr4P+QeglKYAceTB4aM8UxCH9IrD/CB F3kPQ4pH/tFyBrktkhjjTsEgk3Vgguy2jSNYsXoEnlXz0P61tgiYg/1hEdV3HIROB1o+ UxnOsnwGphporYoystRo4lJk3w7NU43OAsWM/G3zRT5VWlVeNopuovWCbQkUGat3l7WS o+ucNAT65YDsTxN+MzFbqRaPSGpUsC4AbtvYA5vxN3C/YKKgJmE8amaBMtCU5Zb3a+Rc U8zw== 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=C88Ei/VihHBAOteN7bDmsYhjQHUxDozERJjKlZZiWa8=; b=UdQL6tJeRChz1APzVnFwVzYHdhlQeGPesXAri+VtKtYQJETg47ub9QWWW+mChB+3sE nHq50DvYojfarf8+K+teB4dvy9Z2tnoi60BBTgE7i9yO2CCh9yNx5Iem8GRb3YNnmn0J D8H3ptViplRie2+CB5xypt2S08wMzjCyzEBwDRbybMdgchvpRpirbjUx2Gzslbyoaamw xQ0lcOCLVfdrTci/ZSBraflz6EY9vnNo00Z/lxEkNH5Y8c5GwTaHZIvXICV9lshqEXUw U4UFAKZjRmVUqQzj7YaBFQAmckyHCKFZECHMcw4QdPU25VlHxgI25E82OFG/VMaSaq+K p5EQ== X-Gm-Message-State: APjAAAUGCfzZMQkne8zFlIt15901YZ3ICs6zKY2xXWdBqefgW09ZT73y MSpF/vMw+WW1ufa3b7FQz8UxXRDBK3E= X-Google-Smtp-Source: APXvYqwD+vvnkVZxdnKS6l/6N0i+a0Nk2m8JPwyPhqt0G/bb5nVSt3ygEePfIvvhC9jNGpTzbAblhA== X-Received: by 2002:a63:ed4f:: with SMTP id m15mr33935349pgk.387.1557164061922; Mon, 06 May 2019 10:34:21 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:51 -0700 Message-Id: <20190506173353.32206-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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 v4 22/24] 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 , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Cc: qemu-arm@nongnu.org Cc: Peter Maydell Signed-off-by: Richard Henderson --- v3: Log errors with -d unimp, for lack of a better flag. --- target/arm/cpu.h | 5 +++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 9448a76186..5c228fee8e 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3510,6 +3510,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 658a5a9822..3824778dab 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -21,6 +21,8 @@ #include "fpu/softfloat.h" #include "qemu/range.h" #include "qapi/qapi-commands-target.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ @@ -5722,6 +5724,45 @@ static const ARMCPRegInfo pauth_reginfo[] = { .fieldoffset = offsetof(CPUARMState, keys.apib.hi) }, REGINFO_SENTINEL }; + +static uint64_t rndr_readfn(CPUARMState *env, const ARMCPRegInfo *ri) +{ + Error *err = NULL; + uint64_t ret; + + /* Success sets NZCV = 0000. */ + env->NF = env->CF = env->VF = 0, env->ZF = 1; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + /* + * ??? Failed, for unknown reasons in the crypto subsystem. + * The best we can do is log the reason and return the + * timed-out indication to the guest. There is no reason + * we know to expect this failure to be transitory, so the + * guest may well hang retrying the operation. + */ + qemu_log_mask(LOG_UNIMP, "%s: Crypto failure: %s", + ri->name, error_get_pretty(err)); + error_free(err); + + env->ZF = 0; /* NZCF = 0100 */ + return 0; + } + return ret; +} + +/* 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, @@ -6666,6 +6707,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 /* From patchwork Mon May 6 17:33:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA45F92A for ; Mon, 6 May 2019 17:54:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8D1A2876B for ; Mon, 6 May 2019 17:54:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD58B287EA; Mon, 6 May 2019 17:54:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5ADBB2876B for ; Mon, 6 May 2019 17:54:48 +0000 (UTC) Received: from localhost ([127.0.0.1]:60194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhpA-0002HG-4o for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:54:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVV-0001PA-9i for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVU-0001d9-BH for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:29 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:45932) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVU-0001Z0-3y for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:28 -0400 Received: by mail-pf1-x442.google.com with SMTP id e24so7119093pfi.12 for ; Mon, 06 May 2019 10:34:24 -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=rV9JIaOzfUN4OkPt3KeztWbx7AsXbIEUWY2EQzqrSHU=; b=JPsVvWSvgo2Fx1dliry01ZRpiz217ThUX6fAXN8kyJBII2va8k4DXmt24Yts3yATwT TyfORURm+fJVw6aaSM0EH2PvE4NxQEoNbgxUpQXTN5mMtrgk9vBdw2bn0awnSWzrAUdH oaC2pe6y6AibFYC+xs0rSaxXaE+5MJW0sxeytMXd1O1+HymLHnyjMMERVf4iF67D97Ei CJnL0tahD0Zme+M1iB2vzyGqpvSKJVZrlLKvI6sFs4sF6C+J0PmSlMUHuVsfXSzqCG2q PrIWSguquJzYL5vl87osooTd/hH02sjzd3VPW5Lg01Fct0chJr75F4neWIDfH5E6pIjY Ndbw== 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=rV9JIaOzfUN4OkPt3KeztWbx7AsXbIEUWY2EQzqrSHU=; b=jIEJc21amS0Okm6YQ/lh3vlhUlCXc/pPd6vFQxGO0MnHBLxNUDSWmIUlGMrM602ZBM 10Pkv+BYdBXG3Ooi1EMa5EgpbRV1lPkmT1K438s3H1TJAyQhFGeSVV289ScN7TUY5v7A sehzprOm0i71xzgUpSjEuIjJSyPGf7Bqge/4o+XA6xqh+xr0QqE7fydoShuRg6cZkjYF akHFREk3w+zhE+e54/S8jf+i9e5MAurM2954SbZINwN1xb5bK/BhwisLK2J+o3ipyupj 22P/3DeQBV/exX264BTILpkORaz4wMUVovB1ZwrreQLQySZRQxMaa4q1SlNuPzb6pd7x nMAg== X-Gm-Message-State: APjAAAWVmlBchjTiOLyQNOyGskF9WRLNzRmWUldF20pmS/D637RXnnIu jmT7eRBXGwyvQyaHk9GhHdG7nPCOJYA= X-Google-Smtp-Source: APXvYqxIOpvAJCQfPxMVpK+99PSEX4I9ehpdwQCerITj+GLWig7BaveIJXxMAMrXO92YHeuDPBCCrg== X-Received: by 2002:aa7:8392:: with SMTP id u18mr35979178pfm.217.1557164063137; Mon, 06 May 2019 10:34:23 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:52 -0700 Message-Id: <20190506173353.32206-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::442 Subject: [Qemu-devel] [PATCH v4 23/24] target/ppc: Use qemu_guest_getrandom for DARN 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We now have an interface for guest visible random numbers. Acked-by: David Gibson Signed-off-by: Richard Henderson --- target/ppc/int_helper.c | 42 +++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index f6a088ac08..9059e70b9c 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -23,6 +23,8 @@ #include "exec/helper-proto.h" #include "crypto/aes.h" #include "fpu/softfloat.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" #include "helper_regs.h" /*****************************************************************************/ @@ -158,25 +160,41 @@ uint32_t helper_cmpeqb(target_ulong ra, target_ulong rb) #undef hasvalue /* - * Return invalid random number. - * - * FIXME: Add rng backend or other mechanism to get cryptographically suitable - * random number + * Return a random number. */ -target_ulong helper_darn32(void) +uint64_t helper_darn32(void) { - return -1; + Error *err = NULL; + uint32_t ret; + + if (qemu_guest_getrandom(&ret, 4, &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + + return ret; } -target_ulong helper_darn64(void) +uint64_t helper_darn64(void) { - return -1; + Error *err = NULL; + uint64_t ret; + + do { + if (qemu_guest_getrandom(&ret, 8, &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + /* Since -1 is the error condition, try again for that case. */ + } while (unlikely(ret == -1)); + + return ret; } -#endif - -#if defined(TARGET_PPC64) - uint64_t helper_bpermd(uint64_t rs, uint64_t rb) { int i; From patchwork Mon May 6 17:33:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10931725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75AF31398 for ; Mon, 6 May 2019 17:51:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6422C28882 for ; Mon, 6 May 2019 17:51:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58A52288B3; Mon, 6 May 2019 17:51:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B66F32886C for ; Mon, 6 May 2019 17:51:55 +0000 (UTC) Received: from localhost ([127.0.0.1]:60164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhmM-000092-SG for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 May 2019 13:51:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVV-0001PV-MT for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVU-0001dP-Hg for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:29 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:35165) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVU-0001ae-8L for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:28 -0400 Received: by mail-pl1-x630.google.com with SMTP id w24so6721896plp.2 for ; Mon, 06 May 2019 10:34:25 -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=WYz5jNmR/GTo+9WP/v5okCDQ6l0w7x39q4Q1GnmCfVI=; b=fwOpYX4qsqgU/XXxKrEFF0vQbJf4HWyqZl9np9N8Vm4S3jFnpuczDSqdTmhc4Bf6rf 21tal0urqhRdkt0k/0+5SMBPLKZiKbVIGWIYpEfbZEqA3H3CEViocjaZim9CZzhflxT1 CVAtJZx69JTBhcab2STBrwVYPwN5YlHuhToJn12+pa8wm2QeHhKoBvgqPVo47jF9XsfZ aHl/AywHNDgty4dc84ydiFxC3jTuK8N44UJb+wkGS+wplmjgqW/Z9JZRlQWDaJ5iJCce fPwqGD7REhr/O74/91An8OiyaDqCX7flBsv/MRql3XhYQXD+8mUR9We1hBOdpGWivKSr jxcw== 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=WYz5jNmR/GTo+9WP/v5okCDQ6l0w7x39q4Q1GnmCfVI=; b=MpQYamcmbrq5LEzr36+Os03bOIBrB7lCDbamReDImiapVWZRuaQ+xBbNBaSHU4N4c/ ocTQVn0EaY2b+0KOdHBWhuotZ4IT1U+EdrM5f0La7n9rR0DWOOqRUb686UcuuOWkSKl+ 2HXDgAPGyYiGTRK/gRiJcV+j8ru2qASF6wQJW/qWWrSf4l9oz2w2IUcPz4KE+jrdO0Wg OXNFMEr1MekUs+ECZG5K8Es1WZpQSwan+WbV2+Rs62HimhIuBxtn8RkM0zvTtPWlC4h7 Qb3wmohvkltXrPJj9GzURH6eA7PlLGAI5yriNDxf6QIywgm6ZeumdApWkOHLlNvs1Haa NdSA== X-Gm-Message-State: APjAAAVolv7e49rpVsJMVaPAv2xnx9sfAdEZRnLE9xrZfdHGhA1DRhV8 m8EDvw42a27ACmXPhhBWsfSaiAGJVCE= X-Google-Smtp-Source: APXvYqw4mhOlhk600dxujgZBmSdP358pAD/Iq+YDm7Vzyi/xLTqPwHCJlZjfITlhMPZL107o9j1ZkA== X-Received: by 2002:a17:902:bd91:: with SMTP id q17mr7601766pls.13.1557164064233; Mon, 06 May 2019 10:34:24 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:53 -0700 Message-Id: <20190506173353.32206-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-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::630 Subject: [Qemu-devel] [PATCH v4 24/24] target/i386: Implement CPUID_EXT_RDRAND 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: Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We now have an interface for guest visible random numbers. Cc: Paolo Bonzini Cc: Eduardo Habkost Signed-off-by: Richard Henderson Reviewed-by: Eduardo Habkost --- target/i386/helper.h | 2 ++ target/i386/cpu.c | 5 ++-- target/i386/int_helper.c | 21 +++++++++++++++ target/i386/translate.c | 55 +++++++++++++++++++++++++++++----------- 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/target/i386/helper.h b/target/i386/helper.h index 6fb8fb9b74..8f9e1905c3 100644 --- a/target/i386/helper.h +++ b/target/i386/helper.h @@ -226,3 +226,5 @@ DEF_HELPER_3(rcrl, tl, env, tl, tl) DEF_HELPER_3(rclq, tl, env, tl, tl) DEF_HELPER_3(rcrq, tl, env, tl, tl) #endif + +DEF_HELPER_1(rdrand, tl, env) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 722c5514d4..1386814957 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -730,13 +730,14 @@ static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \ CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \ CPUID_EXT_XSAVE | /* CPUID_EXT_OSXSAVE is dynamic */ \ - CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR) + CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR | \ + CPUID_EXT_RDRAND) /* missing: CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX, CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, CPUID_EXT_FMA, CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_PCID, CPUID_EXT_DCA, CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_AVX, - CPUID_EXT_F16C, CPUID_EXT_RDRAND */ + CPUID_EXT_F16C */ #ifdef TARGET_X86_64 #define TCG_EXT2_X86_64_FEATURES (CPUID_EXT2_SYSCALL | CPUID_EXT2_LM) diff --git a/target/i386/int_helper.c b/target/i386/int_helper.c index 4dc5c65991..334469ca8c 100644 --- a/target/i386/int_helper.c +++ b/target/i386/int_helper.c @@ -22,6 +22,8 @@ #include "exec/exec-all.h" #include "qemu/host-utils.h" #include "exec/helper-proto.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" //#define DEBUG_MULDIV @@ -470,3 +472,22 @@ void helper_cr4_testbit(CPUX86State *env, uint32_t bit) raise_exception_ra(env, EXCP06_ILLOP, GETPC()); } } + +target_ulong HELPER(rdrand)(CPUX86State *env) +{ + Error *err = NULL; + target_ulong ret; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + qemu_log_mask(LOG_UNIMP, "rdrand: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + /* Failure clears CF and all other flags, and returns 0. */ + env->cc_src = 0; + return 0; + } + + /* Success sets CF and clears all others. */ + env->cc_src = CC_C; + return ret; +} diff --git a/target/i386/translate.c b/target/i386/translate.c index 77d6b73e42..62fa45d778 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -5332,31 +5332,56 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x1c7: /* cmpxchg8b */ modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; - if ((mod == 3) || ((modrm & 0x38) != 0x8)) - goto illegal_op; -#ifdef TARGET_X86_64 - if (dflag == MO_64) { - if (!(s->cpuid_ext_features & CPUID_EXT_CX16)) + switch ((modrm >> 3) & 7) { + case 1: /* CMPXCHG8, CMPXCHG16 */ + if (mod == 3) { goto illegal_op; - gen_lea_modrm(env, s, modrm); - if ((s->prefix & PREFIX_LOCK) && (tb_cflags(s->base.tb) & CF_PARALLEL)) { - gen_helper_cmpxchg16b(cpu_env, s->A0); - } else { - gen_helper_cmpxchg16b_unlocked(cpu_env, s->A0); } - } else +#ifdef TARGET_X86_64 + if (dflag == MO_64) { + if (!(s->cpuid_ext_features & CPUID_EXT_CX16)) { + goto illegal_op; + } + gen_lea_modrm(env, s, modrm); + if ((s->prefix & PREFIX_LOCK) && + (tb_cflags(s->base.tb) & CF_PARALLEL)) { + gen_helper_cmpxchg16b(cpu_env, s->A0); + } else { + gen_helper_cmpxchg16b_unlocked(cpu_env, s->A0); + } + set_cc_op(s, CC_OP_EFLAGS); + break; + } #endif - { - if (!(s->cpuid_features & CPUID_CX8)) + if (!(s->cpuid_features & CPUID_CX8)) { goto illegal_op; + } gen_lea_modrm(env, s, modrm); - if ((s->prefix & PREFIX_LOCK) && (tb_cflags(s->base.tb) & CF_PARALLEL)) { + if ((s->prefix & PREFIX_LOCK) && + (tb_cflags(s->base.tb) & CF_PARALLEL)) { gen_helper_cmpxchg8b(cpu_env, s->A0); } else { gen_helper_cmpxchg8b_unlocked(cpu_env, s->A0); } + set_cc_op(s, CC_OP_EFLAGS); + break; + + case 7: /* RDSEED */ + case 6: /* RDRAND */ + if (mod != 3 || + (s->prefix & (PREFIX_LOCK | PREFIX_REPZ | PREFIX_REPNZ)) || + !(s->cpuid_ext_features & CPUID_EXT_RDRAND)) { + goto illegal_op; + } + gen_helper_rdrand(s->T0, cpu_env); + rm = (modrm & 7) | REX_B(s); + gen_op_mov_reg_v(s, dflag, rm, s->T0); + set_cc_op(s, CC_OP_EFLAGS); + break; + + default: + goto illegal_op; } - set_cc_op(s, CC_OP_EFLAGS); break; /**************************/