From patchwork Fri Mar 15 03:26:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160383 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16272314jad; Thu, 14 Mar 2019 20:48:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkoEGlVOt6CqfkWT7gWtgTf8/tx+RkZeYWElZQ5Zv08y3vu/eQ0DDM0x5vuzGxDIHsuDlB X-Received: by 2002:adf:ea04:: with SMTP id q4mr701483wrm.97.1552621692154; Thu, 14 Mar 2019 20:48:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621692; cv=none; d=google.com; s=arc-20160816; b=RkxANrQU16sxYuSdhxPY1mlKFW8T1EiAQMIxpnrapmxXHC9OGPAsufZZ2y8URxdiYk rm5gu7wFxPTL6vc13Q77gT64XYWXxnx6AyXzM/0qU7AxsB1kYRmnX8ZvLrD9/dW3+C7p 8n0dtylgJZVbBeC1SxrRds00kjBIYoKHV1QxZpLMVu8LFNcrchz0lul8l9csmUogFwhJ q4ZYaXgQihGGnPFmplQIl3KUyG7/8D6feV+hfzhOz2ya8hUn5apKUc/LZIBXJL6sJ0wR OQ8uFGT6xCQ+hNXJEPZ2mEgk7XfzfPd/+Zcbbf6077fTPKYQXEH/qhHXHXrLvYEnxXTI nxQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=5Q5A6gjz66OJ4/9J1TQOfzJkkmyqixXmwmswaFfq59M=; b=jkL+rGPxcO8bikJG5L4YXwqCAZ8qk55Huzb7efrcPboO1j3eRHrn+utgoY195LKBA/ gkYIxH9jEYsN186Yl6txchqjetxx3qQuCmIcmEXuc1R7fCPwobuIiM/Y4nS9zA7unIah aNzj6BsPcMTwWmxp9FQwO646vnZOm6qW26ZTsROE9G71Ap1qcbmpXvoAudf9ONYp9QMO pQlecUhY/jRHjhWu7j7v1MI+awT+mAHe2/N9TYTUnmYXacSLSDuwy9Nue4VpFHlNe2dM A+DnZNX2L4wJHnIi0jSoe9WzDDYB/Va6mPdKqtJwhJLcU6vKSBzGDTfAs2r+Mb7bkk5u bivw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tDWlRM+Z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l7si377694wmc.195.2019.03.14.20.48.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:48:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tDWlRM+Z; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dpL-0007cf-0I for patch@linaro.org; Thu, 14 Mar 2019 23:48:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcM-0005C3-5a for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUQ-0002hI-PL for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:35 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:38878) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUQ-0002gQ-EQ for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:34 -0400 Received: by mail-pg1-x529.google.com with SMTP id v1so698650pgi.5 for ; Thu, 14 Mar 2019 20:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5Q5A6gjz66OJ4/9J1TQOfzJkkmyqixXmwmswaFfq59M=; b=tDWlRM+ZWIb5PN55d+kdmpjGwahOQSv2i3oOOmMKXe3bi50aX/+8mtjyjB0uDCCXyw 9b2Y1yZHWMN+li0L+0em/c/Re+UKFu6b0uzqS+A0X3AQ3FJ0cslTNLhyzXD1Aywl97VP xkXEtlPhXsK3mjJXQVbxQVo1+iIdu9Mxl0ekHvL0SO394J0zVapJAQy/EAV8y1QJ229J dV5UEUntkduer+aFD9RB7lkGx5i7WqgGp8CexJrSYLcAh5mdq/AWgc4e70Wf0c89k+q5 reV9bR3pgX0KJfMaWnk2Cnm6mbFs2d++Q/hwEBlO4QxcmNhOZIPnxEgyip811uOH3LP1 Cddw== 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=5Q5A6gjz66OJ4/9J1TQOfzJkkmyqixXmwmswaFfq59M=; b=OEjPAdV7nBxeO3RoyI3Sqfw7C2oBLOxS82/iDOQzyN+9civNGYCSgelbkEFYM+Z3+K p2rnFctafKxhnAw7l3FchJO+4wkrNOisCBb462f9pzJh5pYC59fQaciOd9L5tAPpOOHK tfu4cu91UGy5aEbX1zkjqDY7pxVi8N3WAJvmhQXrCJEsQK6oYpb05tf0WQSAgMQgt3RZ 9CbEWifCRzLbqNwpQqS/8tPxsYN3TGEA2s0opCRLYxSjaMtdNmckWi51cJTpKYbvVY00 GDlN2sDgtrEqa8ZYNgQ5B4jRXVsytPntwcC/k0xTI5D2OCGN6qAWYm0uUd1eHfzOdCw0 F3Kg== X-Gm-Message-State: APjAAAU4am7RflAMd1b1HqzK29Q9U3HuIjuJHFff0fi9meGZF2jHzGnl ok68i8uTHzF5M41rZYYF13eFBBXg8oM= X-Received: by 2002:a17:902:8693:: with SMTP id g19mr1801649plo.157.1552620393188; Thu, 14 Mar 2019 20:26:33 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:07 -0700 Message-Id: <20190315032629.21234-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::529 Subject: [Qemu-devel] [PATCH v3 01/23] crypto: Merge crypto-obj-y into libqemuutil.a X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We will shortly need this in the user-only binaries, so drop the split into system and tools binaries. This also means that crypto-aes-obj-y can be merged back into crypto-obj-y. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- Makefile | 12 +++++------- Makefile.objs | 8 ++------ Makefile.target | 4 ---- configure | 9 +++------ crypto/Makefile.objs | 5 +---- 5 files changed, 11 insertions(+), 27 deletions(-) -- 2.17.2 diff --git a/Makefile b/Makefile index d8dad39c5d..22c0a76337 100644 --- a/Makefile +++ b/Makefile @@ -405,7 +405,6 @@ dummy := $(call unnest-vars,, \ block-obj-y \ block-obj-m \ crypto-obj-y \ - crypto-aes-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -441,7 +440,6 @@ SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES)) $(SOFTMMU_SUBDIR_RULES): $(authz-obj-y) $(SOFTMMU_SUBDIR_RULES): $(block-obj-y) -$(SOFTMMU_SUBDIR_RULES): $(crypto-obj-y) $(SOFTMMU_SUBDIR_RULES): $(io-obj-y) $(SOFTMMU_SUBDIR_RULES): config-all-devices.mak @@ -496,7 +494,7 @@ Makefile: $(version-obj-y) ###################################################################### # Build libraries -libqemuutil.a: $(util-obj-y) $(trace-obj-y) $(stub-obj-y) +libqemuutil.a: $(util-obj-y) $(trace-obj-y) $(stub-obj-y) $(crypto-obj-y) libvhost-user.a: $(libvhost-user-obj-y) $(util-obj-y) $(stub-obj-y) ###################################################################### @@ -505,9 +503,9 @@ COMMON_LDADDS = libqemuutil.a qemu-img.o: qemu-img-cmds.h -qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) @@ -518,7 +516,7 @@ qemu-edid$(EXESUF): qemu-edid.o hw/display/edid-generate.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap -scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(authz-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(authz-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) ifdef CONFIG_MPATH scsi/qemu-pr-helper$(EXESUF): LIBS += -ludev -lmultipath -lmpathpersist endif diff --git a/Makefile.objs b/Makefile.objs index 72debbf5c5..23950a37af 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -3,6 +3,8 @@ stub-obj-y = stubs/ util/ crypto/ util-obj-y = util/ qobject/ qapi/ +crypto-obj-y = crypto/ + chardev-obj-y = chardev/ ####################################################################### @@ -21,12 +23,6 @@ block-obj-$(CONFIG_REPLICATION) += replication.o block-obj-m = block/ -####################################################################### -# crypto-obj-y is code used by both qemu system emulation and qemu-img - -crypto-obj-y = crypto/ -crypto-aes-obj-y = crypto/ - ####################################################################### # qom-obj-y is code used by both qemu system emulation and qemu-img diff --git a/Makefile.target b/Makefile.target index 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 7071f52584..2c95e6ddc9 100755 --- a/configure +++ b/configure @@ -2769,8 +2769,7 @@ if test "$gnutls" != "no"; then if $pkg_config --exists "gnutls >= 3.1.18"; then gnutls_cflags=$($pkg_config --cflags gnutls) gnutls_libs=$($pkg_config --libs gnutls) - libs_softmmu="$gnutls_libs $libs_softmmu" - libs_tools="$gnutls_libs $libs_tools" + LIBS="$gnutls_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" gnutls="yes" elif test "$gnutls" = "yes"; then @@ -2835,8 +2834,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" @@ -2863,8 +2861,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 Fri Mar 15 03:26:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160378 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16269874jad; Thu, 14 Mar 2019 20:44:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwP6j3d30SS1tzLAmvLJDwrfS94t6l94bXnJr9ri2Skkq+Rp8/7L3FNK7FL/b1qfinbGtYw X-Received: by 2002:a1c:6589:: with SMTP id z131mr513264wmb.120.1552621472200; Thu, 14 Mar 2019 20:44:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621472; cv=none; d=google.com; s=arc-20160816; b=Uc+fTlu1JdDMElozw499/elm4qyg0bY8JbriynOSQU3mY+8htIK9PlvSvuevhtImhN 1dGj/38dsAIYv+Wvv2v0yxW4O4nYOdletBaRguT+CaAXTLPGoAqspBOemGxI33WuR1GE PU1lSct2+07YE4L0KllK1Q/Hzo3OQZa2+2ZG83bjBS06mjOy7SkNZDBOoyhwF39URErE dJslk4QgBvKuHNYDt8RR3b7hiATXuvHSKFqPmuPGesXh9hdp1cNrP0gRquYghziGt9nf IOksUy6ga0BtO9Nx9DOwKKubxdPdSlGpbQhZac1cWifPLnr+UXCcIixDS8NeL9irxcvL XSvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=rp2FmjqCfIvvSwDyOgXPZwMlq+i+lzvSkjm1+zs+Ank=; b=S3Y/12MGkD8OKECud1JKkjujUmyWNnCzwTesOFsVvPz2jN/C32oqXvVghRvTkYKqEz 9EafU+W1gfi53xHjfbFN8PVjtzOBOQNuAHEh+oP8lKpgTyW+Nem+dPkGbG7eRMCRfphR /9tA4PyGwX6JmRuvqwBNK/CIoG7P4l2sZqPPVlAOk9egET5Kl52FKhGm0peqgxKTF3AI TZWV46+hH6vAj2Q+iq8AWTU5emCRFas8SA7jeNpCGuKPKCXMiFffyUdhSYnY27Jj5iph DiCXPEGan2eASQAo+IhV9YrekqBYAr/r6skNct7ejbwM0JNwUAqWohXOJHc6Eb+Zm6Qs vaUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yFmKn+l4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l5si459537wrm.255.2019.03.14.20.44.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:44:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yFmKn+l4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dln-0004WJ-3O for patch@linaro.org; Thu, 14 Mar 2019 23:44:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcM-0004w5-3F for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUS-0002iV-4m for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:36 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:46030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUR-0002hi-SZ for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:36 -0400 Received: by mail-pg1-x532.google.com with SMTP id 125so5384082pgc.12 for ; Thu, 14 Mar 2019 20:26:35 -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=rp2FmjqCfIvvSwDyOgXPZwMlq+i+lzvSkjm1+zs+Ank=; b=yFmKn+l4D2p9RttjLYlPe8ahK/Ep3s3PMi2Yagx1BdPp/VZY4ZEYw6PObDg3ZQeO3x DMYi0widVvQpgVeDYrCI7YDbpWtDPI9JToM7WXytrtDxKrtUHyMCvfLGz5D9XTXYz9nn MdGmVqEzIHiMlAZ2eDJguWxOph0iSViSvYg21j2HwwW7WOdp1pAM5BtJN2exJ86/xmuP Eq9UyYMXFesVa0/JWw5mZqKHSARoXMSSBTgktmvNxK/9g2mGLcgKrlwiXRpnJxJ2Ofz6 qf91jl3mCH1MVyTn4M/qoNuC6QGQ+tbnhTlvrfQsL62T1Ylq8SY7Bxl0lHa2zXUKZ6Bh fOGw== 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=rp2FmjqCfIvvSwDyOgXPZwMlq+i+lzvSkjm1+zs+Ank=; b=S15LYkynTg3RFGI5Laihxq/2ayFh+9savrLHCEdQ1jVBFzKxm8E/uR3M+tjaUo+qVu vKW7IYtG+1SqVPdiTa+V3D0xXeREEqfxZqtPt8JlllYvCgMFJuXkaSNp7XOlX0Pux0Nw 0iAX8gTQZ+ye8S3wot5dYAzR9R7yKaoOuk/CY4d9fh2kioJPyu0gptN0mWAkRWHp1WC/ g7sVi17Xol/eF3PdgmIFq5IofJuCzlZgCj/pURICJ9pbCarHIiHKMgXf5UVMZvznPiZh cEI8JltZHDhqK4XVJSdN5E+8Jj+XZHXk2g4GzHx41cucLzseUnhO4A2cb46PqOhNSIZn FDHA== X-Gm-Message-State: APjAAAXzanh2uwtfKcHMmDhySh+qf0gBoJm8gDQijH27zgk8eWLeVUXE ZjXB6C/Qdnt/RemttFPvtS2zBTi8S1w= X-Received: by 2002:a17:902:b618:: with SMTP id b24mr1739608pls.73.1552620394496; Thu, 14 Mar 2019 20:26:34 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.33 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:08 -0700 Message-Id: <20190315032629.21234-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::532 Subject: [Qemu-devel] [PATCH v3 02/23] crypto: Reverse code blocks in random-platform.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use #ifdef _WIN32 instead of #ifndef _WIN32. This will make other tests easier to sequence. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) -- 2.17.2 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 Fri Mar 15 03:26:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160387 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16273533jad; Thu, 14 Mar 2019 20:50:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRegVypWSUzCnC6KFY7YSuFrkpcRNRDZYy/Vae6YEDWfXil5e00oEGsa1fGmlIMkl4ZFrm X-Received: by 2002:a7b:c216:: with SMTP id x22mr576042wmi.41.1552621809321; Thu, 14 Mar 2019 20:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621809; cv=none; d=google.com; s=arc-20160816; b=ehcGZah0L3whY/Fw1mVUILSu1Q7dUorDSh4QqNu+8/w2ZsqmpjhIxh3wlgWdOMoPP9 u7ANzbOunGOme114vKRDJ0ntBdsn8ACC6ejPi9gcsUpWpoSJelQdjgapE2/pICvcHzrH 2eoBBRgrrqkwR8RJCvaiAiFMvVnoLUQOQAgwmpS6987+nhIPQul/n3Jc9y0nW1kvPpGC CRe7YDWBUYIIgrHDTE08SrFBPUllit0kJ1hhrQ/3HtOmn0KbkU5szILjGuuKz0NmyLcR XzHakA85duVZPrAeSyZcAlZoF1o1cndd6gRR9uizdLcSlvI0vxgKn8KmsGOOPQzIEQ6l nwQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=3rnkQV2mDwDjm+peqMAHfkM55fLPgrlpN1xVPWcrulw=; b=OaUvWwQUfyJ9BNUfEO1uC8KqgUICj7VgdhW1VAKN2UYEeFMN2rrRwKZqdgXACguh8v DHoTBC5L80Fd19iN0JA+NDJ6ZBXTGSkrpjESDXv1E7Ws1jS3XjbFyRPpTo1fhay8zXp4 9oB0dQ+rJoB8142q1KaLWmaX5ulP9n513wk+g24VsfkTn4LwiJIgyxnoW612VQw2FEQF 0v2TduU9MMcR2SuOmUkaQDlqP6PaLHttSHyBYcG3nYrWlMcMBn54rZHwj37Gf9+AvFNh 1r84VYSkS1lBwg22REVeDRASJClPBhxMQSqpqt84Nh10eFA1h8z8W/cj4JfL4I7XsrW1 nLJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UA98FuJ1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y16si459643wro.373.2019.03.14.20.50.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:50:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UA98FuJ1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48913 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4drE-00016J-8h for patch@linaro.org; Thu, 14 Mar 2019 23:50:08 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcM-00059t-1g for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUT-0002jW-60 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:37 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:39423) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUS-0002im-VO for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:37 -0400 Received: by mail-pf1-x441.google.com with SMTP id i20so5282816pfo.6 for ; Thu, 14 Mar 2019 20:26:36 -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=3rnkQV2mDwDjm+peqMAHfkM55fLPgrlpN1xVPWcrulw=; b=UA98FuJ1Vkv5VA/8SatuiOvrtXjTFk3tIiR8NTSiNwHQhKrev91IJpYBABGQvqd8LR +sURLTvbXl7yzMOd9KeHBY45Xd5oabadEzV9LS9Z9YfUcEtJvFGjTzNBGGnOsg6Isgjo TXF8hcgd+klBGcNdaZmoTRrQE7/cOLh3pilLtwYk2R+Z5ez0H2rHx83i4icSNbFN9Dgg t+/8k2Vxw3gPC9014wGPLZPB2U+m1qPHZ0r6nvEcK32q3EZACunssswZJVxa6ZVTCcnY p6sDzyI8IFGTR/2G5D+OM1mpsJuWFKv7NbVMrNrIgW6nuRBhDpzDCYFMIZfVjiyJwqdB um9g== 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=3rnkQV2mDwDjm+peqMAHfkM55fLPgrlpN1xVPWcrulw=; b=cLXSDz7XvcmFQczF2Y1MM+jA9PxxY2twDP7bYNO71c8RYnfc1e1M+dtdFvTbqa0tIo mlAqLYQF1OAozmCLq4D/GFs75R1JZnF9XIlxlngBAfqu3nN+8stlNkKoFGZb8/XXljAp GJtj4B9W/pzxr/hWG7DcloMjrJqge5gPM3pCV7kxxWi/xaTgIKxjyrWUdJdIi9gDxkDP iaKcejtH9Yv0140tY+afPfA4bsPp77Jn2/qsKSAJhy3BMKEFvsXQlFhNw35CQ3hkMh0N mjAsweSXygYwRkFcWUF8AbNPBjIrM9KlNTZ7AvRqhmnnP1vn9NkW94Y21e6jL/piNSNR +xCg== X-Gm-Message-State: APjAAAWLB320OA5P/5eQLJYdq94HrIoLVnDl/IvpDr/KEXczICpIezYc yJhfIgb5Coe3GHa4R3QuxHpSCvmIx6s= X-Received: by 2002:a17:902:b188:: with SMTP id s8mr1720020plr.327.1552620395603; Thu, 14 Mar 2019 20:26:35 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.34 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:09 -0700 Message-Id: <20190315032629.21234-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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 v3 03/23] crypto: Do not fail for EINTR during qcrypto_random_bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We can always get EINTR for read; /dev/urandom is no exception. 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 --- v3: Rearrage the read loop again. --- crypto/random-platform.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) -- 2.17.2 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 Fri Mar 15 03:26:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160390 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16276990jad; Thu, 14 Mar 2019 20:56:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzh8vMShaHJBA3vdN5cgrNLXdMZEneuyTArt5A2EQMVpBR+VsUdJlCh4yM805TVG/B6PmlF X-Received: by 2002:a1c:6555:: with SMTP id z82mr514200wmb.125.1552622160050; Thu, 14 Mar 2019 20:56:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552622160; cv=none; d=google.com; s=arc-20160816; b=WpBvsuo12n173Kn/KKHZ7R2BDrWu0QYKL0+WHbOTgP6K6Ar+qwYkn7qUuNOiEVPYe1 CLB4FMwjgWspzLVXMJvWtDdLL2nEHa2etQvv7Tvj0ktp2ZQebJQHL65z08GvD014I3q4 wM4ZcjUmeJlTfZq8NsIjnJ18sHo1lUzPlPQKyR7S3gKIB+f8RXeKEDsQ4EH8oZcSPlhe Fbk2l1Oi2lFh96jYe535KF8YNQOjDXDLk1XicLlYomhhe4+lKkZ3sOAfJAL+q0ng4xsI PqU1GKMxN2st0jgqDJQ6BLYtVOQkAq3TYDMPyNyJSo/S7K6972OZdaFw4ilTDGvzIYXa 03Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=qYcAKtdWYXUNf1fKI4qFDzlyltObQFn2JF2oGmL9Qc4=; b=rf+lPW5TJJRrxwfwk27aKWmzbM2LucJ2aMxsDHpePMx96HrlvwGzlR3Gn6Dh73Iy2u Ppk1sVNThwtQelY951Iisf7swXBfPVCPn3mL/7kUkpyMnTWrUeltG8iYeiB8vU7Xie99 CA0OWVmn782uSlScYstk7b9a9VnK0wMjX5DJmwZFjFT9USaihdqXndCqGy/5M8Ci356X FQXzSiOFAIUe0alMIoQRjvI9fYtNDTBq3RfJg5EjuirTNpTkmXrbhiI7MXp8a02OhdCh y6DHxLPJH6JohOS7JV5krnN0jxCbaVcnZFQO1ufIsn7YFC6GVGFRMQ7PcsEtpEMAo++H plfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UAVulb15; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s17si517377wri.457.2019.03.14.20.55.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:56:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UAVulb15; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:49162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dwt-0005q8-3a for patch@linaro.org; Thu, 14 Mar 2019 23:55:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcL-00059H-RM for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUU-0002mD-Qf for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:39 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:43361) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUU-0002jw-IU for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:38 -0400 Received: by mail-pf1-x444.google.com with SMTP id q17so5268968pfh.10 for ; Thu, 14 Mar 2019 20:26:38 -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=qYcAKtdWYXUNf1fKI4qFDzlyltObQFn2JF2oGmL9Qc4=; b=UAVulb15W4ZK+fxP3Zn2T9/6HolA5xelkQvJojVlix06yNVK5470tIwR+GhDDJP3CT 25zWd1Fiy5QWkYuwXhGEd961yvButhqW28aUSDmdW2gBxZZd77Yp0Kawan1PFT24ZsYq SmYo4pFMxFy1xUeC96F1QuEvaY3myo57ESgkHzlou/GQmLtPAYase+oLpLqIzLMB58uw xq3jw6jRQ8EG1XOWcPOsBDrMMHY/DBcApYb8Nd/SZAmEndzu7HYRkiu/jt5QpZXMDjCN uXIiP3KIOyp1IlSxj3xWxWY8QSRCtUy3HpLlcagI/snmzy9u52YSyXkfP3lmvzQctHbi 5szw== 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=qYcAKtdWYXUNf1fKI4qFDzlyltObQFn2JF2oGmL9Qc4=; b=BUkxzXFRhZBR5MRxetz//gl2faV7z2YlZJxDMp8Ia8t4EFpkL37jKTpBuPIR/oql0+ JcBqR9MzG3B/SmaWnNKg0I0/hHp/1VnaPJGNPctTvNnGTkYOSZWimkV5pk82Ere7tIQu XtNMhpJo51HN7dgdo7yzTbUxquHuZccpGbGMGFAdcKL9QFfNWBxMO3Wul7hlUv7yUYBu I+I6VvWAlh7rmske2RsHCsKSSSV7QFQLcgqKoiQ3WnXbg+LSOZXz6m0+I7iZT8g/61cW JOY/vE2X2XiYkX2GXff/wL7vKqe7T0WV+7qg3tKmeeZ9XOFkCB+gTc/XP01QXq14azCM scKA== X-Gm-Message-State: APjAAAW9pRzqG2yeA2xCoyn9D+gMNPop3rssV4EtV2EcGmv8/s+uAeN4 NCwX5zYQPYN6T4jEUk7K1Lfa6mLaLio= X-Received: by 2002:a62:5c3:: with SMTP id 186mr1697763pff.35.1552620396869; Thu, 14 Mar 2019 20:26:36 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.35 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:10 -0700 Message-Id: <20190315032629.21234-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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 v3 04/23] crypto: Use O_CLOEXEC in qcrypto_random_init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Avoids leaking the /dev/urandom fd into any child processes. Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.2 Reviewed-by: Philippe Mathieu-Daudé 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 Fri Mar 15 03:26:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160391 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16277159jad; Thu, 14 Mar 2019 20:56:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyL3ErokM/6LzHGxjp+3y4tghb6V2cyRVFe7MJ7NG7ZtOQZdZRYMywheEbeE9Qwo7NU1bxG X-Received: by 2002:adf:f611:: with SMTP id t17mr743481wrp.248.1552622179153; Thu, 14 Mar 2019 20:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552622179; cv=none; d=google.com; s=arc-20160816; b=qu0WDLD868jewP2z6+rnQRiBAbAl02pcaCSsFRyOswZdXwXJizpBoCdHrl+RG6RLuv OtCKFcfgIjbF7qF2zaTyf2k8WqgTbkML5kwpdKiQocHcCL+Pjj30v3wEn2zgranSTKLj Aq/xT1WQF7N6g3sSRjHWnuvjLT9Yq8YYPLsPH1XDKN6hQ4b5OQBQnnkNpEJR3RZgbHnT ZQ+VHq6LgDkg/QygwDuvWvzHVPsaC5/MbSvS+iVRGvm6rJEmRfK653NJeKgvZIEHAIt+ i3FOFUvNDgYHWX0xKt4Y2QfFRVqK2q9aX/qau4vD/sNGmhJCNhP8HOQe1w0nTWcMkP4Z SA6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=nEGE+N+ZBpl/kqs4WAZ53DlvFSXg6yplX5rQG8WIa8g=; b=xHbB7NtxhDx/ZjPb0LNpFx3EOdktSJVfdjXPa2KEg979N70+eTWdgw/VCN8eNf4WQw 9yVI7PeBMFOeLxXAmTTWJMbERLL+QV8mvzbWCTL4cVHg0bsZ+PDIkcDnlsJxlbIrbcAn SGjMq7DqfWQ9ZjgPiEAoKRUPRZpCS4XSoHJzAdC0Vf5PRC2zAx0M8d9LdbTXMGEIAzi7 qS4RwA+PavZoNSGxvCdyc6+jT0x6kBug3uP2OpZwVqmlTfbGrfpPks9+RdRc8QZrmhPT RIotYS6Jsn+/0vSQFR8i2SsO2VCLsUIz2sUlmu1b9m2gFuI8tzbcHpRM54q3N+Ib0Mh0 Gd2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tyz6mo5r; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c20si509232wre.66.2019.03.14.20.56.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:56:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tyz6mo5r; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:49166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dxC-0005sw-5N for patch@linaro.org; Thu, 14 Mar 2019 23:56:18 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcL-00057Y-Lc for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUV-0002mz-KL for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:40 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:40501) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUV-0002m8-Cw for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:39 -0400 Received: by mail-pf1-x42f.google.com with SMTP id y124so5272023pfy.7 for ; Thu, 14 Mar 2019 20:26:39 -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=nEGE+N+ZBpl/kqs4WAZ53DlvFSXg6yplX5rQG8WIa8g=; b=tyz6mo5r2GW/GkviZZ/ISu8xBeD5QX3lwToVJ8/ClL614QMHjRvASeK1FAVKzHkaou uQsxAQCaqElWSkxk5RTqB12WLUB/NBhaoxBFnPZNbhX/7m3Zi5IOZKamml0bsI0SgoDg 0m887ahw6hG5I9NmiqWZfXMfluzSOfy0EkNz4oHzpOgoEa44SxssvlY7UqpAhYk7piMe TOdIeqg7c0cqInIhUlOltLpqKHt0B8XRK3u1wH5ywk72awPuVhsJhM11YV9zzibJTdlZ kHj53ZrZNUuJrwOcEoY7nW9ePH8GKz4EEpz4OJvEDXugTzs219g++dcoGbnud6fKEKLY wfUA== 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=nEGE+N+ZBpl/kqs4WAZ53DlvFSXg6yplX5rQG8WIa8g=; b=EuJgziMllCvyXpl/hRuusRXUb6zBceuwQcr6IAG5oFfMUPW25Qq6IFv+4KOlVSLol9 YPjuecFbRX4Txobf33Zhg6dqMbTNNJEPoU9pMVm6Iw3QFDwcivOetloko5tEDlbhbpEW RRZ1lqq/4Gtlx+2IYi7gKrKEOBA1jwUhPqiHnz1yybVtcooyTxO0V74m5dR+bLtuAuVf 1bFLNow6aifqN1VtAPx8Hhhmh9SS22w5ZTsFVoR6g353BQQedjIDLZ4cT4GF+jc5BWfl ZLxRrY9JlZ3WzVRTWyiPzEOspptCKeUThiZhI+lx6dvc22kFp0PnXN1LDe0i5TxYcQf3 3gbQ== X-Gm-Message-State: APjAAAXjvGBwCc5iBqBfiLeWT/gMH1N9qbjrXh8b27y/woUmKA6z6KiW WXa2qgRSVWGtzjYcfCKMlUSTmJJaPCM= X-Received: by 2002:a17:902:9a43:: with SMTP id x3mr1782791plv.173.1552620398042; Thu, 14 Mar 2019 20:26:38 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:11 -0700 Message-Id: <20190315032629.21234-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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 v3 05/23] crypto: Use getrandom for qcrypto_random_bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Prefer it to direct use of /dev/urandom. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- 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(-) -- 2.17.2 Reviewed-by: Daniel P. Berrangé 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 2c95e6ddc9..2b79c2fad8 100755 --- a/configure +++ b/configure @@ -5781,6 +5781,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 @@ -7163,7 +7177,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 Fri Mar 15 03:26:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160385 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16272686jad; Thu, 14 Mar 2019 20:48:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkZejyfQPNOTH7IuW3qfkFjDvOS9GRgLznQNYWGrgrfuY/XglktfWoWQWf3eWsqLOiMCVo X-Received: by 2002:adf:ea88:: with SMTP id s8mr786790wrm.127.1552621729388; Thu, 14 Mar 2019 20:48:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621729; cv=none; d=google.com; s=arc-20160816; b=TK0RJb0XcL5AyQipCuTGiYjJ3R64FkDguMwocsh54VY2qblvua2h8izPi8JczL7K2z 27Mse2/x51RyVQZxadfVwD46YC/aXnNcGn7zYY0xSTlXn/dBKxq0Gsd5s2yVby+oRiL3 RkGWOVFzSxkE3aQgGNhGWQ0L11Zh0Z4bOeYHGlKfWUKWNZm2EkDhyF/gzK5cEAKaMGSM sIfD1OULwMA4+dIgl+fIAYuYxQr7DIWVwc33g6BCYKJGOJAobqTr2seZrGjp/Vk+nxsA s4wRFIQ53ocpYo7m1kGskiJgGe9/LOvIjXTXSxMqVwHVha2scDUQrSEEkZxgOf9PxE/i oISw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=3QYzFsN6jbxcwP0/vCb7AXuYGCKiZNCkQHkIg1Hel4k=; b=kcep6drGitTNeTcJu+p2OSehpOu5GCpXojVeTcIK77vp0Xg5cbVhYzsXJDOQNwIr5B PgCqIbXP5Sw4hrWCaU9UKrB2qBl1JbOmEjdN8Mj7YbIOCaZ2706Rrb8gGclGq5n7WFpt 0rQKkhWONGox+3VGyq1HXDASo6J/IzXr2MHeEAyTXsjM9Gr0J7iR9+QnXZjmf8tnqAqE 1Y5IPlbZ7xqHkaDUSVwUeaFoZilzt4QHlEhwfk3Tn+ccg6BKYrYGNVp0ksYXMqtwiYvi g61mUtWYsYJqKehngICj7Kx1LVF8PLDAEW0+yp+CzwA+WHB/1sVe1INhgEU/w4utMVB7 ckDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="qWQzU/Tj"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s6si470025wrn.330.2019.03.14.20.48.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:48:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="qWQzU/Tj"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dpw-00082x-A2 for patch@linaro.org; Thu, 14 Mar 2019 23:48:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcL-0005E9-BB for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUW-0002o7-N0 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:41 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:46725) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUW-0002nM-Ec for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:40 -0400 Received: by mail-pf1-x444.google.com with SMTP id s23so5258127pfe.13 for ; Thu, 14 Mar 2019 20:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=3QYzFsN6jbxcwP0/vCb7AXuYGCKiZNCkQHkIg1Hel4k=; b=qWQzU/TjLIRGNMLg6WUmMkkx5OhbIvT1r1jC7ybaTc630onWjVhYpBoqUrKDIeqbjI RUnVc0NOT+oLRCzo1WqDq7VXL8vaeG/KTUsP2+IYETiFOitaxhk95utiu2De3ahXezmb PG7j6VWwmJD3Z5T0sO/b91qwvCuz0kZOyHD4RZ0MrBMp9fHquCcRQme/mUI4eTmitTxk Pza1up/K1NmG60JO8CqcSZynCHKeFGYEZdWNVJgFyjpX/gskqzkdFMjf9FyWkr2ZSsyc eaxRJMFHpNEKUNcMbIfy7KgyFLvCfpWcUydNwRCmrkJzE4bipmd+F68rHqRXOc8QAo8V TPKw== 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=3QYzFsN6jbxcwP0/vCb7AXuYGCKiZNCkQHkIg1Hel4k=; b=p6iNvQt9Aifw0ed/9Vgg91zp/yJFtqDVEe10H7hOMJFJCyUi7HTjzhH/HPRq6H7HcY kmih2xEu0/cpwEX1b6zQqbIyGN81SMYLwm/sI/YtN7KFzzdwgKhbKgdokCnNIr9bQDQe i2NqTpWG1XnJ4980fxaj/7vIXtXW8u4nCcdrq3R6hZGBAc0pqp82He6rhndGJAacj2re G70LtAogcjdteKrgvjCKQqdUbjf8B+6QO3Fma4+UoaYcHzhS1SNxlAatfoDV7OlnhDpQ cc4tX5q7qJhxL9nL7wJLlDB03kDa4Xe1ncqe96L0z0zVkDpDCHHgr+VFsk/qkJh3LXpL 3uYg== X-Gm-Message-State: APjAAAUa9ofuOjnK+OTJdI6W3B3eCn8GzMvS2CyrQFU3l9bRdeQZblF5 CXJlNn0h6gCYZzP9dpwwrBGrP7Xr964= X-Received: by 2002:a17:902:1002:: with SMTP id b2mr1787557pla.248.1552620399243; Thu, 14 Mar 2019 20:26:39 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.38 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:12 -0700 Message-Id: <20190315032629.21234-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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 v3 06/23] crypto: Change the qcrypto_random_bytes buffer type to void* X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Using uint8_t* merely requires useless casts for use with other types to be filled with randomness. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- include/crypto/random.h | 2 +- crypto/random-gcrypt.c | 2 +- crypto/random-gnutls.c | 2 +- crypto/random-platform.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) -- 2.17.2 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 Fri Mar 15 03:26:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160389 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16274350jad; Thu, 14 Mar 2019 20:51:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJN0Gcx4RqZ3G/hoa63y4BfnGNb3mMvZJnH5wWz7filvrcRloAT+/6UDjVmZ2uC8hU5zn/ X-Received: by 2002:a1c:7a07:: with SMTP id v7mr532243wmc.30.1552621896875; Thu, 14 Mar 2019 20:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621896; cv=none; d=google.com; s=arc-20160816; b=PD9iyNw0FboBxz762Ba3rNf0jqg+AzyO+m+Rbmbemu06n1k72d2LHaP8Jq8ScuISWP HfdBHR4qlG2JIAVTkcfM5o+4L0YjYUPLqN3VSAK9DwGFu71EkL/8h2XqN16V5ajxnEj9 NJAIpBWmkwd3ykEWzKrGn0vJTREwzYdbY+0HuVK4aTpbaB1mmWW2GSP0w7yyt5j8e+Nt WQnvZ8jYU6llFzaP0uxFCmgj4wu1YN24fb8U4tnecmr5IgGnjCB0SY4/0X8/RSTFUR2u 4+tcwT54Sqq6oJAwQrPCQLzHR8FccwjRhPlGmIWDY5LoieJWelNRT9++yPG8yA7moBkG o57A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=4poveDpJ7DPmdIGwLj/FIj6SSKHQVllEi0VHCsLFyB0=; b=vCpmy7uNyy/LBR+EfOqHGd0H2G8bT8cWUxN7/znyKxaDx0Kl1d6dprow6TpthP+2p+ QREoOHk20DzBi4oqlmaaGm4hCzrxKGgREV4XjOpWDgZZRf2WwvKtl1av9oI9zq6gDRpJ AFpG6pOT7Ko1e3sJE3z3wITOgiEYK25K1XZRgmGemLUeomARpuZrNS8wi8NoSTmPbcx4 +60+nQImEtJ1GmyGYVTTimGrzdsQL6wtSBrJrTj+GEZ5vDyvgJ5gYfAtGSQqh+eyayqq bbsr7hw3+5tMwuBrWF/hrbKkk/BV0WqEFx5R5O4zWuu/Ty+PmRubVeSRVORqnWMWdlmt JZKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jZD3vM5M; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u20si390826wmc.109.2019.03.14.20.51.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:51:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jZD3vM5M; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:49018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dsd-000219-Qb for patch@linaro.org; Thu, 14 Mar 2019 23:51:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcL-0005BE-AU for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUY-0002px-EH for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:43 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:46981) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUY-0002pE-62 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:42 -0400 Received: by mail-pg1-x52e.google.com with SMTP id a22so5378817pgg.13 for ; Thu, 14 Mar 2019 20:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4poveDpJ7DPmdIGwLj/FIj6SSKHQVllEi0VHCsLFyB0=; b=jZD3vM5MAYHGm3lPyVaw08kpidCfwemSPDesTSQ2Pm0NteM5Usq5lbwgNC6lIeC4Hj PoHpuq/j4CUMobL1ZYF3I0ZK6OA93vK+jaKSU0Aa3+vykTj5WrMnt1e6KVQxE1qKrWpS x9X0hxzMl8+UY6fzR0CF4wX+2Z4Td4dQ8eE4b/DiBP3V5DpuNAV48aTmZechMtJCeR0b ZJ98LV3GTnQIcgtV27JeSuX00XgYUTrB3qoCCt+uvS5KKNsVFaGpzfCO7Sc7F56qIyAa FNVqaDOk6OpCPph6LOwQCRYDxULMkcJjzPgy7iC3JlvD5dgoJwaZNDJa0vP9C7/P3gg9 6O9w== 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=4poveDpJ7DPmdIGwLj/FIj6SSKHQVllEi0VHCsLFyB0=; b=lsB70ipXKhB3C8ofWlpemKusRixULETVzO/+V1E1spZYISuGiX4e+vicv8cZm0BxEl iqt9Zy9/lzdXZCWFw2EDYmcxmtps3XMXmDTsiqqEmXI564VKwxinnxJj5OU+s1U//8FD raPEVM4+qGpbngMYi620OVoKIVviRsUrstMN2/9PYVJC4So6ZbZFr1EG+tFy5kOGi2Kt 0Q7VTX/+6aRjApUhOPsFqc8QZfsNlVQxMedixh41sClCN9HE34vl+WO3Zs2KbdBCZPMd jjMrHLUNLpJXJrmJqpkzOUw0n4sK/aMq2Ts0G+VRcFYWa8hbWFaKrTteXXvHtnmJlnPT aeWw== X-Gm-Message-State: APjAAAUtPNlVFqwXLu5v+z6uCS9OxW4j4Wsf9HLwIVpa13yKf3UDX2oV c4b2Dtt6XyDs7MKS9GRE2c3UkkWNfzI= X-Received: by 2002:a62:57d7:: with SMTP id i84mr1720295pfj.125.1552620400869; Thu, 14 Mar 2019 20:26:40 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:13 -0700 Message-Id: <20190315032629.21234-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::52e Subject: [Qemu-devel] [PATCH v3 07/23] ui/vnc: Split out authentication_failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There were 3 copies of this code, one of which used the wrong data size for the failure indicator. Cc: Gerd Hoffmann Signed-off-by: Richard Henderson --- ui/vnc.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) -- 2.17.2 Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé 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 Fri Mar 15 03:26:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160382 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16271936jad; Thu, 14 Mar 2019 20:47:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZ8CsnJq9Q4gIG0DoMZ0sCeIGAvZDsiCTF1DGf8R9GTUkA95wpdfsGco7LgvE0nAQOKICT X-Received: by 2002:adf:f690:: with SMTP id v16mr758255wrp.139.1552621657087; Thu, 14 Mar 2019 20:47:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621657; cv=none; d=google.com; s=arc-20160816; b=IJcJ9DTC1pp1e/z6cCPICkep6efBSPisGgveX968S5TOlUcMuxjQkraw+hTy5NWiJL QKmXJwzq7dQRauYx5RmQY57FXCYBvxor/SPIcW26UajyLJTL3Da5ccBBBm1nTiIxxZ+O xvdzP0nEzUSh804fFJxynoh+r8SScjRnFDCFErGWXQ4qeppcpcIiEq9KjruM0q0z/38G I4NR1D+dpkVcO+G8kOA0jcI3FlXUzZISfF4vlASUsfHxnJs79X5ymEBy/YWwKN+Bst4g 0415047JHRk3w+kwmpDuilckb7U2kHVI1PTsOHsBPJyKPNiKS9KC0o1XqguWoZq5rikJ e8tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=II4ZitPVyuBuTtikKVKTOwZYATc7zBTEhNb3dHQRGvg=; b=t1qEB+syVbh0vU7Ec5pab0xDXSD4TIWDaqgXgd6RilS5kNXvWq07Q5r1/4Mp6UlNp4 JC9NqygYy3QtiPV5u+0hurUOD/Q2E1cBHcR0MrjyexM9aaxVVPYlzs4EujDOPSmMrEvs VC3Ow2MhtGtEyQdjuOBpmcG150PmXhp7Y5VzXzjXAQRDvVMUSyp2xzVgTR2fkvPjPHeG 0elD64VW9Hh2Uy1Af0kMmtF+0u2iSn+bhdxjilUcqdwM1KpqTLiiw3EZkf7QEDjgiEsR UxrcYSRm7dkaI5VlyEQ+D9OgxIIVUPuhzcYLeO3HRu+BLlxIQr/dRc3sGn3MPBVnSWjo CL4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZaJWCpv2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u1si398623wmc.133.2019.03.14.20.47.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:47:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZaJWCpv2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dom-0007UL-11 for patch@linaro.org; Thu, 14 Mar 2019 23:47:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcL-0004w5-7P for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUa-0002rk-E1 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:45 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:44653) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUa-0002qw-5q for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:44 -0400 Received: by mail-pg1-x52f.google.com with SMTP id h34so5388525pgh.11 for ; Thu, 14 Mar 2019 20:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=II4ZitPVyuBuTtikKVKTOwZYATc7zBTEhNb3dHQRGvg=; b=ZaJWCpv2Xoa4WQlrvPawZrbWqnV6d5uw5TSXRYxCDyzbZt+OxV5K959CZffqefwQXH 02PUnNTkr1/NktsJbrsXnHCJM0bf/0aX82VkVWdSRHbFTkKQVt83fYUUmBa75eQXzJ3r JJ0kGw5N0doqk8BMOv7GLRO0ENgX9qojYdSNEfRcvdUSrpcX3I0LrHzvrXTbwlENyYQc 6HaFmwfJ9/9skiSpwajtxd4gBMi7pXAkzrFVLnJWDfJaZ8SKC2hFFkOnQOLnuo8OMz/p +2n8bL84nJH1AtTJVbZvVmCxdBU/h9BQ4Hoz0guHVw8hP3jd1sBpVdKoeSh2uo04YlBx /aBg== 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=II4ZitPVyuBuTtikKVKTOwZYATc7zBTEhNb3dHQRGvg=; b=SQcx0RtDZCFfYcrNvc+a2C4WNZYuKFH/ADKT4RR1VT4wVwcVH7cQ0X9LJmA+tycg2t 9+UZRRK1uIfBEY/U1d2xL1PYT6JD+qoRLM7EgS6iHrK2gHsU+cq9vLCyVfzL8zedUcyZ vRB/VwPgyS/d9T70UGIT5OslqRvpud56uAYem7JRVfC6FbpmDi6m9YnSrg/uCJXm6KPO kIwnW/gC4j8Cvs6xI5WkD31EpO4iwHc36BfVEfqDuxQxhUzHDBWxd3ILhdt+hirKDcYb zpoe/2887WWOSbYUjSDfHoeMDpfc2hXDMr3ljA+N6/HpbI3pxQ99ytVGtW/aWhz0DY3D eB5g== X-Gm-Message-State: APjAAAWMbiKYa3GgMnjoTmWiDlalN8L4HYHt2cYFRuSNs5EwSmYqY4Vv qjSKhT38zEkBKbMrU6qT/xhTDn/1zrE= X-Received: by 2002:aa7:9102:: with SMTP id 2mr1682269pfh.179.1552620402842; Thu, 14 Mar 2019 20:26:42 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:14 -0700 Message-Id: <20190315032629.21234-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::52f Subject: [Qemu-devel] [PATCH v3 08/23] 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: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand(). Fail gracefully if for some reason we cannot use the crypto system. Cc: Gerd Hoffmann Signed-off-by: Richard Henderson --- v2: Use qcrypto_random_bytes, not qemu_getrandom, as there is no need for deterministic results for this interface. v3: Fail gracefully in the event qcrypto_random_bytes fails. --- ui/vnc.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) -- 2.17.2 Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé 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 Fri Mar 15 03:26:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160377 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16269589jad; Thu, 14 Mar 2019 20:44:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzG+uyX4YF3kKqirAyBekF4Dd3f5gERMDaSZTtnaw1TeNrc9y3q/O0XGvSahefA4qkRn1Bz X-Received: by 2002:adf:e28d:: with SMTP id v13mr731169wri.89.1552621442667; Thu, 14 Mar 2019 20:44:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621442; cv=none; d=google.com; s=arc-20160816; b=WQIT9n2EJKW7GpWylbJZ9fa2pLMeWfPUwi9yH0TotFcY9LQ0MOwE4I1h1HFa6CmsBe WW1t7ROkrv74puAO02DNC5pHYTSuFDU5Ven53Bf0IkMUkG5zmB8WEQ006pwcXoAcSyJ+ I9Ft0nZqmU2C7Wsi3/Au/rfv0ezqxdxHzsdM5PqxZQSfUvzGwLEdIq03ek26sPyoq9tZ gXCM69k7sLM1UWpjZLcjgg2Cxor0gg5HpI1WR50q7xhxAlcDkl+jL+awQCk3jmNKuLY9 +RF7eYAtuZJPOKIiYjtMlxjF5McKWnQOS0K/ZGaBBLetz1uymtA2o9TmHnPiU0VsjE/B 3WNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=54uvFeZxLRAWgvSkjEfhPhjH4PTpHgBkNbG1KG9JKxk=; b=OQroVafGV+JQHmf0W3ShC2XTaBzApljlHeKDVvXaOZ28DBId/KLsID02HQj+AQvpsh r8WlztNThKh5da+9CUNOEjKrpI635r8WR43ORPb98FXyDTtAVgs/xLKX5ku6CRE5CIJ0 mEZ29kUREB6uEUPAjnH/kBpwgrK9zJdOnh6h9IQCxQDoliBMvAnxjWzcODzyv/kWU6Tw 1RL20znlZs3PR9ufC/Lsf/e5Rtyrkt3m87QCYZDRl3d2vUy3V8XkjXy6ki9hgME7ct1C Z21cTZYBhqlH6dCQ4/TZUPaxw1jJaehMGgVS/t3rsGgsEF2qS1Y8ZdHCDZWWVMrMo7F9 /L8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ex1Th0Uq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 1si511420wro.275.2019.03.14.20.44.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:44:02 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ex1Th0Uq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dlJ-0004Rm-Cp for patch@linaro.org; Thu, 14 Mar 2019 23:44:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcK-0005C3-PT for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUb-0002sv-Lx for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:46 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:39425) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUb-0002s4-CS for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:45 -0400 Received: by mail-pf1-x442.google.com with SMTP id i20so5283037pfo.6 for ; Thu, 14 Mar 2019 20:26:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=54uvFeZxLRAWgvSkjEfhPhjH4PTpHgBkNbG1KG9JKxk=; b=ex1Th0Uq7/DU8nGFjNS+zUhx52f4p1lKDIaXWYbUqWJcX8Kwxe5u5sQM2rsDXs7D+c WowP5BKzOBNtzRXXU+ogLEBZQCh3a/6y5IqRIq3cNlH7XL4QNJrAzdhAY1ChpmyykOHe iwpNw1lVnPTPmq2VCOPO4qxTPOGqXU3p48UtyS+vKx5Eu6wsCLKpHcJ75LNXfvoDuOH5 pymmwgiwsLkjj9cqmAhXYYwi44O7niQFrsaloMgAu46fzkYeuDYp24GYguAHJkGsmCK8 NTK33mKQrrDOCyb6RjQLpdvDA6h9dPwtgSXqQ2PKit7zpHz51celEk7CIx8G8WZCme9A 1Q2A== 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=54uvFeZxLRAWgvSkjEfhPhjH4PTpHgBkNbG1KG9JKxk=; b=ak5ZMz9X92YpM1qBzJ3VqjlmW3PXp6gknaUQkn90cnL5I/riqjNrOfsjimk4RFuJk6 /g2+cqvffOSkthK91iIbXunO7u9dO+22LV2/GI9/4XK8XQvFGRf7w2fS2EG6/rN/QaRv rMPc65W50wH7rdXcUtSBoqoIJ06f3hZnBC8+a6TUU7fFLOXzB18SFbAu9BVqkaA6k1zD ki62MOKhrR0d8l1H0jnY3fDOVq0PV2qeqRXFk5Zs8Pik9GLPFcAIMZUi2kRSBvVA3cOg 3eMlI+YKTt8BTnuzvyXOcZfcDeib7X2kfcAhOsrIo30/ymkX1zf5JUy5x7E3Ekl1OBHg 5gxQ== X-Gm-Message-State: APjAAAX8susATHTuZLi/OXze8Vp+aZ08WFeS80yyyewUAAsxC9ASGsX4 5FkRR/thPVITJphfJ/MHSuEmuOBgT0M= X-Received: by 2002:a17:902:d715:: with SMTP id w21mr1805469ply.14.1552620403926; Thu, 14 Mar 2019 20:26:43 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:15 -0700 Message-Id: <20190315032629.21234-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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 v3 09/23] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- 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 -- 2.17.2 Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé 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 835fcd69e2..4d4db653cc 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -53,5 +53,6 @@ util-obj-y += iova-tree.o util-obj-$(CONFIG_INOTIFY1) += filemonitor-inotify.o util-obj-$(CONFIG_LINUX) += vfio-helpers.o util-obj-$(CONFIG_OPENGL) += drm.o +util-obj-y += guest-random.o stub-obj-y += filemonitor-stub.o From patchwork Fri Mar 15 03:26:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160386 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16273329jad; Thu, 14 Mar 2019 20:49:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjxj9C/fRAladfFonIfZFgoXoicgnvd/OS/rbLPgaa1CYB0gMkfw+yKkzQhsBnqOtWP3nR X-Received: by 2002:adf:cd07:: with SMTP id w7mr770322wrm.110.1552621787566; Thu, 14 Mar 2019 20:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621787; cv=none; d=google.com; s=arc-20160816; b=MIADhGqFjcq2K3cttTcGRiuY/x2+SibZVqyhMEj+d47xu1uznnXDuXmrOxcd98f1mH 3mYXHmXW7eGsyXLRishxKMi9b8Z4g4zV8ZNSYoM3xWusvrAAgp15AxZcAcHMPvKoUBF8 SEAZVXn/yobLQBPHjzg6lpamod94u5Vx30cYzaYRiKa0aB6BWIB1Tg3exyKrJR0ItXlv dOpQYkjWHr6FA9aFqRHpJ/zlYL01Er/YXwgrntUr+LXyNNScEJvV9ISlN2ByCsKeptNh e8DxveCsa+8S0dHkG2V0NSjJIIoJdDVc6KsszDXhnQFFv8hkiVAeiXlKYf2MArsGNta+ 0ksA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=5+Jw4ZT6nk5aJg5eDzucU6N22SG+dxTKxW+ellIVCNM=; b=FIWArbAWeB9+zKpCsWZA2ebvz5XN2WT6Dx/nt5eeYc8FYdRUXwkKnqJDl7a+Z491xL CEiScmg631nd29ooqx++ZGOFXllSQ/Cua8JrPtttjA0rIHdhESn8MEM6byeJlSpkNnHK RCFUHNSDXp+tnFaLW50O5GPYZXIO1rSqS9ak2/vaIjGqw06xte/pAkzZzJFO0UaUxyjW P1xK5ZIVuVW4rgfIn1o2A2ftJUDRChWIjbWLirJ/vO3L09gkaoMuRGqFNc17vI9/21GX Pj3zlLKhKNlVpbWj01bwQqvbNOnMXKTWfBcYotSHb8cj1+NGPQfYX2t320q1xJRR0lHR qeTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tMmNvRpM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r7si545908wmc.27.2019.03.14.20.49.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:49:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tMmNvRpM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dqs-0000rQ-E4 for patch@linaro.org; Thu, 14 Mar 2019 23:49:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcK-00059t-OD for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUd-0002uK-2I for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:48 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:35955) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUc-0002tF-Of for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:46 -0400 Received: by mail-pg1-x544.google.com with SMTP id r124so5420878pgr.3 for ; Thu, 14 Mar 2019 20:26:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5+Jw4ZT6nk5aJg5eDzucU6N22SG+dxTKxW+ellIVCNM=; b=tMmNvRpMJrGhYLsEIf4jmznWcXYIftlDl3x4Cdf9zJdFiNrZgBtC6V0NXgLiIFOD/n 6HT16AI4oNtuHY/uJQILouC1ME89evWsGJ4eTBy2BCX7OrGcItJ0vWWjEhz+BETZ1Wf5 jQYWiYCS1EJB8R5gFicUgF2H+bjj+Z1ZxzcfsRJ41WHjb1oIrAaJ7unrKqka2wVjo8VA OJznZEqPi6xD/1o0SVHqeyZDgDf/K2krX6ZsOSci9+MKC5ceD5j/SSII2rS6OeqEE1AD 8VdU2HzQYTKxDMxNDLZKLZ6QOSwB8C3VmNZ4zG5DhjjQr2ATI9g/b2rLvYFnn1mlJN6x IjWA== 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=5+Jw4ZT6nk5aJg5eDzucU6N22SG+dxTKxW+ellIVCNM=; b=alzZCiHISfHymwfH4FLchRWKofkIPWl2Cg+Dkh5sSHT/X8NBvDc+HlE4sjm9EVHYYL N9WH7X/RYJ2RW9hGoURnfadt2wMfOE55GgMZEwW1tD/a6w70Qw55ZI22X4XSF/qKlfar cF3OuIP7lFkMnG0ZgQpmq0nYwxL4QqoNkoiVlMDsj8yZxu9JoOuXNr6opq9MO0NqvVpb KOk1omsgzisxiRkUt6AOsrYoWz8yUvw5hw+wPkfhRjErSMwRMCATRSGFjLTDdV0CUm2Q bNkHbBbSlRMsPuur5UwJMCRPSdMphnxALZMaMRlBuei/YbtKKMZuscLjiuz7jxzm5Dm/ 3f0A== X-Gm-Message-State: APjAAAW003x/6sQC6zwmBOaqUe+n3fp8UkkyYjsp4kSXZj5gc03gF94w MyefPm5hPXVYpvUNO6d4lUHFiIBtHJI= X-Received: by 2002:a62:d281:: with SMTP id c123mr1708816pfg.210.1552620405151; Thu, 14 Mar 2019 20:26:45 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:16 -0700 Message-Id: <20190315032629.21234-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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 v3 10/23] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- include/qom/cpu.h | 1 + cpus.c | 9 +++++++++ vl.c | 4 ++++ qemu-options.hx | 10 ++++++++++ 4 files changed, 24 insertions(+) -- 2.17.2 Reviewed-by: Daniel P. Berrangé Reviewed-by: Philippe Mathieu-Daudé diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 1d6099e5d4..343cc6d51e 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -372,6 +372,7 @@ struct CPUState { int singlestep_enabled; int64_t icount_budget; int64_t icount_extra; + uint64_t random_seed; sigjmp_buf jmp_env; QemuMutex work_mutex; diff --git a/cpus.c b/cpus.c index e83f72b48b..6d88f6bfcd 100644 --- a/cpus.c +++ b/cpus.c @@ -49,6 +49,7 @@ #include "qemu/option.h" #include "qemu/bitmap.h" #include "qemu/seqlock.h" +#include "qemu/guest-random.h" #include "tcg.h" #include "hw/nmi.h" #include "sysemu/replay.h" @@ -1275,6 +1276,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1318,6 +1320,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { qemu_mutex_unlock_iothread(); @@ -1477,6 +1480,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) cpu->created = true; cpu->can_do_io = 1; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* wait for initial kick-off after machine start */ while (first_cpu->stopped) { @@ -1591,6 +1595,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg) hax_init_vcpu(cpu); qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1630,6 +1635,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1670,6 +1676,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1723,6 +1730,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) cpu->can_do_io = 1; current_cpu = cpu; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* process any pending work */ cpu->exit_request = 1; @@ -2070,6 +2078,7 @@ void qemu_init_vcpu(CPUState *cpu) cpu->nr_cores = smp_cores; cpu->nr_threads = smp_threads; cpu->stopped = true; + cpu->random_seed = qemu_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 c1d5484e12..d84f883c2c 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 @@ -3330,6 +3331,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_DFILTER: qemu_set_dfilter_ranges(optarg, &error_fatal); break; + case QEMU_OPTION_seed: + qemu_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 08749a3391..b8da998668 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 Fri Mar 15 03:26:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160380 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16270629jad; Thu, 14 Mar 2019 20:45:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzl8JUzpaSRSrj8Jjfo113koyMOoY/+NPhDmZoHgsRzWOq0wsvhSJG6ld76jFcBe8Yuw6fN X-Received: by 2002:a7b:cbd3:: with SMTP id n19mr495716wmi.131.1552621539953; Thu, 14 Mar 2019 20:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621539; cv=none; d=google.com; s=arc-20160816; b=KfNdLTqAioSinYdgqS8v/Ls7773GtEXiN4fs6gu12XHZFN/72S8H3EY4zi789mg4rL uATg015YbaqpEXKeNZUQx9QqLzjht5SHaKdhMGabReYoJhySIwoGIy80Er57xJvlLDEG gBq7+F4zjnbuVTwnumoNuVfMiBrX09GcCKlv3mCxkJ3bUB3/RmnnIJHN1yDRAm7kiWkA ugn/8z4Hm3EON5P5RAZWNT8VYiRKbqYduqbg2UJ8CNdgfePnQhvvya3FJJRyQaFdreGA IeaIZ8u7oASBBBAtVde+Smf1E/ZKEP3Q4g5jpLSpbuTdOhUgpHq82jBv9S/9ryUb+RAJ gunw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=2t8AKJwpSYkRbWRtZ4Sd+TCbVTcy9tDgABdaXlbp67w=; b=gyesA7Nx00GA+hn5o3qb9t/tYeyegD3qMIN2EJfI2/Pg5/lk1+x0y2EgW2zeF+qZQ1 zQyOlqM9+tBIqu9jWJ26rZ7hjykXHTgRaic0WYrOY6rjxsSXA/mQjlYfGjqKmfhLuc6J MmkRapFtg17FjOvUbe9A7svk3WgmJOMGs9Zl12DQd8LiJVcXVkdiHPAi4EJnRvpt+jbC 4qxmYaV0OvmdQreI19oFWxxCZcmGydu9NLuDI2tPfokJwPgkPUSTOXw4W3uQiK0TACTO ckgqwxn8SoOhCnOsMeXeH9xVJIcFJ5yKplSmiBZlRn1I7cGE+CoxGvisiF1iYT3t1mq/ TUXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=y5JULUEm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b3si591295wrm.378.2019.03.14.20.45.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:45:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=y5JULUEm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dms-0005eP-PQ for patch@linaro.org; Thu, 14 Mar 2019 23:45:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcK-00059H-No for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUe-0002vN-2j for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:48 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:45600) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUd-0002uT-PA for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:48 -0400 Received: by mail-pg1-x542.google.com with SMTP id 125so5384399pgc.12 for ; Thu, 14 Mar 2019 20:26:47 -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=2t8AKJwpSYkRbWRtZ4Sd+TCbVTcy9tDgABdaXlbp67w=; b=y5JULUEma/BW6L1OiXa9oTiD9taJgV+CIWfek2eiwDZwfkSJNDKCXUkWjAoZ/Hewsp hHdf4ULtpho2aSUt1rbcTK1eIUueUsG5AgbXyCdr5xIcwwp9vXJTP1XXPzBzKy6tmWT9 T8oKziqGcOwocbze7ddMfemXoukxSAOBD3kFrKW88/nTp3il21RI44MfaVM3g2hrHxxs DdDZrpch94yCckjhmWMnobq4W0aa7d/Tgqxg445uKChmMw4ICSba18IS9qGND2zzojHw AbA9fQoieEkclpSBvpxPNxClbWUxW+nDEw1xVmo/+/Nv0kbl+aWLhjUCBo3gaD+ljdCG CJ+A== 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=2t8AKJwpSYkRbWRtZ4Sd+TCbVTcy9tDgABdaXlbp67w=; b=twIbUqFwpZqFRvXXbgXoneiQJWpa4EKPTpC4VhXTJaWMA0szk31F2q3NmnJHBFxtiV wt1H/grDP660eHjgU/89SkOrSXGiEhl10nCjKbqRWKDapn91D1j21vb4s6HvZKQBHYsI 2kTZKkrxLxboIvpK5VzXRWLscaieu2P7RFoYt5BId7phF68eimjdXea6/EmlS8n62+5K EFJ12A+JRE9JIt0rI1MUn4KXqkHUbUTblP5lpCb4+PrcJJkSJj7cylXQw3tB8w06hln4 zmLdU8LSmWOe+1mS1uIcJS4Cz0se8HPNvTvVO4QfzUBjkoS+Zbi1FEJZHedVlN446T/M IiyA== X-Gm-Message-State: APjAAAW3mg1CX+KAcFYyGLNU8W3+2A8/8SYbHChWVpuYDh1Y0pjS07gs vY19mMzka9fKJT42C2rPvgDJj3xONs0= X-Received: by 2002:aa7:930b:: with SMTP id 11mr1726326pfj.49.1552620406346; Thu, 14 Mar 2019 20:26:46 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:17 -0700 Message-Id: <20190315032629.21234-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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 v3 11/23] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Richard Henderson --- linux-user/main.c | 21 ++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 13 insertions(+), 11 deletions(-) -- 2.17.2 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/main.c b/linux-user/main.c index a0aba9cb1e..cf7095bdaf 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -33,6 +33,7 @@ #include "tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h" +#include "qemu/guest-random.h" #include "elf.h" #include "trace/control.h" #include "target_elf.h" @@ -47,6 +48,7 @@ static int gdbstub_port; static envlist_t *envlist; static const char *cpu_model; static const char *cpu_type; +static const char *seed_optarg; unsigned long mmap_min_addr; unsigned long guest_base; int have_guest_base; @@ -289,15 +291,9 @@ static void handle_arg_pagesize(const char *arg) } } -static void handle_arg_randseed(const char *arg) +static void handle_arg_seed(const char *arg) { - unsigned long long seed; - - if (parse_uint_full(arg, &seed, 0) != 0 || seed > UINT_MAX) { - fprintf(stderr, "Invalid seed number: %s\n", arg); - exit(EXIT_FAILURE); - } - srand(seed); + seed_optarg = arg; } static void handle_arg_gdb(const char *arg) @@ -432,7 +428,7 @@ static const struct qemu_argument arg_table[] = { "", "run in singlestep mode"}, {"strace", "QEMU_STRACE", false, handle_arg_strace, "", "log system calls"}, - {"seed", "QEMU_RAND_SEED", true, handle_arg_randseed, + {"seed", "QEMU_RAND_SEED", true, handle_arg_seed, "", "Seed for pseudo-random number generator"}, {"trace", "QEMU_TRACE", true, handle_arg_trace, "", "[[enable=]][,events=][,file=]"}, @@ -687,8 +683,11 @@ int main(int argc, char **argv, char **envp) do_strace = 1; } - if (getenv("QEMU_RAND_SEED")) { - handle_arg_randseed(getenv("QEMU_RAND_SEED")); + if (seed_optarg == NULL) { + seed_optarg = getenv("QEMU_RAND_SEED"); + } + if (seed_optarg != NULL) { + qemu_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 208fd1813d..8f7125cd67 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 @@ -5448,6 +5449,7 @@ static void *clone_func(void *arg) put_user_u32(info->tid, info->child_tidptr); if (info->parent_tidptr) put_user_u32(info->tid, info->parent_tidptr); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* Enable signals. */ sigprocmask(SIG_SETMASK, &info->sigmask, NULL); /* Signal to the parent that we're ready. */ @@ -5534,6 +5536,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, initializing, so temporarily block all signals. */ sigfillset(&sigmask); sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); + cpu->random_seed = qemu_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 Fri Mar 15 03:26:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160379 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16270255jad; Thu, 14 Mar 2019 20:45:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwznW85AWxnf1TM9Pl8mzLqWg1QDvVdRAjbIaCobUVnHIymBgiOWwJFl4ra6MeS/BABrDTu X-Received: by 2002:adf:ba84:: with SMTP id p4mr751557wrg.156.1552621507635; Thu, 14 Mar 2019 20:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621507; cv=none; d=google.com; s=arc-20160816; b=fd9GpPTN632v0107oiwCeIYXRCA9LqXufnYMHfvXqXtx9dyalVIFZsFD5VK4b0ttNd r7177bl6D24QGk1W/NM7J3BBpaOaXAT+P25UOMNzjWtN1P0p4vWqA/B8kLReKcO8a2q8 7enIRRsR2d2NCIqF7toIPvs8wuTv4EHhwjf8NI7tF5dUwUv6UMDPLH6K5B+Uwy6cuLZf pw8DqcQSLfEmyfpxhSOfUjRQV20LaphsGg2mTBfWMp5ESPCp2Fm655RkYZktoMEHFZUm lXzKVtHp0eXkY6/LTTTzRcFR02KeENQdwv8JOJBNrCC5/KKbKlscOtdjflNzZWfYnaND Lv+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=QIfc4JulLMpRI8ZlPuSOcyyKpv9m8t9iZ59mu5JmetE=; b=eBYikN4JhhgB/K4ycix4jlOe6Y5vcqB45o+jXF1o9HRrJplI3EQ8GH3lptg/b8QBcl i2lrkNbHGiqtVH5uC1GsE9sPqXfPPpPLvurIlz0aBsMJs+LKjIsmS4u55CetTVCVqbbH CmE0uCDx7RDmysVevICjFAoOqUladVfgm5m2WnbGVcxO0OZTV1gAveNXPmRSN9RO6T+k CCUwa9JW4sdZQWIW/VJ+76B0QNsELIL77ZUvijiUY9iY+ok+dk6/eS4ngvNmN/AD2ltV 9qzwlw5yqPd+qojHwZi/gZ4vhdqX2iZUIgzrn0CuKhsHOKZiH/EdcnGScLSVxImn9mOs LzhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="cWo/ItSA"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f2si728455wrg.180.2019.03.14.20.45.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:45:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="cWo/ItSA"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dmM-0005Zp-Fn for patch@linaro.org; Thu, 14 Mar 2019 23:45:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcK-0005BE-CB for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUf-0002wV-BM for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:50 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:33157) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUf-0002vi-2M for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:49 -0400 Received: by mail-pg1-x535.google.com with SMTP id i7so2200787pgq.0 for ; Thu, 14 Mar 2019 20:26:48 -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=QIfc4JulLMpRI8ZlPuSOcyyKpv9m8t9iZ59mu5JmetE=; b=cWo/ItSARXLp3RHm8KLtpECFBws+44Paaq8kOtUYKvWRhOY3j9g0i/tDgeyH32iFwb Swtf0sveMpN0/smRrO558SNVagg4qg0SCfclvmeNqBDv/ZTN0c84x4BYp1bVzzhbiJoq 6o9k7nfTYOj5lxRwNU/wbzwNrSCQ9M3uJVd6JaV9qHU3DcDeaaQoBZglqmBPue7p+E5Z BnytbYzBktZOl2j8ShBF9c/pV4NevgFvj3cxtmrQ6d5eh1+2Q779PDZVy3ef9nMa+8u1 eZu+ruld56hqzAlJC7G/vPvA3rWPHKjTVJYzLC99OH27JOcLcs0Mb0g8BnSYhT+rXHzX se3Q== 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=QIfc4JulLMpRI8ZlPuSOcyyKpv9m8t9iZ59mu5JmetE=; b=Jri5Hy7H9L3yPGdhouu6g7aoXEjePCREwmc71SyOgW3P+VS4WfxpyiB3SWv2WU6toj qzWspzeyrlLv/0nEcHRDMZv9LkZhGJSYvXm7vv6Sh5WLoDXAAuF0136g8LcFfOXCenrt cr5O3Up54ROop9OmXtvykI7DKDEOuOyOmfSWaZ7gnpT4+1DIGea2t3czrJnmgO4PVtq7 xZr99Gs0a2dBmK0xCsBKNHgf5S2DSKZtPYn+C57J6lq/IgqslBTS4X+KvduO3SOGZDhi /NPUWbNZLbbca9mGFzZpFeSt35aSRUzkt0KAoKgUk0j+8O9zYbc4OnmtegKDc68ls+uD UCVg== X-Gm-Message-State: APjAAAUxlXYuMcA+HCkITdqSYacK8SSJZfQRX1q0Z76tXe61s00ZyYPj H66vhdGc85gbQCPUs4BroOL7GIroUVk= X-Received: by 2002:aa7:8a4c:: with SMTP id n12mr1701396pfa.127.1552620407711; Thu, 14 Mar 2019 20:26:47 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:18 -0700 Message-Id: <20190315032629.21234-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::535 Subject: [Qemu-devel] [PATCH v3 12/23] linux-user: Call qcrypto_init if not using -seed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Cc: Laurent Vivier Signed-off-by: Richard Henderson --- linux-user/main.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) -- 2.17.2 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/main.c b/linux-user/main.c index cf7095bdaf..8478306eef 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -38,6 +38,7 @@ #include "trace/control.h" #include "target_elf.h" #include "cpu_loop-common.h" +#include "crypto/init.h" char *exec_path; @@ -686,8 +687,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 Fri Mar 15 03:26:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160381 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16271349jad; Thu, 14 Mar 2019 20:46:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpwDzw8B2wlkYikfGMdIcnltXLy6JcuWvqBFPTz//vKWEiX1c1FiMKhFxUggdNsgvD6pU6 X-Received: by 2002:a1c:9684:: with SMTP id y126mr564639wmd.124.1552621603449; Thu, 14 Mar 2019 20:46:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621603; cv=none; d=google.com; s=arc-20160816; b=LyGAIoYPYh1oTNu+aMdPubvSasBM6/iP9kOBrDnir+Va3qRPYWpgfQOyHGhmTC0tng NILEALK7U7oc36YXdJVFmURljp5otYMqyNamgZOUkW1T6NnPQLY2W2KgN62kX3tyRma4 Ls62rBcTUj3yWtWoHGbf69EWhqgLz9ph9rjzctyr7ZzQrXaSyKwrI6kri51w9eEXNcIC nWEM8frQuOA9a5N+T24a2yz/Uwk/TBAl7N5C7pwxGNF3RGuA5AaMqlVYcyjJQ5AJdyD7 CIMNVRozncpYaJZSh3+6p3voe0fR2VkFJUkNInVOwSgXBHhRDnmpLojzIuwhoNr7mQmx dT5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=KlXWyx52cjVWhIiLC4AwAqaGQyW3OMCsC+sL4Pwitic=; b=zkeWlkY6T1zX66ERPuMYITECiZRnQa3D0n6frHenh355TyQp+PdF7Rcg5+J7UMpQcA ocCdSy3coYYQexQiQL4zZ9lhoGFpeIhqZmYN/zofTO/yMVZPZ4gho1YWK0U4gWCnCWlJ 2H8QIQYa2+SPcquFRU4jsTGwRk5uusMySPkN/7TE0K35eL7RZm52f/5FclF/s1UEKRXu A4pknOLQ0MFW6Ctmwi5iGVTMwveUxTw7PM50U46P8fCWLjS59pgQZP4CHfq6+JV/ce+p WH6SGqH/g1GKUphTNrc/OQdJ9JO9s8J6xsPCBlMDzNILM4gDGGYZ/P45mGkE8hVVXavS hk6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vYhjdfBP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f1si397535wmj.114.2019.03.14.20.46.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:46:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vYhjdfBP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dnu-0006p7-89 for patch@linaro.org; Thu, 14 Mar 2019 23:46:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcK-0005E9-Bp for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUg-0002xW-EJ for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:51 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:35643) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUg-0002wm-6B for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:50 -0400 Received: by mail-pg1-x544.google.com with SMTP id e17so5418189pgd.2 for ; Thu, 14 Mar 2019 20:26:50 -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=KlXWyx52cjVWhIiLC4AwAqaGQyW3OMCsC+sL4Pwitic=; b=vYhjdfBPoMTH70TRQosxuU9KQ4SzOV2sYgI1+iQaiulnzb7h//9UfIzncKDxIjvNqj mdw2wqz4PKstRWrt+sdDcErzkrsArKjPWstjHPmeqlZdS8gdcAwEyx56pR3lDjKUsILs u4fE6CXZIdmcoOjxkokIop0OPwdXr55XdlQdt6nG57qTGlnfRtEC+pT3RhCqOA7wjiDR acUJXZomhLvnt7Q8ZIAwXV5cbcN4yniDnwLkMCoizZQvbXf9NqtcT5ovL/hQQAoNeVfZ KBpPob+zuESVUT4XvWkHZ2LbpONlXTuUgtnC62pmI/lolBlANb4duyVN0aLEWsT2TjlO XY5Q== 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=KlXWyx52cjVWhIiLC4AwAqaGQyW3OMCsC+sL4Pwitic=; b=M4+Ma7ayfNxDGuk5nUUa+4tY07mlL/5Hi1ch2y5vAhWusD7J44AuCaxf5Lfchzcb5E 0cFrZ1IuwkaVAm7Eo0MTePAt7unbZL/rfer3rFS+ULm9Vs9yLjbnpkBtDs6tEahmhths PTNGgitMCuD3dBSEBfWXaTMmh4z+25UHYMh7mxR7ZFg/1IBcR4LkAABQjVELVmRJgsa3 hiKbrS0AidNNTCQMyjiTGdNQlMVXpLMNaiWGQtDbREiF8SqAUHbK2qP1x6jQfohqAA+a Xk0VAKUYOxuvfBF6pTMBo64FFzJp/xhPr+R660KNKgtVEZV00E3TAkJHT9GGxmPsmXgO QQVg== X-Gm-Message-State: APjAAAV5olzmVquL533wFFWlzJCXVibXiDoBssCC1UMxVSgFNuMQnsEd 6wvyPyC7ToAnaZY4E0mXY+Nf9nnmWfA= X-Received: by 2002:a62:18d8:: with SMTP id 207mr1735301pfy.57.1552620408948; Thu, 14 Mar 2019 20:26:48 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:19 -0700 Message-Id: <20190315032629.21234-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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 v3 13/23] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand * 16. Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/elfload.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) -- 2.17.2 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 Fri Mar 15 03:26:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160373 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16267810jad; Thu, 14 Mar 2019 20:41:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUpOb+Tuvk4EkLURKbmeZY5H9LT3X3Nug0h3QLc2vrTnIjTUenjVLUSL123DOzignyWZ+M X-Received: by 2002:a1c:80d6:: with SMTP id b205mr546601wmd.109.1552621265756; Thu, 14 Mar 2019 20:41:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621265; cv=none; d=google.com; s=arc-20160816; b=y3g78iH2KrJNSxs2N5YcDKeEgVIV25wxAR8iiFL2j/uIttkW7LU7aoizShziyswfbr SW0SrZDmU7sHYrAsvGd91qxtTDQQ/QqvjxKx20Tl1wQ/IfywyKFjnUGuSiij82SYpKu8 oihgcU2WY2R9iMU5sDrewdli/0qFwdNcX5l+2awVfApB1+jOy21g7K0FwOQmo1E4G8XT 6WQrbQ7e/u25g9p6ufuuYvknKNHylQNx9P6sTHnSyCxOozacWPNTyTm0bKpd86dVdlfu PESxQKBEOwvcuM6iN4hApn2qYnXPQ/FgLBA4Mbus51TM3ZFfZoIwxhXnrWgDD5LZAAhH HUbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=mXQoccjIkNzBXVOgwJvr6ZSlCfefC55dbdEM2C22DlY=; b=ujGgJZoxQZwBhyRfqG4R5d6w+YeFFEdAWlwt4g/i+Cx4VPQYgvigKW8FNExtBBDas0 FL21tz4fzeuaHmkWLkDAyxvB9ssddOAnLg7apx08mmMItF8dw7gFKsmTtMK6wGvx4uJf nLY51qLYp6TxbsEObTGM3yB2dU+uMncklkgSGg3wL4ucZXTKHp3ZLBGDF4uRFcXCqY0I CS9L3rBhiPN1XRJcLNpi+KQHUg2UHkGuXlVgMs16prLilftIpwNYLkwCRwVNackYd0p8 j+TD9BJjHXCqjeyzuPoYgnHRx8Q87E+6ZEVN/PNNZM+trZuM6omlWlpHB6yN844zTv1D LDlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cdVPw7Xf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g7si433747wmk.52.2019.03.14.20.41.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:41:05 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cdVPw7Xf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4diS-000270-IW for patch@linaro.org; Thu, 14 Mar 2019 23:41:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcK-00057Y-9x for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUh-0002yp-Sy for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:53 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:40501) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUh-0002xw-HG for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:51 -0400 Received: by mail-pf1-x42e.google.com with SMTP id y124so5272351pfy.7 for ; Thu, 14 Mar 2019 20:26:51 -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=mXQoccjIkNzBXVOgwJvr6ZSlCfefC55dbdEM2C22DlY=; b=cdVPw7Xf6LmFJKnNUWtKYcwinUEuezeu1mlsZUCbfKMQks/itHVIMB7m9ljTxZ6SsJ 3ttrqg/e/taAPIEN7tkrKrDs+G2qNJtNirrJEeXMqwEpYshQbnuBX0BR2/s7QBmBCbQ3 6IYBSLLobfCB8SeGBNCY74dTOa/HmSfOqvaB8UOprq6BpSAHLCDWJj+u2g0+SY1TeXV4 eCvSodFL/rQSujPTBLDwv0LHqCRu17IHDpAbazfaEVsd4kwrMzbEKa+P883CdFwso/Gf aGm7IzK0Izj9k+1zyUjwUOZLJ7TsG/xRU/tuwbZrgOf2JTk5EaGRV1ivpJVPHk52aXTU Kkug== 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=mXQoccjIkNzBXVOgwJvr6ZSlCfefC55dbdEM2C22DlY=; b=qTvLdKHaGbLypcxL7Kixp/MuR6Hwq5VJ0ulW36sC44Q6oMAUZ29/rqLoUzksHTp1AN H2Tie/lRA4rKGyOcDW3+CjNjh8P6OecZSZLG+r/gCKn6IFvyToTU8oA8mHJiqzAYb/Y6 jR9Ip1hqaWoaNVk+tDEvh2r9+ooSRADfnxdbp/lGSMnN/AmnBGHmWI4vb/4chebT8zYx c+9+xmRjTtTEn3NdhrN93WvXxGgaDhhGN59BpVsfuwL80g1biy3vqh7mGBfX++h8PMRR kUim3XjYXniAKQ4pemWUEYQqBu/gZYZ7gNs45Hhj+nTEPbt6m5dCnmqVO1hGWXoC+lxN mCMA== X-Gm-Message-State: APjAAAUY/C25dXB16Oq2H6r9WRd3OHKshuhrJTfjzDuOrkZLkYoYOmxX KN6Pt42bn3MWKcE76gs7lprTJR8wK1U= X-Received: by 2002:a62:5c4:: with SMTP id 187mr1695662pff.153.1552620410125; Thu, 14 Mar 2019 20:26:50 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:20 -0700 Message-Id: <20190315032629.21234-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::42e Subject: [Qemu-devel] [PATCH v3 14/23] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand() * 3. Cc: Laurent Vivier Signed-off-by: Richard Henderson --- 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(-) -- 2.17.2 Reviewed-by: Philippe Mathieu-Daudé 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 8f7125cd67..c2168db1c8 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 @@ -9731,25 +9732,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 Fri Mar 15 03:26:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160374 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16267926jad; Thu, 14 Mar 2019 20:41:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOufRxVzxsDFJ7Drp/yi9i16f75juJnVouyyXdwXZD7v+vCaKB+JWcuahWydRHKjNOg3YG X-Received: by 2002:a5d:5108:: with SMTP id s8mr645296wrt.99.1552621278198; Thu, 14 Mar 2019 20:41:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621278; cv=none; d=google.com; s=arc-20160816; b=CFDhlaWZlh2nnFZ/9w8lgwrKVh128ZQfRRaNtyCEEKFS+ct7E+SsUffgZ9txOPm6TO aKBKoPMMyVP5Ygfp4jE7BCZ8ZwBjRv40HTSfL6OBFzTBHwLuWnZtW4SOy/l2NdrXOx1g 7kK8eWWZ2HGCotnCMIIfh2ucKWaKykjV3/ddXpR6WHhTAG8Ea1g3Yiqv6ikcSERKjihO 4F5Ogmn83xjZnwaO1F4HUfD3+8vwDtGy6Pxd6MOc5qrmrY/QHUSG9AM4PZHjoVMue91E V8+7nptiizIph1XJ7AyZ06uQz0y8A8Kn8pJHxGOhEj4adxY4EFQc3XforAP+SnLwyoeG QM8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=F41mISk5bwRfdJcY6GITxSx+cR75atkMGe95OIJjV+k=; b=VZESTZuOXToqCk4O4bgA3GYlhiImLD7KDiI5069fXYV7O9ork+JR87aPqI8GUzNyED IWqNYHodhePI2iUg29pxxLg/d+0xxsKa77zV/P3DJT7KarmisiV+fH1rp6wgjJm/TzFS OBf6of69pT0y8DeyWxZLjov/mhf/Cq6So7OA/GgDswpVTrNRJGxyp9TxVSqUrXgmzjss 1HYYUo27/VB4blYz9XCsoN/mYXNtJjutoE4aNcdYHCW+BoWfGK4rkq8L9MEpBoGr2KSI OoM0zFwSq8KSE/INSYTmJGqiVKj0HJbAGsHWHx14pj3dLzbbZRuKrRFlCqAeQA+huIGP pdkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MJApcylT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n9si442151wro.266.2019.03.14.20.41.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:41:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MJApcylT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dif-0001w5-4Q for patch@linaro.org; Thu, 14 Mar 2019 23:41:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcK-0004w5-6Q for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUi-0002zx-VQ for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:53 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:38884) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUi-0002zD-Mj for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:52 -0400 Received: by mail-pg1-x52f.google.com with SMTP id v1so699112pgi.5 for ; Thu, 14 Mar 2019 20:26:52 -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=F41mISk5bwRfdJcY6GITxSx+cR75atkMGe95OIJjV+k=; b=MJApcylT+uZZ6DQjkKFN9pH+oafACajjCsf7KUuIQ+fAhR/ZC0hG+XkytDoi8L7X8R aclVjZJj4qPCf8cK1Ci7ATGO/SDZ96YuZqVRAYFtequPHcoonM8FPnrUuOZn62MQOz5u NCaERwxZVI1Vdh7PEEvRW50TCWFz5GKoOGKI0UWxaRaCg1mrGcSrov9YXawH88r0tZHr nM5twGMKdl4n1DC4LBQYWburduuGmYtssr14AxLvxgZcqDV0J/BnHeT9NFnHzzf5qVtB VYtvAFnU41ndbspd3Vakz6IVnpNjoBl82Gat5PzIdGpiYtuz6OW9T35h7vPKZHLkK1QH Cjsw== 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=F41mISk5bwRfdJcY6GITxSx+cR75atkMGe95OIJjV+k=; b=Inh2YW76XYJOBgA/c2/deYH46j8SDZvHpkM7Ueqe6ZA/lDG6JtqVA6D2F4larDGm8C C/MDDZl2OsdDEKJzaTgZ7UsjR5GfNbWxjQug4IijpE1zZfYdgSGT/OuHqMqiJmCegSC1 z/KJlvKhqPFyPUZl9P2Nm0d3W8rLhC0zhEEqbtGP4LQhik/fjCPhROjSNENKc/J4cOBw KAFb1XXPAHwO+ugpPRLZtDZd67Z4fhmDHF1yQjSuOp3QUOfJT9+B9X1GGDE/rl+Z9DkK 42T54uPfMkXG1FiBVUvEFghtISSE4Fc3NeYG8M/HMKgaHgP1d0JUmwM+YwcwwZCpQ5A/ 83dQ== X-Gm-Message-State: APjAAAXClVqkMQfVTWK/maIPxVp8T+ntS+1VWF2gC/bWZOKUK9GIKDzJ GsvBF/vOEkHwLINX6yp7rlfPr9dcYLw= X-Received: by 2002:a17:902:22f:: with SMTP id 44mr1849955plc.138.1552620411510; Thu, 14 Mar 2019 20:26:51 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:21 -0700 Message-Id: <20190315032629.21234-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::52f Subject: [Qemu-devel] [PATCH v3 15/23] linux-user: Remove srand call X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We no longer use rand() within linux-user. Cc: Laurent Vivier Signed-off-by: Richard Henderson --- linux-user/main.c | 2 -- 1 file changed, 2 deletions(-) -- 2.17.2 Reviewed-by: Philippe Mathieu-Daudé diff --git a/linux-user/main.c b/linux-user/main.c index 8478306eef..80cb9fdfbe 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -621,8 +621,6 @@ int main(int argc, char **argv, char **envp) cpu_model = NULL; - srand(time(NULL)); - qemu_add_opts(&qemu_trace_opts); optind = parse_args(argc, argv); From patchwork Fri Mar 15 03:26:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160376 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16268507jad; Thu, 14 Mar 2019 20:42:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaqGfBwxva3cHdy5iQt9mxvZ5Xg1Xq+irQ8JHdN+/99O+74lLWG9ylnUqQE26MiHLdTyXx X-Received: by 2002:adf:c082:: with SMTP id d2mr721950wrf.55.1552621337004; Thu, 14 Mar 2019 20:42:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621337; cv=none; d=google.com; s=arc-20160816; b=H67qOMh7goZqCK3VS62iL+nyNyeWlGGsWwREl9Htlp3XpLiwSrbhJb/7GU4JY7ZwJC SUbTU62aNWPQDQVKL0iEy/HkPd8DPa0ztpugbr3JG8010USxjzrvasQPl7zNXC6P90Uu 2b4Ft6sFlsdL2OOgOcnT6gCpKcta0avQT6EimhbUt3/lCneeA6JeXy3LWr50f+OslJK0 Mx6rUuogEADrhveUiwm7LAz3XGwv5aaCqjx2lqdIF28QSnUN4/7nQJb3ROQbOcSF/CmM NZQVtlaN1cz1BSHj9lrFkuvlNJ0lr5Hm7vZj2xT9wcFpKBaC2JVq/SPndiOVdXTxG/nn KlzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=XMJVRmxir4vbfLAyTItoiDoux1wKrsQiL1gSDEPlj4M=; b=DrbP7yomlmGyYK66dIctrvOZjyVvukAw3CyVFYV1etRPrujiB7t+A4rVhGcvC1s1kx JQuEyocd86HiepLWn2iqOmrhd1EBM1lIMlustYvAfyLnYKvaYM0pql53zRvHRWZJU9RZ OVipJyJwdLtauNqy75yum0UrxfJhj8464vtY3frZc0i2R+Fe0zi+WnWuygVmBW+sToaK nM5JFaR0njVFDunhsv54WOHXOIkWgNns/59YeLnt9AAPq5rWZmSNwSt6hpHx/fFHnmCn 3lvT86ahyrUso8LOauyKqwc0PvAkliISzCOC8EFzOgGyes2BivKhs8Io8Rkcj602hqw8 LXiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SjjUwj0D; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y7si478437wro.195.2019.03.14.20.42.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:42:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SjjUwj0D; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4djb-0002iJ-Sm for patch@linaro.org; Thu, 14 Mar 2019 23:42:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcJ-00059t-MU for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUk-00031F-9V for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:55 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:41866) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUk-00030S-3a for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:54 -0400 Received: by mail-pg1-x52b.google.com with SMTP id k11so5397726pgb.8 for ; Thu, 14 Mar 2019 20:26:54 -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=XMJVRmxir4vbfLAyTItoiDoux1wKrsQiL1gSDEPlj4M=; b=SjjUwj0DUmXlWaQVjmBAR0mLmUigqY+iu0LKulaVGDW1cO5tt636tS3ngti7U0o9p7 t05Mg6hSUUtT5wmQxwaH/RLWz/nQCUguWfHZUTt/wwF/lGiRCscOJZiEfuOXcFXKtXfY uTmbMz/T0/T31NB/LGm4BgV9TBD+myO75R6aLuPFl0OzIPsQynZxDoe89z7XlzitgEep bOPHbBcczF1v+bCtKH/cqlWCvg4QH0/uwQPIEZKPDqvXn4ApDXzCtyDPjJHbIXoZYSMZ besBzNAhJgSRXgQfAM/bvfOX/U5pipTxmMcS6zPIgQef3UafpnoB6gDMnzWWzwqIVWo2 8aqw== 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=XMJVRmxir4vbfLAyTItoiDoux1wKrsQiL1gSDEPlj4M=; b=UoG4APrCYOiLueBuJZYoU/3d9vqJgojzAX0/R695FvGLjtmXheyEEJT3ikq0phfdas z/XWKVe3oiRpihWBIvkwja76koDo915LusykXUL6D041UUX9mEapWEVLqciI3+jyo9xp OXRFXCpo4JX+hU4Fmqz12743pFOp4dKzO8BWmMTms0Ak5dABL+jiowt5Ayj/BaJHqLXi z+0cI1/LOez4opUsfWkT4TZ0IsBlqzb/3dof87h9WLGQlclrob7pVrJkmiklYFNWhXpr nHviQjn2AbGeig0Yr9yNGaEHb4S0Gvv5WrIGsG0tX8e/TuOOd0XLAd1kw62+83MHInp1 z2Aw== X-Gm-Message-State: APjAAAXWPbq4rEcUH6zpO6XIAqz6Cn5SmoH0oreLhJ7cLucA1vPSUktt WT7uXZTP5ohETmBH9RsnEyxpcqELsVw= X-Received: by 2002:a17:902:421:: with SMTP id 30mr1809917ple.142.1552620412804; Thu, 14 Mar 2019 20:26:52 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:22 -0700 Message-Id: <20190315032629.21234-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::52b Subject: [Qemu-devel] [PATCH v3 16/23] 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, =?utf-8?b?Q8Op?= =?utf-8?q?dric_Le_Goater?= , Joel Stanley Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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: Cédric Le Goater Cc: Andrew Jeffery Cc: Joel Stanley Signed-off-by: Richard Henderson --- hw/misc/aspeed_scu.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) -- 2.17.2 Reviewed-by: Joel Stanley Reviewed-by: Cédric Le Goater Reviewed-by: Philippe Mathieu-Daudé 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 Fri Mar 15 03:26:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160375 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16268212jad; Thu, 14 Mar 2019 20:41:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqy0vmqmupxYviQ1PJFAOiT5YT7DNmK5RXNZTrNVuuS2E24pkV6l1tWoxa/9+BqExT3tpB/w X-Received: by 2002:a5d:6b4a:: with SMTP id x10mr711574wrw.63.1552621305016; Thu, 14 Mar 2019 20:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621305; cv=none; d=google.com; s=arc-20160816; b=VFDAz8HVJQzZH3DJpoT5i0D9ZWI4GLWGYXylMv0WYVdxOQrm8R+E6X3mPWbtX1yYY7 TZYoBZeqOvgMR2R4YczienbReY8PU4+JDZzHiLeLMaVJ6/AGeIHWHdMRrsNcV9CN0I9k 23GB329Z8vp4jVgHVapurs3o8ZGW4xQKJyZg/JMLnmhxsRzzoiDyi8dXS8sL4fBBQ7JF GyLxVmiBL/n6KkCh8Ch2QT10iIxrMaFCj5evomx39VbNj7YNFfhrJ4PxD6m9ClSFedrL oNCsuxdTMgQCuY+OQkIPcaImWRrJhqcd9qtHPIHvp5qRYTUg2rTgi0233L5gHDAYprQ9 LYew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=40dndFEh1rhwW/qt+1fjHft74TzjNjRDxNO1+LXr9wE=; b=XR5Zbo49bs8WT9ejoGs4pks3S5EbfhaV/SSVeB/3jq1uCIU4gK2gEPcAn8jLCb6uqS VfyGzszzFvaUmcFU5NPfV+35e/hNwxxmAC6Jw3B5Eref+j5lkna3Z8ZKXkuVLlsNp9JU XpAG4EaNAXj6jfuUNZbUVTfDHnC5YZUBFJWIp6pQ1xnFwUVMOIcoyPs0l+oZbzv9m6Ci z76UFPPIPRZT9ZXqYLudYLEBf9EmB7QC9RB7B7jX2QjuLy2SZ5Rdt26TManzkG1RK9Rt n4uDZNERE048sz+Af9d6BvtPgI40ujpqj8aAidwTQXFQhRVCiPZXo0v5XNhusSNZ3WyW IRHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CElIfdGm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v8si576208wrn.324.2019.03.14.20.41.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:41:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CElIfdGm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dj5-0002ds-VS for patch@linaro.org; Thu, 14 Mar 2019 23:41:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcJ-0005BE-70 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUl-00033v-DP for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:56 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:37579) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUl-000328-77 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:55 -0400 Received: by mail-pg1-x532.google.com with SMTP id q206so5414355pgq.4 for ; Thu, 14 Mar 2019 20:26:55 -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=40dndFEh1rhwW/qt+1fjHft74TzjNjRDxNO1+LXr9wE=; b=CElIfdGmPne/v85S7uvHoo+rC75WrJUtTc2v2CGF+exW2XWwDkSLkwUeCfvH6LU2+B X118oR5cpp7GM8+q6hYz+T2UXGPGNs8MHFfC2AzvkLorMv89ftqeiyKf2abFqyEh5oPA xPQz5LjG/hdV+qbF+y5h02oQuMsZqKsfIy1IpvYpXrZq3dVbxBgKHhU/vuUk0dih7Ika cygEiP8lKcdLlWSTCQXiYJEaXYqh8cSMMEjlYc2LwDKbvBpYoMmeSLNE371zTG260X9A G54+OeOf/8T41M5zjL8jZCcer21BI2UbklnjqCQgcWuA06Ur0HzY6oVo6HdrqQmnAZmI FXhg== 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=40dndFEh1rhwW/qt+1fjHft74TzjNjRDxNO1+LXr9wE=; b=RpcbWatv1ifcEut1rCk87BE/ku/x/BzSuJqDfQODr9nt/Y0NCgYDV0G791yMsskvo1 +iOHyjTpdljzVq6EcX4XgojJO4TQkzfWE8Ho0mkZD00oXdyO+3VH39c9QNxuzsNsO3j2 pz0C4/dXjqw73CBPzwpjt4VDLJVwAqTIjjMUop6llOzd+LRAM5KfTpo/ZqorRqgSAtwC hmb2WxBbQu9D/vMYJO9lw0iDfxGYz671HXhZrCtqzXRxzpbP7zYQsYy8fUFkf9KL5l0F uekjWyPjga0MBryBCyR8aBhXUB2Z+mkU4159XYp7yFTx95pY9FUUoe6RGPtMiijSyZNG zCBw== X-Gm-Message-State: APjAAAU/bhfmZ92LyWqm6+QXkQjvCljkoXCI9KZDavG+ntPMIXk0BR3x ITvpTMPPf5jf9aPJCvHnQKE+UVSi44Y= X-Received: by 2002:a17:902:8a96:: with SMTP id p22mr1783432plo.113.1552620414022; Thu, 14 Mar 2019 20:26:54 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:23 -0700 Message-Id: <20190315032629.21234-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::532 Subject: [Qemu-devel] [PATCH v3 17/23] 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, Joel Stanley Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 Cc: Joel Stanley Signed-off-by: Richard Henderson --- hw/misc/nrf51_rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.2 Reviewed-by: Joel Stanley 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 Fri Mar 15 03:26:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160368 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16264723jad; Thu, 14 Mar 2019 20:36:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6IXDN8XrOfmGQ7MZy4XJBexYC+Yvs7d0wTszrhQFBy0nD1KzEaG7A1HUDUxjswUSsgumu X-Received: by 2002:a1c:cf41:: with SMTP id f62mr549651wmg.1.1552620975650; Thu, 14 Mar 2019 20:36:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552620975; cv=none; d=google.com; s=arc-20160816; b=cTXkAGK0bZILCAssvBujP0IFI1TbPcuF/W8Pok0A7MyoKRNVQ6pwv0LxING33IoX16 W7i8DMluaBbGhlcJWrsImm64QKB74yJkF8iedJHZqEf4qF7Ef93V//KYzqGPK8VthIEN 5kTPH4lgv/myT7Js39d7flpH9M/KZojhVAWVFRg847x4v5piLsak3mtDLCjPSLH4WKGr GK4OR2LMbXn5JRCA5ns9e4ghZc/QXpY0XmgtAV1CbSylDbnMKX/3vBWa9BGjDdcdCzd+ 5y5sq/HH7H8/oGsrikK9AK8tbn4TNpulbr5lhzvD1y5qDNvpF1RidufNWWSPF+A3mPvX APIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=etLbcy1a7zqlIhvc39R877L+TQ7d/3g/A8LNCCGc1X0=; b=VEeR6reQUMXQWKMcXLlVMZoFCYZ/Hmv4KG672YSj8dImj/eSQs2CfxAIM8J7cSo7xd Hs6zRXETTSiVwG7umxhlzcDqi0Nm5zSLAjVVbadG/BBnYSEBRb73Euh14ouZ/BtTuDiV Ev75ramgYh5wIUfvA89+yWu1N7Gddg7TRMkFwvmxGgbmILDb9lE93vyBI8QDz7rZgVwd AI0wkoa6vhrT8vhU4SNh5V8MJiWrS90TWmlfnn8U3/S33Ef9IVcRgILoux87yTuv2msl 7IVN4YnmuPLWLsX4uJEg++7aRGdoWXN1c0mf0LZ4kh2tu6xsH129tv6vGWPxcYvVE22U wg5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=N1+YCvWS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z1si439429wrw.95.2019.03.14.20.36.15 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:36:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=N1+YCvWS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4ddm-0006Dz-FH for patch@linaro.org; Thu, 14 Mar 2019 23:36:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcI-00059H-QB for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUn-00035j-0j for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:57 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:34603) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUm-00034r-R0 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:56 -0400 Received: by mail-pg1-x52c.google.com with SMTP id v12so5434042pgq.1 for ; Thu, 14 Mar 2019 20:26:56 -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=etLbcy1a7zqlIhvc39R877L+TQ7d/3g/A8LNCCGc1X0=; b=N1+YCvWSZOazdw53D7FI4pwwRuL6fG0KC9IfI14M03A9rlUsT4yiUnU8KTBtH4zMG6 ONdH/EHITdbj2n4vy+lTQgkNcNNDsm88ZSFRFjcpsjEkQd2h1+6U8sQLkR1jRP/65AF6 5LZOte7687WnlGApjBrbv4iwMZ2406I/qkkL66dCtrI62E5dZBZlnHGDllqyNQsYOsBN xXk8ZqZZAK82CZboonh3pLOXGermxgW7h0v18CCTi42iWQoRcDjoqt9v8c+I7FFPxOjd 3FHqqQjhD7/5p6IR9g6seCgAjw2MVd1GYuO04B8CR2rSO1MlXK/GIIMZUQKJrhjn5f9C QgwQ== 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=etLbcy1a7zqlIhvc39R877L+TQ7d/3g/A8LNCCGc1X0=; b=D5KfEr2q48R3ZceAxMeQsr/jzOcY6D7WVXGpKtRu+RGEG2/BH3cl50VidE0AOA/VkX EEd01nIf7dyfaO6t24rwe9PBX8fIXf17ZjBqYvyncX9OLgDTJJlgE+AX3RwToSDs+CZC lGBQetLPcWUhnNhcSeW3gxgrmtrs5DEmw2MvGPJqY+3YaEjTu4NefJomon8SPFBMJAWq LSTMdz6r6o41ENxZizw1yU6Hn222zwpIVqaQOXgGxkFl8+ojswAwlscyLHQ+ISCU2a/r S9EAAmDv0rYKF0QCpzybcaUaFqRYOJZWIU3dT64UVueVQAwYllmOPZyEl5uKyN+Rf9NU DqHQ== X-Gm-Message-State: APjAAAVvEV1H4QgUEgNTDLxvM7xhErbcC0bwbnjRYZYSw+en6ORJQ6tm zzdfR4yCDHapLeFgABrTjZihWjjBrYA= X-Received: by 2002:a17:902:1002:: with SMTP id b2mr1788447pla.248.1552620415419; Thu, 14 Mar 2019 20:26:55 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:24 -0700 Message-Id: <20190315032629.21234-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::52c Subject: [Qemu-devel] [PATCH v3 18/23] 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, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Andrew Baumann Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 Cc: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- hw/misc/bcm2835_rng.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) -- 2.17.2 Reviewed-by: Philippe Mathieu-Daudé 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 Fri Mar 15 03:26:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160372 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16267662jad; Thu, 14 Mar 2019 20:40:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxp7xLucbRmpwt0ZfXeaf+ieiTP6Tf5Uc7XDfq84c6fwZrsvDDyuWZroyJFqjyEb0XPMWa X-Received: by 2002:a1c:ef0c:: with SMTP id n12mr559306wmh.105.1552621248789; Thu, 14 Mar 2019 20:40:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621248; cv=none; d=google.com; s=arc-20160816; b=ULIVR57eZV7hxfBD0P5Vogt9RyQggPjJJlZG4KQ2wcflF7Q09nUoWYIRX7p3SI2s0H xM62Unix8y7pODAjAiJYErt806GOwJsREgeAFC6VnVj2krPB9iK0OGUVQlRE9hsYPVuy p96tCb1T5FjoG4o7yz8bFA/V70sKMpKAVQ5541cwOBHmYuTtNZghpw1i0SYLMCDrBNV8 MjufUnaW9PAG/WxoB2CAWDZR1K2ykGb3Dw4XnlA5K65SPWcUtrJUG5eMEk4eBPb/enOy YKk2p1N7cv3+oKq4B9Y8QlUpSZZmQ0SMaCHrdNd6+0XhVtecTUSx3qI5hSAQ0FkxsEEf 101Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=wbb+2FtxbsNv9nDIL4ojxmrs2WISC5sGRSdsm2e7KNc=; b=MtwTWe95UZyv7pG2pfrJamxTZNsgLZsoMVyZJo3c4Q1drmzD8jw5l1Umco17M0db8L lo0ybPtsW+5pdXDJHPF/LNGdmhbIhthtAtBMElOT5FZrGN+iOnF4uEmZs+V5R/DRl0vM zBJ/a1yHoUD/ERTXvEa5occ/6x5indkUYCkPHyX9VL9Im3LvRwJ2TM79yXlDHtOR4RTL wpuPxsrqxdou7VjxlIiTZIbmLLt+Gs4vnWA8p8qPp9a2SEEFyjzHmEfDwbIpuqZfqvzO +dTQHP7tG4r4Ir/4V3WgwjxE/6WFXKJUlAomYFHUfxZ3wmjscuDMc2/tWEsrpnjp2hHm DZIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MpbBVGj6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l2si2478275wml.1.2019.03.14.20.40.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:40:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MpbBVGj6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4diB-0001rc-LC for patch@linaro.org; Thu, 14 Mar 2019 23:40:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcI-00059t-MP for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUo-000376-Bl for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:59 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:39945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUo-00036I-6C for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:58 -0400 Received: by mail-pg1-x52a.google.com with SMTP id u9so5403507pgo.7 for ; Thu, 14 Mar 2019 20:26:58 -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=wbb+2FtxbsNv9nDIL4ojxmrs2WISC5sGRSdsm2e7KNc=; b=MpbBVGj6KrFs2tVEETUExFUhEjqs/GUUqi28oWfBgjJR2MIBDQpuuWcAmXm72g4VB4 cT7OFFGEBnx0tpNzD672yvpL7Mh4CYbkC40a5qIfIiY0IJ5UmFFjnhkwHWtmLwi8MEON Kjpf6aR3vr/wmvaPrTfIqDq/NMFtuvvoDsLE05uWyAgmNQJCknUugQbYhicdE9JUoHVj qEW7+7i+pF72dsesyvegmtp0g7K8ZmjxNJFvcyYPABxUO9vXuwP6zU42EnYLGQzwmcTx 6gPDIIb1Pmw1BKFDuhJoPf3z3l/7jJQZ2XrTz+502ttXx48AGUNiRwlOeR2IDnq/dO96 c0RQ== 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=wbb+2FtxbsNv9nDIL4ojxmrs2WISC5sGRSdsm2e7KNc=; b=bsT8QPJynNG2zw4JvcmX6fnPk6IM61HX8HRPJLUMITotwlqrKcOCxfCteMcUIbAHSy ZUVI/K7E7Flc+Sobr6ePy5y6fRstoe+KcYTZfE5ueO1u53P5y6pYlwpL07mvWC0AdFIV +SKfAvjehYb7rDqBpjGj2QHiG9H7i1huynDdcV98uwFTLfx0OlyAy6woBmljx1bwRlxJ SJH1H68RUnwEwdAAirdBzxgN2jkt4ZdaaDrYP3UynSLCpTIwmmbcefmGCGvO9K4spx3k lP4r2nDpCC9S+DX1wIFoLnMhYkDeS8qcEsETX1odeGrxfo+OmQtQHYLxp5poh1vRNB/n 9/iQ== X-Gm-Message-State: APjAAAVCm/MKDwUmFHqGuFjcibKDhJZpjQ7zLObmlxmx8fFrUcorJZcV in6yPSNhhZbPdNyC1nCZiOhT+lpnKlk= X-Received: by 2002:a17:902:1125:: with SMTP id d34mr1816140pla.75.1552620416859; Thu, 14 Mar 2019 20:26:56 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:25 -0700 Message-Id: <20190315032629.21234-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::52a Subject: [Qemu-devel] [PATCH v3 19/23] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Richard Henderson --- hw/misc/exynos4210_rng.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) -- 2.17.2 Reviewed-by: Philippe Mathieu-Daudé 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 Fri Mar 15 03:26:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160371 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16266886jad; Thu, 14 Mar 2019 20:39:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxD9AtAzBXOs2E/63x4OvLRMoAIZLTNjmkTulaPkQruwXM7RTviSZZDeIRtp3ASus9HxXDn X-Received: by 2002:a7b:c14a:: with SMTP id z10mr466614wmi.99.1552621170350; Thu, 14 Mar 2019 20:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621170; cv=none; d=google.com; s=arc-20160816; b=A1BsaQ4GXpMCzMvrpywtNW6f6zTFJ0fyFYi1VNboZ1z1cddH91Y9v8XxAUvJ4o8sx9 pIDlBnwrImKMP3dyGX+2tRcDD5WVtOy05yMKpzEmx38Hfegg8fZmYyivsDRlZRkJeTI/ Fr6EbI5XwA73wF6TwgWHwkzgMFf7TpywnF9u3Q4OU146A18aeDiAImO91GN4L5T2NyMs DwkgudkrKPNp6Q8H7DI2kY0anxKaRxcYYNdFwdyRO8MjcYlBuMchypax77IYn4ABIXqG K7h8HToyOHL/IuoSmhaxcEH/KWC4w2nvRARFu4vhGV0g5RAjsiry4RsBtqiKXwnNt4BJ DaEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=0RNMXGzNpKfSI3Zn0kJPVJB+xi/AHsbEF6y07Kxt9hE=; b=m8XUD67RjL4PHOTw7BlXaiiQanzVF6dmjJm+Li7XOUABHoDpiabv3l2489Kg7TkESW 7RHxivlahwlz4o9ThqXGshYSkcAATlFCgFn+vRAzlWZ9vb/tPrnMLy2K2vmpZ7Ly4+Ll hDxQS1ibvr+Qa8e/qbpiFrIFMuAuj/t1R8tFT8OtlJNj2AqBA5yZ66LNe757s6mlW+bd Z3hOemt/XTEnxLpz1Uh7IGJCk6uDzUTz6H2QLav6PwdXTLVJBi2XX13XJKcacgejcxX6 D6lSxcmEKzvUCyrsr5Vg8aDmxfoQlcIUuzpuMF0M0nFG2zwAo2J5fjcqtf8qBzw8eBEj KElQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eSlSc9pM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b193si425159wmg.110.2019.03.14.20.39.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:39:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eSlSc9pM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dgv-0000Gc-6I for patch@linaro.org; Thu, 14 Mar 2019 23:39:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcI-00057Y-M0 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUp-000398-NH for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:27:01 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:37766) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUp-00037e-BQ for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:59 -0400 Received: by mail-pg1-x544.google.com with SMTP id q206so5414443pgq.4 for ; Thu, 14 Mar 2019 20:26:59 -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=0RNMXGzNpKfSI3Zn0kJPVJB+xi/AHsbEF6y07Kxt9hE=; b=eSlSc9pMzAVgFMsQVDgdx4Hz9VhifHfio6wiPKqf2up9hGD52fIdYYg6ToucaTf0Mz OrswgbxAP0ZfLRqZhPa6RKyW0CfewsdcKpo+nBWm2Xv97RJPLe0n/08WuwIOdVpF9J1a tObLRGX94VVxBV5UCQ3xE78UEsEBbhYITBMcFXZvKXkT/yeUXAMxfZa6QetKm1jZw1im sWQBVCgvf4/ns5OTdPhm6m02RLGBbSVBlS5q/qoxVa9QOUsLE1W7NIYp67A8Cj8/mpCZ ZsUJdGD8YJDa3VATRfh43+oxdQu0IHcsLO4yZbhfYvUMvVjYOF/Wr6IcJ14AK28o5MEi KXOg== 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=0RNMXGzNpKfSI3Zn0kJPVJB+xi/AHsbEF6y07Kxt9hE=; b=GQzgnhlygrhShlXKODaFPGYmd0sAqUONm9w6qQhceCYugCi7GoYAP7m1jlDWNjUydE WDwCMEq5jEwoNTIRP6Rze6xJcE3vsnrrOM4tYWWTs3zrGzTkW1KR5Rn4qfhPikDup2nj Vw4aUV4em0/T4tOVgrqL5tyXZBNcx1hjtdv3zwhLNwHsuT3TKOv6H2tggcYX9mHRNYjp G6M9T2Nws0QidkAFRKwFCHEp08WsXtYoIpY5fTbmv1vgHSyzys6YfsiBZyebUx8yxKgK h/I19mykSBIV7co8Fot9xZVvFAJeFAt77plChvIXHTfJfKGUrh7rFUwycT1iQlIi4Kss nEhA== X-Gm-Message-State: APjAAAXcQM/idHu+E10uCc04u6NmolGizwEC3/oIX9VbX/B40O1rY+dG QW2QD1GxnFckt+ChSRkm3A28V6FsqxA= X-Received: by 2002:a63:f914:: with SMTP id h20mr1269159pgi.322.1552620417969; Thu, 14 Mar 2019 20:26:57 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.57 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:26 -0700 Message-Id: <20190315032629.21234-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::544 Subject: [Qemu-devel] [PATCH v3 20/23] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This allows us to use a single syscall to initialize them all. Signed-off-by: Richard Henderson --- 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(-) -- 2.17.2 Reviewed-by: Philippe Mathieu-Daudé diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 5f23c62132..ae2381e222 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -628,11 +628,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 c2168db1c8..ebbda9e470 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9741,23 +9741,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 2607d39ad1..7b5d63f894 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5678,43 +5678,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 Fri Mar 15 03:26:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160370 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16266409jad; Thu, 14 Mar 2019 20:38:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjNKhGw/UqK4rA+CBXfTf4gbeJlB74z3PJIwRNUMLqxyR1PqQk9LVroHjlbf5Nd0pbnPoy X-Received: by 2002:a1c:f00a:: with SMTP id a10mr589461wmb.100.1552621122779; Thu, 14 Mar 2019 20:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621122; cv=none; d=google.com; s=arc-20160816; b=SKe2xmKwu9UywwxNDPtXw3wDZdGi0EIDS9BECQ1/buOExSK1aHOBdyDsVZ/r+ommGo uQcF1tiikK8yW+06YiC+y0jjnA3HOKWWcFFTUXD3Tv1n9M8jEuJn5w4DCgTsoHHaMS9V efpsUwIPu2JfPvC0Ic4zjxDiBN5kd5fiGzljgnbjG/1V5MVSGLGBX/flddAaBUtSaTjs A1B1hjkQK4v8VTluNvXSnefMgeP8u8ejvJie3P1S3+fZ4MFawcKVGN8oLoRYvpybiaw2 OiJALVvELrjljJ0iIjljKw98uYypUM1JzlAiMRx/gWQSBDbFQU4JgJXvbIrLDd1NXuaT qabQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=wUaNiLlnpoO4I9xjlRRq8x+Qys7GOrUiY0x3QzlpWQA=; b=fIj352f3s+sX2hAJZElm+WuYfH2wJRhCTXdUr+piiY5S1eUsooW1xC0h0KSvXWG727 ofxliHgpH9pCYqsDTX7ndrEPLp4RsCOYmJwBsj/uLURheafqE3fOdtLxFjTzc0TnNPyU xDIT7qePc4VOsKEjR5dEjLg4zjiqDwpI43WnD2H9ukexouaTb7vTstLyzB4WUvAXuH9s ZUN9tjgKUAZMB/ZrhUQEvXo5i8FXA7fsvNOd/pilR/W4MqL4eOaMkN+T6bP8fvfhXIB/ QYIyZF6XoOlfU0Eec6aPYIn6pYX2Ni+g1fjtBGJpz2sCDBK2VHoM0H5ZUlxeJ/d91IbA GpnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="eJF99u6/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w137si434829wmf.16.2019.03.14.20.38.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:38:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="eJF99u6/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dg9-0008Oq-IO for patch@linaro.org; Thu, 14 Mar 2019 23:38:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcI-0005BE-0Y for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUq-0003AN-PK for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:27:01 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:43247) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUq-00039a-In for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:27:00 -0400 Received: by mail-pg1-x544.google.com with SMTP id l11so5395025pgq.10 for ; Thu, 14 Mar 2019 20:27:00 -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=wUaNiLlnpoO4I9xjlRRq8x+Qys7GOrUiY0x3QzlpWQA=; b=eJF99u6/rZaaOScD53XGXXKCgukmZZ9pb9QlZIslNjMWQegquM6IvFpFosxLl/lS9P cenvq/ikDD3wTm1IWikdr082lBsOyOArY+Q2HmFug056o+3OvzudaLmmbv1CrqCf+oVp 8ZvF45dvX2plSqTVD1a52wWet8b2KMuiIA07cZTIC+Kv3c4ok5RPqqn5XGRaC9g/ZPA4 ak21lgbv9uhOLGjllHVH/7cnJRVQ9/xIYS5Ey2DMoIThQAB/n1b9tsrhhy8/4MWg7aQk 2iyuG3+H0OMZ0fG0dS2FVDWLSzSPNrq/fNgCDG2t1YHKasnmlPwN1G6+/YV1j0SwrHAG P92w== 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=wUaNiLlnpoO4I9xjlRRq8x+Qys7GOrUiY0x3QzlpWQA=; b=N/NQb/JBi6gSDcdlBnBjEocKLohzod/M0Byj71AEKwz3JDFKYmVrgd0sNRluthXPsL 9oyi5t8Znf4c8THf0ULYf8I01nw/Of3GyZmbl+LqqhHjt90yWQ7qJo1IVbKINC5Nvfrl PqtjOAIfhgbci8iyS+i/a8clquDH6NSslNDyg7l9dxsQ3rCnm5NUgyVQglXZIyHoQZb0 aDCet79QKn+larynfUd4Pc6mk86/53GJ/GSWv+5skbPTmQQL/2H8sn0pPAdc8D5Cteds ksbgQcu/4XPmSJG/hntCb4bNNcJUfpFHB4QatiMhaJJ1HL7cRWdND3brzMDasoT8XrbT P5/w== X-Gm-Message-State: APjAAAWwmWU6fnN9HUlblhIl/n2oRxBPr/B6jI3ORAH+rj6ICcRndUKX PTbp67CNCAzND/4Zooh8KlK0FkFbc+0= X-Received: by 2002:a65:6546:: with SMTP id a6mr1277968pgw.296.1552620419297; Thu, 14 Mar 2019 20:26:59 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:27 -0700 Message-Id: <20190315032629.21234-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::544 Subject: [Qemu-devel] [PATCH v3 21/23] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(+) -- 2.17.2 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index ae2381e222..6a078aa1a0 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3443,6 +3443,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 7b5d63f894..4a8d2d4481 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -20,6 +20,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 */ @@ -5717,6 +5719,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, @@ -6661,6 +6702,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 Fri Mar 15 03:26:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160367 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16264096jad; Thu, 14 Mar 2019 20:35:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqx60tztcZFu1CYgB1w6H+aPAiF+XiXXiBtbNkno1ruTAVB/FpCR3eXXfCum0wbhbSqgLSjK X-Received: by 2002:adf:ce90:: with SMTP id r16mr731558wrn.64.1552620921056; Thu, 14 Mar 2019 20:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552620921; cv=none; d=google.com; s=arc-20160816; b=X74SAA4deRsjho5qZya5i3sqrM8RBxZbjeCx7IXqVLIVQ0sIEbMZNIeFdk8MsK0Hpa hgLcFdRAi6YypLQtlDQpVw6R+cA8dJUPQvomxnhCgTgJ/hsSbmWx7xrKCZ2jwfKDwlin 2fTHFQ21eq4ZYMsAbjeD5DAU2iM3MIWhhNwCT8FycLI4BesKr5X7X27ot4Yh33jm6rwP y/IN+Vn7T0JrP74aTABhUFGtgXuOIQIQt47363X05vCFGKMZoRGCz+n6MzfguPMuoPW9 kTjp1jHdjgqhCk4n4ORGSXbRvpIvMzEhS7cabPdd1tAulZftHF5Hkd/RFqMBplhk6A69 cixw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=g09DjJXhGsFzGWxwKf5V5HWGbXw30Sr7rYhBrQNj528=; b=IwX85wUlkI+jy6c0R1P4dAek6tmk4yQ+E4eXpTR89Sv4vWZ8NXEaDjG3x94SFK5Hua LJ4pSYe4wN/3E1IdrfJHd4hPc5FmD3HoMLg/dj/oJpHkvzW+c3V/6kH62oebAsVM4aTx 2DuU1Z4wX26oBl0LPJsLmBPSFDxcfNYujVQVkPru4OjU5GRSBzmAT3RMYmgUdqXyec+I 5R7Hplrg4cuqm9fn4hl+3ie/B0HHk2Tg0AebvispBpwY2ZwPjmCFkgzRun0QciHCVU3x lUHDkqKXpgVO6OVsoRAIKuHcnivtAAyn+A8qpqwQgrZ9J2u2h3dyBBU54K5vIaw5P7EM 0aFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sIlm5vi3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x18si461603wrv.199.2019.03.14.20.35.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:35:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sIlm5vi3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dct-0005El-W6 for patch@linaro.org; Thu, 14 Mar 2019 23:35:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcH-00057Y-Pf for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUs-0003CA-94 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:27:03 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:46689) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUs-0003BL-0x for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:27:02 -0400 Received: by mail-pf1-x434.google.com with SMTP id s23so5258712pfe.13 for ; Thu, 14 Mar 2019 20:27:01 -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=g09DjJXhGsFzGWxwKf5V5HWGbXw30Sr7rYhBrQNj528=; b=sIlm5vi3Wy+q706fV4TQmyPwjSvjhUwoH9WdL2JZuyXs17B8EqdbansQloZgy4cy3F diXd1tsjTTWgsDnzzlGhhs1r5ee3rtlvnBvhOwUFLC0lBG2sb4NUoeGTPTKQS5EwGbf0 G83h3SDSWEcdSP0AsszHCJRsd1aQNkmHqh5jkVQ/Zll9RoJbcZTQxsWk1Y+rws4j2lSK 4DxNEsquHV9f0jJOEiR9IIW84ukXsbMOm+W3Krat1shV6K4nSZJG3f6z5S0Yugodj7Di RSf29mTNGdhnE+wRo1ZkpeYI//ZQBGDeqhx22Umm//bh02rkT1R8U0Rs70uPAb5NCuFP xJTw== 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=g09DjJXhGsFzGWxwKf5V5HWGbXw30Sr7rYhBrQNj528=; b=FlMZ67lWnb0LNBNtOY/OAXxabfiD9UF8SuDPPu2viXiuRrK7GKCa6MYbeT1sHmLNa2 8fTMRoXz1pTJTc5rYngXq47QOl+GaQvMum2jkZs21dsZDs2XHN+SW0qkjjllCbVv2FNu TicK8APsmjv6p7m7uCAg/LsJIJvqF2iPLD1ZGcgz7apdGpa7eD5nWWDnFujcK2CvzdrD paKqfTtGheaNfK+Q4cS/urRLhSabawF0PPl4N7iW8PvDVzEVmuGU53VQIF56FS4kO3xU CXJgs1gx3ezknlTbHjgaVxXFspTwBSnNzVNIsCol4hF46uIJTRhXATgpKXhY/neIBYnv IqPw== X-Gm-Message-State: APjAAAWOR9cCeVfAVj6GL0cDTszu9V7oNENvOzs9weNAQxPGKigR4bJd eGuMjBujb7b35qLQBh96s2U8aU8UbyQ= X-Received: by 2002:a17:902:622:: with SMTP id 31mr1828164plg.31.1552620420674; Thu, 14 Mar 2019 20:27:00 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:28 -0700 Message-Id: <20190315032629.21234-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::434 Subject: [Qemu-devel] [PATCH v3 22/23] 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: , Cc: qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We now have an interface for guest visible random numbers. Cc: qemu-ppc@nongnu.org Cc: David Gibson Signed-off-by: Richard Henderson --- target/ppc/int_helper.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) -- 2.17.2 Acked-by: David Gibson diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index 162add561e..c26531e598 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" /*****************************************************************************/ @@ -156,25 +158,39 @@ uint32_t helper_cmpeqb(target_ulong ra, target_ulong rb) #undef haszero #undef hasvalue -/* Return invalid random number. - * - * FIXME: Add rng backend or other mechanism to get cryptographically suitable - * random number - */ target_ulong 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) { - 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 Fri Mar 15 03:26:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160369 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp16265860jad; Thu, 14 Mar 2019 20:37:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRe6WS9IdBDfu18wKxh1sCjth/ur4Y3sthVU8pXh7TdiDRh3of6FqFiWAVlCQvLX8eCvYv X-Received: by 2002:a7b:cf32:: with SMTP id m18mr523572wmg.98.1552621072055; Thu, 14 Mar 2019 20:37:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552621072; cv=none; d=google.com; s=arc-20160816; b=fN7Bz3HPdiP7e1i7/utji26UYDzJPh30PRHI/Z8eA8UNLEBa1Y2JhlpSZ1uQyt35We 1WEY4SLVycS+kcRzKJ3v3O+cwVqsyy3QbaYBwwY0ipzHwpbhE/aOe8bvB7bUumXyr64x Y5lrb3zt3VITpEonO1UsoDs3uxWsucnWlj2KQKAMDsfzNEx96YdOfl7BrLaIHishmge5 JlamU4TxhJhGZi51E5I5VTqL1KtLLAWyprgQ9Wz6cOUAfP5Qgezajoe+AEELx/LLqzmQ kV9nE6ltosUjjYcjM2YcQqSgbqRmTeKVtxiCjW6vdZinIuhh8geUoeiP1hg4BX2a79f0 Ra4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=ZgJdz5TgrAEa9MUsE7W5Z5vwo/bknf4rpmDLWjvMoPs=; b=M4oaKLMslaJOCZts0n0kQXJbuwOICr1zzgEStD2BLeuNNLY43DDsCInQuVZs2QxbYf flXcel786E+GSItSGIuxOBgJdKbejzLShZhtoLRFYsZLW7CRUQgQJfqIYcumsNCy8y6t 0HYsxwjDPajiLniBj4zo81hr/ziSVQsM5fWlp02pL08yrjTaf5yDSlB+JmRsz9uOm3Uy Mfx96u602mWoJ6bIOja/8GvHouLeG7v3gkhnq558NTTsbqMs4gCxr8zBlPZDTnlPghos GYYhyO5PnjOsIDN+/TrMmoxnTU47RSoC5jMTDVNRvY89Fej2XQWEexsIAxz8eimL6pWe BMyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aScehl97; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y1si455275wru.3.2019.03.14.20.37.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Mar 2019 20:37:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aScehl97; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:48718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dfK-0007kO-RC for patch@linaro.org; Thu, 14 Mar 2019 23:37:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcH-00059t-Eh for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUt-0003Dl-UW for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:27:04 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:39948) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUt-0003Cx-Km for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:27:03 -0400 Received: by mail-pg1-x52d.google.com with SMTP id u9so5403647pgo.7 for ; Thu, 14 Mar 2019 20:27:03 -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=ZgJdz5TgrAEa9MUsE7W5Z5vwo/bknf4rpmDLWjvMoPs=; b=aScehl972pqRk2Deqa8g+oQc4p28xs9GsNzsvBtt/+6EXY5qKm+qm5wM+bWbAJOnkB hMIK3QATYS+BEz2oqAw2p0RZyknriNo1kHpo/Js9A3zaepiJr1E1tQYgO0uPrnPG57M5 USgLvrZa6R9OsDJwNMCM6E/0iLb+CpdulAsT0oWAlHrBmzyIBUSS5mUgxqY3sppY75/h hOB8fY2Kk9LPEFPYgnQ+eJWRXgkUQu+zVHo/0Aq6wBCykchUnAKWx6aWIPtg+O7s2m68 aTEr6NDEHJNQRcN8Zi7rk+4uDbUIOpxMj72ghYAL5gclUtNCTW98j78rWyIyUNXuhUZL 7mmw== 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=ZgJdz5TgrAEa9MUsE7W5Z5vwo/bknf4rpmDLWjvMoPs=; b=lmu0YiBIsrWi8N70ACximMngtiLLknt4BLmVHurVQVLzdvL44Rze2QoKlV9f5DHPWp 5JMqFfHk51Ct9IjJE07g+SKunKERFEDiB+XVUjuVvVBIhv0qnk8f5BBy39txeiORfO/D PPp9vSsHnS7K32vxW1WLHHuOz6GotsmhypNnKp0eWs1y7LliGTxUAA1lBpwNwcH2B46R 0agN/jK9jnMf+0O6fl9FpaxObKyafR8vdGo9/GbIbFaEM/kDUbvWteiAKHPS3IZoVRuY DaWCjI3lAI300RUcjuh83LILFIL5evFL/SBJSapRJaAu91s/PjKWlpflLPGwCxmOLifv vlug== X-Gm-Message-State: APjAAAXWKXoPxC1oaahiWehmkwA1RqO44P/EFMIubd+xS4Hab9tB/7oS HmI546xOTVUKMlzUO8yo8AT7hJ9J77k= X-Received: by 2002:aa7:8516:: with SMTP id v22mr1757692pfn.23.1552620422251; Thu, 14 Mar 2019 20:27:02 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.27.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:27:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:29 -0700 Message-Id: <20190315032629.21234-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::52d Subject: [Qemu-devel] [PATCH v3 23/23] 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We now have an interface for guest visible random numbers. Cc: Paolo Bonzini Cc: Eduardo Habkost Signed-off-by: Richard Henderson --- 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(-) -- 2.17.2 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 d90c01a059..e9fa43346d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -729,13 +729,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 49cd298374..b4922dd730 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -5327,31 +5327,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; /**************************/