From patchwork Mon May 6 17:33:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163420 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp254861ilm; Mon, 6 May 2019 10:36:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTKIy44vkH5MgqgH5yhU38QVhBtFmXSKEEEIhJZkkygBCwKcKg/4OAolrPwttmDi6Pq6/c X-Received: by 2002:a1c:c18c:: with SMTP id r134mr6941742wmf.124.1557164217871; Mon, 06 May 2019 10:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164217; cv=none; d=google.com; s=arc-20160816; b=IBmV74ONq8SbBM7vKASzt4q6/jSMF/zwt1AO2tM1d70azgReDT+VZpslVBfWBX360/ v1xonkaxwQluFnksJFmvSR0zH9jcbEjOmb7cY04NgrVElPK8z/8wvzrTodghbQVqcFTG hSA5/AH9eAqpEwFItEx/L9Ovl1xqEj22KdZlUyZzAi3rui5+M/uqooIZdYlGi65/3Wrz M8TkuFEnJry6V8JomDxkPUW5+a8xr7tRAKOZtgsWbTCJ0Y2VojusqyDY/El18VOWVqEA mMtvh+HFEF2N5xhslVAj4owFhekO/tn8BZJHAFKPhylsYPb9swlVRJK/M7YQAPtdZoHc FuTA== 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=3IcDqOxNxFpx6A0tMNvu47gM3lLo8oZJFxC0ZgDmPNI=; b=vTqUx+V8uIK+c+E7xYn0gtUJvb0tXqOBxom3+WNddvvgIcWreEEab/K1V0J1TUVhe/ 0jCp4h+jtMHNTDq+bJdYa+BqjdoYPoTPvyGbZV6NiVE37RTW/BRMBMP5RGSdTXd9s6rK tqNyT2qMWqKLww/1JCCARbkNa1qCK5sdwDGvTlZVl0zbQ7IafKDWGhG9D9K/QNGj1kyj 68+lz+IPkdHIMfPg8swu8SSwbMIEgIv7g9M8EADUrumJdM4jSAkVuRii3ip3sG+2w5VU qBQhEvctRAMxTdpAq6+10r6cG5FPBhKNw6AXvCeytGDxJO/5xl0aM+PgKJFy/4gYfREe J8/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oKjjQI7X; 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 i17si1913260wro.79.2019.05.06.10.36.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:36:57 -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=oKjjQI7X; 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]:59932 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhXs-0004Ch-Rn for patch@linaro.org; Mon, 06 May 2019 13:36:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhV5-0000xO-1B for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV2-0001EU-VC for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:02 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:46467) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV0-0001CZ-W6 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:33:59 -0400 Received: by mail-pl1-x631.google.com with SMTP id bi2so6693377plb.13 for ; Mon, 06 May 2019 10:33:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=3IcDqOxNxFpx6A0tMNvu47gM3lLo8oZJFxC0ZgDmPNI=; b=oKjjQI7XVRe+sFhrMIATJOL1VyUY+fzx97cMBhwu57e9IPvhP/GSvaazc9Td3vfuEq WzCBcx1EBJXNwmeAkEmX4FSZq8F606fSiynWx4V5g22ZSdG+n/7Z5VwbkSQjH4jtnoCa mvMyDQmv/spUO+bejio3bvbJo3ilzQgkZuJJlUPRwT98ubZzZRY7CJ0dIDZi05MjXW5m xzbxVbl++L1EvLlAglY7Jw0DGGFFFfjnfEJrKBeLbKY6Oikt3oujCBkrwKNTqWX07uOZ k2A6uWHAb69W7UdtXBTHEEJp+dHAupyu9WvvRIajrj7GmN1S+z3bWzXt40sKDkHWXEk2 WGNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=3IcDqOxNxFpx6A0tMNvu47gM3lLo8oZJFxC0ZgDmPNI=; b=SceXMgQ7JRHlq160tbrN15DlQ4drdp8aMsqgngvK9saoCVP6DCvneHvtaqKgIkgyob /X7hE8Ny6Vf/w+2K5mqeGZT74XLsOnQ6YByh2Gmr5W3fJtaLuGuGGpBqqO9nr/HByWw4 GU3yuVGb5KqsdZlR9n4D0mq5vDn7D3tGuqASB5htAiOmb0RtyEf/raEN1f5S52/suIU6 8IFkO3C0Q4e26t10/JGuuevl+jcXlNX7ov8t92/4dfsdXzHUKK2Snx6wQO5H1TxjMsGU gQlfE+jORkNWWn3/jDiYl7aWUzF0+J7c5UW+dicrG1b99P2jwSrDuT2C0caHDOyB43Jy PTNg== X-Gm-Message-State: APjAAAW/k+C+FfrIrZdjYsUzsPnnFCcvzj1LV6Z4E90twIaAuBXrjZai ZUkHikAuazJ/t/3+2j6zHQyxSRIUmJE= X-Received: by 2002:a17:902:5982:: with SMTP id p2mr1790959pli.197.1557164036766; Mon, 06 May 2019 10:33:56 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.33.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:33:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:30 -0700 Message-Id: <20190506173353.32206-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::631 Subject: [Qemu-devel] [PATCH v4 01/24] configure: Link test before auto-enabling gnutls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" At least ubuntu 18.04 does not package static gnutls libraries. Signed-off-by: Richard Henderson --- configure | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/configure b/configure index 5b183c2e39..daadfe9ad4 100755 --- a/configure +++ b/configure @@ -2784,17 +2784,24 @@ fi # GNUTLS probe if test "$gnutls" != "no"; then + pass="no" if $pkg_config --exists "gnutls >= 3.1.18"; then gnutls_cflags=$($pkg_config --cflags gnutls) gnutls_libs=$($pkg_config --libs gnutls) - libs_softmmu="$gnutls_libs $libs_softmmu" - libs_tools="$gnutls_libs $libs_tools" - QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" - gnutls="yes" - elif test "$gnutls" = "yes"; then + # Packaging for the static libraries is not always correct. + # At least ubuntu 18.04 ships only shared libraries. + write_c_skeleton + if compile_prog "" "$gnutls_libs" ; then + libs_softmmu="$gnutls_libs $libs_softmmu" + libs_tools="$gnutls_libs $libs_tools" + QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" + pass="yes" + fi + fi + if test "$pass" = "no" && test "$gnutls" = "yes"; then feature_not_found "gnutls" "Install gnutls devel >= 3.1.18" else - gnutls="no" + gnutls="$pass" fi fi From patchwork Mon May 6 17:33:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163423 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp255536ilm; Mon, 6 May 2019 10:37:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmsQxQgTGjWEsM5dYv9owyXyvN1J3YglzCINOvcBvxRAL4HbMf4uWh40RNT/Jv6GnxFk/Y X-Received: by 2002:a1c:e912:: with SMTP id q18mr17240635wmc.137.1557164259916; Mon, 06 May 2019 10:37:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164259; cv=none; d=google.com; s=arc-20160816; b=wPYUkEfATfpOyIt2n8pHbJ4qiIvnvtNScEIYAwZlouQ5GZUvORFT5z8+ilxjywoNB8 JcbVR0StDC50qK5tQU75YmLejcL0ZfoGfD8x9/8uKJ7wuGKDPAAVmaWw5NYOw529YQHH 82Y6mpYMiI8kkYsheg7L9KSNbG+uN5QUOaE9qVombFNiLh+VBVseJlhMAhtkPWEdP9qq FsD0AbMOWaRDOVMnZzRqCP0IwkyXC/j5MYeUm7QxZtK6aHxQqT8gbNfV93VK0nSpSQJC OPz458kuyjeHA/9MHeQnN/Xv7/oWcoIhbjtPLlszrhrxFeJpjqqSAUmLNTxQgHyMXBa7 OAVg== 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=1xjlqRXirnP5LswdNxna6nzxrI47MTAcF912r95XRb0=; b=cKpFN4jsCYZGFJg0HA155KlqUwiBpJowe/dCxPICJW0uxySiyrpmKdY13alDXCdWoL aiT8WFfiJPASlhdQQ4bJQwPiyPQpNnfrWt8NjSPb2tN8xE4y8s53mmUvItHz3ZFgtf1H KGaPzApN65qUtUszhzFedFn9J3zo9iubIRj5uf6hzZ2ky/B7JCE1PEkqLd3APn03e3nP bHEem/a5M2O0TdfesvxewRgffmLJDpPuBmOtVHdsYQD49uQC3eYzdUI02FH/tcFVmLiF zeQhtYjWScZrd4hwX4YX4fzNYbvA4WgE9/YltMIVqplubfUufvmKLs78HLT23E45ypHX T9ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=t2CugovX; 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 t17si7007482wmh.159.2019.05.06.10.37.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:37: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=t2CugovX; 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]:59942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhYY-0004Qs-Nu for patch@linaro.org; Mon, 06 May 2019 13:37:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhV9-00010s-4F for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV5-0001Fd-1o for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:07 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:33542) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV3-0001DM-1r for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:02 -0400 Received: by mail-pg1-x544.google.com with SMTP id h17so818186pgv.0 for ; Mon, 06 May 2019 10:33:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1xjlqRXirnP5LswdNxna6nzxrI47MTAcF912r95XRb0=; b=t2CugovX1/haMwIVga+gft4+pIDnMUVLUxgHoAcFivygQl7rP7iJdl0OToTNIGpeFn 7To872ySiLXWAWqNo1+AOauzny9sG6PeWH/oVUN/WtGCFx+hQX92YAWGurVodnj1Xpix PT9k0iPbueuPPwQGdexmLOf54fv8Z0Aerny3yCnZBoRRmYS92tpmD16kPk1nTIjkT9Lg Xw/LF1aLnBXnVYKS8pL6AdN7qr9H6GpdxSe1BmrxyB8N/zWMPAuojjNvBN8vitHbdFfd ztF4xbtIraMejUc57UPwaLaKx70MXmSwv7rJjTSyiq5MYD7jLjuUv2Rt/iV4fK/OumO6 TKuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1xjlqRXirnP5LswdNxna6nzxrI47MTAcF912r95XRb0=; b=uCUhJr4GyGR+uCznGsMxjHJEAdsPB2chM9LczMYdsvQBU0jScwqcb9697PuynwIxrL vHuf9jKg8vZ/IO7W2ktXD38hMgrXNFJ3GDxvVugPPntuMPzBPepvIAFUfV2yOGDCiFDz FTaxUZo0YjLDOvEFBz8JpYsryCDOEw9eHZT/IRglYRj3KZktHTZOO5IXuc/7QjXCXm/5 asSOZgSyuU3P/73FaoowZomS3hWMAF+L6rdlxfQ9kYSAdxDyjhbXYerqe1pvFDEsNizg QdcYas6f5gKmOc+6+Rtm9LHAbvqgdgq7Hb0fwy0zwwsOMk1yYGWSjstlS1RtWUKthkSJ Epvw== X-Gm-Message-State: APjAAAUyMCqIQWkORC79/tArasBon56u4szzkS7seiJ0zuPHjQdfrGtm kFib/8pPGLtcM9uI+p7sInCPd1StKFM= X-Received: by 2002:aa7:8b12:: with SMTP id f18mr34787998pfd.178.1557164037998; Mon, 06 May 2019 10:33:57 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.33.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:33:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:31 -0700 Message-Id: <20190506173353.32206-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH v4 02/24] crypto: Merge crypto-obj-y into libqemuutil.a X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We will shortly need this in the user-only binaries, so drop the split into system and tools binaries. This also means that crypto-aes-obj-y can be merged back into crypto-obj-y. Cc: Daniel P. Berrangé Signed-off-by: Richard Henderson --- Makefile | 12 +++++------- Makefile.objs | 8 ++------ Makefile.target | 4 ---- configure | 9 +++------ crypto/Makefile.objs | 5 +---- 5 files changed, 11 insertions(+), 27 deletions(-) -- 2.17.1 diff --git a/Makefile b/Makefile index d372493042..09c8591805 100644 --- a/Makefile +++ b/Makefile @@ -410,7 +410,6 @@ dummy := $(call unnest-vars,, \ block-obj-y \ block-obj-m \ crypto-obj-y \ - crypto-aes-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -446,7 +445,6 @@ SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES)) $(SOFTMMU_SUBDIR_RULES): $(authz-obj-y) $(SOFTMMU_SUBDIR_RULES): $(block-obj-y) -$(SOFTMMU_SUBDIR_RULES): $(crypto-obj-y) $(SOFTMMU_SUBDIR_RULES): $(io-obj-y) $(SOFTMMU_SUBDIR_RULES): config-all-devices.mak $(SOFTMMU_SUBDIR_RULES): $(edk2-decompressed) @@ -502,7 +500,7 @@ Makefile: $(version-obj-y) ###################################################################### # Build libraries -libqemuutil.a: $(util-obj-y) $(trace-obj-y) $(stub-obj-y) +libqemuutil.a: $(util-obj-y) $(trace-obj-y) $(stub-obj-y) $(crypto-obj-y) libvhost-user.a: $(libvhost-user-obj-y) $(util-obj-y) $(stub-obj-y) ###################################################################### @@ -511,9 +509,9 @@ COMMON_LDADDS = libqemuutil.a qemu-img.o: qemu-img-cmds.h -qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) @@ -524,7 +522,7 @@ qemu-edid$(EXESUF): qemu-edid.o hw/display/edid-generate.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap -scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(authz-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(authz-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) ifdef CONFIG_MPATH scsi/qemu-pr-helper$(EXESUF): LIBS += -ludev -lmultipath -lmpathpersist endif diff --git a/Makefile.objs b/Makefile.objs index cf065de5ed..0ce429c1af 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -3,6 +3,8 @@ stub-obj-y = stubs/ util/ crypto/ util-obj-y = util/ qobject/ qapi/ +crypto-obj-y = crypto/ + chardev-obj-y = chardev/ ####################################################################### @@ -21,12 +23,6 @@ block-obj-$(CONFIG_REPLICATION) += replication.o block-obj-m = block/ -####################################################################### -# crypto-obj-y is code used by both qemu system emulation and qemu-img - -crypto-obj-y = crypto/ -crypto-aes-obj-y = crypto/ - ####################################################################### # qom-obj-y is code used by both qemu system emulation and qemu-img diff --git a/Makefile.target b/Makefile.target index ae02495951..ce02924ffb 100644 --- a/Makefile.target +++ b/Makefile.target @@ -179,8 +179,6 @@ dummy := $(call unnest-vars,.., \ block-obj-y \ block-obj-m \ chardev-obj-y \ - crypto-obj-y \ - crypto-aes-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -189,8 +187,6 @@ all-obj-y += $(common-obj-y) all-obj-y += $(qom-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y) -all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y) -all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y) ifdef CONFIG_SOFTMMU diff --git a/configure b/configure index daadfe9ad4..0099e85a03 100755 --- a/configure +++ b/configure @@ -2792,8 +2792,7 @@ if test "$gnutls" != "no"; then # At least ubuntu 18.04 ships only shared libraries. write_c_skeleton if compile_prog "" "$gnutls_libs" ; then - libs_softmmu="$gnutls_libs $libs_softmmu" - libs_tools="$gnutls_libs $libs_tools" + LIBS="$gnutls_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" pass="yes" fi @@ -2860,8 +2859,7 @@ if test "$nettle" != "no"; then nettle_cflags=$($pkg_config --cflags nettle) nettle_libs=$($pkg_config --libs nettle) nettle_version=$($pkg_config --modversion nettle) - libs_softmmu="$nettle_libs $libs_softmmu" - libs_tools="$nettle_libs $libs_tools" + LIBS="$nettle_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags" nettle="yes" @@ -2888,8 +2886,7 @@ if test "$gcrypt" != "no"; then then gcrypt_libs="$gcrypt_libs -lgpg-error" fi - libs_softmmu="$gcrypt_libs $libs_softmmu" - libs_tools="$gcrypt_libs $libs_tools" + LIBS="$gcrypt_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags" gcrypt="yes" diff --git a/crypto/Makefile.objs b/crypto/Makefile.objs index 256c9aca1f..a291bc5b9a 100644 --- a/crypto/Makefile.objs +++ b/crypto/Makefile.objs @@ -34,8 +34,5 @@ crypto-obj-y += xts.o crypto-obj-y += block.o crypto-obj-y += block-qcow.o crypto-obj-y += block-luks.o - -# Let the userspace emulators avoid linking gnutls/etc -crypto-aes-obj-y = aes.o - +crypto-obj-y += aes.o stub-obj-y += pbkdf-stub.o From patchwork Mon May 6 17:33:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163421 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp254986ilm; Mon, 6 May 2019 10:37:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJWAL115FXzPrrIi76+5Pm0o5S9LmDS18oxoTQwk4MoqxvitcwKEFuxPdhCQVMr7Wp1VgZ X-Received: by 2002:a1c:18d:: with SMTP id 135mr17257048wmb.14.1557164225472; Mon, 06 May 2019 10:37:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164225; cv=none; d=google.com; s=arc-20160816; b=z/aa/BOOgur2Unib5IUdsTQudlIxey0wb+u3jkcl6P2AnzgSK308iBH+4o1IwM2hOK n1gkwzc9H6YHlyRQwcuXr6sunGV9ovWqGAHxTc6EENtCoG4/bCSalbbcRQZwoArO0oZj vQbiVfS4qptTvoCVZywDhKmRNysdEVbhMXhnUZ+qRxLqrYDT3rAB2N60aOTPMapT2MFx n5yiDwlWFmOLQEta19IpEAohT6caM9DoElIMhe3TKWt7eWufpWaJq+ts2FbR4m0wJU2h 2iHRzR2ENcGsVaaXek9F7Fxxxlyn8k6OGAIuYq+TbcnxCeCa+d+U3BM12cAp+J2zxZQ7 h8cQ== 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=O1PQbxI86I2bI4Y4HCTdo78SLn5JqRTP/j+lnThrZ4M=; b=fXGvdxT5Oy6Z19XgmYXosEUTnAO+hI/2FElZLtc4Fkg9h3AySp9VujIVp671VHDzXz j/8qr55awclo5xar3FTqlV7UffZRJs2ewNtRZNkuUWkimU7wCmXdhSpSRyuK5w6tD6sT Rmm6aH5iSCedqz5haBfDHENWNL3mywyeXkycXEHjr93bFGVoSk8EdhwK48pI1gfr09Hr 7iZFjgm5E2jyAyg9ReZ93Iew8ZKf254UoXaNak15Iq5tRdFxz7NQDAaFcDbFTGPnihBt ynImUVUEHHJUJAHOSGy1O5leJagUUcELwAtXZu5dVAIRtSnU57op8YDsTEOBGwGqYwWQ TQ5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QlAFgO6b; 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 3si7150699wma.176.2019.05.06.10.37.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:37: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=QlAFgO6b; 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]:59936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhY0-0004Hc-Ew for patch@linaro.org; Mon, 06 May 2019 13:37:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhV9-00010o-3N for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV5-0001Fm-2Y for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:05 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:40440) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV3-0001Dv-2O for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:02 -0400 Received: by mail-pl1-x644.google.com with SMTP id b3so6706946plr.7 for ; Mon, 06 May 2019 10:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=O1PQbxI86I2bI4Y4HCTdo78SLn5JqRTP/j+lnThrZ4M=; b=QlAFgO6bdhjojlKOog/QcrhXghb0rPMOgocTzc6WOYuB9M9c9XWFW5GG7hObkuqCht pBpqklm8CjGR79JFXs0OJlutcc1ViafuuU5LGZNKxVSjPlW+ow3qAZqePYbdOSXJ2LaZ oOy+Ig55KCJhAvOhbuVgWvjPrGhR+AxEe3ma0ockDfm3hgssTi3poJXuG385cSYsLZId +S5M0SuH0w7Gn2JnJmlBLliWl9P70nBbYTtmW4oZHCs5ivlfiXjK1D25tMjpKaJY+B6a iJBA3d2zv91M+nHBuTewjMNGnZTRY/GcCO9Gb1A6A0ToGiBTsr6LXRORaRqj6t5GmygW HyLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O1PQbxI86I2bI4Y4HCTdo78SLn5JqRTP/j+lnThrZ4M=; b=n/0E/1oTSLfjKR4eoF3sf/KmCV4DtGqKxtrE+oqUvl2LDlmU39/eSWfGe0d9zv6UrQ NypLreU0eBKSnq1C+CJ1+1Cp+amMUk8bsc+iVxOCRmxY4xmxAxZSjkIMRnaHvkAEiH30 8I7fUdl5TGObSEvxxw0E5I0fUkWilgOWYhWlo80KNG/JoFLsUaqq4CkfrEnIw3CWZi1+ 58R9AQODRG/+9eBrqDWRyx84FV8OFIfxhUuGmUzkMAZSLFpHJgzqlS86aUzOHD5W7unS 6H4BzDsTUJUCz8HOXLY/Avd0z08MfRRspOWICp+Kly3D6bQHtP+srvvn2G1NWVG2Old2 F+Hg== X-Gm-Message-State: APjAAAUO/p7hwfgTHiuUSg+uq3BAMMbue03uvmuH1tYSPd933cjn7k+G OjHpk70Sdo82YoKIpUWE5mjmAieATys= X-Received: by 2002:a17:902:e612:: with SMTP id cm18mr10597325plb.255.1557164039170; Mon, 06 May 2019 10:33:59 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.33.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:33:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:32 -0700 Message-Id: <20190506173353.32206-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [PATCH v4 03/24] crypto: Reverse code blocks in random-platform.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+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.1 Reviewed-by: Laurent Vivier diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 7541b4cae7..f995fc0ef1 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -32,7 +32,14 @@ static int fd; /* a file handle to either /dev/urandom or /dev/random */ int qcrypto_random_init(Error **errp) { -#ifndef _WIN32 +#ifdef _WIN32 + if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, + CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { + error_setg_win32(errp, GetLastError(), + "Unable to create cryptographic provider"); + return -1; + } +#else /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ fd = open("/dev/urandom", O_RDONLY); @@ -44,15 +51,7 @@ int qcrypto_random_init(Error **errp) error_setg(errp, "No /dev/urandom or /dev/random found"); return -1; } -#else - if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, - CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { - error_setg_win32(errp, GetLastError(), - "Unable to create cryptographic provider"); - return -1; - } #endif - return 0; } @@ -60,7 +59,15 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, size_t buflen G_GNUC_UNUSED, Error **errp) { -#ifndef _WIN32 +#ifdef _WIN32 + if (!CryptGenRandom(hCryptProv, buflen, buf)) { + error_setg_win32(errp, GetLastError(), + "Unable to read random bytes"); + return -1; + } + + return 0; +#else int ret = -1; int got; @@ -82,13 +89,5 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, ret = 0; cleanup: return ret; -#else - if (!CryptGenRandom(hCryptProv, buflen, buf)) { - error_setg_win32(errp, GetLastError(), - "Unable to read random bytes"); - return -1; - } - - return 0; #endif } From patchwork Mon May 6 17:33:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163424 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp257798ilm; Mon, 6 May 2019 10:39:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9PTobYN0mPBubHb1ETgmgpvQyNQHfcAvEsRMjr0KRxKukVrRm0Q0YcFj09FUcNvo1Sext X-Received: by 2002:a5d:654a:: with SMTP id z10mr19599929wrv.153.1557164393217; Mon, 06 May 2019 10:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164393; cv=none; d=google.com; s=arc-20160816; b=byU/d/DNjJ7EEZTqmioUOl6ZvSGoQbu1PsbuXTtUs63YWQMtGAKF4xS33s+YMEOdka 7oCrVhGohjKR064orNsU1+uh1U5A7IygDHLMv+XB2CQIVJDEYvq+Ny6R0hokPXuukdm1 x+9GtzMLmLiwCZyj2OhINRDMo4caHvyETrGAPIITdQjWnc7YwT6eQOESlh0YRE356zr4 jwaRimGYpX6WtklQaPTnTrH/4rZ7WovrHtrOZbblZR4BQ5BSaeKrrZplRXgpjNy5nk2X Ct5e5pnOoqBOWUIGjoyYwIM6XubJ2jbINcnfvgftFXYTc+yoCiOiliSueL9uD5Q55CfY nIjw== 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=SxHcSgvXH46Lcz+sBihH+DQ9BaQG6plA/B5ZKvOuxJA=; b=yqCz8qwfcgTqgchaT/1DI5PvP7o0yDcv0ATzlHTBZ90o8mGR07Qf4aVnJIoBi9fKvJ cTwqjkW4f7/5ujQRrkhaH7h+8tKAlA4wnIG7YHVGoTJxlRB1GlgFV0DOtgyQZ1StdPJS HTfcygQNYWZP436fNB7Z8nym/UOu2xA0szR84U3S4yp9+9NbtljGTj+L2zrN3P5L0lCW OT3dWMqnFF9wTtmJv4xSm8CEmCyIHvOhItJyaNkunhJEcoaBUDiq8qPfrLQkeUtjc1HT nH5TApcCXcxML5lLCfTNg0XQpShOYWRhzwu1nx3cbrXxsgdYJPNClAT0kAUP5ZqwU8xi hn3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pkil7NXw; 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 t62si12196756wmb.2.2019.05.06.10.39.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:39:53 -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=pkil7NXw; 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]:59954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhai-0006Cr-5z for patch@linaro.org; Mon, 06 May 2019 13:39:52 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVA-00011n-5x for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV9-0001IE-3l for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:33274) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV5-0001Ee-03 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:04 -0400 Received: by mail-pf1-x443.google.com with SMTP id z28so7145429pfk.0 for ; Mon, 06 May 2019 10:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=SxHcSgvXH46Lcz+sBihH+DQ9BaQG6plA/B5ZKvOuxJA=; b=pkil7NXwQ0LqaEBzco3zRNKPlgnZYoK7PI32QoHcMkfhprBVa99RoQqn/KxfbNUL6f RzNppNhYONng6jOice7MGDn2zEVZHhdecPTJSWaMIKKLHAH2vamr9OdQ8PvekzWNkR20 /5q+jzRDAzNwpQB3YnfEcbJ4BZxtGIO3pSSu/RPY3MxaLfbkF6ZEQo0nhHc+YjQLcHDN i9fXAcPn/IJOMT5DuRTDMP/EY2DYx2Lm6H0WeDlgBLG3DUN+h9aj4u+4il7mWeSVrVwF 7R4JBa0ynT2c7RW151zD6hJnZmrqnMsjlmlTVzdb7vCpoEy6dQ44Bz90jc8c6ZZ93gSo S5Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SxHcSgvXH46Lcz+sBihH+DQ9BaQG6plA/B5ZKvOuxJA=; b=cMS6Tbr4oiVKNJ56B7PzqlVYh9ooEgFOFq0PlUBPEzwBwFKqb/pBVM3woy6wkLbjOg UaEFdCSH0i3MZFS8qaJwOOvTWvs12/r6u29vfV2R0ETb2jcifRCtz/sQTKsjkFTo1fcQ u0rB7Ahu6pnI4hrRHXC1SYRiKoFQQsxKUCiDop6oUYC02qXt05xhiNXOqeGn0a3Yuhuw w9wLdWaoE1xclv/42hrbpZa1k1wFthL2ziL87nc/ZXZDW8Y27Pj7Wx1Vlw1sRDHzAbuG fca+wQXJcdKZxJ4DgxwBjKAKI2SmlyNQNljHiHuY/c5AHrvGevzqoG8b2LwnwCOr9ALQ WyCA== X-Gm-Message-State: APjAAAXcBHo4lzwkyNNwwTEmCFkxMfBPFXieFuUkLAGrFouQ2nCBFy/O sFr96i+oRoLSYt+PmBqGO71pOfoQu9Y= X-Received: by 2002:a63:4a5a:: with SMTP id j26mr32302687pgl.361.1557164040520; Mon, 06 May 2019 10:34:00 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.33.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:33:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:33 -0700 Message-Id: <20190506173353.32206-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v4 04/24] crypto: Do not fail for EINTR during qcrypto_random_bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+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.1 Reviewed-by: Laurent Vivier diff --git a/crypto/random-platform.c b/crypto/random-platform.c index f995fc0ef1..260b64564d 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -65,29 +65,23 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, "Unable to read random bytes"); return -1; } - - return 0; #else - int ret = -1; - int got; - - while (buflen > 0) { - got = read(fd, buf, buflen); - if (got < 0) { - error_setg_errno(errp, errno, - "Unable to read random bytes"); - goto cleanup; - } else if (!got) { - error_setg(errp, - "Unexpected EOF reading random bytes"); - goto cleanup; + while (1) { + ssize_t got = read(fd, buf, buflen); + if (likely(got == buflen)) { + return 0; + } + if (got > 0) { + buflen -= got; + buf += got; + } else if (got == 0) { + error_setg(errp, "Unexpected EOF reading random bytes"); + return -1; + } else if (errno != EINTR) { + error_setg_errno(errp, errno, "Unable to read random bytes"); + return -1; } - buflen -= got; - buf += got; } - - ret = 0; - cleanup: - return ret; #endif + return 0; } From patchwork Mon May 6 17:33:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163419 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp254836ilm; Mon, 6 May 2019 10:36:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmTwFyr8RZPSEj/+Kdbhv+FEXuQGHUJe1ZQxIkorDuHDKx0F3MDqfCxESQc+3FJjSuj2xl X-Received: by 2002:a1c:4e0b:: with SMTP id g11mr6221039wmh.38.1557164216368; Mon, 06 May 2019 10:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164216; cv=none; d=google.com; s=arc-20160816; b=l08gppW4zTWUGlVzghG30PhBF1dpVNy9UZxu34HYef1pmbHJQV4bU6g6PqwTZFndBk jJBFbGlWj+FmK8HcnF09kCzPN3IYCqnkbavzwpSWcuxM+gqfVZfFUwdXtH3n6YmpokXN HlAUAORyyM8yigbLJFQfLyXRUKIadEDRtNb4+ON7As+ZzLot3SK5RfBbhpsR6Ls96RrA qbRov7lxUPv6H86GqbSsZMyFyCY7UdaDFKyIvhBwUkBJ19mrkBBNpE0n7q1/NpqwIHLW WWqQOdj4vlpR1n4ciQMpAy5l3Uik/zKAfhCRC1oeQjmVGKcFoUeDE+0BgjhxA2zF1tz1 aluw== 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=urHRlG6kBlVfKAPWfqk7nsWOPo9eNvxapFP6SXeaD3k=; b=nNUgNXMsNVEkS+cqjc147yy0953+s7X4vrPraq627EPOnvR9wI+h4Q+/FgmBl4k9C9 YdZa44DNAcf6hB4OXlFK2iUkbf6lEUfEYmnWXTyjo2+cLqXWBvCL4n2ia182olUReoza 0+HPVXi7/edEeQf9tQxsl38IxJeU7JvK6OHEE41NsvW9p1nbvVP6V5EdAJIT1N4VQj84 CJP+HCtJgwCdpa1zWq5iOIThdK8L2yCEYZENpL6X7uIiSkcpJMeOEdWJvqAhI21UJFxr WVtM4uB1dsuYRi1IbXdKjgv9G1CVqx+4pzzEFtTiNgaMPgX9rNSe+/+UH22dOB/tEZoX e9AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eyRaLYBI; 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 g7si2896683wmk.74.2019.05.06.10.36.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:36:56 -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=eyRaLYBI; 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]:59930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhXr-0003sl-7D for patch@linaro.org; Mon, 06 May 2019 13:36:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVA-00011h-3o for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV9-0001IK-48 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:45552) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV5-0001FC-1S for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:05 -0400 Received: by mail-pl1-x643.google.com with SMTP id a5so1769815pls.12 for ; Mon, 06 May 2019 10:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=urHRlG6kBlVfKAPWfqk7nsWOPo9eNvxapFP6SXeaD3k=; b=eyRaLYBIqxXVktyb+HTVaFGi3HFWopEiTqw34tPLVew1SYdIBU21YUVtW/WEm9ut+B IhBNdLflZ7JCc/fEIuhZeMkZaOR3xYlMf4pzAea064cyJHX52nU29X4qJ0SfKmNsRBNY 4NMXrhVuTeGaQqctYnS9nUdcpFsffTKt7eUfgksBdv4FgYgvQoiZSHNJAE5wzJF8ldUi XQQILtxuLr3gnvwpr9xdp+2hY0T41/U7lJnC8aOZR6Th+Ew55T7+bDzPWe0OxpI1zNLp NFXQFGSZ9rt0GwSpz0430BPaIcnN64yQncwg/z+sfKWc5Pepy95baFCb4fm5ccPljbz/ nqMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=urHRlG6kBlVfKAPWfqk7nsWOPo9eNvxapFP6SXeaD3k=; b=I1IOskZRvtXoNPDC3Zvz4qNlkNUTwQb7M4uNKUknCGaeIWq3i62SdJgBwa9zsYEfkU /VCVldbq+RtOdRPhBTyOKNiPZESqkVOc9toQ/3E8snPaL7Hej6pfhlTqWKn+jOP8Uxuu bnVzK3VZJq04fTTmX3QEgNhpQ/QwWrZeg6hIh3izwpeUcYuszZ4kGP4Z1wugSpcZLnoB 8gY/Bvu1xQsLTIznPAmLkzzIDLOGfJHCGApfEd7jOyngHocme+jwFtMCds287TG5883K YMxXhOv8YFao9XSenwy9seHocFLFzVtpGLKPr16uTMezsgJlQPlntUuirbFTO8NgYzeD mK0g== X-Gm-Message-State: APjAAAVX52uATh6ztZDbXAs3QAvk7feqBjC3+nk27iv8lkalPg4EB6Hx c+nAk7B4bMw9Ya2N9yAt7Xq5oIpWADo= X-Received: by 2002:a17:902:bd92:: with SMTP id q18mr33896137pls.136.1557164041616; Mon, 06 May 2019 10:34:01 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:34 -0700 Message-Id: <20190506173353.32206-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::643 Subject: [Qemu-devel] [PATCH v4 05/24] crypto: Use O_CLOEXEC in qcrypto_random_init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Avoids leaking the /dev/urandom fd into any child processes. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 260b64564d..6df40744c7 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -42,9 +42,9 @@ int qcrypto_random_init(Error **errp) #else /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ - fd = open("/dev/urandom", O_RDONLY); + fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); if (fd == -1 && errno == ENOENT) { - fd = open("/dev/random", O_RDONLY); + fd = open("/dev/random", O_RDONLY | O_CLOEXEC); } if (fd < 0) { From patchwork Mon May 6 17:33:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163428 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp260593ilm; Mon, 6 May 2019 10:42:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxLmbcYtVuvejgZS9Bj620azpliiqXyzw5llVCRokH/lBamOlhmIt7CIQsxYOTuOvg9vZC X-Received: by 2002:adf:f68c:: with SMTP id v12mr19596486wrp.40.1557164565036; Mon, 06 May 2019 10:42:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164565; cv=none; d=google.com; s=arc-20160816; b=KHjhxxRG4SSVUOz49073o8EVc5yhgMy61HaA6yAsvQRVTKKYzyoexV5nEfs2kU5Ada ztWdVuKxmgvJ+Zt20syWZMdJ7j6KQDjWHeAF3E54hLaQigF0wUs8vkD0faarNT+Ms9O0 YNpzGyBuGnpX+2jlOACzkfOS5QU4i6eRvENHQKBX90a5Uk9yD6OrE+CEw560ShY3jFps +TQ5Busvg/hymU+ugKWSi3xx9CnbRgnCGqn2+bmfbNDogHuiemsG98n3rMvgox8Sf07A 7j1mYOP3MKhcCxN8bHk/rvyIy7LVdgDQAhTABGo1hjyE+Bni4olIk+rUAxvY8mPblzdZ U2ow== 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=esNllaMlu2hXfZ1dTWICAYQAatBfGQUsBlaS7ORBn8s=; b=UyouThwMeIqwbMOX0tzwSGBqTJNTmL67LOXCD0NjYjIreMfQSJhTsmG0fKOx6Y9Ltp iffnnzxkxrZ3vvDA/o+Ck4k2HtxLPw0v2++VOQ4sVuc3i33lVepKepMO9/N4yc/WSggC ExO9tE7WokOtHiN3iUll/plL/NrO8JAROb7NiRaZWWsLdpNC10C9hTeiqy5+7W/0/5oj ueFqd+nIhd+yz8TdjeVkzKWVPLcJS63LRxdb2D4rFYseMOyBCxyjmNWbwnhx/oeUBKws pRjI4x4Py8NRYbOG8Bn/3QwFsg4Npr1Zt70vxa+38k+0j5OL6ZmFHVXj5hRzfKGcCW92 Gr5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CblyidrE; 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 q16si7812745wrr.110.2019.05.06.10.42.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:42: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=CblyidrE; 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]:60011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhdU-0000t0-1F for patch@linaro.org; Mon, 06 May 2019 13:42:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVA-00012F-HW for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV9-0001J2-DJ for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:42676) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV9-0001G2-2p for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:07 -0400 Received: by mail-pf1-x442.google.com with SMTP id 13so6821932pfw.9 for ; Mon, 06 May 2019 10:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=esNllaMlu2hXfZ1dTWICAYQAatBfGQUsBlaS7ORBn8s=; b=CblyidrERYrSmUe/QNFM9pDuBnu2GOQWyCiYAJ1ahITmWOQMAhWl8z7DQQRlvnJ0EU iQemffNZvxh+sMsxlE6gU319NQvPhxI6oscrfJUe4pNu2e+bK/NvsNlGUezBzggClEPn pe/4qhwwvD8iklYbL3/0FUF6IEfMr7Lpner8Bx/vy6FQ3Lytt6kXQf7O9Qi2gTvVN79A meIXfSOl12vtTjO6Fz3sdZV/1ixL1av8QT7hkZp+62QsQfZHSvby54HrNZ4KdUhbSeZ6 CwPg2ih+X4WtuFSVZMqsZMbLIgd4PUna/4y1w4DppjzNoTtR1UBCvGHjbMknd6Bodat8 V9qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=esNllaMlu2hXfZ1dTWICAYQAatBfGQUsBlaS7ORBn8s=; b=CronMq5aCkp8InOU6uCBh/JYUc39zxocrF2JYgjXhq8elGN1dfJVyzEFrGf/piHqDD Eowx7durjiFH7njyCgOqJ1M6cnA07Wpl4mGGUVlAUUqkrNa46dw5/n6b00VKlvwWI26u nN+hBjxFlegfhLxLM7OYGh0TLbQjunjv8Qnj6p7a1bJJXzMomnpVz5CUW9iTyheizrdH Q4RWY6lThwcqUNIJ8UsKLdruAEOOBNZpqtc8k9En1HxyRq3ZhZyzV8OqVYAPGhmCkph6 P/KuaSn7/KwBWSTB1tUvO0OiWCW9sludWCq6y3OBnc/Ep3s7T6M4PJs5uZqpt4JjuzaD LgpA== X-Gm-Message-State: APjAAAWgcTo4nUaLYMeevjzBc8i4g5qLQThbINOEBQrKdBrRNhmVa2hu eRMx0XK1f4EJX7g///JImWI8MYpJ4jk= X-Received: by 2002:a63:e048:: with SMTP id n8mr33581286pgj.41.1557164042881; Mon, 06 May 2019 10:34:02 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:35 -0700 Message-Id: <20190506173353.32206-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v4 06/24] crypto: Use getrandom for qcrypto_random_bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Prefer it to direct use of /dev/urandom. Reviewed-by: 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.1 Reviewed-by: Laurent Vivier diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 6df40744c7..cb3ca1bc09 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -27,7 +27,11 @@ #include static HCRYPTPROV hCryptProv; #else -static int fd; /* a file handle to either /dev/urandom or /dev/random */ +# ifdef CONFIG_GETRANDOM +# include +# endif +/* This is -1 for getrandom(), or a file handle for /dev/{u,}random. */ +static int fd; #endif int qcrypto_random_init(Error **errp) @@ -40,15 +44,20 @@ int qcrypto_random_init(Error **errp) return -1; } #else - /* TBD perhaps also add support for BSD getentropy / Linux - * getrandom syscalls directly */ +# ifdef CONFIG_GETRANDOM + if (getrandom(NULL, 0, 0) == 0) { + /* Use getrandom() */ + fd = -1; + return 0; + } + /* Fall through to /dev/urandom case. */ +# endif fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); if (fd == -1 && errno == ENOENT) { fd = open("/dev/random", O_RDONLY | O_CLOEXEC); } - if (fd < 0) { - error_setg(errp, "No /dev/urandom or /dev/random found"); + error_setg_errno(errp, errno, "No /dev/urandom or /dev/random"); return -1; } #endif @@ -66,6 +75,24 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, return -1; } #else +# ifdef CONFIG_GETRANDOM + if (likely(fd < 0)) { + while (1) { + ssize_t got = getrandom(buf, buflen, 0); + if (likely(got == buflen)) { + return 0; + } + if (got >= 0) { + buflen -= got; + buf += got; + } else if (errno != EINTR) { + error_setg_errno(errp, errno, "getrandom"); + return -1; + } + } + } + /* Fall through to /dev/urandom case. */ +# endif while (1) { ssize_t got = read(fd, buf, buflen); if (likely(got == buflen)) { diff --git a/configure b/configure index 0099e85a03..5138a1a45c 100755 --- a/configure +++ b/configure @@ -5806,6 +5806,20 @@ if compile_prog "" "" ; then have_utmpx=yes fi +########################################## +# check for getrandom() + +have_getrandom=no +cat > $TMPC << EOF +#include +int main(void) { + return getrandom(0, 0, GRND_NONBLOCK); +} +EOF +if compile_prog "" "" ; then + have_getrandom=yes +fi + ########################################## # checks for sanitizers @@ -7193,7 +7207,9 @@ fi if test "$have_utmpx" = "yes" ; then echo "HAVE_UTMPX=y" >> $config_host_mak fi - +if test "$have_getrandom" = "yes" ; then + echo "CONFIG_GETRANDOM=y" >> $config_host_mak +fi if test "$ivshmem" = "yes" ; then echo "CONFIG_IVSHMEM=y" >> $config_host_mak fi From patchwork Mon May 6 17:33:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163425 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp257921ilm; Mon, 6 May 2019 10:40:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDBjuLRSLM0ibuUfsqfOQDJL0cQiH6WL5ieqxzn61f726dBuJAvuFfHWMqYH7jBLjSfsB9 X-Received: by 2002:a5d:420a:: with SMTP id n10mr33364wrq.325.1557164400994; Mon, 06 May 2019 10:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164400; cv=none; d=google.com; s=arc-20160816; b=cZia14gUb1GAF5i6+cDSZhTe1soKbey/V93ttoIiBkxKHvLRXpBXnsPtc4DR9g08q+ ig4fcIov+AHSJ8+Y8fkt6vnBfrl5Qq0sTWISpVanvzXG9ZwkjeaVJGTES2ebHJvoW61C HaKy+ApfGzM5vwVng9Xnn2D0PT4GkzHACRm3aW3tYbwfzERrTyNu+OKUT+M/D+1OuYZy mkvuRfzWuDy1jT3Xwg0IzPeDAI4Go3jWdmYmEwWIy1/ZMCnf36FIIYUZxjM1Mqr1K5Io tlBUQbG/pqNPnGD89n3kwd7wPMFFvkXf6LotxfKpWfdT/EoRLJ7oXbuW9THSvHGa3tux hmOQ== 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=Jdxoq0cd07u7NwCDIf4s8w4ApIde8s71XHdZkh2CqpM=; b=SJaoBC7zF6sBfFLITTI5slFWbe+XRLh5FJ5zDTN/OyItiGYj0UA4LY6seBWiA36yi4 0wjkloSLIcgQT3VtQBMJ/RYWFUpou6ao75RJIPzfuw2ofdisZE+s0lK8tl78mOEFiv+F zVBg63XV+UMJ8i5EQeLTmocuw7vjq1wV3/qgVQyGZHdmrhDQOeJPswfMrtlygR20uMW8 hTD8H8xDJQTNJkMBn1BeWtiFL/YOucPNU/NT8/reey8KhecEyY+723YMwGdqmx02yDYV YYluOIhimUCEW6tKuA3yhP4P1IaJz8oCLAPUFbMt0nmBuTVtY1HQFPaEZPbtRpaqr1TN NW5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mV1tPHz4; 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 q14si7837850wro.170.2019.05.06.10.40.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:40: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=mV1tPHz4; 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]:59958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhap-0006bg-QF for patch@linaro.org; Mon, 06 May 2019 13:39:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVA-00012B-GK for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhV9-0001J7-Ds for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:41747) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV9-0001Ge-4C for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:07 -0400 Received: by mail-pf1-x441.google.com with SMTP id l132so2178005pfc.8 for ; Mon, 06 May 2019 10:34:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Jdxoq0cd07u7NwCDIf4s8w4ApIde8s71XHdZkh2CqpM=; b=mV1tPHz45dpuWrSvod7+7lKaee7aXsf5FBPuk2C13AMjacbAK6WA/YKpDSEqFPWP0o v3kfjGtFfB1LGynKc+uRc16OzXhdbxJRfFXxkOwXQykOBnqG5giiF89cO2OlV4XoNjpo 8Yv1dgWeSFeUVOU0PoIeWGjTpeAbwuwcGMNtlvyUJe9IsvAFDva9gz5LUqnJnJRJhpPT 2Oa8zeRLAYfmRJzCJTmSCsStXNWL1jBECLmMhlIrMGFgBSRW/aTUWJlZ/+GqI+gjbxZT U4lhxqzrQv+c/K3m69/+0OiJd06mhizauRz1WYqJaF6Zrg+979Bnb0WZ+gx0psMmDVre otcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Jdxoq0cd07u7NwCDIf4s8w4ApIde8s71XHdZkh2CqpM=; b=dXAhbJRAbVgo3D8Sabr2sd7de/kDFlAjN7doi2xF/lAJgeiyX5RQDCXftChcWsR9IZ 4/AV6SSs4sCH3W89GAmI5KTipW6tCQbHo8AJPre/nbSHqc1mevw2249LeZ8A/xATsF1P q0D/uoONBhO1VEJTl/2VFcvVrX/X+yYika++Ad9Tjj9NXqfhiox+sAiqxmKJrBGe/cW1 qBkTxsSgPAIjUt3JXbWzW7aJpJ/JmizJJXMFzmswTVVuxiZid0lx69Mx3LIyI65J3+jq zCWlZf5tiZFYcuMY2fuxlBbKkcebISy4QuyS+0/fpm3cMICLUFIVv/TCj+0jDZTMH2AP 8rPw== X-Gm-Message-State: APjAAAUdA4eoSVJ5q6xXw4JPCWkXi8mCRFogoAzFg6X3wijh8b1DAmxX Re3YzD8Sx1Ar6ws4OH6eA/vWsp0BvAY= X-Received: by 2002:a63:2c4c:: with SMTP id s73mr33490534pgs.42.1557164044062; Mon, 06 May 2019 10:34:04 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:36 -0700 Message-Id: <20190506173353.32206-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 Subject: [Qemu-devel] [PATCH v4 07/24] crypto: Change the qcrypto_random_bytes buffer type to void* X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+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.1 Reviewed-by: Laurent Vivier diff --git a/include/crypto/random.h b/include/crypto/random.h index 8764ca0562..fde592904e 100644 --- a/include/crypto/random.h +++ b/include/crypto/random.h @@ -34,7 +34,7 @@ * * Returns 0 on success, -1 on error */ -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp); diff --git a/crypto/random-gcrypt.c b/crypto/random-gcrypt.c index 9f1c9ee60e..7aea4ac81f 100644 --- a/crypto/random-gcrypt.c +++ b/crypto/random-gcrypt.c @@ -24,7 +24,7 @@ #include -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp G_GNUC_UNUSED) { diff --git a/crypto/random-gnutls.c b/crypto/random-gnutls.c index 445fd6a30b..ed6c9ca12f 100644 --- a/crypto/random-gnutls.c +++ b/crypto/random-gnutls.c @@ -26,7 +26,7 @@ #include #include -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp) { diff --git a/crypto/random-platform.c b/crypto/random-platform.c index cb3ca1bc09..66624106fe 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -64,8 +64,8 @@ int qcrypto_random_init(Error **errp) return 0; } -int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, - size_t buflen G_GNUC_UNUSED, +int qcrypto_random_bytes(void *buf, + size_t buflen, Error **errp) { #ifdef _WIN32 From patchwork Mon May 6 17:33:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163426 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp258369ilm; Mon, 6 May 2019 10:40:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBAhHDFlNzqAeTTrMv4u4sa2FP4ATu3UanlgDwaxc3P2940tFHui/Z3B0AsWzEd+u2CLOL X-Received: by 2002:adf:f508:: with SMTP id q8mr796074wro.225.1557164429832; Mon, 06 May 2019 10:40:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164429; cv=none; d=google.com; s=arc-20160816; b=rHR6S2P38Se05a6w3ZvXkMCVBeECpeyLjtYgzS9U627Nounyw/IxZ7MjaHckoIzl1S 0TJmdZbtmJLNLowcYRV/T1sfgjbW8LQTv70yxlcNGWMzYX0DTKDuxzot7UD7G6ylzl5F Z3wxX+8fVARpPJv3/ufE4sukhoWjarj7NcH2Q7mndzerb60BwWkHFXnfwuSmng6Zcj7r hDcmotqJsFNTIT04SF2yUJORA5FvEMDGZQR20V98Lkk7bCv4djhveA+xi3pKPMXJUnN9 5skX+/LZNjETUzGOCKBs2KpAj1dHGLm+ni9Nf6XTJkrReucERM7d5VddkdNa9Pke+sg4 lbBA== 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=jYAIQMfujH1Yj8GqMNdb9ZgzR2B+8AW7wjG3BA673NY=; b=O3807r+sPTbDtUTqPBoIB2SPWEa4H2oLWbgA5IWwP3ENWZkBeJhssBNuSnz8XOFHDt KPqV0ucovIqfzfNWrsJXUCGiwsb95DSkaes5gtrH/7gNwDwxjfWERAYx4N5cheHMK7ac K6CbijAG9H8no0Nr11OgTchU5QdPEFAJDH2Yfo0EaAbBMwaJ3jIoKt4uf7uS5bB+vqOz UEu3Wf37dh8fGIp9HGnm3/jkjyHRhijKHzCDANDFGDhGUNa5iWj3CuVulckucec8deSw tY/McSMQB2wz/PCCy002+Ikkgs2pzHLDNDaYpV6tapQGvkYsLdTbm5vFX9ucX/NC8Kxd sRCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mLk6dAg1; 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 x5si487603wrl.368.2019.05.06.10.40.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:40:29 -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=mLk6dAg1; 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]:59971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhbI-0006gR-MA for patch@linaro.org; Mon, 06 May 2019 13:40:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVB-00012t-5m for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVA-0001Jj-3J for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:33275) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhV9-0001Hu-C3 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:07 -0400 Received: by mail-pf1-x444.google.com with SMTP id z28so7145546pfk.0 for ; Mon, 06 May 2019 10:34:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=jYAIQMfujH1Yj8GqMNdb9ZgzR2B+8AW7wjG3BA673NY=; b=mLk6dAg1QsjNbOm4DQ60Gu/71PfAo5s0UVcwGKOTIgmRy1yEjAWDGZj+ixu4KPy0LV wyk29yKHH9c2inXYUpr1O/VdFBEKgC3fNmFRchbiYAGm2sxwRkUWW7IyoJqfHObtjbxr pXTa4TmOykFdfDb8tU/evt1Bx3m3YiddcZu2uKeZTj2HMRCR8FADxOEq4p4fsdeewNS1 2T5Fx+hnst+1TYvyT5NNBFUpqu/QcXRCPmtnNw8tbmvLaK5Ennp2Xs5xxMTMyW3TeotE xOrjEW55mv+bAQaw4Ar93r+DmotWmAQwULfyizrE4YQIWz5TQXQuk4pUcmCcc5SD7cx9 etcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jYAIQMfujH1Yj8GqMNdb9ZgzR2B+8AW7wjG3BA673NY=; b=bNgl0Egww3oOTKM/KhzhxYObZi5FGTRmrcmmIS4wsfje/x4GJRB05IlyBNXsbCxLCn kVHQcNHtdvFsFGoKB4U6rRPIDF1V0HlXw4Kl/H1M93QDEVnlHOXVLsYi7NCcSKlcekHg dkQ0rAbQstf8TJKrQVWnWHzSO9grD5W/wbeM/ojKMId+eqyDt8N2POjzBPYlYx4plyQA jcTOLtsv+WGSY1EeoAMY0zlw8tJ0Phe5nn7DKcIGJKgfmkROz9FSooXUgrF/VXZSTKXx vryyw4BjdBdq2t9aV4g7umXYizUb53VX92bnlHFRJcQi6Em262iqtSBrNzLVTsD8hHgA skzw== X-Gm-Message-State: APjAAAVZKlSfzClSECsQcK6krDrweLvZQpFNPrR5v9a73l3h9QVJCp3k 6HlpYPNxei3rz0lgwdwmhN1tPgufPiQ= X-Received: by 2002:a62:1b8a:: with SMTP id b132mr34709412pfb.19.1557164045886; Mon, 06 May 2019 10:34:05 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:37 -0700 Message-Id: <20190506173353.32206-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PATCH v4 08/24] ui/vnc: Split out authentication_failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+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. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- ui/vnc.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/ui/vnc.c b/ui/vnc.c index 1871422e1d..785edf3af1 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2535,6 +2535,18 @@ void start_client_init(VncState *vs) vnc_read_when(vs, protocol_client_init, 1); } +static void authentication_failed(VncState *vs) +{ + vnc_write_u32(vs, 1); /* Reject auth */ + if (vs->minor >= 8) { + static const char err[] = "Authentication failed"; + vnc_write_u32(vs, sizeof(err)); + vnc_write(vs, err, sizeof(err)); + } + vnc_flush(vs); + vnc_client_error(vs); +} + static void make_challenge(VncState *vs) { int i; @@ -2609,14 +2621,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) return 0; reject: - vnc_write_u32(vs, 1); /* Reject auth */ - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_flush(vs); - vnc_client_error(vs); + authentication_failed(vs); qcrypto_cipher_free(cipher); return 0; } @@ -2638,13 +2643,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) * must pick the one we sent. Verify this */ if (data[0] != vs->auth) { /* Reject auth */ trace_vnc_auth_reject(vs, vs->auth, (int)data[0]); - vnc_write_u32(vs, 1); - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_client_error(vs); + authentication_failed(vs); } else { /* Accept requested auth */ trace_vnc_auth_start(vs, vs->auth); switch (vs->auth) { @@ -2673,13 +2672,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) default: /* Should not be possible, but just in case */ trace_vnc_auth_fail(vs, vs->auth, "Unhandled auth method", ""); - vnc_write_u8(vs, 1); - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_client_error(vs); + authentication_failed(vs); } } return 0; From patchwork Mon May 6 17:33:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163418 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp252516ilm; Mon, 6 May 2019 10:34:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKZ402ARIxE19xO5OLw+U9cxUdX5NC1QF2qXJZLZ2OpDDjZakWKM/WDsJNFNc3eZXFBGyc X-Received: by 2002:a1c:eb18:: with SMTP id j24mr18427284wmh.32.1557164080964; Mon, 06 May 2019 10:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164080; cv=none; d=google.com; s=arc-20160816; b=nXICqHq0jYLyuULqke0S5lZdrnWOzcSdhw/1GkmZAHy8F1/gBiMf9isc+HJTVqYbyI HhGxXROub98LXwG/1uU8RZmNQNjmkZCn5Lu/xXGzmwM1sQDEcdKbQMNBhlg+CupnR3bD r8SYHkSME+y/01xsf1uhdf8iNnyFaRaDpxwFbEhrLGH8lcaUBQof2jVxETpd9b6DbZ+H YUuQzRW0CbKrVuUCRaWcV2tCmL/G62xRRvj9Jj6bbqL1fTCOXruPpX7Ni4cPLsfos0u8 1ZMRzUwp/1GLlVIg5y8ZrRb6NxebD8/FOorGvCQM9koLqdO1XbblDdCVyj/8rl/HcW3n tjKA== 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=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=Mo8xhBTKrNPDNkQ6SkEeeeFsVY2vcAbR4HZDzWBmSbazK/RJnF7wxsQ6Uzgh4HjWZj Z9YAZjCbSjuJN2c9s8i9NX1GyYWWupRLX3nneWNqlwcxrjN2GFDpSu3hW3d2R2lqRQY3 mHM6PXK2KdMCAS/YgiCL1HxUwAgwzlTPtigak5Ou4RfXEpNw+e7Aqtp7Y+TQfb8wUaN1 aiCmq2HpLFfKbgBAfUt6/5eUdsPqM+cLNpnOvggY8LInsdmQCAK6pgg4GQ68BkuDsWgT HwNGQMgHLna6bNzl7VwlgQJK7TbTXFDctG//E56Je+M6MdqqXr095YyZmO2itYCEYI/+ /RNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=n8q6IHGm; 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 j13si2117575wrn.209.2019.05.06.10.34.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:34:40 -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=n8q6IHGm; 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]:59883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVf-00016u-RB for patch@linaro.org; Mon, 06 May 2019 13:34:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVB-00013I-KB for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVA-0001KR-H5 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:45882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVA-0001JI-91 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:08 -0400 Received: by mail-pg1-x543.google.com with SMTP id i21so6781675pgi.12 for ; Mon, 06 May 2019 10:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=n8q6IHGmbXLkHiw8TrdDI1Qnr0lkZsTs2wkjYQ3BIKve8qI7/ZptgDyrOOpXbZqimF bg8lDUZih+BLgc6jPoUEZ4Wvh0OVv4yCrIw576Y77P1avSmPj+EaZE+oZrvX4ZpBFVIW HLSOIwoVVV73ExFEhfBmtvfHRDu7wto23KWyqk+9mKAPkbwMkEMZ3jNr9qdfGoMjZWYH YgY8I7PkCuldJjHS0beqsCh+b0mzwAbtvYxuRzv4nx7g5uAwUztMKEcoB7uFHXSfMahe x20bh5Yksyy4z36/l6gqCgYj7jF3B38aO7nPlF+PAcr8/uSLqLdhhjZ9md6o1fK9IN+7 S/wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=iTXkZfSg9fLlKzQvr/xozElndTn1EJVKGLW/JnmSe0Be6oUsQVH5RoHnnaLCcD1lqU A02hMfEQK99+rHdCNa7I3pZrgiZrydzrkHYVrHXZi/DGP6BUwyodIViBOuzdwwpHEazB nmmN7jSRw4MQCLpIF3svO1njvfotVF1jYnFYWKd+lLsnQdmhrE9k5dUENK+2nBw72nG2 QF7TE6Tr2v7gQ0PymtmFbJcehIhA9W0ilk+OsjU7T3HNALQM3bwKNxg1vtAVZAR4Zudc cHIzageKMdPM9AIldP7GQNo8otGhAZqEySyV3LwhtEKYtopEpJeQxYPFiyHw9PHANgju LV+w== X-Gm-Message-State: APjAAAXyJkCOGo42RV9/15DRfldhxV+ZuONqUt2OfME9tMt1JP6jQSOO 536CxmA7uYWAYEhySBUfeipqKq4Fxgc= X-Received: by 2002:a65:5241:: with SMTP id q1mr12586526pgp.298.1557164047018; Mon, 06 May 2019 10:34:07 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:38 -0700 Message-Id: <20190506173353.32206-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH v4 09/24] ui/vnc: Use gcrypto_random_bytes for start_auth_vnc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+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. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé 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.1 Reviewed-by: Laurent Vivier diff --git a/ui/vnc.c b/ui/vnc.c index 785edf3af1..d83f4a6ff9 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -43,6 +43,7 @@ #include "crypto/hash.h" #include "crypto/tlscredsanon.h" #include "crypto/tlscredsx509.h" +#include "crypto/random.h" #include "qom/object_interfaces.h" #include "qemu/cutils.h" #include "io/dns-resolver.h" @@ -2547,16 +2548,6 @@ static void authentication_failed(VncState *vs) vnc_client_error(vs); } -static void make_challenge(VncState *vs) -{ - int i; - - srand(time(NULL)+getpid()+getpid()*987654+rand()); - - for (i = 0 ; i < sizeof(vs->challenge) ; i++) - vs->challenge[i] = (int) (256.0*rand()/(RAND_MAX+1.0)); -} - static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) { unsigned char response[VNC_AUTH_CHALLENGE_SIZE]; @@ -2628,7 +2619,16 @@ reject: void start_auth_vnc(VncState *vs) { - make_challenge(vs); + Error *err = NULL; + + if (qcrypto_random_bytes(vs->challenge, sizeof(vs->challenge), &err)) { + trace_vnc_auth_fail(vs, vs->auth, "cannot get random bytes", + error_get_pretty(err)); + error_free(err); + authentication_failed(vs); + return; + } + /* Send client a 'random' challenge */ vnc_write(vs, vs->challenge, sizeof(vs->challenge)); vnc_flush(vs); From patchwork Mon May 6 17:33:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163431 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp263416ilm; Mon, 6 May 2019 10:45:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqzffgy84kO0F3talaIXlt+cc4IQa2I4Z+WEtmgUZAQK0lr/bmGJ+wWD58T0W6sQ0kO83gDJ X-Received: by 2002:adf:e3c8:: with SMTP id k8mr18738985wrm.329.1557164738558; Mon, 06 May 2019 10:45:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164738; cv=none; d=google.com; s=arc-20160816; b=fD0iHn3zzCe9V1S4DuL+Qp4pQdjeTG8AxinXC8LymhgFT2FyGjC5dNmd9Dcc2mH7Qr VypPOrulnHEdjDOSZx6qUb2Cm3nVYUf+a0AdkEHFhOvX2FSZYQpY9PjX+fIf9iFA5UDK euHooLvR0c1ST4hz8izhVzzxwkequ7uJgt5nc2s/NhaDT+OibgTXjcpnHxWLdRmEhZEJ pgRnhTT6oRi4mOVMoAOSTqgJet+vSKKayYApHQir53kXXWvljsZBTC+CpHHVlNSEO0kF EpLuqmx9aMne/k94IsD4gmVwMZkf8Xf/UFJV64uO0t6ONnlS3RROlH+fZxmVLR2ET6GM l5Hw== 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=lbaopiF28XTSe0kOgA43uLo7FEzHh7vNLBWI3VxuLJg=; b=Kg5HxSAN//+LJOrptSwI9dMPdVsZ974MZwVqIKyEHLDWo6YOFrRek9LJoWSBwqgFv0 ZIloGUMSmvEAit039G/Ngrdtp05lnRaUUrbpWBQ2cp/F1ynRalvkai/jifFuWmcvqm+S tY5s/0RLPL+x3Tysnuatlwkal/Frs3Wy1rlEUweuUpQYQOXHTHekzcJqYDFrqA67aQym +UCt91zlDFAwungLXBGfLatlYiCQuqW/QyUB0UrELIoCMUzhRSU9kcEt2ZIPrutyHhaK L6AVXLjSr2ZfhVc/HFJeFhPrjbgUAPbMdxGqad0/2INaJQ/YckDiHicJI6xpiqAJvTMy YEGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yHrF05c4; 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 i6si7914755wrv.164.2019.05.06.10.45.38 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:45:38 -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=yHrF05c4; 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]:60068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhgH-0003Qz-CH for patch@linaro.org; Mon, 06 May 2019 13:45:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVE-00016R-U4 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVB-0001LM-MI for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:12 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:36746) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVB-0001Kp-E7 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:09 -0400 Received: by mail-pg1-x533.google.com with SMTP id 85so6797447pgc.3 for ; Mon, 06 May 2019 10:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=lbaopiF28XTSe0kOgA43uLo7FEzHh7vNLBWI3VxuLJg=; b=yHrF05c493lMI8Ycww/BdgbvwfwJzJL5/wDqNnvOANcNr7P16SfM4ZjBV2sWr7/88s zVcxZGB6bK1EN+NT6V7Brj2A9qpWDeX+kCgoCSEyTtyLsgUMcPpWkRayX8bZeVoSke+x TnX8ktXtmpSacFwJYp2rhRn3X/kITXHTKRSOxZbNfNqcL4h9rWBxoeJ2XlkLZDYSPC28 TA86sZVN1Ku25AmdK1dYjzYLSZGk+UisA7C4DRFGuAqJzlq5ywFs+WSDh+QUUl7c7OKz njDSrjusjlM55A+ONe6V3c8qFxQMM2EcgPGCUymS7NV3Ok+vx4RV+OqSzAygDpqKnCOe BALg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lbaopiF28XTSe0kOgA43uLo7FEzHh7vNLBWI3VxuLJg=; b=cgNWJNzXLFbdaMk39hHh0kurklsqSIEKVzJ+iJaufFQNC/cX5rLm+HjI1+L08U7mIX /l/1OlnfjrJJpTSe9fyuwNLfQjpLS5vIJ0PtyjoGYEQvkjYqUlnAE0rCBwbAkx/PPA2h BIfgCY//G7KNG9Vmes7WlfHt7z+rh4tDkkj+EEYGR12c3K8x4Evg3l4Lp17Ta5rrtjCN wh9iaEmggktat7Zuw9GgfRRNld27l6FlEd5Uo6ajQh05iAiJnRz/v1M+VQ/Gu32pTvxA 0VU8Vo0KDtohA5S6kPoSVP6iPs0Js36Cfnr0OgZ6eAvJDh0IX58TYQgqP3qHgRA1q6lD XCAQ== X-Gm-Message-State: APjAAAU7JXYuewPUxNxSIy+xx7MuTmP8f1pkdGVAH7Q+95N05aBzrzgr ry6/Yf+AL2/Zv4Ob9TrKoqG55NGeAt0= X-Received: by 2002:a65:66d2:: with SMTP id c18mr3106926pgw.427.1557164048174; Mon, 06 May 2019 10:34:08 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:39 -0700 Message-Id: <20190506173353.32206-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::533 Subject: [Qemu-devel] [PATCH v4 10/24] util: Add qemu_guest_getrandom and associated routines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+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. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: 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.1 Reviewed-by: Laurent Vivier diff --git a/include/qemu/guest-random.h b/include/qemu/guest-random.h new file mode 100644 index 0000000000..09ff9c2236 --- /dev/null +++ b/include/qemu/guest-random.h @@ -0,0 +1,68 @@ +/* + * QEMU guest-visible random functions + * + * Copyright 2019 Linaro, Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + */ + +#ifndef QEMU_GUEST_RANDOM_H +#define QEMU_GUEST_RANDOM_H + +/** + * qemu_guest_random_seed_main(const char *optarg, Error **errp) + * @optarg: a non-NULL pointer to a C string + * @errp: an error indicator + * + * The @optarg value is that which accompanies the -seed argument. + * This forces qemu_guest_getrandom into deterministic mode. + * + * Returns 0 on success, < 0 on failure while setting *errp. + */ +int qemu_guest_random_seed_main(const char *optarg, Error **errp); + +/** + * qemu_guest_random_seed_thread_part1(void) + * + * If qemu_getrandom is in deterministic mode, returns an + * independent seed for the new thread. Otherwise returns 0. + */ +uint64_t qemu_guest_random_seed_thread_part1(void); + +/** + * qemu_guest_random_seed_thread_part2(uint64_t seed) + * @seed: a value for the new thread. + * + * If qemu_guest_getrandom is in deterministic mode, this stores an + * independent seed for the new thread. Otherwise a no-op. + */ +void qemu_guest_random_seed_thread_part2(uint64_t seed); + +/** + * qemu_guest_getrandom(void *buf, size_t len, Error **errp) + * @buf: a buffer of bytes to be written + * @len: the number of bytes in @buf + * @errp: an error indicator + * + * Fills len bytes in buf with random data. This should only be used + * for data presented to the guest. Host-side crypto services should + * use qcrypto_random_bytes. + * + * Returns 0 on success, < 0 on failure while setting *errp. + */ +int qemu_guest_getrandom(void *buf, size_t len, Error **errp); + +/** + * qemu_guest_getrandom_nofail(void *buf, size_t len) + * @buf: a buffer of bytes to be written + * @len: the number of bytes in @buf + * + * Like qemu_guest_getrandom, but will assert for failure. + * Use this when there is no reasonable recovery. + */ +void qemu_guest_getrandom_nofail(void *buf, size_t len); + +#endif /* QEMU_GUEST_RANDOM_H */ diff --git a/util/guest-random.c b/util/guest-random.c new file mode 100644 index 0000000000..e8124a3cad --- /dev/null +++ b/util/guest-random.c @@ -0,0 +1,93 @@ +/* + * QEMU guest-visible random functions + * + * Copyright 2019 Linaro, Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/cutils.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" +#include "crypto/random.h" + + +static __thread GRand *thread_rand; +static bool deterministic; + + +static int glib_random_bytes(void *buf, size_t len) +{ + GRand *rand = thread_rand; + size_t i; + uint32_t x; + + if (unlikely(rand == NULL)) { + /* Thread not initialized for a cpu, or main w/o -seed. */ + thread_rand = rand = g_rand_new(); + } + + for (i = 0; i + 4 <= len; i += 4) { + x = g_rand_int(rand); + __builtin_memcpy(buf + i, &x, 4); + } + if (i < len) { + x = g_rand_int(rand); + __builtin_memcpy(buf + i, &x, i - len); + } + return 0; +} + +int qemu_guest_getrandom(void *buf, size_t len, Error **errp) +{ + if (unlikely(deterministic)) { + /* Deterministic implementation using Glib's Mersenne Twister. */ + return glib_random_bytes(buf, len); + } else { + /* Non-deterministic implementation using crypto routines. */ + return qcrypto_random_bytes(buf, len, errp); + } +} + +void qemu_guest_getrandom_nofail(void *buf, size_t len) +{ + qemu_guest_getrandom(buf, len, &error_fatal); +} + +uint64_t qemu_guest_random_seed_thread_part1(void) +{ + if (deterministic) { + uint64_t ret; + glib_random_bytes(&ret, sizeof(ret)); + return ret; + } + return 0; +} + +void qemu_guest_random_seed_thread_part2(uint64_t seed) +{ + g_assert(thread_rand == NULL); + if (deterministic) { + thread_rand = + g_rand_new_with_seed_array((const guint32 *)&seed, + sizeof(seed) / sizeof(guint32)); + } +} + +int qemu_guest_random_seed_main(const char *optarg, Error **errp) +{ + unsigned long long seed; + if (parse_uint_full(optarg, &seed, 0)) { + error_setg(errp, "Invalid seed number: %s", optarg); + return -1; + } else { + deterministic = true; + qemu_guest_random_seed_thread_part2(seed); + return 0; + } +} diff --git a/util/Makefile.objs b/util/Makefile.objs index 9206878dec..c27a923dbe 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -54,5 +54,6 @@ util-obj-y += iova-tree.o util-obj-$(CONFIG_INOTIFY1) += filemonitor-inotify.o util-obj-$(CONFIG_LINUX) += vfio-helpers.o util-obj-$(CONFIG_OPENGL) += drm.o +util-obj-y += guest-random.o stub-obj-y += filemonitor-stub.o From patchwork Mon May 6 17:33:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163430 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp263352ilm; Mon, 6 May 2019 10:45:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcCq86trCYIVWOO5zAfT207EB/LSzfClIuSsukbdjjAJiFTx4FXpTXTiW9UuEQ+Uq+AAap X-Received: by 2002:a1c:7312:: with SMTP id d18mr9449673wmb.147.1557164734573; Mon, 06 May 2019 10:45:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164734; cv=none; d=google.com; s=arc-20160816; b=S/DAyHyXgN2pjhRG5yAeqgNTT56xQu3cTj4Kx0sI+HtxY7a4/jTiRSY9Fr1DxyF96f OWR9WepxV/0uApMVTcvxnAjykqgCBzz4h2VD1Y6pX6shOnwKu+Dcfli7HmxvgDxTVcq9 EygFtQWrplndrVLlXS2iGSFkyu0cAGxUxoT9W+hKxcwJkJzzYUnPXAMr7q4GV2xOLJpz ABjp+Io17+eK7TM0WmPxaZDAJMi6s80TSz2vcRQZKFtooNzEYkfYksQJ+6D+4h9i7bhH 7iEJBy66osB1faJbvEIGdbAeaWiy3BE3rBSGt8U2GdRjmQj8i43TJ/iqJMhqpkHmeoPt Rfmw== 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=J+zhFbaacEoUzexA1I0BDxycgRD6FbkODujZaWxzKG4=; b=vYQ7yf7iwbuU9+nxNaEeuq4vQix04FesfVE0QN2RfdA7qZ8PkSrUmkgqPNX51X54/q mhZh9GsBC/4O2JYrsTj7AUn0iDAMxMm6zrB/7D6ikJsVK0LkiSwhqlNV143fJAL/PnCe U6/P/7yQQNAHpz1fSi6iiQK2CL4MtYLA+ObGC5Fnr7KEEJNYJYJXXfsiO5Y6vsn1QJZ7 pHltrsPJj8vHOXuiODrddvZNuNr+QcYRrAqpSgmsXuiyd7+SqR+yVjZzUlin+oRlxA87 jImQf1RQ61zDznjMJzETAzqgTCMmDp6qDKxhwHBJDcP2Fz25VEpjjx7G4Ktya4kbpQwe n/bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=t2G1W0uY; 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 t16si7932057wri.160.2019.05.06.10.45.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:45:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=t2G1W0uY; 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]:60066 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhgD-0003Nb-A9 for patch@linaro.org; Mon, 06 May 2019 13:45:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVG-00018g-PU for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVF-0001On-6c for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:14 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:45881) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVE-0001Ln-Vs for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:13 -0400 Received: by mail-pg1-x541.google.com with SMTP id i21so6781728pgi.12 for ; Mon, 06 May 2019 10:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=J+zhFbaacEoUzexA1I0BDxycgRD6FbkODujZaWxzKG4=; b=t2G1W0uYDa4lW1lyiUP/+916G5cnH0fvYVtJHpWaKgtjj79q9QieSkhcIEQrkmOtOq p4rROWn3YYVqwBWIRo5PD223/6NAU1iCuqpktZ92QNXCkcO3WFTh2dlOZCg+r2jtSh+c by6kN0hiDudH/FBzvgbCZvWCH2/SUcKCBdwgs1/wTQbmSdlGJqXbiOXHiiStuHA17WHr wx8YmTy4WbHZ4Q720A3DjWUwNEOUmWacppchbxulTMVmGKGB4kUa8sEtLZMBmJZngaDk R6eYjIXxYVzLe6dZSsWT6dGge6dPkvwxl+D6cT/wZ+h+2k+7h9Nt3ys1iUpwMrJ1dPtb G9fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J+zhFbaacEoUzexA1I0BDxycgRD6FbkODujZaWxzKG4=; b=t6QQ9R2HncoYzYGIpZP6nKZBJ/G62YitQdjUxHrg2U/jMvu2vJbbZOYKIgtFLzyX9s sHLxNYrfUcfAylXHB4HIN0b/pLs99snLsYLPNYCls4Yi4UVNW/7zmilDPBOdZOnZPUW2 d34sxismIruIh31Ri5auXnBbBYx7IqxCNbe+cplcFVEuXbEO5nfynMS1+673ie062RdX lhd7pfV7Qaj1gtLGfMkMtI41hfk9ZTXdmsRhGTQ8xtkH6EdhW2aF67ZHzvv8bXJsFNtW 1TYlS3nBNtKitXMrYzgT6eCIl7jyyqstiS2fKKFriIPj/0lE6aR0w/31x+L4d8E4GDHv ftaw== X-Gm-Message-State: APjAAAUki8Uze8nln5NgaVnCqNzqIPd/JzLrZi5bTdKiTLFeJGI+Xj0/ CSr/XcOv7qz6H3vAAUFcFcTXG77mD14= X-Received: by 2002:a63:d949:: with SMTP id e9mr8476264pgj.437.1557164049399; Mon, 06 May 2019 10:34:09 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:40 -0700 Message-Id: <20190506173353.32206-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH v4 11/24] cpus: Initialize pseudo-random seeds for all guest cpus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+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. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: 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.1 Reviewed-by: Laurent Vivier diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 08abcbd3fe..9793ec39bc 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -369,6 +369,7 @@ struct CPUState { int singlestep_enabled; int64_t icount_budget; int64_t icount_extra; + uint64_t random_seed; sigjmp_buf jmp_env; QemuMutex work_mutex; diff --git a/cpus.c b/cpus.c index e58e7ab0f6..ffc57119ca 100644 --- a/cpus.c +++ b/cpus.c @@ -50,6 +50,7 @@ #include "qemu/option.h" #include "qemu/bitmap.h" #include "qemu/seqlock.h" +#include "qemu/guest-random.h" #include "tcg.h" #include "hw/nmi.h" #include "sysemu/replay.h" @@ -1276,6 +1277,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1319,6 +1321,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { qemu_mutex_unlock_iothread(); @@ -1478,6 +1481,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) cpu->created = true; cpu->can_do_io = 1; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* wait for initial kick-off after machine start */ while (first_cpu->stopped) { @@ -1592,6 +1596,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg) hax_init_vcpu(cpu); qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1631,6 +1636,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1671,6 +1677,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1724,6 +1731,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) cpu->can_do_io = 1; current_cpu = cpu; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* process any pending work */ cpu->exit_request = 1; @@ -2071,6 +2079,7 @@ void qemu_init_vcpu(CPUState *cpu) cpu->nr_cores = smp_cores; cpu->nr_threads = smp_threads; cpu->stopped = true; + cpu->random_seed = qemu_guest_random_seed_thread_part1(); if (!cpu->as) { /* If the target cpu hasn't set up any address spaces itself, diff --git a/vl.c b/vl.c index d9fea0a119..d847b3ebad 100644 --- a/vl.c +++ b/vl.c @@ -128,6 +128,7 @@ int main(int argc, char **argv) #include "qapi/qapi-commands-ui.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" +#include "qemu/guest-random.h" #define MAX_VIRTIO_CONSOLES 1 @@ -3319,6 +3320,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_DFILTER: qemu_set_dfilter_ranges(optarg, &error_fatal); break; + case QEMU_OPTION_seed: + qemu_guest_random_seed_main(optarg, &error_fatal); + break; case QEMU_OPTION_s: add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); break; diff --git a/qemu-options.hx b/qemu-options.hx index 51802cbb26..0191ef8b1e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3601,6 +3601,16 @@ the 0x200 sized block starting at 0xffffffc000080000 and another 0x1000 sized block starting at 0xffffffc00005f000. ETEXI +DEF("seed", HAS_ARG, QEMU_OPTION_seed, \ + "-seed number seed the pseudo-random number generator\n", + QEMU_ARCH_ALL) +STEXI +@item -seed @var{number} +@findex -seed +Force the guest to use a deterministic pseudo-random number generator, seeded +with @var{number}. This does not affect crypto routines within the host. +ETEXI + DEF("L", HAS_ARG, QEMU_OPTION_L, \ "-L path set the directory for the BIOS, VGA BIOS and keymaps\n", QEMU_ARCH_ALL) From patchwork Mon May 6 17:33:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163427 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp258469ilm; Mon, 6 May 2019 10:40:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNj7Gxgf4to1FoijK/OEO3rLXqmlmGzM1TkOg8nGJDPs9hyAhmfoW8DR8LRytW2G3goJGE X-Received: by 2002:a5d:53cd:: with SMTP id a13mr18705436wrw.201.1557164437098; Mon, 06 May 2019 10:40:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164437; cv=none; d=google.com; s=arc-20160816; b=mdF47Pmp6/YpvhFxWZpxu71goxqYbvUCBYyQ/3u0tRnwQZdPLVwhrkz+So4Jw5E3eh d8Lx4I3i/N5hJOWEbnu30CQzK2bVtgTMbqyHfl0zqI3sxS/DJXWex/JCWUPWTndoSvvb fnQZicVkSbbCQQwESkpWwTs14kUHP0GpgLCoZ3m6RPItFLcHJ5gvnaF8foJhICVwpped eLSlZ97zZ4rWUo/8loADA6yTJ1a6ijV4d3CL7+qaNZFKIwDfBVPyRglL5g0ZjlYhdMPe M86y0B5xl/DC1fDgqTacOiFiz6BDQAoJ5vtN36en9tlrkV+WUnvxqr070l2jmcoCdwYE sSIA== 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=Fj9NAT+dC/44CVxKQ9vRk+R9FLW3wBp4fXibMqKhPs0=; b=oYf1qyUGDGybnPAvDQ0VCi4ja4gNlL7Q9l5We4jffZfjfoUS/68ud4g6R7vGKVglWB 7acGo/cPKIVkCCxDGFGLJmtflI0EPOnasXIomndA1IO2M9XGMbSBIlj5qgIei0kDBlMS kkfK5HWw3Y8S0foYxyTDBcZ7O8TYNvd0SqwoTeM+jxGXuN2cNbknjFv/Ock7gNK093Fq oWHUVQhsMXMaxH75P+nZz0NyRAx3QwIYVkErS1/awCn0dDZVrpa/P0vlVzPpTFN8rMau GrY/iU8p96JsONauijS7tmGSvHL6nJfTaqpyi1P+XeeL5ZXL9WIvtTK4IK7Xy+YTKeB5 I9ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NS4nASxH; 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 a21si7030912wmb.116.2019.05.06.10.40.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:40: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=NS4nASxH; 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]:59997 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhbP-0006rj-TX for patch@linaro.org; Mon, 06 May 2019 13:40:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVG-00018h-PG for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVF-0001Ou-70 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:14 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:40440) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVF-0001N1-07 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:13 -0400 Received: by mail-pl1-x642.google.com with SMTP id b3so6707168plr.7 for ; Mon, 06 May 2019 10:34:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fj9NAT+dC/44CVxKQ9vRk+R9FLW3wBp4fXibMqKhPs0=; b=NS4nASxHHKXLy0BIyjl1W6Y0jZRvqItBP8DTW46Iu6scDsjW7PAngMCDENbFU3Pe8O inOUA56K/FjJPK2G7scK7/3cibtebx4f8qqd1HcMKifsbavxb88zgn6WIYna/qGOVlVb 9zPiUg0XYrSgtHOUyXTX1gNx1066/e//ZkquhlBzDlfIeot4G8LnZxin9T1mCIWG5GC2 x3LlzYf9gV67QqaZGFADNFu4KnP4wXAwoqhwim/AScSTO1ViKKbzAMdepSVqokzVEC95 iniHUQbcoPeARExpqyaWn5oF2LgtJA1hvjgcx57hxiqN5w+x0iE52WlhoUOEq6BY/AKi 3AMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fj9NAT+dC/44CVxKQ9vRk+R9FLW3wBp4fXibMqKhPs0=; b=C4iKdFnnvclX6ARMZxUXVPGMHv5arO2PuZoXt1LZqfitanINcWMVPDbHv2oyLC5t4/ siNfIaupJTF/NrfYonRqar1ARmD7Y+UotfekzjxdBHw5PVAkIdVXsqZ3p3DXNSmBWmv2 R1CpWmrep2X6QVKfmX2vc9ZYoStVHsICIBq/0hOGd5XCzJUcmJ72rPZ9y0vjwuA+fP4f 5GN0V7zZhbEyFh+20kLrESMLpLjp70lhBdk78+Uu9C9qt+UqnFruBuvE58rlKYyYkths kKxfaK8DF2zMtExi+/z0zC4Rlu8DJqV/jI35dKH04s5as73kMI2szfMQ8yPaLLe4YACe TIJw== X-Gm-Message-State: APjAAAVOC3qaXZBofbVO3P4xdZCYynAab5biR0TqcMRetIGPHBXJavHN ppVQd044bNT5qYMmWIkCR5FnsMRkURk= X-Received: by 2002:a17:902:4624:: with SMTP id o33mr33953868pld.191.1557164050651; Mon, 06 May 2019 10:34:10 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:41 -0700 Message-Id: <20190506173353.32206-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [PATCH v4 12/24] linux-user: Initialize pseudo-random seeds for all guest cpus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier Errors-To: qemu-devel-bounces+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 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 21 ++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 13 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index 3d2230320b..7dfb202e5d 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -34,6 +34,7 @@ #include "tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h" +#include "qemu/guest-random.h" #include "elf.h" #include "trace/control.h" #include "target_elf.h" @@ -48,6 +49,7 @@ static int gdbstub_port; static envlist_t *envlist; static const char *cpu_model; static const char *cpu_type; +static const char *seed_optarg; unsigned long mmap_min_addr; unsigned long guest_base; int have_guest_base; @@ -290,15 +292,9 @@ static void handle_arg_pagesize(const char *arg) } } -static void handle_arg_randseed(const char *arg) +static void handle_arg_seed(const char *arg) { - unsigned long long seed; - - if (parse_uint_full(arg, &seed, 0) != 0 || seed > UINT_MAX) { - fprintf(stderr, "Invalid seed number: %s\n", arg); - exit(EXIT_FAILURE); - } - srand(seed); + seed_optarg = arg; } static void handle_arg_gdb(const char *arg) @@ -433,7 +429,7 @@ static const struct qemu_argument arg_table[] = { "", "run in singlestep mode"}, {"strace", "QEMU_STRACE", false, handle_arg_strace, "", "log system calls"}, - {"seed", "QEMU_RAND_SEED", true, handle_arg_randseed, + {"seed", "QEMU_RAND_SEED", true, handle_arg_seed, "", "Seed for pseudo-random number generator"}, {"trace", "QEMU_TRACE", true, handle_arg_trace, "", "[[enable=]][,events=][,file=]"}, @@ -689,8 +685,11 @@ int main(int argc, char **argv, char **envp) do_strace = 1; } - if (getenv("QEMU_RAND_SEED")) { - handle_arg_randseed(getenv("QEMU_RAND_SEED")); + if (seed_optarg == NULL) { + seed_optarg = getenv("QEMU_RAND_SEED"); + } + if (seed_optarg != NULL) { + qemu_guest_random_seed_main(seed_optarg, &error_fatal); } target_environ = envlist_to_environ(envlist, NULL); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 96cd4bf86d..ce377b2fc1 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -110,6 +110,7 @@ #include "uname.h" #include "qemu.h" +#include "qemu/guest-random.h" #include "fd-trans.h" #ifndef CLONE_IO @@ -5441,6 +5442,7 @@ static void *clone_func(void *arg) put_user_u32(info->tid, info->child_tidptr); if (info->parent_tidptr) put_user_u32(info->tid, info->parent_tidptr); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* Enable signals. */ sigprocmask(SIG_SETMASK, &info->sigmask, NULL); /* Signal to the parent that we're ready. */ @@ -5527,6 +5529,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, initializing, so temporarily block all signals. */ sigfillset(&sigmask); sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); + cpu->random_seed = qemu_guest_random_seed_thread_part1(); /* If this is our first additional thread, we need to ensure we * generate code for parallel execution and flush old translations. From patchwork Mon May 6 17:33:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163433 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp264099ilm; Mon, 6 May 2019 10:46:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJyXO1aBa7C761/ynN/dMXns4jr1hvdtmuU15kwjfjd7BNvYFQSR6lbu65sbjyAcLL6tbx X-Received: by 2002:a05:600c:2190:: with SMTP id e16mr6539047wme.113.1557164772377; Mon, 06 May 2019 10:46:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164772; cv=none; d=google.com; s=arc-20160816; b=mUVMw3XSbnM4ZmCIPXb8wvLmopsavRE3ycD3Mc9Wj7zXT3LB9RMZSlKz3b5uigdlP2 sU9T1FZvv/vZ97eVSXudk4Syk5pp4Kh9b8TCHva2NZKJl2DVkPi8Q/+QXf63wu0x+sJ+ QorsJhtUFhC/jf38FuoS3QW0NWcwOPcMJ7yyhaY5vMJ6z3CYjaGbr3otEtOIH2JSx8ST NyK5mSGXW13nlSmU4LZt6TerEXupEfeCgRbMhgj+VWAoaLAaohojKQhAcrVKAf+3ZYGG pHcqmnUFqzbpzP5DdsCb4srRS5vlksHCcMqBBHhHRuLHYBAHlu/J7LOU1R18ZVD3mwCf UK3Q== 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=HH/L9mt26ecHO3SVHPhMrOoX9weRmZOQf65hlibBofo=; b=z70I7BnLM/j+Nzw8Zvvq7U3fRrqGZpvYtlhDVHrhnRnm25tiJ0uBLxuRrit9fmor/r M9WcU/zYgUrjDmHOVsCs8Rc6KApNyw43xALt5AULxqe95tJ8ikin0NngOIQJYWkyCGsj XZc0lYwXDxWnHwgY+18HMV1P89schZ6VuckawK1gPgBlSTyLF+sONRcSewSLktKrSIMr FTv1/eq1os5S26W2VspX4EXnMt68nspxcKhAA3PpBgGPyLkH7hneQgZwjcqQ3Td4UHHV TYdaoC5VHQSU72TnlV35Fekgk11DODCxlfQ4lWTd+fGeyZd05TUHZbisG8bGeSWIvslc QW9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=x3XXvdHg; 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 j10si1941416wrp.218.2019.05.06.10.46.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:46: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=x3XXvdHg; 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]:60072 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhgp-0003Vr-AV for patch@linaro.org; Mon, 06 May 2019 13:46:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVK-0001Cy-Gr for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVI-0001R5-Mq for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:36747) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVG-0001OO-Ph for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:16 -0400 Received: by mail-pg1-x534.google.com with SMTP id 85so6797515pgc.3 for ; Mon, 06 May 2019 10:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HH/L9mt26ecHO3SVHPhMrOoX9weRmZOQf65hlibBofo=; b=x3XXvdHgCk4PbDzhb99ICvZWxdjsdUNjfjS4HLi+oUzM+5m1Wz9OBa6cvk9mq117H8 n4Lv98wqzKAEFhQGhNysVaOKZvBNAUNaOeVlWh/i8IGVEeWHt8Bb8osvCTy1N7CNvDDF iyvVHwvNtbmDQYuIUelAsdxG9c29VvOM+jxeT9BMnzcGs3s8FS9YBdrsUYiEcdULAOl3 o+a+4MWmqoNJZP6zFrg/oMRanxDMEHQbdgTWpFI8XakuShJzyQ/p1dI9+YWfnlrcZwJk ud8eDaZn1Jse4HM5jRgYaVPiY5Mn8p2F2rPkukqMoubFksOSbHvxUwIHX+O6rCRLRM6K Dswg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HH/L9mt26ecHO3SVHPhMrOoX9weRmZOQf65hlibBofo=; b=pPgtOxq2tQWn7osvtT466FflQtZPn1A7V+AEJZ+M1ziVyNxlOHbShZY3dReWz2GH59 F4KFMdrhhIxa4wcyL3hXHriuc6soqk8fBjC4dGZtLceWtcfgJBicgnnqbV0rDx9M1pqg e2GedNg6htA/0aFq4aE1Tl++W4qumE8PThBxuj/EkQtJYztQerXDoELBZCwX6DuPHmUc VGaRa13GuLfsj5/24IQ2XAjQ3Xh1YTDbe0gr5Q/8R1z+WxNCOJ9pg/pI3dGlj+eczm2k qN+hj/7k6EkbwLr06aYPnC7yfyuQL7lPlo743jlxHMEwPns1LnkqoyudSJLRWpMqkVjk BVWg== X-Gm-Message-State: APjAAAUmXb3ySMMM8ce75UJ+WlahHt8KUOPDVwQ4Dr+CfBpSnBskv/kg /Zl1R38RgAwOWEeze3p2hMOJs2bHFjU= X-Received: by 2002:a65:6496:: with SMTP id e22mr33710784pgv.249.1557164051833; Mon, 06 May 2019 10:34:11 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:42 -0700 Message-Id: <20190506173353.32206-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::534 Subject: [Qemu-devel] [PATCH v4 13/24] linux-user: Call qcrypto_init if not using -seed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/linux-user/main.c b/linux-user/main.c index 7dfb202e5d..e05aebe4e1 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -39,6 +39,7 @@ #include "trace/control.h" #include "target_elf.h" #include "cpu_loop-common.h" +#include "crypto/init.h" char *exec_path; @@ -688,8 +689,18 @@ int main(int argc, char **argv, char **envp) if (seed_optarg == NULL) { seed_optarg = getenv("QEMU_RAND_SEED"); } - if (seed_optarg != NULL) { - qemu_guest_random_seed_main(seed_optarg, &error_fatal); + { + Error *err = NULL; + if (seed_optarg != NULL) { + qemu_guest_random_seed_main(seed_optarg, &err); + } else { + /* ??? Assumes qcrypto is only used by qemu_guest_getrandom. */ + qcrypto_init(&err); + } + if (err) { + error_reportf_err(err, "cannot initialize crypto: "); + exit(1); + } } target_environ = envlist_to_environ(envlist, NULL); From patchwork Mon May 6 17:33:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163436 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp266726ilm; Mon, 6 May 2019 10:48:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyj7QpvEkMHWtGzdlB0tZoRr5brnQzoEUQD+ETaRsEMdBFMTi/CwHWaSrLdpgyAsqOuKYP4 X-Received: by 2002:a5d:6ad2:: with SMTP id u18mr9050982wrw.199.1557164925315; Mon, 06 May 2019 10:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164925; cv=none; d=google.com; s=arc-20160816; b=Ak2tYmg8tsczpjYRN2xsrTvL630lqIGE4igJf+8nGJIdZSJLG2fwwnB28I/x3hMiOM 7DeXGaIsGiBgR1DCE4CUv11JgXyFqdodw6+AGtSxIGKl8M8W7XiGWfk5jVlqoDYOnLr0 jNrVMGNbCK9XgMMZ6sKpqZ9beNBWrOM6/gS5O5h99MyGQnFj7iV0A+UMpq6dqRO178iE 1hNlblvZpkGHZj/ylwKBLKxJr33d0sp/HQhtrytVuydXUzzeywQ/g2VRQxXWTJWN+7hC bTn9xTNJ0eVvpsTvnszc9tBhoOLEsJ9+GxJlNK5OPTDzfITK1f42rnXpbx3JH+hSMTip KNMg== 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=6ZLSvDsE417cQFXtdznOdElqMvcAzRRA3vqOLnZRXkY=; b=QSQ6BkoA44VMI3hB9Vo8VUazupF4S9QrQ9KUBY2MiIEN2/SZxHKA6tIiq31Jp890XX H3IlClgr6btoDsA3WzG2efrjNlaJrL41E7ZZuP6v/NzkH95lEExqrX8XO2+xTpqFZe7Q KPH5jMfU+Y8JWBfZvMAGvHVUfg8uRun7XDvx5PO8qOes6xRLbMnJmw/23KeiARq9XRza avpAtcWJfu4hpfhJvivfU9wo54NInUN7jrKUN6iVUd1nddywPAW1A0lf344L4o1WyH8C dpuN+jHq2QIJM25eJXRdRi5C7t93V+wah3R4m0SfnH97rzYibIDEvkQqsit70JGOtUlC vxqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=E32KfjgM; 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 n7si5384359wrs.10.2019.05.06.10.48.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:48: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=E32KfjgM; 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]:60090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhjI-00065e-82 for patch@linaro.org; Mon, 06 May 2019 13:48:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVK-0001Cz-Gs for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVI-0001Qp-Lf for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:37276) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVG-0001P9-Ol for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:15 -0400 Received: by mail-pg1-x544.google.com with SMTP id e6so6799970pgc.4 for ; Mon, 06 May 2019 10:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6ZLSvDsE417cQFXtdznOdElqMvcAzRRA3vqOLnZRXkY=; b=E32KfjgMlH1BNZqxvEe87rzW5aXT1ryTedZZsN1NoTPRj8Lo5MKTENOVYjBnYfpgQg vI74qDBQ6nv8qxXXDbvERkYtVaZ31P3Cl+Vt6tGex/nFUQ+UT6Po1dw5GesRWry95Jko ofBkUgbvbqwLTajEGDRqWgdm7ymFIk14MvdVu0+eL8V/oluZMMi+wDHw3c8/RUzCAfYX 8lwUbS1f42yaO7pdTL9RuljvwMIUuAYI7+aZco1eMucsi4JO9ixoowwuz7SctYK2frWy 3tIAOI8kS8r/4C6ZvmE/9DeGVwIkTOTM9mC+Pxe4xUPs5YBoEcixmRz6as2LTlM/95Zn wR5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6ZLSvDsE417cQFXtdznOdElqMvcAzRRA3vqOLnZRXkY=; b=CZ1Q8NW9hb6hL9Ri+DI6z4szHgEZTFRuqEI4X22qxudm8sbGY7XdVWeEeHkE1R4lvi hKoCISA7xjfjuHSSOE1jjeOuIYPpmUV5YcH8ZVJ+UkA+luDbPGFR1ugrB0AI3/WDDJzp nFUNuOX+obeQM6dDl92NEvboPb7eiqHS2SGndylMp4BWXF5xTscLqyKNZv8oNne/HDtc Bw0gfC6YNh/EcnMZMSJXTEbRm/lWALIpt0v36zWSytVmeklhPxNHKEDwsblutzZ6E2Ic z4hPSt4kFM0W15KjbRM3I4tLPYdKuXkoABoiqvQMQU+mBLfQu8+7YCZNgkhZhKjOUvxO 9wYQ== X-Gm-Message-State: APjAAAXuc/jZfwI9HNurogvIjpkdA1Pjiv+zhs0yrHdvvU0HM3r8xHXA HrCvCkjHmJAaWh6hTFPtH3AUhNiVAnM= X-Received: by 2002:a62:5a42:: with SMTP id o63mr36429284pfb.170.1557164052846; Mon, 06 May 2019 10:34:12 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:43 -0700 Message-Id: <20190506173353.32206-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH v4 14/24] linux-user: Use qemu_guest_getrandom_nofail for AT_RANDOM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier Errors-To: qemu-devel-bounces+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.1 Reviewed-by: Laurent Vivier diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c1a26021f8..e673f7ea55 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -7,6 +7,7 @@ #include "qemu.h" #include "disas/disas.h" #include "qemu/path.h" +#include "qemu/guest-random.h" #ifdef _ARCH_PPC64 #undef ARCH_DLINFO @@ -1883,12 +1884,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } /* - * Generate 16 random bytes for userspace PRNG seeding (not - * cryptically secure but it's not the aim of QEMU). + * Generate 16 random bytes for userspace PRNG seeding. */ - for (i = 0; i < 16; i++) { - k_rand_bytes[i] = rand(); - } + qemu_guest_getrandom_nofail(k_rand_bytes, sizeof(k_rand_bytes)); if (STACK_GROWS_DOWN) { sp -= 16; u_rand_bytes = sp; From patchwork Mon May 6 17:33:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163439 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp269649ilm; Mon, 6 May 2019 10:51:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4LGDBvCFD5ie1cto4PUT++lPWtk5b7E/9Zqv+VBvddAJU1cYxkXfOLtX0kXbCsxZ+cmNW X-Received: by 2002:a1c:7c18:: with SMTP id x24mr6251577wmc.15.1557165100168; Mon, 06 May 2019 10:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557165100; cv=none; d=google.com; s=arc-20160816; b=zp0mCBuwf8onC0sKtz1QhmpakJbD2v0PhQu0gQ4DPsEbT9/Dv6XIInzDT3/GSeQ6LL yGAr8sWrbDKTdn+NiMgibcfyNZlfS8z5vLacZFyhOzrN4P784sKfPdXLDGhDjrCJJBoL qbWy1GVBRxKCsJ9u62q5DxVLWXr5opebv9OaBNLQDJR8Wx4pg7pIDp4erdws+o1fUi08 5ojKv4Zy/LbCMwL9dMoR9ITdXqOuTOYYdeRTm23SM/JeIK1oxB3x8T80AyDwwan0Ayg3 3VbJbLX9eLAPCtgGMkkhYacr1G82eBQCrdqkdvQbq5DcKcevXrEe/leCi286k7CWvGkF /Hjw== 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=XGj6206fsdJxol+0Im+/ya3c6hhRI8KMqoTGs4TcX0E=; b=Rsgbq1cxkCB4wvvJfQSOIDtPq93zXh1CV8tu9zvnGBIn9Qe1m59hAc2sc11j2Rbs+k c8MExgrmsC/vqSmgCLXOCFY87s6uI+/LxnMoYn/sYTQUI9Xc7u4wo7JmUByLAuBObNlB Io8jtvxct7yTKT9J8WRG13UNca5/vNrIOEylax8UwwBq0pGIGRxgHKOXyXCku8oB0jn2 WsEHZBn+tj5CnACJyyrZfrYVhU++pXmBHAa0I61WtmCqv2Sw2ciXd9JbbtB3WDwKqZqx gpSiHwnGD0Nw/uIx72+YBZulSWraab6on1dCKwgJrPUXHPMrvREsvk1QCNEG7yGILGMA 9ZhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Hck4bxZS; 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 g13si6191849wrs.166.2019.05.06.10.51.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:51:40 -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=Hck4bxZS; 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]:60159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhm7-0008PU-1C for patch@linaro.org; Mon, 06 May 2019 13:51:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVO-0001F2-0G for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVK-0001SS-Ho for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:20 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:46569) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVI-0001Pg-LI for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: by mail-pf1-x42f.google.com with SMTP id j11so7111844pff.13 for ; Mon, 06 May 2019 10:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XGj6206fsdJxol+0Im+/ya3c6hhRI8KMqoTGs4TcX0E=; b=Hck4bxZS5lN1BVH0JeCN8+AIj+HAHE6FayH8F6hePk6Qw1lfF8V7mKFyn58QNGu7gy EpIQBnLb6TLsUEatCYigkrtbK45Y0EIaCp1alybwgBBCr07U/cfCVq/PvvbARBJIO134 uHgLRXsRaHWc6g977fBaP3z/8PnYxD/RZNGi/eynnEjHP66cff4GwSdivixRJyeXgYDC RABXB28gDF0yjCKhD5X6o4+4KyzI7YlfDXEzBLqIoylhYSAh0JaQFHPf5OHiJtLPAM6t GA3ruEeUqEiokd5aQ3A/wW+0wRl4bORI50RyjtM0H1o4la8uxjrN0fHRanwMh9OTC95r 07rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XGj6206fsdJxol+0Im+/ya3c6hhRI8KMqoTGs4TcX0E=; b=S1R2FzDbgYTRO+plzWO3fvOgdHOIkyCosMXz2JqgJWkcXOmvOVX4+8yk0BuGXrGA8z XQpab8gitZU1QfAX3zrHteidMR6c4714SBF5squLHFoHjwRz1vWtr0KksBcJ1qdFmGcX tu7Y+LGGNMF1mGWrOQpol6gsphRZxWK5QVfI82W2bArC65EolmLDvjD9h1ZEbuzTT4Rq hE3P8pEiFUtfgjgVVuNpyW8lKjBgpErowGpDtXwH+N1bDNCtq/gsFnACyI8bOCxl0AVB gM0zrF7h9uB2TXFyG0Qx0cR1HNRAfWv62UTkINsnZebdk9yHcvUNEMb+5KMzN0jVpsNQ nkrA== X-Gm-Message-State: APjAAAXHI+nB3xvgnIgFA4FNfOpxa+TK/P2AY9oH9Pkl0RAdsrjDUmgH Hko6pT6WyMSFildxf5H5Rj4cEisz/aQ= X-Received: by 2002:a63:1d02:: with SMTP id d2mr7013533pgd.26.1557164054000; Mon, 06 May 2019 10:34:14 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:44 -0700 Message-Id: <20190506173353.32206-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::42f Subject: [Qemu-devel] [PATCH v4 15/24] linux-user/aarch64: Use qemu_guest_getrandom for PAUTH keys X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand() * 3. Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé 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.1 Reviewed-by: Laurent Vivier diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h index b595e5da82..995e475c73 100644 --- a/linux-user/aarch64/target_syscall.h +++ b/linux-user/aarch64/target_syscall.h @@ -29,6 +29,4 @@ struct target_pt_regs { # define TARGET_PR_PAC_APDBKEY (1 << 3) # define TARGET_PR_PAC_APGAKEY (1 << 4) -void arm_init_pauth_key(ARMPACKey *key); - #endif /* AARCH64_TARGET_SYSCALL_H */ diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index d75fd9d3e2..cedad39ca0 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qemu.h" #include "cpu_loop-common.h" +#include "qemu/guest-random.h" #define get_user_code_u32(x, gaddr, env) \ ({ abi_long __r = get_user_u32((x), (gaddr)); \ @@ -147,24 +148,6 @@ void cpu_loop(CPUARMState *env) } } -static uint64_t arm_rand64(void) -{ - int shift = 64 - clz64(RAND_MAX); - int i, n = 64 / shift + (64 % shift != 0); - uint64_t ret = 0; - - for (i = 0; i < n; i++) { - ret = (ret << shift) | rand(); - } - return ret; -} - -void arm_init_pauth_key(ARMPACKey *key) -{ - key->lo = arm_rand64(); - key->hi = arm_rand64(); -} - void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) { ARMCPU *cpu = arm_env_get_cpu(env); @@ -192,11 +175,11 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) #endif if (cpu_isar_feature(aa64_pauth, cpu)) { - arm_init_pauth_key(&env->apia_key); - arm_init_pauth_key(&env->apib_key); - arm_init_pauth_key(&env->apda_key); - arm_init_pauth_key(&env->apdb_key); - arm_init_pauth_key(&env->apga_key); + qemu_guest_getrandom_nofail(&env->apia_key, sizeof(ARMPACKey)); + qemu_guest_getrandom_nofail(&env->apib_key, sizeof(ARMPACKey)); + qemu_guest_getrandom_nofail(&env->apda_key, sizeof(ARMPACKey)); + qemu_guest_getrandom_nofail(&env->apdb_key, sizeof(ARMPACKey)); + qemu_guest_getrandom_nofail(&env->apga_key, sizeof(ARMPACKey)); } ts->stack_base = info->start_stack; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ce377b2fc1..b73d1d9f65 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -111,6 +111,7 @@ #include "qemu.h" #include "qemu/guest-random.h" +#include "qapi/error.h" #include "fd-trans.h" #ifndef CLONE_IO @@ -9724,25 +9725,45 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, int all = (TARGET_PR_PAC_APIAKEY | TARGET_PR_PAC_APIBKEY | TARGET_PR_PAC_APDAKEY | TARGET_PR_PAC_APDBKEY | TARGET_PR_PAC_APGAKEY); + int ret = 0; + Error *err = NULL; + if (arg2 == 0) { arg2 = all; } else if (arg2 & ~all) { return -TARGET_EINVAL; } if (arg2 & TARGET_PR_PAC_APIAKEY) { - arm_init_pauth_key(&env->apia_key); + ret |= qemu_guest_getrandom(&env->apia_key, + sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APIBKEY) { - arm_init_pauth_key(&env->apib_key); + ret |= qemu_guest_getrandom(&env->apib_key, + sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APDAKEY) { - arm_init_pauth_key(&env->apda_key); + ret |= qemu_guest_getrandom(&env->apda_key, + sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APDBKEY) { - arm_init_pauth_key(&env->apdb_key); + ret |= qemu_guest_getrandom(&env->apdb_key, + sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APGAKEY) { - arm_init_pauth_key(&env->apga_key); + ret |= qemu_guest_getrandom(&env->apga_key, + sizeof(ARMPACKey), &err); + } + if (ret != 0) { + /* + * Some unknown failure in the crypto. The best + * we can do is log it and fail the syscall. + * The real syscall cannot fail this way. + */ + qemu_log_mask(LOG_UNIMP, + "PR_PAC_RESET_KEYS: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -TARGET_EIO; } return 0; } From patchwork Mon May 6 17:33:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163429 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp262812ilm; Mon, 6 May 2019 10:45:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvB4eRw84DwmWKWZxGhvBg0nJBVO9I/EPBzZbO66h60YJlkz8ulaUBgK/45O+d8Ea45Zqa X-Received: by 2002:a05:600c:34f:: with SMTP id u15mr3070890wmd.60.1557164701568; Mon, 06 May 2019 10:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164701; cv=none; d=google.com; s=arc-20160816; b=mCSVJEnEZR0AlBi2YcL2wWo9K4+q9uVAC3FdHa7I6IXJGV0PqY3ap7ErToZ5YctHCn 0Jj2WtlqvvrOTDfk3O0TlfV7oHKCqtcEnA/wsw5+1mAl71fZxG4OgBb6Ns6Iec4VhEGz PHFm9U+uzotv37jJtlgUTIbqCfN8RXwzaw8E1MqIzyswL/MU6LTGK6AzalDVnl8F74bd wU+lWQ95CYfBt5hrD91ZdqBJMHt98qjVS1Q45Y125WAxuHSfJbROekfZ1fC0ziY7mJRY SSqSJ42hsqIw1GLRcXL/1oZPcFYgQ91pL7M0+of8hxVlJM6zOomsTZUO3Sl02xyU6Por kEjw== 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=eiE9fqe9KMXKwTkJClxb0B2B9ssy/VKRiWp6bsH/0U0=; b=vCjClHBdqM9B/FM8FE6+6xswQg4s2wirmTQjk5eX/Y36FT2wGEbIu3eqUFauz0knw0 /PlsEdFpGOUZGIVSMW8k07FHMcTZ5oqW5z0GzbjZH3LlafCI5KL8aKXWbsEQ4FPJx53I ylYutOpjx5zJNjS2wrRbMpt4eemDGeIHtt1CockGjL/46rPpC6txRgyFtlNpK4prA9KL cDdHoKp/stShngDgqc5X6DCNZZPKQVpJfLUeS5vsFmlKFuhrX5wNs04zA/3pMKdLsgGG I7r6tb4SjUbVwqDlmlbmNzlMGdCauunXVLUh5QPQIFrvQ29iv2Cmzo25UEzKOouLxPmZ tkrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sK6KxzCN; 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 k11si7321616wmk.169.2019.05.06.10.45.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:45:01 -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=sK6KxzCN; 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]:60032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhfg-0002pg-F0 for patch@linaro.org; Mon, 06 May 2019 13:45:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVO-0001Ey-07 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVK-0001SO-HZ for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:20 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:41751) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVI-0001QJ-LW for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: by mail-pf1-x444.google.com with SMTP id l132so2178234pfc.8 for ; Mon, 06 May 2019 10:34:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eiE9fqe9KMXKwTkJClxb0B2B9ssy/VKRiWp6bsH/0U0=; b=sK6KxzCNzNFZFFS5hBP6i9IqgAut+jrnX9Azs97fkmeWcNbvdyHnS+KSS1jSUX4bij x9wop2iwo3pTvk9yCrAaL2NncN6cjXJtPhkKEaDwWJJT/I9AKcf7N3+LEasky95cyzPw fiddB8n9QZyfgkT8pXBk5ZRRKPR4IIGdYgSM64luPmO5jc9fiUK57eoUKqArtPslpPo3 6UKxJ71IkqdFyuqic/UiUJYtRHGytAbJ/1qcEMnA8fZ+I6QxTd31GvdoeOipUHA9NlhU Nlmdn1BguZGgKaBS2WpBjT9sOurvC1A2SVs7tOeitcwZl6pUrwb/RnpGX7ggFu/LtXg4 u66A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eiE9fqe9KMXKwTkJClxb0B2B9ssy/VKRiWp6bsH/0U0=; b=HZPFvVJuWcBTfiJWNm1Q3nOeI5QUIPXP6/F0Rts1Wul6vwJ0UuD/kEE2dFdL3oEA6b G+PYXYbDcMPV7h1GR/AgoTedwVpaF1Kl+8D0hfqfi3wZY+UslGOwqUTwnIAZdAPHDRK0 lMEi6YiTdyAVEQTjmkH620ynvyvFQvonJCOfI/IEy3i+ImsVU66wGP1wITysM6aCYzkM 5Q2EfJJL4u0diuNoxloHNRpWJwuFLKlC08kvFVjggsFl3sTJrSzS8HZx1siqvLOUgoB7 0lr2735oDRYsZ1HhRIhmbhOwbkl0GR310cmvG6tVRWHNvrIRDtJRP2YuHlW3bnvcWWrQ FiUA== X-Gm-Message-State: APjAAAUdXkBHhoR4oItMSzTeSzOGbyMSbsYU1w+jbZBu4IDyjHqFfddd vm9Nuq3wOiPJkgwHQfAmGX5f4a7DKQs= X-Received: by 2002:a62:5286:: with SMTP id g128mr34058692pfb.226.1557164055105; Mon, 06 May 2019 10:34:15 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:45 -0700 Message-Id: <20190506173353.32206-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PATCH v4 16/24] linux-user: Remove srand call X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We no longer use rand() within linux-user. Cc: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 2 -- 1 file changed, 2 deletions(-) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index e05aebe4e1..5d1c6a115b 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -623,8 +623,6 @@ int main(int argc, char **argv, char **envp) cpu_model = NULL; - srand(time(NULL)); - qemu_add_opts(&qemu_trace_opts); optind = parse_args(argc, argv); From patchwork Mon May 6 17:33:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163434 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp266128ilm; Mon, 6 May 2019 10:48:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8NzNYlqZgxXaft6Q2wiahiN+PlzvgxaC5No0mm345D3mzz1zFv5v9EtC2/T0zwXXAcroF X-Received: by 2002:a5d:4ec6:: with SMTP id s6mr18099062wrv.87.1557164887173; Mon, 06 May 2019 10:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164887; cv=none; d=google.com; s=arc-20160816; b=1CatDtQBbkHDPUUm8MAZYYfL5PM/nqv5SuzeOTWcYqwCrgar6dX3TGEXVToiJFknTW djY5Ozay72+OM68yQ1tNUaOJT0U1Fm55WYC/L0SxCKCfxZK1S2bYEHzyEW/pDkKXzb0b XqOkGqjqtUL0o3VHdpze7wxokpI9L1enRAnXb013N3wH+qAcZ/Hn0pQG2zHzjp0bCjVe czOFBXOQu3Y0ZhIUdOilj/wxkup0H/zVwIxTx/DXOMOKlEsb1jrl8phoLD8lQg36kqjH BEaX9V5CD1liMCbOBtsZfVsFSn9lUn5QRgpAqGUSUX5i8QTEwMR/vzEoUam6LD7M5l2Y aNWw== 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=PvlwPcZPY/FWFYh3k49LzzqKgqvSGwd1QF+0Yp8Ixq4=; b=bXAoWMuoq3gRkzx/2JHcA8SATLle17Qy0GKaZQrK7NzSFrxV7lVs5mDASdJRzrkIWL 4oS/obseQUnmRkysx277p2fNH79UmlqzAdZCHQp76MCnv/+dzrckUfso4m0nA84d5/TN 5wzDZxe3IRmCnhWzEUW06Aqa7uuLwIfRCXkB7ZXcuOLhHPeHrXxRpNeZgKigc0SjpKWl Z4Sx5XLEuJmt0GeUV9wB6sMqUJDkmKVZZzKYYTgvpdpWLhi41gHteuPHxrcWEuvAQf1O 1a5M/kE2fLp0C0fmq8kth6Ly/NNTpnxpuOEAW8srAysD1Bciq4bH4VKHOvQR+TwoRGml yJWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=FtmpCYW2; 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 l4si7630445wrr.52.2019.05.06.10.48.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:48: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=FtmpCYW2; 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]:60086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhig-0005ct-5c for patch@linaro.org; Mon, 06 May 2019 13:48:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVO-0001F1-0I for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVK-0001St-P7 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:20 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:42678) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVK-0001RD-HR for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: by mail-pf1-x443.google.com with SMTP id 13so6822231pfw.9 for ; Mon, 06 May 2019 10:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PvlwPcZPY/FWFYh3k49LzzqKgqvSGwd1QF+0Yp8Ixq4=; b=FtmpCYW2i5ojok4k2vEbCXHVQi8yP6K+LoxD05vBTGP6vq75Rr8lHdm28xNtI1ZI0u a0G9OW/fI7O5IQuKSpA3guGEmMDdUH21sF11J4eRhjs76Yrp55Roy25FjdjbYRv0CWo5 JFo8CizPG2FVHATM80gGMAmsFljmdbsAhXj9NON++vRlBEBYmkvrfP/XOCUp3cBZpTD1 GcX4okn94qath5pIaWbNh7r09RU+zJj8m23PaCQpKDpFEzrRGw71AjjBSnje0eXiEdvC 773e4TxrfZR5ltJqobbxmuSo3we4hj1v6IlxPLzKEp9qxVW0YO6p6s7G9BkfyaLIBT08 muAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PvlwPcZPY/FWFYh3k49LzzqKgqvSGwd1QF+0Yp8Ixq4=; b=o2BWax92tK7qkT120zorgOalvVrKxDe6ls/Uzi6+rGxveGuZ+umA/Wsbr6zbUWcfEy nSlBmR5NXvSm0jR8hoG2MHQkXzQcpNEtOUtzNBXI/C13qb8cDREYmz6B0YfsBV1qfXyv QzZph5eLil0MHAZJtujBN9TlQC9d+dXrGImX/SXZ59/VWGO7YYPxcldQlNFwQXEjOW00 oh1pX8ec3PaX6vyZs5IEiTpveMJd+V5ug1aQqQp7fZx3NsPJOD5X+xporRoZyTWoUPKb NBAcUBMN+6SWeHYamMC63BZjx399dh9qkU3o6aHVSvTLFAKp/l1ikrleCMb4k8lHI4Fd n6dw== X-Gm-Message-State: APjAAAXYYkRcPkDER5Mwtgtr0iIDlgcAnO5rlWuaWyEs1tkGn0k35j8l U5SGCpv7uxQkFuRu61AuCq7IdQJb5OQ= X-Received: by 2002:aa7:8243:: with SMTP id e3mr2434449pfn.213.1557164056133; Mon, 06 May 2019 10:34:16 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:46 -0700 Message-Id: <20190506173353.32206-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v4 17/24] aspeed/scu: Use qemu_guest_getrandom_nofail X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+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 Jeffery Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Reviewed-by: Joel Stanley Signed-off-by: Richard Henderson --- hw/misc/aspeed_scu.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c index c8217740ef..ab1e18ed4b 100644 --- a/hw/misc/aspeed_scu.c +++ b/hw/misc/aspeed_scu.c @@ -16,7 +16,7 @@ #include "qapi/visitor.h" #include "qemu/bitops.h" #include "qemu/log.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "trace.h" #define TO_REG(offset) ((offset) >> 2) @@ -157,14 +157,8 @@ static const uint32_t ast2500_a1_resets[ASPEED_SCU_NR_REGS] = { static uint32_t aspeed_scu_get_random(void) { - Error *err = NULL; uint32_t num; - - if (qcrypto_random_bytes((uint8_t *)&num, sizeof(num), &err)) { - error_report_err(err); - exit(1); - } - + qemu_guest_getrandom_nofail(&num, sizeof(num)); return num; } From patchwork Mon May 6 17:33:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163435 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp266611ilm; Mon, 6 May 2019 10:48:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBI53vTfzIJQtuRtSbaw1U4Z+/T/Ko6NCRvZwWWqrz+mHI2Yis8YuJNkCZrAwfXYSd0W6I X-Received: by 2002:a7b:c010:: with SMTP id c16mr17639915wmb.82.1557164919014; Mon, 06 May 2019 10:48:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164919; cv=none; d=google.com; s=arc-20160816; b=ob1Lze20kKhNGRdNHCiNSsJEIjUJGxAuecxqP7DSIsFVBFEvo2CsHt6RwNQE7uBTaA Gg4+k9CfmGQcpONji8U1FzvgWmbO8Tc7jq7uVxzGjuvuy7kRvzQm5tDPXEHsPwhNVNUE U8Yj4C5jZg2/4npOAFpVo1HbAjxOgDuAtCWlQYiS/sLcOBkXX7l1E70Mvwh7XDUI1ZBO 1fANYfjpF2f7H+CmBFSLiKYBVaStdDQZfYbLKXGlPHZa6nW9bge93PSYdl5s3Dy0GE+K A4FJEAhd8ZQ2zgom/LHvP1bSquWMEF9/D4eOfpZ6v3n4oh4EpMt0hbrIOmGPMgKRZbfq 79JQ== 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=N99BQlBfn/0a0vkPsRVGBD0Y+fTNw9UH381I+mLvorI=; b=dffRzJRSSB2l9e2ERxxkoqHW2sZlSIpXaNVB9VS/qsCI/zmL3CgwlBPR16IOkli5Hk w+9oysztnyv3aZ61QXIeoEGRjkVzmyyvFR6Ao0OpzYbHFxaoJu44a3m6rPPIlxGKzb2W 1NmVBZgkkaN6jG3yLHKxOW10Eu2j8zuE6sBsrlhrQrni2xmYufTQv+i4TNqUdAaQyPFi 00aPN8IjfZqdcG9P/wR2yWiBD1Ugp4ZvjqbUW9J1Qr/5O1hqpLoDmV84wqPd5OywSX+C pvsPs/he/O+ZdO+0YC/TE4BpcHbP0IhBnUYO/tNVwvbBh9HWh9DOtD4reCe76eCBV6Dl +5Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Dg5+08ul; 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 u11si7763919wrr.404.2019.05.06.10.48.38 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:48: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=Dg5+08ul; 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]:60088 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhjB-0005hg-UH for patch@linaro.org; Mon, 06 May 2019 13:48:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVO-0001Ez-07 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVK-0001T4-Pe for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:20 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:37703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVK-0001Ry-Ia for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:18 -0400 Received: by mail-pl1-x641.google.com with SMTP id z8so6722983pln.4 for ; Mon, 06 May 2019 10:34:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=N99BQlBfn/0a0vkPsRVGBD0Y+fTNw9UH381I+mLvorI=; b=Dg5+08ulJwFtevhdXETSihRnqYW53GxvjPzw9ZR3Qx6fNBXqDsUz+BEg2OG4QoUPe8 vkoX4Cs3zdwrbURmxP7Z5gDG9uvSpuYLcAl2mt1cL2BfZWIJDouEdvI3YxOExef4pqDP m5dU93hcjaSZu/r5Rq/WnMWTNMIyIDCMaIuzmiHaojzodxuIcuUpU7QSkftKg1DT8hcJ mNvgznnAm2labFfkUIS9R/KqaLXyETesGAqL8i2q5hn4GBphmnJHBn+SMNi+9FgWyjKF xqr9Jb/vVNb6XzFDBMUBx5vJA2Xli40KCjRhl+BZdwcIDuCapR5tZ76B1tHpCOrESQ/I 5vfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=N99BQlBfn/0a0vkPsRVGBD0Y+fTNw9UH381I+mLvorI=; b=fK0tgBJuWWwyf2phhUO24LUVeIorSMZ7OJc491yH5Rle2HYkYqzTM+HE/+UeT3Z0gx J9tUWbFqhe0bmpImswdDt9jcq2xZEwnDeGajJJH7crgIrvGwVFe2SnfSX+WY5SM1p5YX AEf8iZw8ZklrjgQEc0UpzWtbOUv9JfQ0dkqCb8SXmepYaoe1MDElzYWxf0TYJOzwTMUL vcS2J6NP7GEb52l4JPLZeoeXSJRoVBZHPCe6SK6HFmEmCwsRjh+Fg2Jq44wUP+nKFyOC pG1SN5Hwy42FOEBaSKGlYoULVA+8UaWq1Oc6onUg1UFD+a/zFtqqKLMMTBNGH9qnsa2b NzAw== X-Gm-Message-State: APjAAAXdjyTU1cxZ+PIsDJNYI3Ffw0Oou3ue8oi+bNfABRTcBSiOdoy6 2OH+2ucw9Yoidcpap/rfMvj6LIvfpH4= X-Received: by 2002:a17:902:76c5:: with SMTP id j5mr34356896plt.337.1557164057250; Mon, 06 May 2019 10:34:17 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:47 -0700 Message-Id: <20190506173353.32206-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH v4 18/24] hw/misc/nrf51_rng: Use qemu_guest_getrandom_nofail X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+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 Reviewed-by: Joel Stanley Signed-off-by: Richard Henderson --- hw/misc/nrf51_rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/hw/misc/nrf51_rng.c b/hw/misc/nrf51_rng.c index d188f044f4..3400e90a9b 100644 --- a/hw/misc/nrf51_rng.c +++ b/hw/misc/nrf51_rng.c @@ -14,7 +14,7 @@ #include "qapi/error.h" #include "hw/arm/nrf51.h" #include "hw/misc/nrf51_rng.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" static void update_irq(NRF51RNGState *s) { @@ -145,7 +145,7 @@ static void nrf51_rng_timer_expire(void *opaque) { NRF51RNGState *s = NRF51_RNG(opaque); - qcrypto_random_bytes(&s->value, 1, &error_abort); + qemu_guest_getrandom_nofail(&s->value, 1); s->event_valrdy = 1; qemu_set_irq(s->eep_valrdy, 1); From patchwork Mon May 6 17:33:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163442 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp271642ilm; Mon, 6 May 2019 10:53:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhZgw99UFwTaKSxqSzo6aWsyd4w68010qG/sWAWRji7/QqwuTawfwnejrXPog09IdiZVHR X-Received: by 2002:a05:600c:21d2:: with SMTP id x18mr3392760wmj.81.1557165213346; Mon, 06 May 2019 10:53:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557165213; cv=none; d=google.com; s=arc-20160816; b=otSJ1y//VazH/fgnYjJOHsWutmnbvbMaTyf7NqF/dhkgYFMBPad5LyeBNsybpmlP9L Ds/FNCciBAe03ncXiEC3AI3FUk44Yu2wL1j+BkoYgeBNnI+6Hxji11FjALvZPZWLkOt/ whpaTDGJ9JU5ctp2JbNolnK4S0RRH9C3JtHaqwaDv1g9z0/4nRRZoFHVJcKodCHoq5mK KqI3PFJxb4DJ8fB4lGOXFb4aQrBuGtMp+T8r9qUClQfmrcKU9h9RihURKlvi+QOpqfIh 1+hUNXx6STcFFxwHTPK54p1XWw4kAn/SXQmAW++6MF00O4STU42qTzeZE0MxVIHj1jHf QdMA== 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=2div2YVLjVe7DwdMLbNY+nkm3nkpzeNz5eXH0qLyY8k=; b=iNpKcj55otx6fOORcY01Z+sb7z79bLJ+lU0B1rAkW46Zopy40HL+JdikWxsV7ue/df 5AsnYJ6xNjvtbMqHnOjnVN3uXpxeIW7VmJ9PSdkF4SX2Z9ysKhDJJCiejQHp1OhLaXzU 2MpNoC5q00JzGsZiNpy+NPz4lMYqMsejECIbd3K/QooDlE89arqhcMBb7vkKxM2G8ChV DX9HOpcucci/W6yLsPD3BUEUoZDLDm23Mtq+qWwolQhhfAQXSEwsu07cyrcX/OlozO2s Twf5mj6/8v4u69yXk6rVwcUPz/903d0yoMFnu8iHI/EZ4g1GXVntTJpfGKU9GzGy3Ene 5BtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="HO/a2KJO"; 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 n1si7878630wrj.139.2019.05.06.10.53.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:53:33 -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="HO/a2KJO"; 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]:60184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhnw-0001OV-81 for patch@linaro.org; Mon, 06 May 2019 13:53:32 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVQ-0001HV-Aj for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVO-0001XD-Dw for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:24 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:45199) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVM-0001TN-NK for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:22 -0400 Received: by mail-pf1-x42d.google.com with SMTP id e24so7118995pfi.12 for ; Mon, 06 May 2019 10:34:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2div2YVLjVe7DwdMLbNY+nkm3nkpzeNz5eXH0qLyY8k=; b=HO/a2KJObdqAqpfzLvR4kxvp/QT1f95D5xt+K0LIV2VzAmNoQrgm2U+Nb2uCf6ok6p yN33eYIsJXEMa86FMzwRDP162tq0K7ekCNjWz9cOGIOkeG/onWyEg4nEJGAXrkw460tS NOSp1OhPx2HiQ9GQAkxvRiGX4f+tuL5IXORfBo1QJ+G4iJR+U3OivNRjq9vrDvSriY8v dLij5r9lDV1F5g6q7TqaGK/4pGnx/duV/MfxhsjPjcXBmgD7RKOPbeUaIj154olp8win XrtNK5cif//1qeYt0l/YvCjKD4GRFKh7boWflcS9pGWDkuwDHwYfRu+GwoFgVdmC1L8e adNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2div2YVLjVe7DwdMLbNY+nkm3nkpzeNz5eXH0qLyY8k=; b=qHVUzgOwFrAI3mn0sqI9OYd6ipCYN/3EtlKtjYBK9g1a5pAS5e/bnf543tYzjp1daP jVx6Co1aOlKZz4KUnWFkf7DZgq2ZSuxvIDED1goildRYioadkXZNryU4Ha7XgTyR7gtC mvq2QCjgT+zDHQBG7oXO/e3QTv89GbP1AYyKl8t/p1tNA2bO12crSdWsjv41rBfwifyc cllYLDqBqMAhSlEBlSkud+aNPteiH+djKJ9mz0RIA0BF9pT1Hb2eLsQlhSi/bmdIeJoE 0IrlkuL182G/5gqJCQknXuUJrjzBlkOJevJQq1sW0T8tSI/z6dD88RdPTQrn9QfmChVO E6wg== X-Gm-Message-State: APjAAAUUYVYo/rjOg+kJFCYwrHrO3617Y4RAIa69UBfrngp7NOykif+q q5uYn9XSksGDB5Dz5Q8D68fL+NPA86Q= X-Received: by 2002:a62:2703:: with SMTP id n3mr10803121pfn.199.1557164058577; Mon, 06 May 2019 10:34:18 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:48 -0700 Message-Id: <20190506173353.32206-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::42d Subject: [Qemu-devel] [PATCH v4 19/24] hw/misc/bcm2835_rng: Use qemu_guest_getrandom_nofail X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-arm@nongnu.org, Andrew Baumann Errors-To: qemu-devel-bounces+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 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- hw/misc/bcm2835_rng.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/hw/misc/bcm2835_rng.c b/hw/misc/bcm2835_rng.c index 4d62143b24..fe59c868f5 100644 --- a/hw/misc/bcm2835_rng.c +++ b/hw/misc/bcm2835_rng.c @@ -9,30 +9,26 @@ #include "qemu/osdep.h" #include "qemu/log.h" -#include "qapi/error.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "hw/misc/bcm2835_rng.h" static uint32_t get_random_bytes(void) { uint32_t res; - Error *err = NULL; - if (qcrypto_random_bytes((uint8_t *)&res, sizeof(res), &err) < 0) { - /* On failure we don't want to return the guest a non-random - * value in case they're really using it for cryptographic - * purposes, so the best we can do is die here. - * This shouldn't happen unless something's broken. - * In theory we could implement this device's full FIFO - * and interrupt semantics and then just stop filling the - * FIFO. That's a lot of work, though, so we assume any - * errors are systematic problems and trust that if we didn't - * fail as the guest inited then we won't fail later on - * mid-run. - */ - error_report_err(err); - exit(1); - } + /* + * On failure we don't want to return the guest a non-random + * value in case they're really using it for cryptographic + * purposes, so the best we can do is die here. + * This shouldn't happen unless something's broken. + * In theory we could implement this device's full FIFO + * and interrupt semantics and then just stop filling the + * FIFO. That's a lot of work, though, so we assume any + * errors are systematic problems and trust that if we didn't + * fail as the guest inited then we won't fail later on + * mid-run. + */ + qemu_guest_getrandom_nofail(&res, sizeof(res)); return res; } From patchwork Mon May 6 17:33:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163443 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp272120ilm; Mon, 6 May 2019 10:54:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwVUfOrh4Vx0kL69KoU+tkTdZMw92d6lUIx2p1Lz19Oar6BM4xPLMxBKcW7JHiewjVvQHar X-Received: by 2002:a1c:3982:: with SMTP id g124mr17545174wma.25.1557165242492; Mon, 06 May 2019 10:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557165242; cv=none; d=google.com; s=arc-20160816; b=OI8E4HjXcRgFzuZxVQ3s0wuOr8G/15yi6hXBeEGOL2kj2j//qDkEFJ+GwMLlgK6Je6 H3Jvl47EjhrnKql1Tz484r/4NK+umdf/Zkp8niuaN48vCGT1TQrSA9WiPeehNh47hFwE w18HN7e2bkjnzicQ/Q1tuk6xt4YtIBk5cVJvGucYEyN+ugMehH2rgdl+w9w8AoEs+0qC EhCXAUVFylai8L4Bj8n5lMwruCE7Nww3E/X0EJKn+lPzveSKiMqoE+sPsjLE5OYXm2F7 X+EI2pPWKK2U7zZeeWu6uGAd1uYIKFUn+YuHQSYh/rscdqDmi7f30qzKxVnNxGuzFxDw S0yg== 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=WkMgXREw0aoSQxhQGI3jtOyJDuRA2/EcPM5PhnT27hg=; b=x0RV/2mQVHOoqncRJYsyquMFPCpj08SOcwQ75DPA21UlACp1bePdVPXdOx4I+lw72n HL+QEALNxubjrpPyGtzg4a4a03uO0ID8vOt3eVqT4U72SF+Fg3gu5jVXq7T6OnGdEc0x DWBTGwq39vItOeaUc4wGmzAnpUPl5GK2GBnbeQ0cOYwm32Qgvgh3+qDqfjrV+sPZOT4L tNzVbwc4b++/qVHvXHCLIYLleEgM+XDeSVXQm7pCQWrn3ZmvxJbG9nT+OGKo+4TimGtl 30aGuw7Rm+6izY5zgxbFebf/5Rgl5tAI/1XUsUsnnry8we/xbofJ3ej1KnIWS/k4psDT 5tTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=M0lQsOCD; 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 63si128037wrp.222.2019.05.06.10.54.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:54: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=M0lQsOCD; 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]:60188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhoP-0001im-FF for patch@linaro.org; Mon, 06 May 2019 13:54:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVS-0001Lo-6v for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVQ-0001ZM-BT for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:26 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:39619) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVO-0001Uh-Cf for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:23 -0400 Received: by mail-pg1-x544.google.com with SMTP id w22so5482385pgi.6 for ; Mon, 06 May 2019 10:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WkMgXREw0aoSQxhQGI3jtOyJDuRA2/EcPM5PhnT27hg=; b=M0lQsOCDnQ1jXB8oOlUdFWQEnQl2GKBcG39v9z7yxfTA5yax80UsmGLJL3XbgGwRIZ w8RJlHAQ+ehS6e7VcrU2IsXp+KANuR7/iwP+VM7eBCxb8meC1VxMltyitzx7SzJSURXB DGQ5EC3fnwwcmYznShqkqR/yg6BzPaEQ/6GBcRCBPo46g8zOui0qUU6qqeB7ZAqfrPXh fJS+HIVgnBy55567Zj7eJvPEHlLg/tjyAnB3ndc9hC4scZhErZmcpqtLnYs1mCIWagY4 clTC+PnhZ5/8tS9DSZg0TRAnlj2cFe22ajUUea5otUju4fD5s2PThdjBIe4zBwyBSs98 T+Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WkMgXREw0aoSQxhQGI3jtOyJDuRA2/EcPM5PhnT27hg=; b=hSElmU8AHGFTwkK6Q9lM7jrNlzJXFolzf+O9FiI2ITk5g17O9KBCkj7eplVzVQHGxE lsQZy1VZ/5HakDufIw54mTcjWup/40IU16Kx+ISx1xS+ak/rpEoc/gyLJRozgCVHDBfB bgG3Ho7y/j9LWPbPxnP18792JY/jV5q2zfokpwxdYiPBo/b7dm8vm9XLv2iO+ruyeeFF ubWlVrYgJSseqh/RhyQ79SJlb0KsMXxMVNKQO+Lu89kmIEbi56vaLkQDHAnqVj/MRnvv TYEv5rNec0ztXH65SFiO5ne4btQUzKJtncWGqsYJP6LgzGGBE62rTVNmSgk/ZwmBMK93 ZEhg== X-Gm-Message-State: APjAAAW8R7Ojs2b3j9oCEUD6W6ihyUOP7RlM0LFRahB0Ic4uiWnTR+ri 8LmXcoC8yj9m82ov5JONocO89bGQkOs= X-Received: by 2002:a62:5915:: with SMTP id n21mr34013649pfb.180.1557164059592; Mon, 06 May 2019 10:34:19 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:49 -0700 Message-Id: <20190506173353.32206-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH v4 20/24] hw/misc/exynos4210_rng: Use qemu_guest_getrandom X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Mitsyanko , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+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 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- hw/misc/exynos4210_rng.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/hw/misc/exynos4210_rng.c b/hw/misc/exynos4210_rng.c index 4ecbebd2d7..0e70ffb404 100644 --- a/hw/misc/exynos4210_rng.c +++ b/hw/misc/exynos4210_rng.c @@ -18,10 +18,10 @@ */ #include "qemu/osdep.h" -#include "crypto/random.h" #include "hw/sysbus.h" #include "qapi/error.h" #include "qemu/log.h" +#include "qemu/guest-random.h" #define DEBUG_EXYNOS_RNG 0 @@ -109,7 +109,6 @@ static void exynos4210_rng_set_seed(Exynos4210RngState *s, unsigned int i, static void exynos4210_rng_run_engine(Exynos4210RngState *s) { Error *err = NULL; - int ret; /* Seed set? */ if ((s->reg_status & EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE) == 0) { @@ -127,13 +126,11 @@ static void exynos4210_rng_run_engine(Exynos4210RngState *s) } /* Get randoms */ - ret = qcrypto_random_bytes((uint8_t *)s->randr_value, - sizeof(s->randr_value), &err); - if (!ret) { + if (qemu_guest_getrandom(s->randr_value, sizeof(s->randr_value), &err)) { + error_report_err(err); + } else { /* Notify that PRNG is ready */ s->reg_status |= EXYNOS4210_RNG_STATUS_PRNG_DONE; - } else { - error_report_err(err); } out: From patchwork Mon May 6 17:33:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163432 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp263603ilm; Mon, 6 May 2019 10:45:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqymGrxb1YEvyBGzAOM7Y0iY9RVliQhdBByOBeE5Mny4hgVIackW0UX+N0vA0CJLKfVbiqBq X-Received: by 2002:a1c:cb8f:: with SMTP id b137mr3014366wmg.142.1557164747766; Mon, 06 May 2019 10:45:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164747; cv=none; d=google.com; s=arc-20160816; b=YpsqdPpQarRT6SkzPRjJOKFlGUxcYCA5sTcXgEolno7NXAefkJV5aQPkkoIIRpCP0M HeJGJkMXmAxvlm/3VBgc66U5vxdydG/RmkWNTAFaYqVLmx6TkWpQUcQkAkzJEz/BKmYY JCgqaiEALDOpf+Z5Xm/pQBB9EeXmPolmDDc4OujDSk4gKd6DkXsbrpKlqjzbXPqkXHQu pzCZV3pr/doFWr+Yaql3I6wTvLQNFsAXR1sz/2c7rG554/PWrxXeVoHtuVxiwC5r/6Nr fk1B5STPfhY7v4muF63zUMEC7bxYj1Tl4320OlLsiOh4nvhAJhYDhI1GQ6QEqtA0rwKw iwHw== 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=G/LPrgJph2n0xWoB68vwNP1sqZ2D7Ndofy8Ou9toiJU=; b=CKrVL5DPIO7GrCDG70LaObMb2oY6LYq96Dab+6HoW/JjVhis6htqCJ1Vp+cwNOg5VC zzohV3xtl8bhBul+Yd7WkwUKrWOedWPZ0CZEAE+eXNKXJWBaXKmr47KmVIt9dDWcbeXO bC5oMXI/QoQQGzptNV+ogOcqPtsTgghMgSYFSr72Z35gqSnqaPn4vYFdtH3HkD09o7v9 vm650gnl51/UKKQ2vxmyeaAuX2n+ubzxCuxElc/WURY5WUdweVWCfcTAuAOyuDPz6WxB ZvIDn9gFs0KotDhKAUrHB75dJM4sLTecTSI2/UmosP/4DXPQDIsBSdkJiXTNf+/Lr6lQ /N1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=YJoMSrBO; 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 j7si7714868wrm.199.2019.05.06.10.45.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:45: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=YJoMSrBO; 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]:60074 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhgQ-0003Yx-Jd for patch@linaro.org; Mon, 06 May 2019 13:45:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVU-0001O8-6C for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVS-0001bj-7p for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:28 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:34688) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVQ-0001WQ-9S for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:25 -0400 Received: by mail-pg1-x541.google.com with SMTP id c13so6806405pgt.1 for ; Mon, 06 May 2019 10:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=G/LPrgJph2n0xWoB68vwNP1sqZ2D7Ndofy8Ou9toiJU=; b=YJoMSrBOLQi8prawBoxDvEKjN3YKYVPmoPjPR89Li6b2Y76kuJeYFSrp74rYSEYtcP gEe9bdA85TOOEn8okOJ3YOwG7OXTOOwAFrPg+p6EwwmHkCJTvXYTVwPCuiDMLH+ghsjx bfZ/r2N8gb6hOntpg7l/20DFJXFlcoz4lseKrkvtDlaLdPalgbjK1sFONV8Pdm9yFHfY tALj3qydYFOODDsPHdw7gY2qbs1UeSBsG7un5SP98Mj1kIBAxkT2kU0nJQHYfqXoJ1dS KJIRbDmab6zw0fgyPVZkvlHqtXXbr1VhuEnJKRFz0hi1QByQRj/jJrMvBBlLniQmh6sw bx8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G/LPrgJph2n0xWoB68vwNP1sqZ2D7Ndofy8Ou9toiJU=; b=i1bGrEJIZt+gGyfDqMYGR4l9duPdpS3uw4jV3F+2oGqXPe0kUzjr13of7jJ3XrdnU0 p3Ti+RydoaFx7tB9BtItIy5iruK7pTVHY7Td4I64aVjEqM8etonx+n8f3KeUJkd2m022 GzM/cTrBDfb02zoQuxB3AChO7xsx6Tf7vu8Mgp0TvzdUHrA3wpnWBgHA5gtWlY6to/IG 6UDc2Xb0I09EST2SgrOtUf8L+GBoLjYA3FG9bXeb/9rkNtKZI5YKBbFyxAaPLPf0kqwV N74VdOUiKaviwZM4MOaU6KIX5bu6+88qNkKQ4MAyXKkUTvCG+9e1zBisk1HeHDEsbl5X JhyA== X-Gm-Message-State: APjAAAWLRYjGeAU4ZPPtw+bQ8yEn8pBn1ixiJ6pqoziIIzF8G4yBbSkq WCW8TP/DEdV6F0M+x4JVkS8iHuPoukE= X-Received: by 2002:a63:c104:: with SMTP id w4mr33151579pgf.409.1557164060772; Mon, 06 May 2019 10:34:20 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:50 -0700 Message-Id: <20190506173353.32206-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH v4 21/24] target/arm: Put all PAC keys into a structure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This allows us to use a single syscall to initialize them all. Reviewed-by: Philippe Mathieu-Daudé 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.1 Reviewed-by: Laurent Vivier diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 22bc6e00ab..9448a76186 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -636,11 +636,13 @@ typedef struct CPUARMState { } iwmmxt; #ifdef TARGET_AARCH64 - ARMPACKey apia_key; - ARMPACKey apib_key; - ARMPACKey apda_key; - ARMPACKey apdb_key; - ARMPACKey apga_key; + struct { + ARMPACKey apia; + ARMPACKey apib; + ARMPACKey apda; + ARMPACKey apdb; + ARMPACKey apga; + } keys; #endif #if defined(CONFIG_USER_ONLY) diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index cedad39ca0..2f2f63e3e8 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -175,11 +175,7 @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) #endif if (cpu_isar_feature(aa64_pauth, cpu)) { - qemu_guest_getrandom_nofail(&env->apia_key, sizeof(ARMPACKey)); - qemu_guest_getrandom_nofail(&env->apib_key, sizeof(ARMPACKey)); - qemu_guest_getrandom_nofail(&env->apda_key, sizeof(ARMPACKey)); - qemu_guest_getrandom_nofail(&env->apdb_key, sizeof(ARMPACKey)); - qemu_guest_getrandom_nofail(&env->apga_key, sizeof(ARMPACKey)); + qemu_guest_getrandom_nofail(&env->keys, sizeof(env->keys)); } ts->stack_base = info->start_stack; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b73d1d9f65..3c26f6f9d4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9734,23 +9734,23 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, return -TARGET_EINVAL; } if (arg2 & TARGET_PR_PAC_APIAKEY) { - ret |= qemu_guest_getrandom(&env->apia_key, + ret |= qemu_guest_getrandom(&env->keys.apia, sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APIBKEY) { - ret |= qemu_guest_getrandom(&env->apib_key, + ret |= qemu_guest_getrandom(&env->keys.apib, sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APDAKEY) { - ret |= qemu_guest_getrandom(&env->apda_key, + ret |= qemu_guest_getrandom(&env->keys.apda, sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APDBKEY) { - ret |= qemu_guest_getrandom(&env->apdb_key, + ret |= qemu_guest_getrandom(&env->keys.apdb, sizeof(ARMPACKey), &err); } if (arg2 & TARGET_PR_PAC_APGAKEY) { - ret |= qemu_guest_getrandom(&env->apga_key, + ret |= qemu_guest_getrandom(&env->keys.apga, sizeof(ARMPACKey), &err); } if (ret != 0) { diff --git a/target/arm/helper.c b/target/arm/helper.c index 81a92ab491..658a5a9822 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5683,43 +5683,43 @@ static const ARMCPRegInfo pauth_reginfo[] = { { .name = "APDAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apda_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apda.lo) }, { .name = "APDAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apda_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apda.hi) }, { .name = "APDBKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 2, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apdb_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apdb.lo) }, { .name = "APDBKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 3, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apdb_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apdb.hi) }, { .name = "APGAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 3, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apga_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apga.lo) }, { .name = "APGAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 3, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apga_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apga.hi) }, { .name = "APIAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apia_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apia.lo) }, { .name = "APIAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apia_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apia.hi) }, { .name = "APIBKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 2, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apib_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apib.lo) }, { .name = "APIBKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 3, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apib_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apib.hi) }, REGINFO_SENTINEL }; #endif diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c index d750f96edf..7f30ae7395 100644 --- a/target/arm/pauth_helper.c +++ b/target/arm/pauth_helper.c @@ -403,7 +403,7 @@ uint64_t HELPER(pacia)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apia_key, false); + return pauth_addpac(env, x, y, &env->keys.apia, false); } uint64_t HELPER(pacib)(CPUARMState *env, uint64_t x, uint64_t y) @@ -413,7 +413,7 @@ uint64_t HELPER(pacib)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apib_key, false); + return pauth_addpac(env, x, y, &env->keys.apib, false); } uint64_t HELPER(pacda)(CPUARMState *env, uint64_t x, uint64_t y) @@ -423,7 +423,7 @@ uint64_t HELPER(pacda)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apda_key, true); + return pauth_addpac(env, x, y, &env->keys.apda, true); } uint64_t HELPER(pacdb)(CPUARMState *env, uint64_t x, uint64_t y) @@ -433,7 +433,7 @@ uint64_t HELPER(pacdb)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apdb_key, true); + return pauth_addpac(env, x, y, &env->keys.apdb, true); } uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) @@ -441,7 +441,7 @@ uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) uint64_t pac; pauth_check_trap(env, arm_current_el(env), GETPC()); - pac = pauth_computepac(x, y, env->apga_key); + pac = pauth_computepac(x, y, env->keys.apga); return pac & 0xffffffff00000000ull; } @@ -453,7 +453,7 @@ uint64_t HELPER(autia)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apia_key, false, 0); + return pauth_auth(env, x, y, &env->keys.apia, false, 0); } uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) @@ -463,7 +463,7 @@ uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apib_key, false, 1); + return pauth_auth(env, x, y, &env->keys.apib, false, 1); } uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) @@ -473,7 +473,7 @@ uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apda_key, true, 0); + return pauth_auth(env, x, y, &env->keys.apda, true, 0); } uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) @@ -483,7 +483,7 @@ uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apdb_key, true, 1); + return pauth_auth(env, x, y, &env->keys.apdb, true, 1); } uint64_t HELPER(xpaci)(CPUARMState *env, uint64_t a) From patchwork Mon May 6 17:33:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163437 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp267058ilm; Mon, 6 May 2019 10:49:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaOKcMecmgeJdqSwC6ChoymaQeqELVOywjAvLkwO3wYwFEeB/sz5YlorMoW349gTtqu+xV X-Received: by 2002:adf:d850:: with SMTP id k16mr11551828wrl.57.1557164945267; Mon, 06 May 2019 10:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557164945; cv=none; d=google.com; s=arc-20160816; b=EOIqkVbg8JntXvSWkv0/nWuOWJiKSYlkQu234WfWD+SwjV3sLnjJI49jwjXi0HE+j8 LmETUpi7I2Twv8ZkrUDq6opWY4/8CYkFB3GS0cwwplxkrbaoWPRTFtc8X9NWVbanFmHB /v2ibH4HJbnecnU6GBNRF8iY1Rvuc/iLemIVldMvGQdzvMvmrBHdxs89neiWRUG31zzh E8PaRxQ/ScmGT1PwAJwL65JkarQeXGTP9phzW30coTraTwmwfatcnGZ6w5vyFnfeCxnB uXJR95R5u3mYgicwHdQuhiR0pF3+thbnzt466CaqRknhgsiP1zaCJEskNzv6o0E+FSac /reg== 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=C88Ei/VihHBAOteN7bDmsYhjQHUxDozERJjKlZZiWa8=; b=OIT0Kb3QuopH0GHEiKgljlwa+iKEB4374VTdjk0BWIZcVC74BCFZDgRO2F/qSiGqkf HkDt4CR1VdRkXXLydFxBvIJopNQm+MP60FmHyNo/vAuC2OE1unH3FoF/MvnJz5aejUxy vIMgDhaDZWe5K7Ht1pxaHMPXI/kBUBqsPxAwvkrfBWOTY7K3339dmn+u9opfXoD4xQTX F9RO6yiWRSF+zwK79JEkFn8RsMkUxoOscIdtweR6D2pyMEP56Hbp3BFqoMm05UZxeAu8 e1ASyM4YOHKDsG1tUmlSAEQkdK5sUV/qRGY6uiGhf3dtx+BrC662PfwZ8aK7xRDN3ddK hxTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=sHvcnbl3; 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 o1si5578203wrm.5.2019.05.06.10.49.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:49: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=sHvcnbl3; 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]:60100 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhjb-0006I2-JP for patch@linaro.org; Mon, 06 May 2019 13:49:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVV-0001P3-4Z for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVS-0001bn-7o for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:29 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:33544) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVQ-0001Y1-C7 for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:25 -0400 Received: by mail-pg1-x542.google.com with SMTP id h17so818712pgv.0 for ; Mon, 06 May 2019 10:34:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=C88Ei/VihHBAOteN7bDmsYhjQHUxDozERJjKlZZiWa8=; b=sHvcnbl3E2ZWklsiprgp0xlEK/K7eAg6GixcuLtR3Tp/kBdNtfHYZsgPBZ+R3hSlfs qwvWwpIMH3mzRoU4wVKCaeW5d4UO+pd1ZCa+Yzr4P+QeglKYAceTB4aM8UxCH9IrD/CB F3kPQ4pH/tFyBrktkhjjTsEgk3Vgguy2jSNYsXoEnlXz0P61tgiYg/1hEdV3HIROB1o+ UxnOsnwGphporYoystRo4lJk3w7NU43OAsWM/G3zRT5VWlVeNopuovWCbQkUGat3l7WS o+ucNAT65YDsTxN+MzFbqRaPSGpUsC4AbtvYA5vxN3C/YKKgJmE8amaBMtCU5Zb3a+Rc U8zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=C88Ei/VihHBAOteN7bDmsYhjQHUxDozERJjKlZZiWa8=; b=UdQL6tJeRChz1APzVnFwVzYHdhlQeGPesXAri+VtKtYQJETg47ub9QWWW+mChB+3sE nHq50DvYojfarf8+K+teB4dvy9Z2tnoi60BBTgE7i9yO2CCh9yNx5Iem8GRb3YNnmn0J D8H3ptViplRie2+CB5xypt2S08wMzjCyzEBwDRbybMdgchvpRpirbjUx2Gzslbyoaamw xQ0lcOCLVfdrTci/ZSBraflz6EY9vnNo00Z/lxEkNH5Y8c5GwTaHZIvXICV9lshqEXUw U4UFAKZjRmVUqQzj7YaBFQAmckyHCKFZECHMcw4QdPU25VlHxgI25E82OFG/VMaSaq+K p5EQ== X-Gm-Message-State: APjAAAUGCfzZMQkne8zFlIt15901YZ3ICs6zKY2xXWdBqefgW09ZT73y MSpF/vMw+WW1ufa3b7FQz8UxXRDBK3E= X-Received: by 2002:a63:ed4f:: with SMTP id m15mr33935349pgk.387.1557164061922; Mon, 06 May 2019 10:34:21 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:51 -0700 Message-Id: <20190506173353.32206-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v4 22/24] target/arm: Implement ARMv8.5-RNG X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+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.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 9448a76186..5c228fee8e 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3510,6 +3510,11 @@ static inline bool isar_feature_aa64_condm_5(const ARMISARegisters *id) return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TS) >= 2; } +static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RNDR) != 0; +} + static inline bool isar_feature_aa64_jscvt(const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, JSCVT) != 0; diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 228906f267..835f73cceb 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -310,6 +310,7 @@ static void aarch64_max_initfn(Object *obj) t = FIELD_DP64(t, ID_AA64ISAR0, DP, 1); t = FIELD_DP64(t, ID_AA64ISAR0, FHM, 1); t = FIELD_DP64(t, ID_AA64ISAR0, TS, 2); /* v8.5-CondM */ + t = FIELD_DP64(t, ID_AA64ISAR0, RNDR, 1); cpu->isar.id_aa64isar0 = t; t = cpu->isar.id_aa64isar1; diff --git a/target/arm/helper.c b/target/arm/helper.c index 658a5a9822..3824778dab 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -21,6 +21,8 @@ #include "fpu/softfloat.h" #include "qemu/range.h" #include "qapi/qapi-commands-target.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ @@ -5722,6 +5724,45 @@ static const ARMCPRegInfo pauth_reginfo[] = { .fieldoffset = offsetof(CPUARMState, keys.apib.hi) }, REGINFO_SENTINEL }; + +static uint64_t rndr_readfn(CPUARMState *env, const ARMCPRegInfo *ri) +{ + Error *err = NULL; + uint64_t ret; + + /* Success sets NZCV = 0000. */ + env->NF = env->CF = env->VF = 0, env->ZF = 1; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + /* + * ??? Failed, for unknown reasons in the crypto subsystem. + * The best we can do is log the reason and return the + * timed-out indication to the guest. There is no reason + * we know to expect this failure to be transitory, so the + * guest may well hang retrying the operation. + */ + qemu_log_mask(LOG_UNIMP, "%s: Crypto failure: %s", + ri->name, error_get_pretty(err)); + error_free(err); + + env->ZF = 0; /* NZCF = 0100 */ + return 0; + } + return ret; +} + +/* We do not support re-seeding, so the two registers operate the same. */ +static const ARMCPRegInfo rndr_reginfo[] = { + { .name = "RNDR", .state = ARM_CP_STATE_AA64, + .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END, + .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 0, + .access = PL0_R, .readfn = rndr_readfn }, + { .name = "RNDRRS", .state = ARM_CP_STATE_AA64, + .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END, + .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 1, + .access = PL0_R, .readfn = rndr_readfn }, + REGINFO_SENTINEL +}; #endif static CPAccessResult access_predinv(CPUARMState *env, const ARMCPRegInfo *ri, @@ -6666,6 +6707,9 @@ void register_cp_regs_for_features(ARMCPU *cpu) if (cpu_isar_feature(aa64_pauth, cpu)) { define_arm_cp_regs(cpu, pauth_reginfo); } + if (cpu_isar_feature(aa64_rndr, cpu)) { + define_arm_cp_regs(cpu, rndr_reginfo); + } #endif /* From patchwork Mon May 6 17:33:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163444 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp273899ilm; Mon, 6 May 2019 10:55:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqywcV0irmZzOmvOTiF5hJkuMaAGorsnxEXFzBu9ZT2KOj3EYzDRqYbji9VeHioffs7da+B0 X-Received: by 2002:a5d:4707:: with SMTP id y7mr2969755wrq.59.1557165355332; Mon, 06 May 2019 10:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557165355; cv=none; d=google.com; s=arc-20160816; b=Spftza3OYLJwDDSVPaaDLZBSVlOSmyZeks/o/ZJK8yATEfW946YuocXKPNI3487jXG TjIi8PcujKsEWlRtTycQks3uElBFErPCaCvxYwBPhmr1cBO3jocTyNXGF9Xo3wQa+Hz9 OFqiDKi9xf1IF+2122AEO94ONaaMMVmmpnBJXKyIlwH0Ky4BTGkBhjTqnGv2ODA9MRHG oFCw1A5QZPR45nX275twoKukgrDTYyt1lggpARv0Jre+DhBEbtwcSe/vqpneQb6GxNJV W6c8GjULFo07gj0XL5vJtnG3eE3Ktlu+GSqG8EIxJEnESSQMHqAee3YbA3bVli7A+js0 Z/+g== 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=rV9JIaOzfUN4OkPt3KeztWbx7AsXbIEUWY2EQzqrSHU=; b=JSR3COjxZ9fMMaNsdmlKq4Q5ui6CGH2nfWZX/1KtYHoCHFv9OPkcYwIKP5Ki+0Q26C Yo+7a/vPuO+PkNRk/w6ONPF+NtkmBSRrYBbdGlp9L0dkKRbhpSRNUj1M23O1m6wtR+o6 T1/s9VkvLTimDEpvC4IxrP8D8tScfM7GFUZOITltrTIxaG7Uo2kAsGDTNlJ/DqS6IJ6Y X8kwo6yWQ9UIBXIoUVigsC1OS6EbjCJcSlGDfRolPXjq70gc4BUroJWmUcZCxzwdysS2 tsEAZmjwNXIx35RbHxFZ039GCaSEBp9M1ZO7VgqFea6gP9GoVAsFRl9O6vk4xUy9d6Zh EVGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JPsVvWSv; 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 x185si7303137wmb.73.2019.05.06.10.55.55 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:55:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JPsVvWSv; 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]:60234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhqE-0003G3-8B for patch@linaro.org; Mon, 06 May 2019 13:55:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVV-0001PA-9i for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVU-0001d9-BH for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:29 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:45932) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVU-0001Z0-3y for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:28 -0400 Received: by mail-pf1-x442.google.com with SMTP id e24so7119093pfi.12 for ; Mon, 06 May 2019 10:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=rV9JIaOzfUN4OkPt3KeztWbx7AsXbIEUWY2EQzqrSHU=; b=JPsVvWSvgo2Fx1dliry01ZRpiz217ThUX6fAXN8kyJBII2va8k4DXmt24Yts3yATwT TyfORURm+fJVw6aaSM0EH2PvE4NxQEoNbgxUpQXTN5mMtrgk9vBdw2bn0awnSWzrAUdH oaC2pe6y6AibFYC+xs0rSaxXaE+5MJW0sxeytMXd1O1+HymLHnyjMMERVf4iF67D97Ei CJnL0tahD0Zme+M1iB2vzyGqpvSKJVZrlLKvI6sFs4sF6C+J0PmSlMUHuVsfXSzqCG2q PrIWSguquJzYL5vl87osooTd/hH02sjzd3VPW5Lg01Fct0chJr75F4neWIDfH5E6pIjY Ndbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=rV9JIaOzfUN4OkPt3KeztWbx7AsXbIEUWY2EQzqrSHU=; b=jIEJc21amS0Okm6YQ/lh3vlhUlCXc/pPd6vFQxGO0MnHBLxNUDSWmIUlGMrM602ZBM 10Pkv+BYdBXG3Ooi1EMa5EgpbRV1lPkmT1K438s3H1TJAyQhFGeSVV289ScN7TUY5v7A sehzprOm0i71xzgUpSjEuIjJSyPGf7Bqge/4o+XA6xqh+xr0QqE7fydoShuRg6cZkjYF akHFREk3w+zhE+e54/S8jf+i9e5MAurM2954SbZINwN1xb5bK/BhwisLK2J+o3ipyupj 22P/3DeQBV/exX264BTILpkORaz4wMUVovB1ZwrreQLQySZRQxMaa4q1SlNuPzb6pd7x nMAg== X-Gm-Message-State: APjAAAWVmlBchjTiOLyQNOyGskF9WRLNzRmWUldF20pmS/D637RXnnIu jmT7eRBXGwyvQyaHk9GhHdG7nPCOJYA= X-Received: by 2002:aa7:8392:: with SMTP id u18mr35979178pfm.217.1557164063137; Mon, 06 May 2019 10:34:23 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:52 -0700 Message-Id: <20190506173353.32206-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v4 23/24] target/ppc: Use qemu_guest_getrandom for DARN X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We now have an interface for guest visible random numbers. Acked-by: David Gibson Signed-off-by: Richard Henderson --- target/ppc/int_helper.c | 42 +++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index f6a088ac08..9059e70b9c 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -23,6 +23,8 @@ #include "exec/helper-proto.h" #include "crypto/aes.h" #include "fpu/softfloat.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" #include "helper_regs.h" /*****************************************************************************/ @@ -158,25 +160,41 @@ uint32_t helper_cmpeqb(target_ulong ra, target_ulong rb) #undef hasvalue /* - * Return invalid random number. - * - * FIXME: Add rng backend or other mechanism to get cryptographically suitable - * random number + * Return a random number. */ -target_ulong helper_darn32(void) +uint64_t helper_darn32(void) { - return -1; + Error *err = NULL; + uint32_t ret; + + if (qemu_guest_getrandom(&ret, 4, &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + + return ret; } -target_ulong helper_darn64(void) +uint64_t helper_darn64(void) { - return -1; + Error *err = NULL; + uint64_t ret; + + do { + if (qemu_guest_getrandom(&ret, 8, &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + /* Since -1 is the error condition, try again for that case. */ + } while (unlikely(ret == -1)); + + return ret; } -#endif - -#if defined(TARGET_PPC64) - uint64_t helper_bpermd(uint64_t rs, uint64_t rb) { int i; From patchwork Mon May 6 17:33:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163438 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp268899ilm; Mon, 6 May 2019 10:50:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNLjMtf9lMFSblrHC25RY9/4eHCdptSlVwzQZiukJqR0KK5GhR2KmeKCaxpvFJp8FTlRtd X-Received: by 2002:a1c:4c14:: with SMTP id z20mr16843666wmf.116.1557165058360; Mon, 06 May 2019 10:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557165058; cv=none; d=google.com; s=arc-20160816; b=oAQEEqnPFWOGfK7/vpIAPf6ol7yZgtnqGpU6oiyXbnZM0v9GEM8PbqwlZP4H8BIhZr E7mnmp5R+h+pa85+iC/fUW8ReaXg90qw8fJA/BL/idIp8ZaFE6KFtP9HcP8mRNfr6jcI 1EozvnhxoecdjGC68yrSNppRz1YlDu89CurQTFEAakqxopf+LYyhurs3dZ+Cy88MpNVw apG+FfYXkEHlCDiP/TV9ipNNsji5dwLppafH69Q8xU6axEWk3ge1Hm6Rba4cAJh/QxzQ TSk6TgQu4ZZB5N+kbQDIYZms+6drWAvUoRysdZWvrbBH4ESXJ0nrXnajPaBsel0kHuS2 aiYA== 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=WYz5jNmR/GTo+9WP/v5okCDQ6l0w7x39q4Q1GnmCfVI=; b=pelvC5P9EVg6TTvtftj1O0GYdYKzizjQeHUiytI5c/Ql+OEn4Nd5/Vat6pzpaPfCVG GUiVUjUquxPEFV7SkoV33CdTb11DR5ZOqPrKZXzem89x5LGw+8AyJigi1ZAIhHZD0vn1 5UTlDErSc9T8R3S8ul2N2fVKjOPvEVjNqGC8OpDLg3boxJ8kSuxLoXT2JYMQiMca8sPG E5bspu46Zg1Cg8ymB1CAn1KQla+7ruOxqjJDVrzBt5pG00IOkVbyatK4nh6wdjzyGBRh dG0RiY7AGSeC0vw2mcQzu6CSc/X3gGOvbQUVAETjONUquTrqwikoOawizaLqnDSO+e1D jH+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fwOpYX4q; 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 r15si7731789wrv.394.2019.05.06.10.50.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:50:58 -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=fwOpYX4q; 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]:60150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhlR-0007MQ-8H for patch@linaro.org; Mon, 06 May 2019 13:50:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVV-0001PV-MT for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVU-0001dP-Hg for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:29 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:35165) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVU-0001ae-8L for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:28 -0400 Received: by mail-pl1-x630.google.com with SMTP id w24so6721896plp.2 for ; Mon, 06 May 2019 10:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WYz5jNmR/GTo+9WP/v5okCDQ6l0w7x39q4Q1GnmCfVI=; b=fwOpYX4qsqgU/XXxKrEFF0vQbJf4HWyqZl9np9N8Vm4S3jFnpuczDSqdTmhc4Bf6rf 21tal0urqhRdkt0k/0+5SMBPLKZiKbVIGWIYpEfbZEqA3H3CEViocjaZim9CZzhflxT1 CVAtJZx69JTBhcab2STBrwVYPwN5YlHuhToJn12+pa8wm2QeHhKoBvgqPVo47jF9XsfZ aHl/AywHNDgty4dc84ydiFxC3jTuK8N44UJb+wkGS+wplmjgqW/Z9JZRlQWDaJ5iJCce fPwqGD7REhr/O74/91An8OiyaDqCX7flBsv/MRql3XhYQXD+8mUR9We1hBOdpGWivKSr jxcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WYz5jNmR/GTo+9WP/v5okCDQ6l0w7x39q4Q1GnmCfVI=; b=MpQYamcmbrq5LEzr36+Os03bOIBrB7lCDbamReDImiapVWZRuaQ+xBbNBaSHU4N4c/ ocTQVn0EaY2b+0KOdHBWhuotZ4IT1U+EdrM5f0La7n9rR0DWOOqRUb686UcuuOWkSKl+ 2HXDgAPGyYiGTRK/gRiJcV+j8ru2qASF6wQJW/qWWrSf4l9oz2w2IUcPz4KE+jrdO0Wg OXNFMEr1MekUs+ECZG5K8Es1WZpQSwan+WbV2+Rs62HimhIuBxtn8RkM0zvTtPWlC4h7 Qb3wmohvkltXrPJj9GzURH6eA7PlLGAI5yriNDxf6QIywgm6ZeumdApWkOHLlNvs1Haa NdSA== X-Gm-Message-State: APjAAAVolv7e49rpVsJMVaPAv2xnx9sfAdEZRnLE9xrZfdHGhA1DRhV8 m8EDvw42a27ACmXPhhBWsfSaiAGJVCE= X-Received: by 2002:a17:902:bd91:: with SMTP id q17mr7601766pls.13.1557164064233; Mon, 06 May 2019 10:34:24 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:53 -0700 Message-Id: <20190506173353.32206-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::630 Subject: [Qemu-devel] [PATCH v4 24/24] target/i386: Implement CPUID_EXT_RDRAND X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Eduardo Habkost Errors-To: qemu-devel-bounces+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.1 Reviewed-by: Eduardo Habkost diff --git a/target/i386/helper.h b/target/i386/helper.h index 6fb8fb9b74..8f9e1905c3 100644 --- a/target/i386/helper.h +++ b/target/i386/helper.h @@ -226,3 +226,5 @@ DEF_HELPER_3(rcrl, tl, env, tl, tl) DEF_HELPER_3(rclq, tl, env, tl, tl) DEF_HELPER_3(rcrq, tl, env, tl, tl) #endif + +DEF_HELPER_1(rdrand, tl, env) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 722c5514d4..1386814957 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -730,13 +730,14 @@ static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \ CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \ CPUID_EXT_XSAVE | /* CPUID_EXT_OSXSAVE is dynamic */ \ - CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR) + CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR | \ + CPUID_EXT_RDRAND) /* missing: CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX, CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, CPUID_EXT_FMA, CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_PCID, CPUID_EXT_DCA, CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_AVX, - CPUID_EXT_F16C, CPUID_EXT_RDRAND */ + CPUID_EXT_F16C */ #ifdef TARGET_X86_64 #define TCG_EXT2_X86_64_FEATURES (CPUID_EXT2_SYSCALL | CPUID_EXT2_LM) diff --git a/target/i386/int_helper.c b/target/i386/int_helper.c index 4dc5c65991..334469ca8c 100644 --- a/target/i386/int_helper.c +++ b/target/i386/int_helper.c @@ -22,6 +22,8 @@ #include "exec/exec-all.h" #include "qemu/host-utils.h" #include "exec/helper-proto.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" //#define DEBUG_MULDIV @@ -470,3 +472,22 @@ void helper_cr4_testbit(CPUX86State *env, uint32_t bit) raise_exception_ra(env, EXCP06_ILLOP, GETPC()); } } + +target_ulong HELPER(rdrand)(CPUX86State *env) +{ + Error *err = NULL; + target_ulong ret; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + qemu_log_mask(LOG_UNIMP, "rdrand: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + /* Failure clears CF and all other flags, and returns 0. */ + env->cc_src = 0; + return 0; + } + + /* Success sets CF and clears all others. */ + env->cc_src = CC_C; + return ret; +} diff --git a/target/i386/translate.c b/target/i386/translate.c index 77d6b73e42..62fa45d778 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -5332,31 +5332,56 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) case 0x1c7: /* cmpxchg8b */ modrm = x86_ldub_code(env, s); mod = (modrm >> 6) & 3; - if ((mod == 3) || ((modrm & 0x38) != 0x8)) - goto illegal_op; -#ifdef TARGET_X86_64 - if (dflag == MO_64) { - if (!(s->cpuid_ext_features & CPUID_EXT_CX16)) + switch ((modrm >> 3) & 7) { + case 1: /* CMPXCHG8, CMPXCHG16 */ + if (mod == 3) { goto illegal_op; - gen_lea_modrm(env, s, modrm); - if ((s->prefix & PREFIX_LOCK) && (tb_cflags(s->base.tb) & CF_PARALLEL)) { - gen_helper_cmpxchg16b(cpu_env, s->A0); - } else { - gen_helper_cmpxchg16b_unlocked(cpu_env, s->A0); } - } else +#ifdef TARGET_X86_64 + if (dflag == MO_64) { + if (!(s->cpuid_ext_features & CPUID_EXT_CX16)) { + goto illegal_op; + } + gen_lea_modrm(env, s, modrm); + if ((s->prefix & PREFIX_LOCK) && + (tb_cflags(s->base.tb) & CF_PARALLEL)) { + gen_helper_cmpxchg16b(cpu_env, s->A0); + } else { + gen_helper_cmpxchg16b_unlocked(cpu_env, s->A0); + } + set_cc_op(s, CC_OP_EFLAGS); + break; + } #endif - { - if (!(s->cpuid_features & CPUID_CX8)) + if (!(s->cpuid_features & CPUID_CX8)) { goto illegal_op; + } gen_lea_modrm(env, s, modrm); - if ((s->prefix & PREFIX_LOCK) && (tb_cflags(s->base.tb) & CF_PARALLEL)) { + if ((s->prefix & PREFIX_LOCK) && + (tb_cflags(s->base.tb) & CF_PARALLEL)) { gen_helper_cmpxchg8b(cpu_env, s->A0); } else { gen_helper_cmpxchg8b_unlocked(cpu_env, s->A0); } + set_cc_op(s, CC_OP_EFLAGS); + break; + + case 7: /* RDSEED */ + case 6: /* RDRAND */ + if (mod != 3 || + (s->prefix & (PREFIX_LOCK | PREFIX_REPZ | PREFIX_REPNZ)) || + !(s->cpuid_ext_features & CPUID_EXT_RDRAND)) { + goto illegal_op; + } + gen_helper_rdrand(s->T0, cpu_env); + rm = (modrm & 7) | REX_B(s); + gen_op_mov_reg_v(s, dflag, rm, s->T0); + set_cc_op(s, CC_OP_EFLAGS); + break; + + default: + goto illegal_op; } - set_cc_op(s, CC_OP_EFLAGS); break; /**************************/