From patchwork Fri May 10 01:24: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: 163807 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1732731ilr; Thu, 9 May 2019 18:41:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/tnlEbYmpEMkHPyYZHYRElAprYhF3lz+POjOPARBe13xTsacf1f6s7dTt7u/UW9pwrwZD X-Received: by 2002:adf:ecc2:: with SMTP id s2mr179282wro.258.1557452514461; Thu, 09 May 2019 18:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452514; cv=none; d=google.com; s=arc-20160816; b=AoztbswXxTInNpDVVANNw3Zzar3Es2dDQLE7Fvp2eVlfkSOE0dbrbFzogS7zC7TDYV TQSEzJJlvY3xwq16UquMcMH4RVlozFlgTtXZhKx0IycyOf9zRIsBbXYokJvAP9tug3LU Jm7eglZ7EDmSQWrpNepDkm6JSm2Cq9jsw44byXaizSD1mcw5JdtKkOr7Rn/DYqS1EKXa Nku11jlcNbUEylsHxrqaNr3uHafh+xx5KDXo0uRQ7Z7jWHeZpdtWcYiyV5RzboVH1rNe HPUgwcYNt9FgN69xITwmCvKy2Fk6bR8Wyvj/2t6i3PAIGOpvt+qn96fJvRY/L517naPs TzhA== 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=5jZKWwQgoaRofSd9MpX36fg/EnNSkz9sJL+VHY1E4dI=; b=EvogWoykTQHc7dsI8PeM8oWPc5zwz1EK0hxMdukaYM4nCA+T1cNZrnpPHlynVhYS/6 0gebxubmbtE5Tyxar+nVtoRWND+jXNvaXIw8oR3+HNIxsjIS13MYpkmZOdlS31OU5V4Y DZIkl3RVvG7AEzymIqp4WMJMLh/RxPKtlWZGxPzX8/V+THA2pAxf6D8SEsoadi8aJsBl ECKFJ/hmAvzOm1quo2erx1A7JR5znK+3M/Wssly7IAmJWRBKHr6Z+mIVgf2IaXs3QQ9m d1hVdZNTE2Wx7Sn3XrwWxbzodJkU9aUAc/jGDcE9uuGPFW+0S5iyVc5+5xTJDdS3Dg4F NJRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Jlw2BOZl; 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 n10si3020057wrj.434.2019.05.09.18.41.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:41:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Jlw2BOZl; 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]:35233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuXp-0004Um-Dd for patch@linaro.org; Thu, 09 May 2019 21:41:53 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHk-0006Iw-K5 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-00014L-6x for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:16 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:41833) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHj-0000tH-04 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pf1-x444.google.com with SMTP id l132so2251967pfc.8 for ; Thu, 09 May 2019 18:25: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; bh=5jZKWwQgoaRofSd9MpX36fg/EnNSkz9sJL+VHY1E4dI=; b=Jlw2BOZlKaGi4oH9ckPffXjBPBWonfzGjuoLuJCXqBKIfZo1izQxjfnMkEUDtp2eqe sNODli5s71TxhSrvKmTWjD1HB08x7h1IrNQkDfmFEQymsvdzubDehDiSiIn++6NptVwU CCS/Dz4S+pKOJUDPMhnrBVtiJHNivHUKt908SKDe9rOC7hlvsD4JfFJUillV24psR4zj d+AgUynHsDNpamr4I+Mnb0z5h40LeWLosjNr/cr/qUi7EDejRx0wWCArI440gvqlZmK3 LcxHhRrG992xIZgAvXugzILeT9vbbH50j1dq6mbJLrP/s8vA96nZ2k9ntn/e+QZIVhcQ wQfQ== 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=5jZKWwQgoaRofSd9MpX36fg/EnNSkz9sJL+VHY1E4dI=; b=hSu5S39RR+6GU1hECNcpUfuwV6kVRvX9PK0xP7seU2VLLyUlpt9y1FFsAhx4HF1rz4 pkB53UakX4pGakBIiRgfKJWspX+N2ssk2vKt70NkWk9jdayLSI25s7Irg0akDvyPx0IP NVLt04C92UPArKPENqAHyK7oWST179lX3+bmin/SS3AIuBH7GCN+jwmMFVoY9tEUoI8s 1qGoD5xaY6H9+AxG6J8M+zNtfLXJ38HfYDspXaWuSr5SvZBRFrgy18FcPQS+9mWrsaCc NCEj24DcVQuXt/tzyNzdkmOZdQPAnAr1w7lPoRS2Ndi4ixUlFU+Aakh15RMpBuiLVzU5 zagw== X-Gm-Message-State: APjAAAUlkEYdBWAyB+/k7+G1rZKKXE6GqoJrNiPTQaH/Meib9E8CuVOn H0ScnfJexY71QNJVTmqwvWfkI9I6pAA= X-Received: by 2002:a63:682:: with SMTP id 124mr10106503pgg.243.1557451501382; Thu, 09 May 2019 18:25:01 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:35 -0700 Message-Id: <20190510012458.22706-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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::444 Subject: [Qemu-devel] [PATCH v5 01/24] configure: Link test before auto-enabling crypto libraries 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. At least Fedora 30 does not ship static nettle and gcrypt libraries. Signed-off-by: Richard Henderson --- v5: Include nettle, gcrypt. --- configure | 72 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 28 deletions(-) -- 2.17.1 Reviewed-by: Daniel P. Berrangé Reviewed-by: Laurent Vivier Tested-by: Laurent Vivier diff --git a/configure b/configure index 63f312bd1f..c4f27ed453 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 @@ -2849,43 +2856,54 @@ has_libgcrypt() { if test "$nettle" != "no"; then + pass="no" if $pkg_config --exists "nettle >= 2.7.1"; then nettle_cflags=$($pkg_config --cflags nettle) nettle_libs=$($pkg_config --libs nettle) nettle_version=$($pkg_config --modversion nettle) - libs_softmmu="$nettle_libs $libs_softmmu" - libs_tools="$nettle_libs $libs_tools" - QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags" - nettle="yes" - - if test -z "$gcrypt"; then - gcrypt="no" + # Link test to make sure the given libraries work (e.g for static). + write_c_skeleton + if compile_prog "" "$nettle_libs" ; then + libs_softmmu="$nettle_libs $libs_softmmu" + libs_tools="$nettle_libs $libs_tools" + QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags" + if test -z "$gcrypt"; then + gcrypt="no" + fi + pass="yes" fi + fi + if test "$pass" = "no" && test "$nettle" = "yes"; then + feature_not_found "nettle" "Install nettle devel >= 2.7.1" else - if test "$nettle" = "yes"; then - feature_not_found "nettle" "Install nettle devel >= 2.7.1" - else - nettle="no" - fi + nettle="$pass" fi fi if test "$gcrypt" != "no"; then + pass="no" if has_libgcrypt; then gcrypt_cflags=$(libgcrypt-config --cflags) gcrypt_libs=$(libgcrypt-config --libs) - # Debian has remove -lgpg-error from libgcrypt-config + # Debian has removed -lgpg-error from libgcrypt-config # as it "spreads unnecessary dependencies" which in # turn breaks static builds... if test "$static" = "yes" then gcrypt_libs="$gcrypt_libs -lgpg-error" fi - libs_softmmu="$gcrypt_libs $libs_softmmu" - libs_tools="$gcrypt_libs $libs_tools" - QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags" - gcrypt="yes" + # Link test to make sure the given libraries work (e.g for static). + write_c_skeleton + if compile_prog "" "$gcrypt_libs" ; then + libs_softmmu="$gcrypt_libs $libs_softmmu" + libs_tools="$gcrypt_libs $libs_tools" + QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags" + pass="yes" + fi + fi + if test "$pass" = "yes"; then + gcrypt="yes" cat > $TMPC << EOF #include int main(void) { @@ -2898,12 +2916,10 @@ EOF if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then gcrypt_hmac=yes fi + elif test "$gcrypt" = "yes"; then + feature_not_found "gcrypt" "Install gcrypt devel >= 1.5.0" else - if test "$gcrypt" = "yes"; then - feature_not_found "gcrypt" "Install gcrypt devel >= 1.5.0" - else - gcrypt="no" - fi + gcrypt="no" fi fi From patchwork Fri May 10 01:24: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: 163788 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1719786ilr; Thu, 9 May 2019 18:25:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTw8rMSoYy/beETnAi5+db6bsw0tzHVb5+ZXBjWHVDwrXm4z2h/uZ+izA+gpiCihEkNMpX X-Received: by 2002:a5d:5501:: with SMTP id b1mr5127809wrv.196.1557451548152; Thu, 09 May 2019 18:25:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451548; cv=none; d=google.com; s=arc-20160816; b=qirQqJ776VyNCuoM/r45ZUZDkETPfj6HrrFV9ChWg5jE1vyU5T7QgLF6IIqthi/WMp mtpspo0fddM21XJ16h2Adsi5o6ukH3Kq9W7oALJ+X8w1JDgUiLUBGr6PEpCn+PHJhNe2 M6ELv2RvG1TBVa22hS8MqvyLFwYLul3RaIW3y16RbVekcXCOaAZZjUWvn3P77pRcgvCY v6uqup+oJQJ7+uQL+F+vfEMGeDY1iR/Y+Oa/9NU9tIijTSmFZDDgn0ac2E/mwUCID8kC cQQ9B8qEnyr4iAO2FtrqipABLNGPlLbIUJq/DGRPRzQEfVjgMyfG7huWo+WRyUSJM1QK Jg/A== 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=Fwm1k5v3NRHCLn/Bn3EHiCpV8kVUpNoBlaYzJ8dxxt0=; b=YCyDv8Px6Q0FlJi+/N9s1W7ssHKFEHlQLNFB8UagKmBc88v/1YirVjawhT5z5sdLnt 183UQsIHRx1PKSc9Xy5NlWdRBpVEa1kV2tUK17mt3AbZt/mD8mhWZpnHjXXwT10MhbHE 1ZtpJveSOlT6ZTuH/0jYCQZscg2xWlkY4t8BCn18UOoApOudTx6MLuFpVqExVjB6Efxk Bapb0qpn8WOtRbbltfVmNkw2mDvrQEfh9BGKoe6bra+Czl0s/biCv68EV9ZVFDRnllxF zyaRIHWw2FIdjhfUjc5St5Ashaq5rPD2EBbHF8ubovZcxG+3XS/iCVzv0n3Rev+GJOHi webA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="l/MAxEtb"; 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 h13si3038715wre.7.2019.05.09.18.25.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:25:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="l/MAxEtb"; 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]:35008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuID-0006L1-92 for patch@linaro.org; Thu, 09 May 2019 21:25:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHi-0006Ii-Sb for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHg-00012i-VH for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:14 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:44638) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHZ-0000tr-E2 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:07 -0400 Received: by mail-pf1-x442.google.com with SMTP id g9so2244262pfo.11 for ; Thu, 09 May 2019 18:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fwm1k5v3NRHCLn/Bn3EHiCpV8kVUpNoBlaYzJ8dxxt0=; b=l/MAxEtbYYxCF6JVXlX9X5JLnFHYh60XhUl//ffcjufrkLID03DBGv1I3gKaXQLLWB fetxxcF3LjTfPH1/6i80/BCbURKuCQUZy63lZBof30hnepXQzCZEPSCXHAqmKOrfNlGb isA/UQNb47tN5b2Pv92dHMK0h9w6EoWE0UJ7S5CpfgIGG3lMBmjvqPONBdK7jfu9WV/y qgHDAPR1RgNzY7Cd2QyT6V6+8TQOo/IwojVW6rYMeN+5NvMXg75v7qLEbQiBo9yn3XeU zaMtBpaeA7LHWaR1mK6LG9uk7ug1AcUlk65D9gaReKPReEwi0HCzSRkR7hVTdhjJhMAy fzDA== 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=Fwm1k5v3NRHCLn/Bn3EHiCpV8kVUpNoBlaYzJ8dxxt0=; b=kuuDxHa7b/lOlmHEBLln6sM9BUxB8RElkHUdLES2SnzYA7ttn96ky4tgAFF+ciXIKu Osm6lhyve8Ga2BWhYaX1y1X687IO9CRcMVG2zc9fj8RsOiC8Peu/wfMnKRh3oJTOwQPj klmlVS5DuEXc+LvGvH+RCx+efM9Nld2692c2MtNsh3eIwNEnsLdeBaFYULTSqirRAjIb ArTwroHGzJZ9sAz914zsM/JcC9cQitsC9za6OMthka86p77qDtbh3Pu0S3n8cMeL8nEK e0JODx1o8riN2pWYAaG4GqUeIYl/9bF+eqcjar5a5n7AlbXugUB+uc6MuNgLioFzdg2E N9uw== X-Gm-Message-State: APjAAAX5tvUX0fIHg4QKhaI/D4JJ37T7eVamrWxzovAkieu8KlVimpif 05cwhiEEx5kIgwkR3kncy2dcKlEOaH0= X-Received: by 2002:a63:2b0d:: with SMTP id r13mr10039683pgr.400.1557451502591; Thu, 09 May 2019 18:25:02 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:36 -0700 Message-Id: <20190510012458.22706-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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 Reviewed-by: Daniel P. Berrangé Reviewed-by: Laurent Vivier diff --git a/Makefile b/Makefile index a971247cac..7c9c208207 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 c4f27ed453..68b34a93eb 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 @@ -2864,8 +2863,7 @@ if test "$nettle" != "no"; then # Link test to make sure the given libraries work (e.g for static). write_c_skeleton if compile_prog "" "$nettle_libs" ; then - libs_softmmu="$nettle_libs $libs_softmmu" - libs_tools="$nettle_libs $libs_tools" + LIBS="$nettle_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags" if test -z "$gcrypt"; then gcrypt="no" @@ -2896,8 +2894,7 @@ if test "$gcrypt" != "no"; then # Link test to make sure the given libraries work (e.g for static). write_c_skeleton if compile_prog "" "$gcrypt_libs" ; then - libs_softmmu="$gcrypt_libs $libs_softmmu" - libs_tools="$gcrypt_libs $libs_tools" + LIBS="$gcrypt_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags" pass="yes" fi diff --git a/crypto/Makefile.objs b/crypto/Makefile.objs index 256c9aca1f..a291bc5b9a 100644 --- a/crypto/Makefile.objs +++ b/crypto/Makefile.objs @@ -34,8 +34,5 @@ crypto-obj-y += xts.o crypto-obj-y += block.o crypto-obj-y += block-qcow.o crypto-obj-y += block-luks.o - -# Let the userspace emulators avoid linking gnutls/etc -crypto-aes-obj-y = aes.o - +crypto-obj-y += aes.o stub-obj-y += pbkdf-stub.o From patchwork Fri May 10 01:24: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: 163808 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1732928ilr; Thu, 9 May 2019 18:42:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0LKemEY9Ef3xb7+JVSZ3IxQ6ZZdgXZ2xKGeF/WnuVlwCfWA8RWWuCJ5I22Xa06x+hCxGk X-Received: by 2002:a5d:50c7:: with SMTP id f7mr5413750wrt.95.1557452530473; Thu, 09 May 2019 18:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452530; cv=none; d=google.com; s=arc-20160816; b=MCjaJ4IrUAl4JsO7HkgNLJ2JvcJSEgz3AmmEFiZkXid8gw6xV5Nio7tEcH0PGSX0eu hTErL506fXMnA8B0euN4V+rNUILTArxNKyIQewG4FMt+itKADb/EyWXfzDmIPbofSm2u 2MH+tuKpWi9B6tO3aDBae4hFfJ7ucYGPXpAOOmhtjsIZG0IbyaAU+fztcSot5oN1QIrH gJi9kbS+Jv4yq+dbMqGRa4gBDBHx0iEu6DWzqO7s4WeIuE5/hAf8BlLp2Pvg1ERtSD67 yvNvT3lUf0fBrkyCznVwp5KY3/TjHiLs4LlkBxl+zHCqpIqIRIuVWN3Trv1iyZd4H+vG FKEA== 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=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=WfaX4d1qITjFp6NSx/r8QyZ5+VuJ12iFwK0npRC5fAJe1M/hkFTz0OOy9x4mIUjBef 4CGBF+6KhLWypcGWYhLVLSjoJ6KHl9n0V2vYoUe6H+mdC8yUx0Xlsh+qNG9GMg79EjB1 F/KSa6COv0gfsDNb7x1PKmQz/NCKeWrrruUnBp6o8sufGsg66Ingp9xcMlWuH8iBvxwB 5M/t3OFSGB/dXYp1r5Tds2GjM1tSBSZ2ocQlGOy5kh3iICpvXtc+KGVhTMGRCj1RAUTU vY8sv5GtkiH1HHpLMQyUgjeXqKHwQH6bF8nbuC+s8h05CoATEO877tVQzP//R5E5o3gi UgHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h0ZEFgoo; 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 k3si2628956wmi.124.2019.05.09.18.42.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:42:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h0ZEFgoo; 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]:35235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuY5-0004XD-H4 for patch@linaro.org; Thu, 09 May 2019 21:42:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHl-0006Jj-Qy for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-00015I-O1 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:17 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:43030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHj-0000ug-HI for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pg1-x541.google.com with SMTP id t22so2116429pgi.10 for ; Thu, 09 May 2019 18:25: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=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=h0ZEFgooJH5WHwPFZMSTligDsA88+EizQ2Gi+JTj1Gqh2Pky11aDt1EnB3vorhNP4o pRCm091sCUrQ0Xg0L3f79HpVXkJHUo9Kt/bvwi9mDCe3BCojk/1TRvOl+fo4Ed6qAv6d 62hcqB+zRhovSakJfwLyOvkba4xXTFWu/LPDSLHIwgLLzZGLfraXnWiMCZKtr63042vI yECcmWNAaTpjk4ce4Kl8iyM7LUr7d5B+R2nOZRfMsPQxB5sIRHBkRnhWp0U7PsmmxUb6 3zaAaVgy6LRf2jMuS7GYc7otnyGdvGDNjNlHoQ3kBf3uIMnmhAv0Bxm8WpnIfe0tOaQB 7tuA== 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=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=tottwBsIMMJ/sv3OVtfFl4rbZyE5yDEieXhsMuD6VeC0vQywokkMYoMV0+yvBxYETr XLyeeLTRpg9EAj4ih5Ht0yjUmOsh1DLyArKHWVJJPBKj0wSHEq7KQDk11MANHtzQtXA4 iCtRWSEkR94pfa1CFzfVVd46lA8Ui4gwnI7TDWX5C0U1Rhg420Su1O9880mPCOoBASOO TJmYCTNbpxHdDuV5yoF0fkPhAr6W7zCZdUVhulkYVALbCmxxVYRenCsvsXOOPbW8lnyA Ara1VizhBl33Jjz3zWLRhu93CbAaI9AVHL/vqQOKpXsG0gbjnHAGzDMN5dYZHHI0o6Xt jVgA== X-Gm-Message-State: APjAAAVzVNNyAjhtwtc+xLf9Y8cDFPzrX/VAKDcIheuRXolQSutk8zTT AOTIIIgffexhQ5w20JaziYk2TLmo1aA= X-Received: by 2002:aa7:8243:: with SMTP id e3mr9817358pfn.213.1557451504149; Thu, 09 May 2019 18:25:04 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:37 -0700 Message-Id: <20190510012458.22706-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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: Laurent Vivier 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 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 7541b4cae7..f995fc0ef1 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -32,7 +32,14 @@ static int fd; /* a file handle to either /dev/urandom or /dev/random */ int qcrypto_random_init(Error **errp) { -#ifndef _WIN32 +#ifdef _WIN32 + if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, + CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { + error_setg_win32(errp, GetLastError(), + "Unable to create cryptographic provider"); + return -1; + } +#else /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ fd = open("/dev/urandom", O_RDONLY); @@ -44,15 +51,7 @@ int qcrypto_random_init(Error **errp) error_setg(errp, "No /dev/urandom or /dev/random found"); return -1; } -#else - if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, - CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { - error_setg_win32(errp, GetLastError(), - "Unable to create cryptographic provider"); - return -1; - } #endif - return 0; } @@ -60,7 +59,15 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, size_t buflen G_GNUC_UNUSED, Error **errp) { -#ifndef _WIN32 +#ifdef _WIN32 + if (!CryptGenRandom(hCryptProv, buflen, buf)) { + error_setg_win32(errp, GetLastError(), + "Unable to read random bytes"); + return -1; + } + + return 0; +#else int ret = -1; int got; @@ -82,13 +89,5 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, ret = 0; cleanup: return ret; -#else - if (!CryptGenRandom(hCryptProv, buflen, buf)) { - error_setg_win32(errp, GetLastError(), - "Unable to read random bytes"); - return -1; - } - - return 0; #endif } From patchwork Fri May 10 01:24: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: 163792 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1721965ilr; Thu, 9 May 2019 18:28:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRm9nKkVcndEv5tU+qYUYGgFIVagedsI2IimlYgtu+26kF92/b8SdNwDko6piBAhfFyWdd X-Received: by 2002:adf:ec04:: with SMTP id x4mr5391226wrn.18.1557451715987; Thu, 09 May 2019 18:28:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451715; cv=none; d=google.com; s=arc-20160816; b=EajYDw/bTyOLAITsZIfdmkOlEAHcajBo6OJn6uTh6ii96M6SSZyxLpB1tEIypHAemI h1h5u4QAfF+ZeBKLuv2tQg2LPzHm3yTud43dUK1J5+n+agsUEKDD5lc6b+1egT4J2vBb DsWwq0WoF+VxeiR3iN+F65jWkbaHvU+fEQqR18bxZl1r4OLet/J7vIVKfIIR3vID9ONH eOJFwZ0G/OORXgxXwRmKzLJ4uLoibuO36Ei4P1GMRBjpXRGyILQHMxC2Fh3ZMS+zU9KO xxw0yJcvrn8RVAHv2FxqmabKXbd6yt/jPUyBSsd/AKU5LvJBKEHi2KFPOREhA7wEFbIX Z1+Q== 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=8Bh7531eyDC2/9D2e9XWW3j4XTcdT7MvDIqTNSwlf4w=; b=lbakVQlDbexqJ2Y9S5ZvFpP3MQgO7PX2F1kYhFhPcmmCX6kYS7C+MRmrlFZp72e0yq jiUuSubbqBHAWcgzaMz0f6m6e81IMYMZ5mPQXiztUukh7qFvtnQzT6NlNqZQiitl5cx2 osoxW1CFh+zjj17YLQDoJDZt0rH0YbUi4athZboPswpfe5v9L5B4+Kx5s8SbLJ8eUEcQ YL+D1rO3aPz4Siw2idn+uVLVHvbNxnQ/jvvIEUHJYxbyYhoqmlpO02BkQ47HNHQd3dUB /HSzKAcw4HIwTYU0zIsdJBEI5f5ZGvCXYkEv0nZirs1NlvnlYKNqBudpSMXEE7lLAJE6 TEfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DwcFA9lK; 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 j5si2566323wme.179.2019.05.09.18.28.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:28:35 -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=DwcFA9lK; 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]:35030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuKw-0000se-UN for patch@linaro.org; Thu, 09 May 2019 21:28:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHk-0006Il-4t for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-000147-3r for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:16 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:40271) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHi-0000vJ-TD for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pg1-x542.google.com with SMTP id d31so2124830pgl.7 for ; Thu, 09 May 2019 18:25:06 -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=8Bh7531eyDC2/9D2e9XWW3j4XTcdT7MvDIqTNSwlf4w=; b=DwcFA9lKFVT3ktTPBdbJzkZtg1ifSLhXJomWhhU457RtwvhB+1003y9TgSYGyTBbyM /z2t6iHq552O93wdb/aYLTkfJAAGBfO0YjBNo3D/Z+zYXgoU7Wuj59ZIi39uy3kMUq/L lcZvUPsnxQyu/HnLIdWIYGkJvJBbhF7oDzUJxTbTQCR0Via3ambGFaBgQ3/3MEPpaIRU Gp9EtjI4RnnjFRaMQEV5//jOUgha3LEcCnjNX8VJbAjJlVfSF+p+uW5t6lpjdpCDDzpF 3oFvj+uUaCnXK16KLelYS4hukbS5p/hUuMa4JHrfhnCphhdy9GbHpPoQV6zUXpf2DYW3 7DZA== 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=8Bh7531eyDC2/9D2e9XWW3j4XTcdT7MvDIqTNSwlf4w=; b=BVQXGPm+CrEl7641O9EKC5zPd6O9raAFqt9+zY654CF/T/ZTmbtPFoz37rzu5sVWj+ NxlNTf6OuPLRt/KAcJRVoL7vvN28lFn7+MXVzXLxFWAnInCBFPGSJLnZ+Isu5VdCM9jW qFhKmTu+aRgdVgil8Ve1Ei1VZXQv15zUNVlwNsZg0ifh1/YoaDkO1/T52n6D2Nj1XEve XDP2zVvrsAWAUTUMRxUNNmEOthlIPDmNHKHceeooXXb7pOPxMfEYi82xjdlq7Qm0Qtee sAHs1Mf5g1CQ/Qn/rK8P46+dilIWTu3X80XEqRKpfblFbLATgtpqwtDbxRCwq6w5EOEt jzYA== X-Gm-Message-State: APjAAAVxovuw/xRid+n6DLxfxBaGZ7OI/6zF+lWvHat4RaPd9swICcZH QDK4gcuZuEVQ5L6ykVEotT+dKzvNIkw= X-Received: by 2002:a62:1a0d:: with SMTP id a13mr9876113pfa.198.1557451505482; Thu, 09 May 2019 18:25:05 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:38 -0700 Message-Id: <20190510012458.22706-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v5 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: Laurent Vivier 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 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index f995fc0ef1..260b64564d 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -65,29 +65,23 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, "Unable to read random bytes"); return -1; } - - return 0; #else - int ret = -1; - int got; - - while (buflen > 0) { - got = read(fd, buf, buflen); - if (got < 0) { - error_setg_errno(errp, errno, - "Unable to read random bytes"); - goto cleanup; - } else if (!got) { - error_setg(errp, - "Unexpected EOF reading random bytes"); - goto cleanup; + while (1) { + ssize_t got = read(fd, buf, buflen); + if (likely(got == buflen)) { + return 0; + } + if (got > 0) { + buflen -= got; + buf += got; + } else if (got == 0) { + error_setg(errp, "Unexpected EOF reading random bytes"); + return -1; + } else if (errno != EINTR) { + error_setg_errno(errp, errno, "Unable to read random bytes"); + return -1; } - buflen -= got; - buf += got; } - - ret = 0; - cleanup: - return ret; #endif + return 0; } From patchwork Fri May 10 01:24: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: 163794 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1724127ilr; Thu, 9 May 2019 18:31:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwimVs7PMvMn4DEe0gUZak6JL6MUiIY//GOoatL+5Wo/D0+5O7yFWRBtNFnEvR/1eMjP87V X-Received: by 2002:a5d:55cc:: with SMTP id i12mr5417069wrw.179.1557451863892; Thu, 09 May 2019 18:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451863; cv=none; d=google.com; s=arc-20160816; b=RaLhzYrS13Y2ZG7tva0t1GrdHYhi0OMlfKmMn6c5b0mDWMQ/pvH+bVhGQnv9PrKBUQ klakTdme0dGTbStsBirWF5+r1opgQnGfVe+iTBgbkDgmK/yJFENdfmYnD81siJSJQOPM VYBiZUTTU5at5uOzG3yZrOE2YC52Sh9YizRj8FkORsFiPUBkvIlKWpdCzPEMCFkeZBuL SsEDcqo721XUGJw2XPU0ziPJuxFslCtVjzzUO+jbbfniUhyUeurJq0pfUJCYbWuAuniS ljtX8G0DkpYDgLS7L/Fpyt1+/CgNgBz+QSgTn+Meg+0j7TUoXGB4BzawRt2IyD+/W/Bf zsig== 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=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=p3LIRLjIj2X8NAk/EActDXlaxPPUDn6wZt0tg1QtoyKlRY/OCunIy6dmNodhvqRmjY PdvO3ZsRc+BfMGjcaocQSA3X1vfeHX1UDUrTRIVs5sgyDRiffeumR4Z0PRdUIYtIMSe8 yocppoc3H1aybZEh0FG4IYKawXHJ+OsdjCknkx7BDF7/c75HHLFBfuLcRAdmkwETiAhN 8awzFHDApmztmOQNINTOgVEYnFkw+lrK/1byP3EFWjPNJBJwK5o/CNx1AW+2E8LUt0l1 cxsOPlhqwt++iIc0T9YJ1+DM8m6yzQRrkIb15bJscv4OMr+Nn0vtdsSPvcIl5tXwV05M +xdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=q9FC5WjX; 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 s15si2635054wmc.4.2019.05.09.18.31.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:31:03 -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=q9FC5WjX; 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]:35080 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuNK-0003Qc-Q8 for patch@linaro.org; Thu, 09 May 2019 21:31:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHk-0006Iv-Ig for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-00014R-AK for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:16 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:47002) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHj-0000vt-3Q for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pl1-x641.google.com with SMTP id bi2so1971614plb.13 for ; Thu, 09 May 2019 18:25: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=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=q9FC5WjX7Sjp9A4E/k9cgfEf7yTbFV4yLRQJSZnkUh2FFec8t/Uz+/GgB650uA+f3T 4aU9dWy+5aQR/SyeX59WPaPYYNzcMbWumNI3YgklONkhrwwyTZmifKDWZoK0hPT4jofh Ft8MN8WWsuOiozsvu1Ueugk8/sainc6H6uQVjYlLiZ1RaLJrqqZ67AZ7idWXiZrj/6WT hdSGeOZOHojHZR7HV42rejEG0kZzc2nL3Ns1yyhSg6OQ7dC+Z9g8aDJBTpzrFNBYAQAV EB+4+YrgLhz+wxCYxoJ0wR6IP7vwqtcC53jBxnlfks0WS03jZGUlrADPgzQlPdcuqQNs HpRw== 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=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=obp1S+l9cKA/u1QRzzZWW5BzD8MbU2EbgpAmpIc5SSvV3uq6QcaQln/+ePaapeeNkN BuTu3Zby9RFmvul3NRX8FkWdBejxL0IBltut3ROIX0MlrdQEYXEBBUQ1ENBg2TT/QjfB lGo3cs3iWLYnm1i54SrWcQ9GJjmvaWIR68F8yCzVGgU0A6bjZyNwcKCykuekd6MsPgEU cVhuV99VEvJRuf0PgQE5eWJLyxdrANhWDIZi9EUyv6LbEcifo6w54BJzft1RVb77Puza E2iaSDTlG3mMPNIX+oCUxntz2c+WK0SB3RN2ZWG3ySJsSNRoRdievOS1ke3N5GXJkUK3 gbxQ== X-Gm-Message-State: APjAAAWXFHByz/XLiTjuNk3bAS3cQekNx+GhBlju648lFn+e3DXHszYW GNMKOgUAm4C8Z0G+SvC3663uW6v5u8A= X-Received: by 2002:a17:902:7c8f:: with SMTP id y15mr9415198pll.339.1557451506794; Thu, 09 May 2019 18:25:06 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:39 -0700 Message-Id: <20190510012458.22706-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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::641 Subject: [Qemu-devel] [PATCH v5 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: Laurent Vivier 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 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 260b64564d..6df40744c7 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -42,9 +42,9 @@ int qcrypto_random_init(Error **errp) #else /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ - fd = open("/dev/urandom", O_RDONLY); + fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); if (fd == -1 && errno == ENOENT) { - fd = open("/dev/random", O_RDONLY); + fd = open("/dev/random", O_RDONLY | O_CLOEXEC); } if (fd < 0) { From patchwork Fri May 10 01:24: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: 163793 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1722011ilr; Thu, 9 May 2019 18:28:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqwp1oJ4zuwUYW1nohEDRxW4SZDnxxkPO5wXgfsD1ezwK+KALiiuWTBO4MuqrN0UwvC/KCAg X-Received: by 2002:a1c:a711:: with SMTP id q17mr4294176wme.146.1557451719745; Thu, 09 May 2019 18:28:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451719; cv=none; d=google.com; s=arc-20160816; b=azGzc3/POFhCrYFilqTlOXNFc0hjSoTwIgPpDmxYj+NygoKKEyERp68iElvnOZlkwo NX1JmD3K7ZStQHsiheH5Im2uvZu4ck4Kulow707RIRkdMrqt2N6Er7zmHG1DTMYZqzjt 2IzCuOquaeWG8tNzr5OqLa1zn2RqgvLEJWjTFSHNIXD4bsEAkMJcI58MvqFpZz4eFFrZ l7jjOg0hRB/ysIp+mPl19t+j1SrK4lXzWbu13hP4o1AD4DiE6d0U5eVtXapAeWeYkodT bCn+QBCwpik6bq4gFG4HL6rNdwCDRycnQNl4lA9Q/g0rkPdJ/lQweNznEmOKz/Vqt+Tj dRPA== 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=BFNXO+CSJUIyB4vBsJmwl02buO19GtyllxlmqyS+gn0=; b=zZLHh/eFRqxwSgsb9vAC38gCcU6BJCLeAo18UjxnYF4Ro2hZnWSjDXf2VB7mzU6dYi soPy65ai01ruMjuVIVGxZXwv8x2t4JlNUbhpmTYFohziGp0qc2bStEcBJQfHnRQdlv2B LGzsNNWbEEO/q5PM2m/nQ12UXcWA70ADqn2JSnHdGVOLg3uU89RFmdS/JF+3dSSmNbdy p1XJVOEMXVBivoaZ54vtGQSH12HQS0qbPYm0P49wDLsei3xDlarrnJ3ct8hiKdB18onj gwK7WMSkZAXYXAgL2id6pK/VSG3UcBcVWFkPSgaIa4FuLG0ZAcSHMpgEFH59XCHBN3Pr 2wMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XxvdoYnu; 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 j2si2686976wme.89.2019.05.09.18.28.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:28: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=XxvdoYnu; 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]:35034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuL0-0000wV-MC for patch@linaro.org; Thu, 09 May 2019 21:28:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHl-0006JE-6z for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-00014r-Hm for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:17 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:46793) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHj-0000wf-9W for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pg1-x544.google.com with SMTP id t187so2110959pgb.13 for ; Thu, 09 May 2019 18:25: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=BFNXO+CSJUIyB4vBsJmwl02buO19GtyllxlmqyS+gn0=; b=XxvdoYnu/rv+yVFaQhy06prW9DgtX1zofcjIsKgTv4Vg+lbuzWn/7KYvh+qt7Ev5aY 7uN1GvLgirtJ0T87KDGPIhqKAVUecvVj0EHZoP/zDM2+tM73IlWJ8IO4BMxtFwP4FIBi 7wGbn2eJ5t/eeZ8N+PXxbk+c7lMD9al9Roa81UagbADYK8qlvBtlnYYhKiuv64yIypXj kHU7eX4G5sxjJLhevNWYE9I02jJHtifpWeiZQ5v8V7DZxoAogbvPAmj4X87Eh8rxduQ1 bBGc1PFXifsGZtbaYRHPLo/r5DYJNDMPrU3P2SnWPZN3fNRfL66MQgz3la9ZfT1y5H+T FZWw== 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=BFNXO+CSJUIyB4vBsJmwl02buO19GtyllxlmqyS+gn0=; b=P/IaUWn5ev0gDn7ofDw/Nsqh27lYTuqRwUGsqYls1m1J6y2GagxFIAYYzX94H8cZ4T akf2S9HvE4Ung6D8PULeV8v/3QvIsyYJZabM0G735HNCWf1j4v8ibLIaxUlcUTbxgkMP jXmk4g77AkWaK0e1ZCeqAtqCB87ji9sNLTyrmiVv0rSIqK/8kn5SulArDkljFx1TIyt3 FBGqoCdi94NIV0vFRDNu6bX3LKk+GFbIV9t6T9dYDs2UnZj+jOzAIpfZSjR5063+E3rd EmYlDPKSp04nhkpUyfVXrNKPY8gzGt1ZgTbHyNm355R0lvDyYBtVrPSSlu8EFAZWnM0/ iU1Q== X-Gm-Message-State: APjAAAWRv6DISxWH1iVKQ3Adamls/H9kDH7cPQy2mkc3iAGWeKF7LnZb 4tZGJEN0CRZ0dBn975DzdtB8iy8EgnA= X-Received: by 2002:a62:582:: with SMTP id 124mr9913664pff.209.1557451508029; Thu, 09 May 2019 18:25:08 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:40 -0700 Message-Id: <20190510012458.22706-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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: Laurent Vivier 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 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 68b34a93eb..346f89ea6c 100755 --- a/configure +++ b/configure @@ -5815,6 +5815,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 @@ -7202,7 +7216,9 @@ fi if test "$have_utmpx" = "yes" ; then echo "HAVE_UTMPX=y" >> $config_host_mak fi - +if test "$have_getrandom" = "yes" ; then + echo "CONFIG_GETRANDOM=y" >> $config_host_mak +fi if test "$ivshmem" = "yes" ; then echo "CONFIG_IVSHMEM=y" >> $config_host_mak fi From patchwork Fri May 10 01:24: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: 163800 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1729081ilr; Thu, 9 May 2019 18:37:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyi2T90nEtlhT44m6sfwaDGCvZx8YYeyZ+uuoRpcQLPtZGE78/7PPVL/UgeDx5+a79zVgyY X-Received: by 2002:a1c:b3d7:: with SMTP id c206mr4841197wmf.77.1557452232153; Thu, 09 May 2019 18:37:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452232; cv=none; d=google.com; s=arc-20160816; b=uJApjY5swAffi5FNbSFp4IUnZRLQDj4TwvV9z1YfhWa7laQCWKlfCmaO4NkJV+iRSH vgftLgkTQEzLdYKDL4kflrOgZrlaX8xEpO/Z89Kf7fC1fWaXLF8HtgwTMtyjD94FhX8H 63qbG6LenNpNfXtWGWTc14bYLBp4iNRiMtB1FuG8j3EL2P3VVT+r9AR8HAV2qJpl/awL LF4Q1HWq+PEjeiCNqT0mxCMBClrGlbHlZV64XJ0vK2WIs2Uqp1OjsHMRPQbI5n/clxU/ EAVqF4QkMS99NF9KmZUVr14g0HZaIgE08M10eM6I+y6KCbOt7wxmgfBHnRniT5g2IDbC HOzQ== 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=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=0nbhFfAN2ma5le3hZiOS3NiBefByDG7bpzbIipI26pgnaeL8V8bmd/L8Sgj8hhPDxO d5ZJb7jgWFrj98QdxAlRrXOPjtH20c+b9RMw+2bvWYlgfegJoAxEdyfpwyQ7/D8eOQFp 3cn75HFaPsx4Qp4/5yx65t1tw7qfk7D1za9uFZh0XOOCp0yVApUJ02tf1Fc7l3+K+uhd I+Oi73f9mM+QeU5smBQLOWVGBZSaXkEzBhf+W3LecHC62Eb1uaAdHjaV810cEKi/A6MQ P/fDtjXKgJcJCzDFfUXQzlHx5kCZMxg0xkNlb+jZAxyVPtmytXmUjuWWNMw3gklZRXkY 97Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=x1MhPPBz; 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 t10si2701648wmh.8.2019.05.09.18.37.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:37: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=x1MhPPBz; 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]:35158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuTG-0000mm-Rl for patch@linaro.org; Thu, 09 May 2019 21:37:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHk-0006Iy-TT for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-000150-JL for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:16 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:46176) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHj-0000zZ-AA for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pf1-x444.google.com with SMTP id y11so2239129pfm.13 for ; Thu, 09 May 2019 18:25: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=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=x1MhPPBzSmgGNoeKDU1r/iSLWIObmL4ruPAPjFk2gF5V2hkUlPbign0V91FQliMEv+ C+T9mFpCzsNhyWICh2G7bqVQ0aXjWQ5ihnA2i3gW2QGeQIHXfTnRUSgJvJ6JYhcluEVl jLGMP+5jh79dk38+nY5/GV+Z+2g1TgNapKFkRHyvflkEUT5QPkt+ySDMmIXjPObBkjG5 FxzBpP5kTLmRxqC4j7xtBaa3L7EwNA6uRSbymKdO7xrSh/aZwwHuqkKuUXVQZbH2EK9m uNekuTGPLhar1Dl9rvQ9XzIZr2KrGgzcAu+d7clb1ThKMX/32gXgNub7VQZfeU4C4UP7 Kyuw== 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=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=ijwMdb3mu2wUQE5kYs+0ycMiN+VxmgiPFNHxFmoMqwtAeNKG8leUMVAEpL0vLd2Y+t EofsvhGK7LhpFGyy97ifQTY4xfQSg3yXJhR5L42Wplfiiy7SmgNUWeG1S9yKJieLVnNx wsgQnwjDMM8Tbl0yRYK0VZEhZkfTFZx/OykKkC8VUulctzsLntZkvM1DBpz969QtiLwf bPw36DI8hIa140+4qhznFTq1okDmioBSai48CqV+zH3oMso83MRrsEu0i7PIN0kNTR5u 35UaXQwFHSZSvBA68XtcYKvyRuOMUVfygH+r/zLdgKjqFLPq75iyP30y8dV6v3/gfpPf Heeg== X-Gm-Message-State: APjAAAVWajt0EsJL80fhVP6Cjhov3bMDvGtaMx232k7boWURJNc5j7I/ +SJsNp7ZcsB8yP6iyb5XlVbIDH2IJyQ= X-Received: by 2002:a62:5e42:: with SMTP id s63mr8247249pfb.78.1557451509230; Thu, 09 May 2019 18:25:09 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:41 -0700 Message-Id: <20190510012458.22706-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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: Laurent Vivier 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 diff --git a/include/crypto/random.h b/include/crypto/random.h index 8764ca0562..fde592904e 100644 --- a/include/crypto/random.h +++ b/include/crypto/random.h @@ -34,7 +34,7 @@ * * Returns 0 on success, -1 on error */ -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp); diff --git a/crypto/random-gcrypt.c b/crypto/random-gcrypt.c index 9f1c9ee60e..7aea4ac81f 100644 --- a/crypto/random-gcrypt.c +++ b/crypto/random-gcrypt.c @@ -24,7 +24,7 @@ #include -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp G_GNUC_UNUSED) { diff --git a/crypto/random-gnutls.c b/crypto/random-gnutls.c index 445fd6a30b..ed6c9ca12f 100644 --- a/crypto/random-gnutls.c +++ b/crypto/random-gnutls.c @@ -26,7 +26,7 @@ #include #include -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp) { diff --git a/crypto/random-platform.c b/crypto/random-platform.c index cb3ca1bc09..66624106fe 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -64,8 +64,8 @@ int qcrypto_random_init(Error **errp) return 0; } -int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, - size_t buflen G_GNUC_UNUSED, +int qcrypto_random_bytes(void *buf, + size_t buflen, Error **errp) { #ifdef _WIN32 From patchwork Fri May 10 01:24: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: 163803 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1729470ilr; Thu, 9 May 2019 18:37:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBOBJV8nK8jvHefKLAyP9BE9OL6GFMAnetegD7U2lE9uN8zlJxUXut/BHYWSc3x1JtawCF X-Received: by 2002:a5d:468b:: with SMTP id u11mr5571783wrq.276.1557452262982; Thu, 09 May 2019 18:37:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452262; cv=none; d=google.com; s=arc-20160816; b=xl5ATCn0wZq+c5j+mrhCYK9s0zAtagxjeBksiwe6Qj4F5xnl9u8JK9paZYWXt/l5qJ eUmEXMOc5fbgVa/yxcuLIwuXQXx9J7Gis5YZWkqpFqDcq0OSTliuI0xKuBBgsL2zfNJq JhhOvJ16UFesDCsLRuJq8jF/ZVPfDKWeqNn5sHO0U5Riz6rsGpNdDqT7ZIPNMW3608KA 0e6XEna0BRCw9usrblNAbLKnGIUgMxQbN7XktKopJRedgAai8ZkIbQ/pRTALx8wSzWw/ K60a58kF8n8rDB3T0ixzgIREMbcxIbT5L8/P/ILQUjB5aEdu6P0QkctSxsWcXI+ewiJ7 y3EQ== 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=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=mUSJvJBQepGoaxcAJql9Fe2suDSxN+ty8V2hP9XpkCcZQVNbeiqvNjUObG//LApwet McSlZ+qo+i+rC3Ka5IbesyptwevwUUbJz8EoGqtIvwZo4gKmJpJ7v4bZ/CncTRQTkH1U nQpnvc3QI55Z+35V6NrBERg/Z8kPr2POIeqPErtgaZaVvruXe10RAfs3E4bdr84uCweg 7jdmejJ/1XY3uRCNFusvksw4Mn7mlHFDN1lYqi40XTraUVxOUUro446y7RNPy+qkxjcR aQd9p5/P5aBA9/JF51gIFbAhpb/Ao6kSxFvLXz3IEUjkmXXNOh48b1HpRaH1CDbD+fsB Di0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=y2g1Rits; 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 h66si2766285wme.128.2019.05.09.18.37.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:37:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=y2g1Rits; 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]:35162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuTm-0000rP-0c for patch@linaro.org; Thu, 09 May 2019 21:37:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHk-0006Ix-Ra for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-00014l-GS for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:16 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:46003) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHj-000111-78 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pg1-x541.google.com with SMTP id i21so2107040pgi.12 for ; Thu, 09 May 2019 18:25:11 -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=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=y2g1Rits7EabH8URhQFjlCxR1PX6UaETo8kTzAGIRREYFBIZkP2TCQ49d1BSYqHqtS aaysfVPPg3je/PAHExurerfrD0QFHLhLpB5eXTX9Bm2gM9o4/0rhrOMlpwRWHmTCbCVy jszUfwcTN7/MIN6guL5HuSMmYSxSX/oC/fNYdq3QtziEZh/nYMRY7F2W2y2JeR2TsPs8 zYz/ePlmNOZsJKzrS9mqlrxW7n6z/p6f0/6Bd1m9Ilezils2ZX4PREW41Yp5zEvdONKx AuNKrd7a8FIbr9aWBXNFnCN3b+uPqj3JVnypRlEFitBS0y1MbfjrtAHcOmklgT2EfW4U fIAw== 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=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=GzZ6sdsQnCxaP08WJJVqg6PJeegbCSKeJSjuYCKexO9rjX+Dr5eXHngzl6IAyzwI/V 0o6PIj5z5wF3XNBoPVORTvjuBDC+RD1uQfzz3axtmU7K4vfPIGaVe9++oWayecwAimOI cm4ZuIoM1zH4SIVpwEKm49Qc/1jM4jAlXzyPMnEULV1BHfzT2HBkE4VExzMeAJhGXxPk LJc62QOib5ddwwByZRffPC7xcMYh80tigz+rRAJ2YehoZseQ/8V51NBCub7zPCkgMOEO W4N2VYxXdGeaaP+OZUlesUKTzQLCdVPA+oN/ucBrxIbQ+Ij/7Zu60chlSzmtz1fMv1W8 6Geg== X-Gm-Message-State: APjAAAWz3ujSzbDI1YJdS6ds1Jv2j9jyEYFx8m+7eNSsZdIqLLn0Oesa OaMsp6jBX8jdsifxjaQPmYBM3dW3epE= X-Received: by 2002:aa7:8083:: with SMTP id v3mr10156834pff.135.1557451510326; Thu, 09 May 2019 18:25:10 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:42 -0700 Message-Id: <20190510012458.22706-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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: Laurent Vivier 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 diff --git a/ui/vnc.c b/ui/vnc.c index 1871422e1d..785edf3af1 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2535,6 +2535,18 @@ void start_client_init(VncState *vs) vnc_read_when(vs, protocol_client_init, 1); } +static void authentication_failed(VncState *vs) +{ + vnc_write_u32(vs, 1); /* Reject auth */ + if (vs->minor >= 8) { + static const char err[] = "Authentication failed"; + vnc_write_u32(vs, sizeof(err)); + vnc_write(vs, err, sizeof(err)); + } + vnc_flush(vs); + vnc_client_error(vs); +} + static void make_challenge(VncState *vs) { int i; @@ -2609,14 +2621,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) return 0; reject: - vnc_write_u32(vs, 1); /* Reject auth */ - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_flush(vs); - vnc_client_error(vs); + authentication_failed(vs); qcrypto_cipher_free(cipher); return 0; } @@ -2638,13 +2643,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) * must pick the one we sent. Verify this */ if (data[0] != vs->auth) { /* Reject auth */ trace_vnc_auth_reject(vs, vs->auth, (int)data[0]); - vnc_write_u32(vs, 1); - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_client_error(vs); + authentication_failed(vs); } else { /* Accept requested auth */ trace_vnc_auth_start(vs, vs->auth); switch (vs->auth) { @@ -2673,13 +2672,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) default: /* Should not be possible, but just in case */ trace_vnc_auth_fail(vs, vs->auth, "Unhandled auth method", ""); - vnc_write_u8(vs, 1); - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_client_error(vs); + authentication_failed(vs); } } return 0; From patchwork Fri May 10 01:24: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: 163790 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1721621ilr; Thu, 9 May 2019 18:28:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPMuaywVx+f/ECJKJQQYdF5liio0mUuWfQaji5k7WFpitYMLJJl7vTGuyB7WJKYzqJoB/s X-Received: by 2002:a5d:52cc:: with SMTP id r12mr5390217wrv.163.1557451691638; Thu, 09 May 2019 18:28:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451691; cv=none; d=google.com; s=arc-20160816; b=tevjOWVK8kMUgSb2leXkgjJHGLb/MUZTJxK+Jfcc0w9bOe9elSlqN86i/eMIj5913B ZfLyjK2kT3mGVNf+SkottHH+SSthM9KqI/+bJHRrIFttoL6Y17CmQqIQnx7l+nKNM0tI qf0VVXrkm0AiK+bKa3THKr3NMmsKPYMCtoWQODY/iaRPp7z0hoeqr0KvWxQ59TM1pCHF 5lGoBrdvCLA+dZ3/M5YAMUNfNnUX+a3KA8ULaEmCbgldbr2uAVC6XdqKr3Cl0P898IRl z5yHIGCjKb5owODj5x86kZbDoIMvwwRz0sr7PteAA84OfOw6Mj/p2qv+URnkcqCYe+IX Jawg== 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=xmXHQaelSM8rDlzwsi23ffSEsHhlJ3XeS44lOJu6G0ADWoQ+jFUygNbQPl0R/h+i1Q 6ptM5Mdyb3bHJ5H10wUOoMpYk6eZWAaz4itHW6iANe03CYNValR40rPQmjMvQc9/tpPm eWmMSUkhgxXi6pU5x7vCbbKNiOqESyGx2uFUNgnNX/NcjQ29YE+Btm05T8/t3u7e/XS4 TaR070psZDrjqCGvpuxEOCZwQ22kOZXyisOM9JoGwyGeOhO7q9vYnCIKVeaB0WcRkx1n poKPFIUVty95wwCTwWW1djV/fHVqIkhLKuDsy43vzDRjWCmKoYWwt4zh4AN1Xlp+iZP3 kRuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Y+F5NpWS; 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 v7si2860174wro.295.2019.05.09.18.28.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:28:11 -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=Y+F5NpWS; 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]:35028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuKY-0000s2-J9 for patch@linaro.org; Thu, 09 May 2019 21:28:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHk-0006Iu-EY for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-00014F-61 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:16 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:44434) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHi-00011w-VV for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pg1-x542.google.com with SMTP id z16so2114604pgv.11 for ; Thu, 09 May 2019 18:25:12 -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=Y+F5NpWSy54b0g/wbhbxsHPDmCfYJqWRX6IM6C4VBvXuB4apYAabzsMZnZhbWdy8n9 jGWOJ+uKDDk0UZMadgtD940JWfNqC+Jcn/oUjAyYJif0YLFarhMza857k9KdlUBBXHNJ 3jswznxCkEdcsnVLqP2dwHHiabZ7ljI7z3D061mO9xL2Uy55VduIqOTSwEJrN2Q/guEE WGz0ih1/Or6TH98/iTGNzN0dj6Z0p/Lw9bLoOKWb4d7yBB1ghG6AMPG21ab4HlDiqwjx 2cq6Nst2HxZ7tfCNpevOAJb8ht9VOqIuJgygpwCR3ZCKWggxbH28+frtv71gYILf15jp 708w== 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=aMVmAGPedm0DyjoaQJg1cSvweQijFC9OsZXnegNK6uAyJ+zCt7JC6RFH9ir8NsLOr6 8YexdSGU2VjGj79yhuAsdzsAU7cbomcgNhqBog7Dk4lr/bsqJJsfazWQWrcAax2VDv3L PeK1Wr4xcU/6aCsl7YM+dTbbHQ1gqCwf/98CjsG3/K0hnISjnICOOA6VAiJATsau082h J0gknB2mOPUy6ZzxduZpx8Va/XCH0n9jghvOS9VEucSM7qd/h6mVMWP6Bpjk9FicNId3 VPBFadTd7fmCdl2gkb37pT6r4nBJguuzAK4M82lgzoSk93MKfzMfCjg0W6RdDT212c4B CDBA== X-Gm-Message-State: APjAAAXLbgLDn71d6od4AB07MXCMy1+YtPHG9dvVnz4gbk/MOQ4e1fxh /3eYJYMj5+L1OTR6sOP0Z1CF5XKcIh0= X-Received: by 2002:aa7:9116:: with SMTP id 22mr9828663pfh.165.1557451511450; Thu, 09 May 2019 18:25:11 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:43 -0700 Message-Id: <20190510012458.22706-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v5 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 diff --git a/ui/vnc.c b/ui/vnc.c index 785edf3af1..d83f4a6ff9 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -43,6 +43,7 @@ #include "crypto/hash.h" #include "crypto/tlscredsanon.h" #include "crypto/tlscredsx509.h" +#include "crypto/random.h" #include "qom/object_interfaces.h" #include "qemu/cutils.h" #include "io/dns-resolver.h" @@ -2547,16 +2548,6 @@ static void authentication_failed(VncState *vs) vnc_client_error(vs); } -static void make_challenge(VncState *vs) -{ - int i; - - srand(time(NULL)+getpid()+getpid()*987654+rand()); - - for (i = 0 ; i < sizeof(vs->challenge) ; i++) - vs->challenge[i] = (int) (256.0*rand()/(RAND_MAX+1.0)); -} - static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) { unsigned char response[VNC_AUTH_CHALLENGE_SIZE]; @@ -2628,7 +2619,16 @@ reject: void start_auth_vnc(VncState *vs) { - make_challenge(vs); + Error *err = NULL; + + if (qcrypto_random_bytes(vs->challenge, sizeof(vs->challenge), &err)) { + trace_vnc_auth_fail(vs, vs->auth, "cannot get random bytes", + error_get_pretty(err)); + error_free(err); + authentication_failed(vs); + return; + } + /* Send client a 'random' challenge */ vnc_write(vs, vs->challenge, sizeof(vs->challenge)); vnc_flush(vs); From patchwork Fri May 10 01:24: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: 163809 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1734905ilr; Thu, 9 May 2019 18:44:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRqIhKZ0cfdVYs+3QOBHFQP7kqyGps9Spw45X01pRvEQwZYtPVirHWZmsRhlzbO+anMhy2 X-Received: by 2002:a1c:f910:: with SMTP id x16mr4898541wmh.122.1557452683582; Thu, 09 May 2019 18:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452683; cv=none; d=google.com; s=arc-20160816; b=fYHZaGPutS7r46m/h+pBr5bc/HnKNu2vQtIGs+s5JDSauXcLy07Cw4HYN33Hw581kZ oALqSLBkx7mqJ/dPhQG0Hpuka2RBGFlemkuSPLq1p5qin2DRPVunZ8rtRxjzhEPsn4sN q5d+VNjBSKsK7d9gtME0Xf7oBBsAaOZ0nBPmTouG6y4t3F/+uYY0oDLYn9zht0wLlBLp fc6/Up1T+4Mm6MAAaTBhVBjF5QLVFYK+mkPmMEPXb+qXvmTiQ24XJbrB2EfDgkgtyARc hytbxb16sS7w/XASd44fhh0nBBNUOsY2L2p/bghcd2pEzOYKtKee2mu7+ShfGGhvmMqu UfUg== 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=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=VfCejlq+ZJjM/e3PWup4D6IYkQQnrVg8+FC1NQR8K0NnIcluoT+Yn0mJcN5mSE1m3V 9KNR8p2SfR/JIsaZU8791s1oMbKw08yPRg+6Tqz9aBJa+qk79vYeKnz8kJ+XOUEMkezI wePol7BiP87O5SW3dxcOKqGg3x0xmDofp6c9E0e57hnsYdsSDBg1zcErSn83MtAoghfv rqVSEDZ3lqv0tap0k/EfV/QV+nThJ8RyB3r+/BpVmH/r750ALPqjO+6xuqR0IYJw9B3F fI9yl7ENZNqgO2FBUVE5ggsxrRsvoxNHjZ0/b787iZVwdbNHfhQr04XMbJEfpYaFK54O M6oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Dh1bR6En; 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 b131si1009311wme.151.2019.05.09.18.44.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:44:43 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Dh1bR6En; 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]:35256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuaY-0006A1-F3 for patch@linaro.org; Thu, 09 May 2019 21:44:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHl-0006JK-99 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-00014a-ED for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:17 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:35532) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHj-000131-4q for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pg1-x542.google.com with SMTP id h1so2133989pgs.2 for ; Thu, 09 May 2019 18:25:13 -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=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=Dh1bR6EnDAHMFYiDyXSI+QMvVpvs98e1/TEjvyTfRMq/Vcrj4MtghlV9Hp+HkCSlTb +rJ1oazYGkqCVfAvu0huABd9HAIsBRgF1acGJhG+U3xTasor7bT96Y+zV4hP72dXd1m9 q7fJrRnygqMBpdHCzPnnhtjl6NnfcBys2sAwJg+LZ1DTZEWDerDxxR1T58ajmI4n+7Do y316UcO8CnjrRFH5RRjd8MLX7jroDHPyiDyDgYZw6qp7tCGlReh2KqxgAZUzjkmoUjAt klod5utO6HESZN8ieaAJEZ6cMk3hHJaM50LXpCuRKDyEFDt+RjvfIPZ3xpZyD8ohRMLw HiXg== 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=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=t54PA7N6kJg8nss7rG3qhevJwQ85o7dNbOlQ4CSBkrSFw42uFqit4D83WKB5wYW6WY 7Wl1CvVIu9sZqkGux9hgijr/ghZ14fO6Z1Pvzy6I7s1BTfojp7OdYHWl074DtCxllvEo jeMV+fNJjOeep8EukVm3c8cZuHMraZvc8Kno71RK0EixaaI5+NP9TJ/J3eM4Qhn+RNj9 4SxF0pvPkSmXqvx/a3zlM8nV7Xru8mNYAG/IoyN494v/B9TiSBQD1FaGE7seiXPph2/P XQ6XMSNJDGYiZYRB4p8+htLYXIPIttGR2wGbfkU4b+ZrDtIhf4c66hOS2zIS0qzdFdgY It3Q== X-Gm-Message-State: APjAAAXgEc5jisZTNRBLVWAk4FpaoA9fNhj/CVN2b3twOGCXFxOzIDo9 /PQd6JVyfUkMCTQ2oBLil6zGY+BXN7w= X-Received: by 2002:a63:8dc9:: with SMTP id z192mr9840616pgd.6.1557451512612; Thu, 09 May 2019 18:25:12 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:44 -0700 Message-Id: <20190510012458.22706-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v5 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: Laurent Vivier 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 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 Fri May 10 01:24: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: 163801 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1729112ilr; Thu, 9 May 2019 18:37:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjgHohpCGYE0BakEL4DOz+FPEPsdN5PEYtxJ51hrsCw6p8C+7ZYf773QnjDintnzfUBgGC X-Received: by 2002:adf:dc8a:: with SMTP id r10mr5466221wrj.15.1557452234179; Thu, 09 May 2019 18:37:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452234; cv=none; d=google.com; s=arc-20160816; b=xD9BR9o6lX/OLsvhI3jMt6nanP5iheFid/BTPZzFS+lQj/gVGInt8tNjaZWhOi0VQd 0cda1c17G9GqE31/rirM1s4scB1fYEGco9U8Qa+ip5JV/uk3vxhabSaiWSYheli9wyfC aghZpuAVq9PbN5138E4ui7ZpeUhc8TIa8hbMKAnXffvn1tF00eBEr4XbJmn3bpOFPVM9 xOiJpxQj0fNuMpOKNjL2dUjTS5SUw0adFaFqKhBfUjw/bTt+qP9QINHPqhDF/Ucg1Avd HblcrVsLRyt+5/rsTlJ7UOuOF1Hni7+SRCMwX48pxiYIo6OjT3LtU2dJVQ1ZfWaiHLCc HX3Q== 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=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=bkE8afCSKjfPsR7fgbmdbQ4E9wg03Ngr6ljSuu1sRofGBkxKswUU4UBVt7CmDN0r3u HSTrDOCUhGdImQXZ8wO7Xba36OH/fAj1DfsqrfHc92fbldgxIvT71Kl2xd0cIGT2Ikk+ Dv4kv5OS2P3ZH5/yIv8ZeTqPvZBdbU5fN8tvx3b3z5aocrnFrGZzDOESvhNncjQjZmNc Hlv/Ivz9oYxxiaX4mMx42AK4U1F1cgBKBHujPpWTmo39atUimDAI9t/G1e+oQsh2I7CO Db6iKaDA83PcHZpOgRr7j1JSMYsBVyhBIlSdcAjR/1we3Lu9M7XbHEAc6KjWaGC2xBhI CiPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=j8P2tzpn; 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 k12si3144846wrv.21.2019.05.09.18.37.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:37:14 -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=j8P2tzpn; 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]:35160 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuTJ-0000oo-37 for patch@linaro.org; Thu, 09 May 2019 21:37:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHl-0006Jl-SM for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-000156-K3 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:17 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:40273) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHj-00013f-9s for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pg1-x544.google.com with SMTP id d31so2125001pgl.7 for ; Thu, 09 May 2019 18:25:14 -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=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=j8P2tzpnte+SI9rVHVDw0BwJyYRgOSyAnzi3bejGi6puCKW8FtfkBUDN4sga2EKyI1 517pnckY6YQrLv6XnEBN7W/FLlYNwqxnyflyS03CvsB+/s9bLvF325v50n2mWb7WY6nq js9l8p0jBfH1snbf0fRYW470bUJwUVhYZCiIlUag67QHlH93ZHE12WtFKAJqvYqBNr2X 7h3TynJB1XhzmvnfqRGysbSOdBwvvYwOSs8kTxw4dLecTY6Rz6noiVSPxJdK9ygW7Avx kPVSuWWXaNvNXzK16YfZFtVZVxPYaBwHsuti6fla2EWIJo6y0a6oXk+ZFOsTTR6DxOro NFJA== 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=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=eCHvkmc2nQKiKmkoJbXgLZ7avH/HOyjMYATFyC5F1ag13noahDf1G1CpeHwnBFqKUZ HF4pAVLy/cB3NgmYRVT0eeRh8FzfjTSC0zg0cRyPyP2S+hREsnwDcw1xopOxxlKhlGkk oJ3guigN5LF4lR7KkUgGaQXgXEiNmXxKSQLaaRds9jZyuaUcXAJA18T6iA0LFp+H3wQV TpsTW8w2/VXkenGJqhOVUl8XMGrhoI9i+AMQM9kKbwxovzUONlKjEbCsqU6mV+0Jg3l/ km2/5o2RSyS6oGKTaitEg94aItxZKfbn01HSTHIXTUGvuukyQLBbv/netocy2LSZhcBO 2BFQ== X-Gm-Message-State: APjAAAUmbPrhegO8D/ssaKrHuipFAIGadyQy3bkV5M4JRaeZ3N10VCAK CQZzp6uroH2fKIOYjAb+C28+n3MKi+M= X-Received: by 2002:a62:594b:: with SMTP id n72mr9866146pfb.186.1557451513774; Thu, 09 May 2019 18:25:13 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:45 -0700 Message-Id: <20190510012458.22706-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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: Laurent Vivier 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 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 b6709514c1..e1d75a047f 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 @@ -3347,6 +3348,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 Fri May 10 01:24: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: 163797 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1724618ilr; Thu, 9 May 2019 18:31:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNRCKjx62bjtyCUQfKuHAM4dcRLWGRFZvZnwzdEumKVDBcoNBIJy6d7Meg/jGGTqO7hv03 X-Received: by 2002:adf:f788:: with SMTP id q8mr5461672wrp.181.1557451895648; Thu, 09 May 2019 18:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451895; cv=none; d=google.com; s=arc-20160816; b=n0UkQWv4Z4t40mhUFih2k+MoFTz1FO8MfgDk2qirrUvZYKR+0zF4PUO6214/Tqco1r Sqm2cZoaLEzhWEFyI4w9Uwr3ncmtyrq5azw8PQElnMkrcHR07rF1XaIBTq7a86k+BSaT JxgOf3YkaoI3NO/FJOKFX/H2ckN3RzBeYE6dOSUcUz0NTiPtjegtEyfIvH9Tgg2QLDQm rlXYSI4ugm6LIl7qWPfsJ+az65/OWtzApN8xm1zUuCE4A8Yh0z6OWVhbOgWMbs7jqL4B 0TJoV9TGEOLa4j6GplJmuAdcrAnPD9HzHFrNOJepSATPxtxEYFporpZU+wi3evR4/RDZ 6J3Q== 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=I3gtAlIWwDdw8etvrF0cUhXO78/4AJyRaaREgjfC74k=; b=WUecqDQR8snKO/VRoREE/INZxTizCoVdH1MnjHiCjRghENye5Mdr76oyJEvYs03iEz /YZdWN7lNcGDg9Nj05rLu4eg0bC6GBEa47WfAAxfLfYXDJPxSvd2RH5zkTk6PV/0sQY9 aFC7WTJrPlyMB/8JvYn0YdbquVvFViDR5+2AnqikBGhGTe2HXzMXhG5K8Y3r+lgt0EJv 6B2zmK4LgB99UMk2f7hK+Fktje1/xYovEuVKRPWv0d9Bbx7GQLdyA6MvYq/O/na81K2K V5p2tj94Kcgb8WTfM/BTsAg29kmiwtayZ6et12co3TS40giVWgcqZzrWxQkerFw9JEr/ b/vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=lWSrTqIG; 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 x4si3154854wrd.107.2019.05.09.18.31.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:31:35 -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=lWSrTqIG; 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]:35088 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuNq-0003Wy-FT for patch@linaro.org; Thu, 09 May 2019 21:31:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHm-0006Jt-81 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHk-00016y-JH for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:18 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:36158) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHk-00015O-B6 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:16 -0400 Received: by mail-pl1-x642.google.com with SMTP id d21so2000876plr.3 for ; Thu, 09 May 2019 18:25: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=I3gtAlIWwDdw8etvrF0cUhXO78/4AJyRaaREgjfC74k=; b=lWSrTqIGyEpoxCi5qCJh3C98tzIqCjZHmhq/gwqJWOcc4vawGnvQI+fLvSNkizm8PN 1CnRNl37I5h2vyYkwxLPa4/Lo37E5AZyGQnQWKynsP6n57pO5F6+TVC9l1PM0WMHNlpK Xsccb/mWv1Xw9PvfI64hLDP7oeiVomDRyOryMbjeIKFcIAhT2uXYF+x6tNSxq7Qmlzem SwlGUgHW0Jx4XgbVtqKmhK9XNF8hxgsVzZZqRBg5Ovpj7p3eCh0LHkUQtGXROUcGafw0 4iggZlf4uRgWJAnP1P3mkZ9PT0UFQPC9IJdX9tMbEdU3rKEv1o7qVzEzeM9/UECI4AXR B18A== 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=I3gtAlIWwDdw8etvrF0cUhXO78/4AJyRaaREgjfC74k=; b=aRVRHi763scAL3ZfglgsyeCYhbhzjrc3hyscA2b/Gi4XncCcGlfw0ncNR5866S939p 2xwgu4+DgP7+g2jUykDCdJZJb9V2rR0VJXTDgW3NhDhxVWwNsjRu48c7xec80Z7CcE4F kzq4n85hDCf2MFThDV4ntZ13wEEqeFn89fEPY0ILCSPOS1MEZh+y2FWelJGUcWHF1KvJ qd5uNq/0VZZEBExsJtPp01Pf9cQxcud5c0h+3GHBjM4a4ZDqsZ3a0Sg7i7RmUBL22EQr 2EzkCDV4fU1THs9u30zuzfAK/80AJeHHlH492XoXAkNMccBMwXqHTNQIeepnUkIq7coK yuVQ== X-Gm-Message-State: APjAAAVwhy1xxv//xwvzjs6Rl4K7wOra5d80kThHXfvjzr1+sHzsLL/4 cnUytTLKHM7dN2A3b9Fe/t7Mvt50obg= X-Received: by 2002:a17:902:868b:: with SMTP id g11mr9342202plo.273.1557451514950; Thu, 09 May 2019 18:25:14 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:46 -0700 Message-Id: <20190510012458.22706-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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 --- v5: Retain srand() until last user goes away. --- linux-user/main.c | 30 +++++++++++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 22 insertions(+), 11 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/linux-user/main.c b/linux-user/main.c index 3d2230320b..7e704845c0 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,20 @@ 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) { + unsigned long long seed; + + /* This will go away with the last user of rand(). */ + if (parse_uint_full(seed_optarg, &seed, 0) != 0) { + fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); + exit(EXIT_FAILURE); + } + srand(seed); + + 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 Fri May 10 01:24:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163796 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1724580ilr; Thu, 9 May 2019 18:31:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFYpZJXrvX+c0OKcvnW7nyoXVZLTEMbF1Vh2RQcOqAP1Wmf07VZJMpe5KFSH7+qCl+Az8e X-Received: by 2002:a5d:534b:: with SMTP id t11mr1306953wrv.297.1557451893189; Thu, 09 May 2019 18:31:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451893; cv=none; d=google.com; s=arc-20160816; b=TMoOIUbmosJAFtEXwMM556Owdw+/tPURwuM0Ja9BNoVoixaLg6PlGjpl+lLeAL4Nvv 93Psw6qBZUUSeQQfVTkfy4Nt5+2jHe9aEHVQdObnBfy2sGr3a14GPL9k0REEGwOQEJ0i 5l1OZy5mM3qH6MpC/8Y6uu+jTs2L+E3J77VDSm8ASVvrf+UISrTDC2/DuOjF31wq/PwY /aG25kPOUdbpZ+lMSgCdz2NcyVFk45xF72RL3NP4ll2/m+3CX7Vn+B3zVCNrQC5O4svv fKJ6ElkCkVPfohc5919OZVBcfmR3R27IrkkvQzqz4MVVk9GNUbNcybjNYyqF5C0XamT0 ravQ== 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=tONOpjcj0FxXSSZHZXrkhjP/KybbzntorN3yULUFX+s=; b=Ri3UXyrFlIHHEdUwWm+Nr24NKgOAGuXfKMwQNW8Cl/ad5xj0qZq6DLKQer34epfTN7 vtly5Md0+vK7JMtb7VHuwWfrm0efj7v2KDtIC5BwHCIEBprZhMhSrici7IWCFVTC071T oUz9e7dlrylE3rw8Yjx0AosbIuYkFmf8hUevG7OQzP/XsCQeSRMdZp9KbsKRx6io0LAk K1onH/1QRO6pO66ZAVJY55lo1wD54hHfTCJm5QK4JcPCGTTic7ivkf0Hj6ZA+N9K3LHH xBF/I/vOb6HF+2n7jyk9ljLJIGew7ZjKrwXRrG7HMgYnY75Ps+1fVqTf/MMN+kVRxwHS tUGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Hn0kJtcI; 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 h2si2610645wmc.12.2019.05.09.18.31.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:31: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=Hn0kJtcI; 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]:35086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuNo-0003VZ-4K for patch@linaro.org; Thu, 09 May 2019 21:31:32 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHm-0006Jw-M2 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHl-0001AH-JG for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:18 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:46793) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHl-00017d-AA for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:17 -0400 Received: by mail-pg1-x542.google.com with SMTP id t187so2111125pgb.13 for ; Thu, 09 May 2019 18:25: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=tONOpjcj0FxXSSZHZXrkhjP/KybbzntorN3yULUFX+s=; b=Hn0kJtcIGSs8sY/Top0YETZFmIkr6AZJr+Zvn08N4c6b5XAl4b4BnZZfYg5XNg8dvF gKMWFE+0Gq/JvtQMhoqehkIs5hzmdPKk0ri28OhD7aAz+1PFj558c/COZwSCz3ZiLRCi yllE1d0a7prfOdDO3sdIF97vHAv82Is8K4Mf3G5ciDV7pt6HtMY78jotQ/lHrD5xmgOO Mx4QDoXPSC/cSGdgHsERuJyhuwx8OkeQOjQ24ikgu6VwFLb7jGhXUcoIsxe1wBAV7x/D 5f3ogj3Gr3SfEb/6TclFLRuqgz1FYXgYmWeMeomc5gVOFA09WiW/+I9KBoscYIOA41uL iriA== 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=tONOpjcj0FxXSSZHZXrkhjP/KybbzntorN3yULUFX+s=; b=FNBuqsCzC2/vY0gyq2MlgXiYlcXwcV9fSNmc5SanoUPNff2eLWcrgH3WGlakA10PMD Oqp98E1SwILPDOlvXp5GjWr0nHmFsymcJVPjADhYDm9/QVkKU8b1dvSilM6k+0miiqC6 TrDEfDBtxmreuVZTRDiXq9E9yLirBM1l5VCIV5fw8elvwdCQhCPMhncO6B8TeAWApCTP Foigmm3f6+qBzzSlBX9Vlye0bZITniJ7Fv0REX2/59ZQlpmdCVpLLq1Lmnn2yipuT67E /DMS5vF2XKsmg8nvbaEITqzn0PJty0ALlPcHZfDaP6jHorDO3ZPx1LDEmFz6f7d3+lm2 uHeg== X-Gm-Message-State: APjAAAU4Jc+7C8p+/DvVstpuhTjD9+kS3I7xdjgIr0wo2kbJERCQ0px3 f7Wayw6zZe3Z8ATKSIysftG5eplQfUs= X-Received: by 2002:a62:6497:: with SMTP id y145mr9981088pfb.255.1557451516085; Thu, 09 May 2019 18:25:16 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:47 -0700 Message-Id: <20190510012458.22706-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v5 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 | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/linux-user/main.c b/linux-user/main.c index 7e704845c0..e455bff1b7 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,17 +689,27 @@ int main(int argc, char **argv, char **envp) if (seed_optarg == NULL) { seed_optarg = getenv("QEMU_RAND_SEED"); } - if (seed_optarg != NULL) { - unsigned long long seed; + { + Error *err = NULL; + if (seed_optarg != NULL) { + unsigned long long seed; - /* This will go away with the last user of rand(). */ - if (parse_uint_full(seed_optarg, &seed, 0) != 0) { - fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); - exit(EXIT_FAILURE); + /* This will go away with the last user of rand(). */ + if (parse_uint_full(seed_optarg, &seed, 0) != 0) { + fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); + exit(EXIT_FAILURE); + } + srand(seed); + + 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); } - srand(seed); - - qemu_guest_random_seed_main(seed_optarg, &error_fatal); } target_environ = envlist_to_environ(envlist, NULL); From patchwork Fri May 10 01:24: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: 163799 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1726653ilr; Thu, 9 May 2019 18:34:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/sWyjMQ4klOFF83YfVLPlx02vOB2G1MjtNYSLr29W+53gbUDPCw991yo7Flg3MyJ4jFj/ X-Received: by 2002:adf:fb4a:: with SMTP id c10mr5273284wrs.309.1557452045361; Thu, 09 May 2019 18:34:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452045; cv=none; d=google.com; s=arc-20160816; b=LLsVanQCIKqCRICXE2zsfdUMyrvNXHbUuI/wZ4es92TgW9ho+Hf3nUWphbvalJIeR/ 9uxjjRrhi6DnkHLmO1ibUSNMH0iSZA3ESI55o9wvMrZF41KeGg6/WyYM1gyyVQwgI7mq hPHLWF+JjIv3n7vN5SmxwrB7hcY9D3ZRF72a0jnLwKTrp3eCU6r1ApCd3bjcJUwH2Dzz 1FxUjAt+77T8m27XFz3nwZxhwrzVHeLAvKn9IJqr+pREpWCgiZaFuZIptARkg3ERofiZ rqsRc2akqU1XGhu6VAiqXolNEmY5X4G7eNNOBWhrT3tuPlOlIdnxee0o9uFwW+z129ch yoYQ== 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=Rw5R34uV/AA62KXp+YUGZEBrbetteys0TOZc4Uvv8RM=; b=A93kMaxqtDnTC/YaH3Jt56+PbZ3zGO5KfhMUtj/2uXv4OZROgxsHUmFemcyb3Onh0C mcBQgJyntK7bvd6ixouzMxSaOKj2U4AzC5C0m0ocOyhV06aHL6XtbGkdGDpTs6IboEbV LqsiyVLJ7KnaQjicYOMb74LH9y3O/UkB99Byz7pdzZ0jAmSao8Z3Vne3I72QGeH/+W2Q CnHobJZR/sTIG0lsbTbBkNxay8/3IqZbFs/UIc9chP+HTFhIIrT12nQCJnVtlY6u5P40 mWX+we4wVJmWus2DmQPaencGXSZckhlJ0eDgSgwC27OqNkck4RpvucLAnXueq/WNKqsR wqrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aB2fPoOW; 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 f3si2657134wme.155.2019.05.09.18.34.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:34: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=aB2fPoOW; 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]:35102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuQG-0006Br-91 for patch@linaro.org; Thu, 09 May 2019 21:34:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHn-0006Jy-Ro for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHm-0001D8-Sx for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:19 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:43033) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHm-0001B5-MD for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:18 -0400 Received: by mail-pg1-x544.google.com with SMTP id t22so2116689pgi.10 for ; Thu, 09 May 2019 18:25:18 -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=Rw5R34uV/AA62KXp+YUGZEBrbetteys0TOZc4Uvv8RM=; b=aB2fPoOWuQCw5NIc5+gb078QFH6muv4uHr2aYtDjwlaZsJIRmcfCOBCCm8ftdQNCMK 7CPbCGUK200HhSjdkNMtg5Cj3nN+5fKAInsKpNXiWqsUD3Fp8DS6YzQlcnZ/WzeMRnHF 6LHPBaPbCBawvZWV62E0HO+C+METlFtxLegUmrrFboVAyY+H5tUd9JVhNQyzzZaaXkDQ Xq0dWc9lPVfDhx34Ai9YGpHNWbRUJwseEkV2JseS7zj1m/Kuk47rOADXWQSOdm2wJjHS yFKBEA6YDBOhgfShvmvk1I7ABQXEkPcbfz/0L9ozLmsbaBk+gNQsOk+NI5ElSkXUABBr 3kJA== 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=Rw5R34uV/AA62KXp+YUGZEBrbetteys0TOZc4Uvv8RM=; b=qX7lUplvLpmtTWQC53bYxpSt9f5bETMGNM2+vYAe0cX4KS/9IHAhJcMtCzqUAU1PE3 ou2uHaCmWjrMTFvZO0vpKCw8fAePd2FJyxVLoavbCpGIwEtTLNzhXYCsNJFXXYk3AvGH 0myV1dRjB5gyqefE1jx6AfORh/dllgOvnSRb1PKQSpIqYhJC2xXDSy938LNQlxottfu9 sKZNoqQlrpxcYwAep6cL5u8QPKkn5bs0U6jml88JKc0GI427sBaqlVNNBgN5WPBMoIo3 lZRikg4HwXR8EHsGtWU3NbZ/slFbLIz/JeTQ7ceyOte0o+EIc23r1wA5hPaR6zphpV5s LNQA== X-Gm-Message-State: APjAAAV3LHrwZ+hgS0OKrK2QasfCFE0/qiehPNWCfe9TpYan4VpSFYO0 McPJueiDHpA9F2ikApqmAPyp6fNuMts= X-Received: by 2002:a62:b40a:: with SMTP id h10mr2261748pfn.216.1557451517305; Thu, 09 May 2019 18:25:17 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:48 -0700 Message-Id: <20190510012458.22706-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand * 16. Reviewed-by: 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 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c1a26021f8..e673f7ea55 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -7,6 +7,7 @@ #include "qemu.h" #include "disas/disas.h" #include "qemu/path.h" +#include "qemu/guest-random.h" #ifdef _ARCH_PPC64 #undef ARCH_DLINFO @@ -1883,12 +1884,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } /* - * Generate 16 random bytes for userspace PRNG seeding (not - * cryptically secure but it's not the aim of QEMU). + * Generate 16 random bytes for userspace PRNG seeding. */ - for (i = 0; i < 16; i++) { - k_rand_bytes[i] = rand(); - } + qemu_guest_getrandom_nofail(k_rand_bytes, sizeof(k_rand_bytes)); if (STACK_GROWS_DOWN) { sp -= 16; u_rand_bytes = sp; From patchwork Fri May 10 01:24: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: 163802 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1729236ilr; Thu, 9 May 2019 18:37:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJ/VT2dr57yNPV8lZ3GhXU9hA/TPpZKgMtmNIF+Q8+fzuBhq8dgv34RPd2IijYYXf4fiYt X-Received: by 2002:a05:600c:2291:: with SMTP id 17mr4822902wmf.132.1557452241536; Thu, 09 May 2019 18:37:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452241; cv=none; d=google.com; s=arc-20160816; b=S1eMpgplpmcV47r7VJdApd27HKe3uAmAv0VqmAkrYd9dTLeay8VXuFnhSPRsugN2Jz FzPgh/vNYEmNPyBzgrsCs3NqPu0CF2c8QpwlvYLXpjRd0nNf6mbbseQSTV1f3yJq8mB9 c1H/LrC3BHiHhR77OsdoyVtU/ktiQWR9cJqnSOgGTcCfqSkP24JXEkvMW7FtdncxEvVY 7ll8HjSA8OKcc8DVkV72HMH+s30v0w3mLsDOiytZxrj6/daaZ1tKkJyXHTzfdZGRqo32 TVQ2ZogKGgRiwgtPfX92NyNZ/7RgDLkpfcx+hzszPbpvB8JR6DRkvYodAGEQ/116JonF 3KmQ== 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=M7wM7CMb9yJ0rZAORuKMiexMi3ObpDV7xIyaPPwNN9U=; b=RbOwXUkgBLD1QDH81CtNaHdz8Rw/fohtrpH9EqUP10v04X9FvbFHsDOdXoM54vBYmC 2l882oLlxj/G+J5Tfd6GFH/g6cZsUSRlbfppxyVbmdw1e45venHk84vjKwivMja5NXpY 9Eu6Zj1ncC7vevmtTkj3BCN8rOmU7gA/pC1uB8xGFUfB08mEaW7Y6l1bYu8tB4/AKjGw 09w5RuMMQn+fHoplRL68PGy6t51zO5o54Qz8ce8Qf9ucp4yRjVBifr5ZkupFxz/pfoNo /uwAsybdDfyQSsSdF+Kt0XL2Q2MowbsKOcd4n9nrd3eDIhKSDjaTxkcvSoNcnL9hamUo 31Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uR++jkEe; 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 u21si2683455wmj.78.2019.05.09.18.37.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:37:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uR++jkEe; 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]:35164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuTQ-0000t4-9z for patch@linaro.org; Thu, 09 May 2019 21:37:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHp-0006Km-Qv for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHo-0001EX-Gq for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:41822) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHo-0001Dq-AM for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:20 -0400 Received: by mail-pg1-x535.google.com with SMTP id z3so2120709pgp.8 for ; Thu, 09 May 2019 18:25:20 -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=M7wM7CMb9yJ0rZAORuKMiexMi3ObpDV7xIyaPPwNN9U=; b=uR++jkEe52arp+C1asTUaDSfQI1mZY9lzkgsjR/NRp4rAbEwp2FoHDYaAFDzpUEx1K r6782ax9N3FgA88onqfRR9QTvcZNXK9xV85qBIX+fPZlNz/cdrcU8nk8CJcb1pNUdw+y 1sUjCk4Jl4VB9gCnUpsuEs8fuZwsrGJSeWFXzFoYevz02iH+HeYPXkDpl+HbP4Fl2Z1I 78wsUmwvxxdyMxk7sUP3+oQ6X2sDto6gZiQ6KKEPelBIhQMojrw5vxdTRZqVj5V3v7uY 1+YI8B9RSdXNCgOX44CtUjN2uDpyuBTETHXMicPrqdRFyIG1MxeBQvHLJ9hrSpam9wY6 ATRg== 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=M7wM7CMb9yJ0rZAORuKMiexMi3ObpDV7xIyaPPwNN9U=; b=RtyvdgUrfCdy5l/IDx1va8n6/Dn8HkjSO50GuXtcLLFL3dyhvrePWHnTDH54d6Cgst 5Ws28Baxo6qtU2+Dtj3SZXtSaJAkYaYmWYxzzDQs4MaAtViA8ZfVEk31RnQ/knYv/pln kJYV/Z888j4VyM1gjzmaPOoaHXCxDcsr3SoVBuYcZKzPaxphxPQCpUTRPqO/ehTuuKfX RV10nA4JKEU17cg6H2Z1/qBllHYkIlRdEd8jcjHjGoXJKUd+S491/UCPqDfNgPhzkwgL vaHNYTV+XaUEaqg2o2HTyAAfwK9Cvjivql5LQncuxvp4QiEFjdP0cuthDgvjBUXgzIdZ A8Kw== X-Gm-Message-State: APjAAAUSjfru1SbKIkyw6dDQGxfBU00hvfvd37fMibdlde6ADP6yQL0l QSIULsFxq3sDBjqGS50RJ2IDx9TRzrA= X-Received: by 2002:a62:56d9:: with SMTP id h86mr10198597pfj.195.1557451518812; Thu, 09 May 2019 18:25:18 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:49 -0700 Message-Id: <20190510012458.22706-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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::535 Subject: [Qemu-devel] [PATCH v5 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand() * 3. Reviewed-by: 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 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 Fri May 10 01:24: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: 163804 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1730236ilr; Thu, 9 May 2019 18:38:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrlL8p1O+UOihZs3KUK/UCHLUnUZWnYZC6qHU3ZWQrITUZ8/HdYDuCTnzN66kciwlBNgMB X-Received: by 2002:a5d:6912:: with SMTP id t18mr5655516wru.17.1557452324717; Thu, 09 May 2019 18:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452324; cv=none; d=google.com; s=arc-20160816; b=WZ6TaYyfzz3OsfM7eK6sNaPQv0dMzHMlJfsyifnymMh1td3Fc+K9C13rizWQUS5Zqu LnhMBuRuNQ2xRIpeCdPwOL0ylZqAAizFv2n00CB1aD0GNLqv67qhYEdkgJAc4Keu9NiD kjQlmmp+CkHNLdJrOgk/Hp5wWWTuj062ymZYstoUn5R4igJZHYDx42GFa5j+E+Si5OCZ OgZKcaEkS0OfteokTObTp3+B5Gkbz74XTsnzr7zn/kNHA2FNkHDykbrP37fH8LZda2BY a9in70sxtGwdCpQTCM09sDxuqaEQ3k1MIegTO2y8amWQySSl6p7qSNkSEPLbFP4EOjUO iHpA== 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=m8x2+ISq8VDA34RGun8yoxuib+WCd51kzqEMsPfii4Q=; b=NQpotJa3nlGjuAFBemzdIP3mXAusOuBneoU7rl6mSeGNpKzlUhmFRHk+h+mrJluLd0 RhL+I8KcTjkwWT+IhQnb0X7qnO0NiB5fO/ghvG4ZbSSZVuB0CsjDqU4Sf22j6OX94uK3 p6X0tQxpyLq+U/UCnDP+abKhfPrbBHlRZVU34c3doW32e+1iZjHno2upkS4K04FuFxZD WgOzED1IXXShsggVL40AGsPfBgmfyN4un3vPBI1DXi86KNkGiAqJ70yhK+37j/IfXQFU x4EMoUyjt4850tD0bElFyh2qE5IDRt9I39H86v+aq3jm75308RLkuYcNXkHVdnR4NIWQ 4Zpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QTSz4jph; 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 u7si3126899wri.426.2019.05.09.18.38.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:38:44 -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=QTSz4jph; 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]:35176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuUl-0001cn-KQ for patch@linaro.org; Thu, 09 May 2019 21:38:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHq-0006LA-FJ for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHp-0001G1-HM for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:22 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:44626) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHp-0001En-BN for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: by mail-pf1-x42b.google.com with SMTP id g9so2244589pfo.11 for ; Thu, 09 May 2019 18:25:21 -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=m8x2+ISq8VDA34RGun8yoxuib+WCd51kzqEMsPfii4Q=; b=QTSz4jph9S4OEHX0O5EabZ5iXAOs0H+CP+JG+4vlE6qvDaDaYukMygwb5yWkxD3Sax FJi9MaYsQV9JwwOvNWLtSPayMkZVVhwNTf8khaebgPdJlsVX5F0L8r9ofTib/ppupl1D DKZDdVwqi/zGHdZ3TWpmhoZ3BiWNeMFQPHjAw4iGbDrrXHWzdBBF2Aca0xQtmnwJN5ry HNwqYQpqqnH6OV8jGEJCHE4m2Mg6xUf679MlFzlkyZAn6/r+6tog+oQpY4OZOHRiP36J NcfUAB5jMyfs/6ct014j2Ac9u8hCIhhSlUfX6wVSvIhlbX5SzBp3TPm1eMa72pH+DCT6 BmPw== 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=m8x2+ISq8VDA34RGun8yoxuib+WCd51kzqEMsPfii4Q=; b=iHY4DwWiMfuE2a0hPnHmhUQ1l7IuWmh++/jFW3QaIaPqQR00Q04i2rIu2X0pBNnUyf qnCYXSHNMXM+vjNlSjYhdumzI/ohTL+BlSvtvtjACbRhPTxW6wHtYi4lvsAYWZDLZZQv eo1OQ9Xbw9w6V1/x1f6jpkQTNI26bt/omfdW/Dgbusupi5sechxQu28tGxbGYpR1gYSh 8/lE0TrlaYMJg6hT27u+CGDCvaLWXdSOpLKLLOmJ3jcbAdrYtybzhuC2PlirgPEiFbKN 3YmWOEe11/jFanrj/u1/VzKELos6rdZ3ASnHide+8NF3WJSd7Xggb+gQ1CYbzKiRo2WP UwSQ== X-Gm-Message-State: APjAAAWiTJoEgkgjY6Ds/gMOJhpvuS8UO/9fIWPwnXRkegK8HzpdApLw oglJLd5M6BjvsDYE6duAR4khsXD/kb8= X-Received: by 2002:a62:579b:: with SMTP id i27mr10077584pfj.205.1557451519977; Thu, 09 May 2019 18:25:19 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:50 -0700 Message-Id: <20190510012458.22706-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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::42b Subject: [Qemu-devel] [PATCH v5 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 | 11 ----------- 1 file changed, 11 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/linux-user/main.c b/linux-user/main.c index e455bff1b7..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); @@ -692,15 +690,6 @@ int main(int argc, char **argv, char **envp) { Error *err = NULL; if (seed_optarg != NULL) { - unsigned long long seed; - - /* This will go away with the last user of rand(). */ - if (parse_uint_full(seed_optarg, &seed, 0) != 0) { - fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); - exit(EXIT_FAILURE); - } - srand(seed); - qemu_guest_random_seed_main(seed_optarg, &err); } else { /* ??? Assumes qcrypto is only used by qemu_guest_getrandom. */ From patchwork Fri May 10 01:24:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163810 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1735072ilr; Thu, 9 May 2019 18:44:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPPiBfvRE7teUOOfpEWenAR6oNnCrJCQJUjfFCFVxOTZcsYFAmkl9dLPVja/5PqMiBXchd X-Received: by 2002:adf:ea86:: with SMTP id s6mr404555wrm.44.1557452694160; Thu, 09 May 2019 18:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452694; cv=none; d=google.com; s=arc-20160816; b=bAXGw/UJJwlS7Y+2t+pzq6N/RNo4IKOa/B8QE7oJCL4qMVcA2nxewPC9jFoKJXHh7b BGMGpiEiO6yTzLFNhLHGp0uJfi5OW/u3Brj7NM7IBB2AyecyOveNYWNJTEy0anT/Fn2a 5YIuZBMqTuyKtv3VHb+JFLcWENkczOL3XUVnCXeoCvYiBAFPD07LISt0iTXj60SE7lOk 3ZA7QJWaUwn44bAMQxKNa/LTpYsudPgbNakJCalEXf0qP2YEmToQI7u0hokrC56QOiuW VL44jmO4Ia6QAQsjmU8qXnJjm6+ssBQ/NN2LdBB/K5csOqK6jDRwuKWcc4beDxWZNL5S ktxQ== 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=NqFQGLUWEK2q+OruuYLxByccY86fvPfXVx23TDmISjI=; b=GQ3wdmR32ReRxIQxbWu9tizkISd/UYBxMaOoKx/T7v7wr2yW+c7UnNF/xRRzCDJtCW awnWRFt5LY2GpV1lzlx8oMNuXwVTZejnrLFvv3fK9ZIDx1RVDyX0zbSrnLiBjG9F9tL0 YFhNkqh6Utjyovv6PLNCa6VpB1Grodj0umx+4H0lli2m4MA9hpaaBzen568vQ8fWp9JP XW6SlpZ46T65kKIE7dD0xCy8JVnjn/BeGh1syYrvKEjnO7HXlnCONXQPUBF7lHnmuLaQ /iQWUDdLdSk7Zqm84dlaFJXmGUIwiWFUGMjIEJok2aA0n1Q2tjTpxf7xcubzaGee1O/l r47A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PmKaoaZe; 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 u124si2647319wmb.23.2019.05.09.18.44.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:44:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PmKaoaZe; 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]:35258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuaj-0006BB-6s for patch@linaro.org; Thu, 09 May 2019 21:44:53 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHr-0006MG-MD for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHq-0001HM-Gu for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:23 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:44641) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHq-0001GO-Av for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:22 -0400 Received: by mail-pf1-x444.google.com with SMTP id g9so2244611pfo.11 for ; Thu, 09 May 2019 18:25:22 -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=NqFQGLUWEK2q+OruuYLxByccY86fvPfXVx23TDmISjI=; b=PmKaoaZexxoZh96Z5SSBy4MbrFYGDyGKI6XKBNjH7wuaKs10QNgrTo1r9QxWIm2Cxt o9BXZS6H/B/w1JbrIW62I5XQTVJ2JlkpYmG9vea9erBWiW8RnLJlcExHDm9tv4oWRvVy fn14ogW1auLxR6kQG1c07EiYK0NnlBTeh6377EL8KTopwKRG3l+gIsuBKJ6UTihSQioE r+HMobJf+sYB91Zk+V6XdadNcyhtm6c0ULvTP/pKGjhTt8SB6g6t8PXm1oAiaI/QlmsF F3jUIInF2+ic9gJ0zx/REhj82vTKXclXusWv6lzvAqUcitO/1FQs7rBqjnTDAZZSg1ft BMyw== 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=NqFQGLUWEK2q+OruuYLxByccY86fvPfXVx23TDmISjI=; b=mFfLX/azz4z0gdHbD8yk9OImpVoeLtCgXlNC+UrVzGmm/fOqSw5jdZUmvhqAKfPYT9 2xtcxdBr2V4K6jcbNdzVnuDvNHQqY7+SikXbDwI4p5usJ0d3nzlF2wLQrU3JrhR0Tla9 EgMyhH5TBuVIUVPA4k4iT9gaCueJtNBmTFk1l2kiOgEFJqMde/4m6QdCoueJhyI312gc OsqgNp5wWxIVzCixc+daSy6seSTRAfwhKx4KvmGCEEcZ3iteQkNHi547bO7yx+V6pRfM Mvz1aWI2jVuSsLXxM+sf5tZgOjUD61UP5wboWksHrW+dCGTY2yRaU/Bw2HlU1t4fuyTm fDyg== X-Gm-Message-State: APjAAAVgOlzajDOJsNFEKjlRzcW3yKkbzShRKsHXKvCgvH47TRRneOL8 uGzQIVu8jNzEMAYtdMdxJ9Hrgv1zSZs= X-Received: by 2002:aa7:842f:: with SMTP id q15mr9927856pfn.161.1557451521062; Thu, 09 May 2019 18:25:21 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:51 -0700 Message-Id: <20190510012458.22706-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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: Laurent Vivier 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 diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c index c8217740ef..ab1e18ed4b 100644 --- a/hw/misc/aspeed_scu.c +++ b/hw/misc/aspeed_scu.c @@ -16,7 +16,7 @@ #include "qapi/visitor.h" #include "qemu/bitops.h" #include "qemu/log.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "trace.h" #define TO_REG(offset) ((offset) >> 2) @@ -157,14 +157,8 @@ static const uint32_t ast2500_a1_resets[ASPEED_SCU_NR_REGS] = { static uint32_t aspeed_scu_get_random(void) { - Error *err = NULL; uint32_t num; - - if (qcrypto_random_bytes((uint8_t *)&num, sizeof(num), &err)) { - error_report_err(err); - exit(1); - } - + qemu_guest_getrandom_nofail(&num, sizeof(num)); return num; } From patchwork Fri May 10 01:24: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: 163805 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1731262ilr; Thu, 9 May 2019 18:40:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4r7J3qA3Qn8CqE9SGMbceL0k0dk1KIL7J0aa/qCrn40ZwuS3gixOBm+utDo4qdO5X48WC X-Received: by 2002:a7b:c3da:: with SMTP id t26mr5183629wmj.40.1557452407371; Thu, 09 May 2019 18:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452407; cv=none; d=google.com; s=arc-20160816; b=PRE6snzSH3eP4CcdkAZEVyBN3Are1uPlZLEAclw//J9ZVIL9EZZXH8YuBF497exyUv yP81n7e66UwKj4bsyM5DzASzELnXHrcwKs6mOlQUbUEulYd67rQUAN6tzb1CJGZupKeS 605+yi8TKRhMyRbpxUpN+UU/iw8srtOEKzZE4oCsVWkQUxvXgCSQdtODorZd1cMsbVTN QLFFTgkAuQdy3hGpnGUAoEJAdLOaS8wgR9E8V1B1K67JmBbvqopfS4aaAZDOqndlBhuE MMB+JVmhq0BTIEp1jY00RbUQIZv2/Rb04WhshKgbQtVL5oqMkIyFmavsRIJuweqBHsOT VIMQ== 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=iRt1ekpVqMBTFPlbEkwvccpMEH6z9s1kPn0wCee76Ys=; b=UlaxRIfL78pzLMZLJFL4lhQS+gXvm+8vm8TMQnpa1V/FqjkDtUQ5JrkZ+1+rTSBo5F OEBV9qpYVqG0e5fOanJAZ2telIHAv5TgTBW9yfayFpHvrs/kZxlhBiajNxApkfCvXHau AoSVAxI7vPx5kP9eYSvMrH8YwAxr1SvUHm4ZqHqm3/+5xXsFjSUNhEdYe0nNpjpxuLyD Q+Hfr92z5C+XND5lTq4dDzkm/lCLHNmotgxwhdhbRHrXnEPsz0oCB3xwl22Hr8GmSNIH ArLODQGQvGrdQaCE/fqs19qinU0erU4QEesZQ24gVWBJiwvxhlESYBKVOrN/ebP1/r3w OeAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xZKBvI5w; 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 j33si2657256wre.178.2019.05.09.18.40.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:40: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=xZKBvI5w; 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]:35201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuW6-0002qn-Cx for patch@linaro.org; Thu, 09 May 2019 21:40:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHt-0006NW-2w for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHr-0001Io-Vm for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:25 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:33020) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHr-0001I3-QW for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:23 -0400 Received: by mail-pf1-x441.google.com with SMTP id z28so2271820pfk.0 for ; Thu, 09 May 2019 18:25: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=iRt1ekpVqMBTFPlbEkwvccpMEH6z9s1kPn0wCee76Ys=; b=xZKBvI5wkHxN8vjZl6NblWPq5dSgQO4dYbU3Bgo5lChSGqLdi8PvGxQsaPmWTMXKUZ prPiD6tUxsooCy/3NbroKaReKsUjU2y7JhTaph/hTZnBk5B/kt0ISR0iUZ5ZAue0M1Dr UzJMuyWoGIW85R+sqeMwRFV+6tpYmwVzaBBLSuzYtJdqd+TMvxeQVCCDg5rI02Loah1S OtQFJQn1X4liUzI2pp8Zi6UEb2lfk41tWRuSOMA6MN5lizf+F2U0naiPVrRll/cIy9Rt A85xKvcWmrTsztX+lZDaTNeghRqz2kOcinMD+0uYVdfZ/UzOaT/dnwhuaY2INaqW/ItK 6hIw== 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=iRt1ekpVqMBTFPlbEkwvccpMEH6z9s1kPn0wCee76Ys=; b=COe5TcuM12Am6FNniBFTKa5oGAD9+wagS5mtdCjogD4A2IlG0Pbhtx9aOMTlwKKd6S EVss67lUjsgv1agny/1WmOD+4EHtQoULuB1ZioRPhjjhjERJjrVqefEPX8Tw4U2K96r8 fjqEVTe0l2LjDPQeHjgSxe4W72R7LTcLdo0FoaoAsN7lHT3CQNJ4nYV+3fOx4led+Fpn fUo7nCSsuoBxeEECzfJ5kmTOALm61oNQuD5Q3jZQhPg5GZhbh/WH43nylnNMhlcqBlcL kaX2CScou10h5mS8dVOGReAMacSG65/b33ug0ZumSvfUMBW7BAE9VBRm2ZiMAZr33oSC w2Ng== X-Gm-Message-State: APjAAAW+6w9tEuqos9ZnLHtLhWt32CCxtEUnDmoWPxa5pLlMgT4G7K0m b9ToSk0jZ2EPUYrbujpbT2GTuBdf9KM= X-Received: by 2002:a62:4281:: with SMTP id h1mr9882033pfd.162.1557451522632; Thu, 09 May 2019 18:25:22 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:52 -0700 Message-Id: <20190510012458.22706-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 Subject: [Qemu-devel] [PATCH v5 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: Laurent Vivier 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 diff --git a/hw/misc/nrf51_rng.c b/hw/misc/nrf51_rng.c index d188f044f4..3400e90a9b 100644 --- a/hw/misc/nrf51_rng.c +++ b/hw/misc/nrf51_rng.c @@ -14,7 +14,7 @@ #include "qapi/error.h" #include "hw/arm/nrf51.h" #include "hw/misc/nrf51_rng.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" static void update_irq(NRF51RNGState *s) { @@ -145,7 +145,7 @@ static void nrf51_rng_timer_expire(void *opaque) { NRF51RNGState *s = NRF51_RNG(opaque); - qcrypto_random_bytes(&s->value, 1, &error_abort); + qemu_guest_getrandom_nofail(&s->value, 1); s->event_valrdy = 1; qemu_set_irq(s->eep_valrdy, 1); From patchwork Fri May 10 01:24:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163806 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1731819ilr; Thu, 9 May 2019 18:40:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXerE3dNscmJ9DBbAQXscC3T/topXT7PkxPxLAvw8XquBrv4NeLgq0GoazPINdaCWrcA0k X-Received: by 2002:a1c:6c1a:: with SMTP id h26mr4741442wmc.89.1557452445904; Thu, 09 May 2019 18:40:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452445; cv=none; d=google.com; s=arc-20160816; b=G3MzBg03I585Fk0FagxOrPmgMKhgjw48pa50lGTHuBFwIflfl5XrJ7qtzr6J6dkF6Z +c5bxPYwUbLG1q+QToCT9Y6s4vi92NUv+r3hyakD8bytlLP6iEREKIeqzR/nmx60bgRF s9bE5+RyLEa4YuJjIJ5ccwLF1WqhXY1vbCtZPTU4RQotOxEMP98R+kKD6AFS3mnphs3/ inLiiTUT+iYkRK+mhEY0+FA+QYWVxOQaCXM6JZXA5xLMQqgtdb68el+t9UW/NiNi7tzc JrOpyFtPTdxbMnkSeE7r74+XpIEmq++G+BVwgDGnYa39XEJzxqCJjBkhWdvfru5tCL9f O9xA== 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=CbChhlXQdosoI4MWUK/zk2WTRGwUvizy4vwPQDmKAqs=; b=l/SjgPbzaMhpfK2khuBCYRKj0LGf7Bu8Jp2oL7uCSgu+zb6VtTiV5x0LO4cPnoKbRt cFNb3HP2gAIDXjP8zmV2Ji2nso44OcCGW/Z4W9gLfn3RJtktadQYlfllzmmlDDZP08PT UQIFQojNrtwMxtFsss+aw2VatGBK9je5C5+YeQ8RDAHXczEq0Ylc1qQQ3LGFM0WQgO/A sP9F9VlSrkmoynk25raWbMs6uqotX3jpmsbcd/Ip6bPDDfMMYjIyKPjTUflTIzFQ/s9x TQwR+p6noiMYKM7fAnUxTs6weiEB4uPiFGuEEZsU/14agDjPoUpj1q6NXB8FwJm59FmX VMoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mGlxs+Ik; 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 i8si3027881wrp.407.2019.05.09.18.40.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:40: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=mGlxs+Ik; 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]:35220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuWi-00035G-RL for patch@linaro.org; Thu, 09 May 2019 21:40:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHu-0006P3-Bc for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHt-0001LZ-BA for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:26 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:37563) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHt-0001Jn-5i for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:25 -0400 Received: by mail-pg1-x52d.google.com with SMTP id e6so2127761pgc.4 for ; Thu, 09 May 2019 18:25: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 :mime-version:content-transfer-encoding; bh=CbChhlXQdosoI4MWUK/zk2WTRGwUvizy4vwPQDmKAqs=; b=mGlxs+IkXNYa9y7ymy9eoOjb1uY9oIleFJoAdb2sQNqtgw9XGoWKqDvOQQ0KHuyHWP GBqOzvAQZXaQyKYddxNliA2cj/LQ+BWNKktDhMxaziCB7gQ7eQ3VxC7waceUkjIci+vh O6F/UBGLbxI86EhfpCRx7vInAa41BvVpwauHa30wEjgyaWmYCLFSo7utNrSdLnlnv6d6 bcY754D/Va8ma506KyuJpKTtNv1e+Ikep8BjK3GEjxEEFggMz6xAGUxoZYkrKskARBD3 +ujpaYssXBI0o3IXk/rID2La/D7wGbflEbA0gXG8cvQU8wKXyak0+36rK8oM8lnzXXzZ fmLA== 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=CbChhlXQdosoI4MWUK/zk2WTRGwUvizy4vwPQDmKAqs=; b=mKSB4FldhNIZW2U5qt/uVrJ1iZnp6g3W2wGede2Opm7/W+fJY8BDA+ow9LTUPyGFIB B9xzaWoTX+02E1qbnN5jykqf+Lpc7FH0kfxI1nwitO9QBk1OyS7EYNrQywtvB9Vm4eot qaMHe1OdXa3aAnOWx3SwAUmYw0OhkUjXrFfkwdYgjmA4uilD41q5hTMkqz/lcMMZTyd1 RTnvIlhKxhORXl1HNjs5BCj+XgTdkHXL8/kCCN+txPGhRDiK/fHZwsN7wElvr0EIOVhK 5fO3NYR3D36TPqGRcPeljjX8693DZtbc39Py3FINFyZ8p4k3xUW445AR5UHj4QJUWpzQ 16wA== X-Gm-Message-State: APjAAAU9lGRRz406PS8uJdToOI/ZjhG9icV4uG1RIUnS/fEMsrmAN1zb IdRY4bJmZo8G+gLcZY/sOuinK8WPMTw= X-Received: by 2002:a63:6804:: with SMTP id d4mr9965353pgc.240.1557451523832; Thu, 09 May 2019 18:25:23 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:53 -0700 Message-Id: <20190510012458.22706-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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::52d Subject: [Qemu-devel] [PATCH v5 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: Laurent Vivier 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 diff --git a/hw/misc/bcm2835_rng.c b/hw/misc/bcm2835_rng.c index 4d62143b24..fe59c868f5 100644 --- a/hw/misc/bcm2835_rng.c +++ b/hw/misc/bcm2835_rng.c @@ -9,30 +9,26 @@ #include "qemu/osdep.h" #include "qemu/log.h" -#include "qapi/error.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "hw/misc/bcm2835_rng.h" static uint32_t get_random_bytes(void) { uint32_t res; - Error *err = NULL; - if (qcrypto_random_bytes((uint8_t *)&res, sizeof(res), &err) < 0) { - /* On failure we don't want to return the guest a non-random - * value in case they're really using it for cryptographic - * purposes, so the best we can do is die here. - * This shouldn't happen unless something's broken. - * In theory we could implement this device's full FIFO - * and interrupt semantics and then just stop filling the - * FIFO. That's a lot of work, though, so we assume any - * errors are systematic problems and trust that if we didn't - * fail as the guest inited then we won't fail later on - * mid-run. - */ - error_report_err(err); - exit(1); - } + /* + * On failure we don't want to return the guest a non-random + * value in case they're really using it for cryptographic + * purposes, so the best we can do is die here. + * This shouldn't happen unless something's broken. + * In theory we could implement this device's full FIFO + * and interrupt semantics and then just stop filling the + * FIFO. That's a lot of work, though, so we assume any + * errors are systematic problems and trust that if we didn't + * fail as the guest inited then we won't fail later on + * mid-run. + */ + qemu_guest_getrandom_nofail(&res, sizeof(res)); return res; } From patchwork Fri May 10 01:24:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163791 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1721950ilr; Thu, 9 May 2019 18:28:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIkuPbHKTTKid8/YX9ybcs0wxaFsjrKkrS2GwDmcM7RcqiyzaDHlr467MpAoNduyf5hG2g X-Received: by 2002:a1c:ef09:: with SMTP id n9mr5024530wmh.104.1557451715318; Thu, 09 May 2019 18:28:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451715; cv=none; d=google.com; s=arc-20160816; b=CA9xjLvQ6xSjkPwAd0jWmwf/lLDN0fLnOOWwT5tTkLPK1yGLQN4woFPSvRmcO25QKP zsuaXNGXqvl/zV10I0Hyhc+Mf7Xth2mR5xwDE6tlUf/f+Z/GGOxZREF03unOyoMEhgMX 5MCifRx2SPVzvkbTen5qeAsBiOPViixnKSy0Of6q4B0JFFT5Jpc1Ph/+O7UDcL9ZLUZB 0ubNIo1WHYPXZ/PvehmlOJZEot4eQK7dsAHXByCh3dSgOXNAHhwzWHfR+qJSlSU6xXNw LoCJjHbtbgx0izFpWAp7PGKKDq9e45b9IECwxK+P1QAgb34lq5ZgsnkNHUUP0CxA2B1r 3f/Q== 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=SUOVHO6j5bto5JT3YOaz6mzG9aMKtYONtCxKiBQvOSY=; b=ShAy/2LbTVQ5MQzBIx/H283ECDDjjDpuj+vseWHekNoxq1IrGeC2eIKIXZ+uLavryk dX6Um3+g/yi9tsZhuNAH7qpHjk/ccex6WsRg6XB9DPIM34imhusf7DsgVMjzo463KFU5 nXWiHKxvCNvGX1reA/WU5ifL9HXitcUbH3LIhArZFX62IhnLbER+WjIwtA/6eme6tmJ/ kQYlbTsAYhwYjwxsv7Q//o3TYDv1bDMrDLEu0H6X32GppsLB+xvLlbM+r4oVuNQfDVln TKWyaSYyIpQ/EhTm5HQ2bw+iCNh5ETAOlE7t3EwAa7sqOiJf0KvK7SmdorqvSYStDUlO QIqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yTX7Rz1f; 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 n14si2976433wrt.265.2019.05.09.18.28.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:28:35 -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=yTX7Rz1f; 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]:35036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuKw-0001As-7y for patch@linaro.org; Thu, 09 May 2019 21:28:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHv-0006Qy-PB for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHu-0001NM-M2 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:27 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:35254) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHu-0001Lu-Gc for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:26 -0400 Received: by mail-pf1-x443.google.com with SMTP id t87so2267050pfa.2 for ; Thu, 09 May 2019 18:25:26 -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=SUOVHO6j5bto5JT3YOaz6mzG9aMKtYONtCxKiBQvOSY=; b=yTX7Rz1f4JFetaDPpeaTvLwRQg8laV+kMLAqlXwDf0bBw6PkyU1VTCDgUB2b0MEvdm XMYAL4CyArzDQ/1T+F6rq759JmBPCFMztWbTgFTFLbb+w8yFhs0bRLi4RzW4Txe3DPlP m3H6rPfg5B7qUHH5h4oJXs36IquYPi9x0D2LJelsjuOgez9BQo92ing7uwoYuuZNO3WP nogDUipeKF9ESiFdtWRaBDuuhMmVG48NgS/+qqUINC45keVJnqniE+YSgP3wmZOqmGfH xOF5Ncjns3uStSx41NCJXuHxD7DORbEnOeh+TR9CXr0EVTCYYk7OBuyAGUpN7KUX0BN0 eNxw== 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=SUOVHO6j5bto5JT3YOaz6mzG9aMKtYONtCxKiBQvOSY=; b=umUVU4WhkyARYVmh/TZA7nHGaFu2N3DNNR46ji1a7AbiT1s2XaC/C99jDaBGyg66q/ ByWKCQb9ElJLahqIScJFp9/Nmp0gztSaWmohV5WBLSiG8ZsEiHoBXKkNlkiBZnC66qin zmSKfYa2j1dnjQlLL/tUzuFrBqbWQ4Q+3uZIYvffOjNIXCZbY4KmepdmOqu2X8Z/cHpX DL7V2em/1vnWVghVf8/K++G2rRQCZS7TUQlLecbO/PY3pZFoLnYpyCx98m15mUqzAfL2 AorFfINgPFcLIIrOmulK7FSrnPqHSfF1pvnE3xAl9h7XMmPzpu5lttwnY6YM6HxMCuYQ HZVg== X-Gm-Message-State: APjAAAVc9C+GASma998t6SrVp1H4eZBggatK1cSCFpQ6llRVacEH3rsU nJCIASQYE9E+HfLB13H9IHSDJeMUthc= X-Received: by 2002:a63:8149:: with SMTP id t70mr10054715pgd.134.1557451524878; Thu, 09 May 2019 18:25:24 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:54 -0700 Message-Id: <20190510012458.22706-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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: Laurent Vivier 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 diff --git a/hw/misc/exynos4210_rng.c b/hw/misc/exynos4210_rng.c index 4ecbebd2d7..0e70ffb404 100644 --- a/hw/misc/exynos4210_rng.c +++ b/hw/misc/exynos4210_rng.c @@ -18,10 +18,10 @@ */ #include "qemu/osdep.h" -#include "crypto/random.h" #include "hw/sysbus.h" #include "qapi/error.h" #include "qemu/log.h" +#include "qemu/guest-random.h" #define DEBUG_EXYNOS_RNG 0 @@ -109,7 +109,6 @@ static void exynos4210_rng_set_seed(Exynos4210RngState *s, unsigned int i, static void exynos4210_rng_run_engine(Exynos4210RngState *s) { Error *err = NULL; - int ret; /* Seed set? */ if ((s->reg_status & EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE) == 0) { @@ -127,13 +126,11 @@ static void exynos4210_rng_run_engine(Exynos4210RngState *s) } /* Get randoms */ - ret = qcrypto_random_bytes((uint8_t *)s->randr_value, - sizeof(s->randr_value), &err); - if (!ret) { + if (qemu_guest_getrandom(s->randr_value, sizeof(s->randr_value), &err)) { + error_report_err(err); + } else { /* Notify that PRNG is ready */ s->reg_status |= EXYNOS4210_RNG_STATUS_PRNG_DONE; - } else { - error_report_err(err); } out: From patchwork Fri May 10 01:24:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163811 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1736038ilr; Thu, 9 May 2019 18:46:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5rpKjK+ikjTvVjAqjk63lHKOuHnaWs6f6fwANlDy9TwMuqqxfs6M7dqhkd0yJt+EFlAQM X-Received: by 2002:a1c:acc8:: with SMTP id v191mr5273920wme.72.1557452765462; Thu, 09 May 2019 18:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452765; cv=none; d=google.com; s=arc-20160816; b=KfWQIt4qV36Nl5qq9x92X77cES3EaSnDJiXnNN10SNK52ZTeWj7xdv6FClUOWRcuBx GrfLGIP0lp6xfA+8EwnzicEVzBbQfFDfXSA7KJDiOJdJDO7HjVVm+T4jAwR1B83Hrz/C E0PQYjNjZ1Wi7kO9fyms65lquffAMzl4JrUNEMMlvv+8In9C9w54tBBSZxo1w7r8WmDk sIC0zd+gFJzQNt8iPqHaUmE0lHrlXp8gERtKngI76FgYyProHP9Jw7ylQ+ime0pX5uQO CiwIidYIOYG1GsTP19EO0inYMERVCqtS60ND0xEWy5eRbFJrooG7jqpWO0qhNH7wPpAf CUxQ== 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=4yQStDlYusk0tpOPhVM2XauFhXzbtZR092pnkvrSzO8=; b=oCGvXWLfH/wJjL7kVkTdV62qFtM7ynaAQL4vjO9DgoHEI641gqkJuF5pueVACXEKtj /xD7SwKalhU1gL55ZpCq+F8SRLzfetSH8eOGEQznuO47A3x1LMZUnsuWNfq7iz3pDDDt OAjjJ7BO1lNm59Kac3wuqEkyVDV6UwyFY3zaC/XsH50y8d+Bwuiv1HTCk1OKiZ2MxW5e J53rEAh9MKHCAFBArGOGiYziVTzpABTBfleQDl8sOv5XDJlJEW8mSok2gbLdSscMGtWZ 1cRfvPHaFX3MjquqtGMQiDpykJ/knjOaaNeHzwzjWgsB4xOTZNRUEdAb72qAKyju6jtV 5JZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Dbh3eAN4; 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 k3si2633341wmi.124.2019.05.09.18.46.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:46: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=Dbh3eAN4; 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]:35295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOubs-0006rT-EB for patch@linaro.org; Thu, 09 May 2019 21:46:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHx-0006Sh-9s for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHv-0001On-R2 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:29 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:34130) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHv-0001O5-D3 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:27 -0400 Received: by mail-pl1-x641.google.com with SMTP id w7so2004738plz.1 for ; Thu, 09 May 2019 18:25:27 -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=4yQStDlYusk0tpOPhVM2XauFhXzbtZR092pnkvrSzO8=; b=Dbh3eAN4xeUQPYlvZCTaLZhRkDAJJNfY1pJGsYOE0b5Jj3OhqjaneGJi1qpgWOp6ZB 8pnjQots5dxxOs7mpuE/L/sG5whzxgJjm1s0LKgVd9ccJJPzMIKD8YBTgrXqRdlqBX/U NR1siiB1z4FGhl3yd+GJ088bgEBI4wdhz5LjYSzLPyZ0mISAJp9XLY0P9BcwDSttCHh5 AjTgW9AjZengYf9iRgzChjClL5cBSXaBVF8u31UAmINExzKPK40DhHqYRDy4fV7kEwGb yR6EwZ1crYnzc64HX1hMvPmChXqxF7w8A0qcpCQ3o3beSgFoV/YGno6TOrTCxBOMBamO XIPw== 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=4yQStDlYusk0tpOPhVM2XauFhXzbtZR092pnkvrSzO8=; b=c8SryC8IZYqEh4fQ5mBRSFFKl+iNmDz+ba0R3bdW6hFzjxlYBHD9H9Fz22EkSYVCg4 dWalWDhJfAPF4C3mk7NqWxNs6JMgIo1ig5Lkz0OCD/+/J0iTZl9hOYM0DD23m77rg+Eq h5laJnVB8p/rDm0Tet5dOzX8Di05F8hbBoEelf5nYgY1kOUFiVn7+vMgfoPubi9lWZAp Syrsdk6Emwso2gIMiGz/2/S9e67vethj3qyba7TcQqGHp7497kUl1kzOygZ0dM3+QJ69 cqrwn8fcUF2GhvtLXFE1TzgXGOx2/DC4EMyi1aubhk+YJeWqPzyIp/qEr2Bknv0oMNDu FMpA== X-Gm-Message-State: APjAAAXZvwdnJYqA7eRWDlGd6Xk/7U+x0r91ln+uVIX0J+bUcyR4N6gr 84ft70L0k9o/OZ3jrETBDWXTgbT6M9M= X-Received: by 2002:a17:902:f20b:: with SMTP id gn11mr9423582plb.126.1557451526171; Thu, 09 May 2019 18:25:26 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:55 -0700 Message-Id: <20190510012458.22706-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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::641 Subject: [Qemu-devel] [PATCH v5 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: Laurent Vivier 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 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 733b840a71..892f9a4ad2 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 1e6eb0d0f3..7e88b2cadd 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5707,43 +5707,43 @@ static const ARMCPRegInfo pauth_reginfo[] = { { .name = "APDAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apda_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apda.lo) }, { .name = "APDAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apda_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apda.hi) }, { .name = "APDBKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 2, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apdb_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apdb.lo) }, { .name = "APDBKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 3, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apdb_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apdb.hi) }, { .name = "APGAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 3, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apga_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apga.lo) }, { .name = "APGAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 3, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apga_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apga.hi) }, { .name = "APIAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apia_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apia.lo) }, { .name = "APIAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apia_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apia.hi) }, { .name = "APIBKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 2, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apib_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apib.lo) }, { .name = "APIBKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 3, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apib_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apib.hi) }, REGINFO_SENTINEL }; #endif diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c index d750f96edf..7f30ae7395 100644 --- a/target/arm/pauth_helper.c +++ b/target/arm/pauth_helper.c @@ -403,7 +403,7 @@ uint64_t HELPER(pacia)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apia_key, false); + return pauth_addpac(env, x, y, &env->keys.apia, false); } uint64_t HELPER(pacib)(CPUARMState *env, uint64_t x, uint64_t y) @@ -413,7 +413,7 @@ uint64_t HELPER(pacib)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apib_key, false); + return pauth_addpac(env, x, y, &env->keys.apib, false); } uint64_t HELPER(pacda)(CPUARMState *env, uint64_t x, uint64_t y) @@ -423,7 +423,7 @@ uint64_t HELPER(pacda)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apda_key, true); + return pauth_addpac(env, x, y, &env->keys.apda, true); } uint64_t HELPER(pacdb)(CPUARMState *env, uint64_t x, uint64_t y) @@ -433,7 +433,7 @@ uint64_t HELPER(pacdb)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apdb_key, true); + return pauth_addpac(env, x, y, &env->keys.apdb, true); } uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) @@ -441,7 +441,7 @@ uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) uint64_t pac; pauth_check_trap(env, arm_current_el(env), GETPC()); - pac = pauth_computepac(x, y, env->apga_key); + pac = pauth_computepac(x, y, env->keys.apga); return pac & 0xffffffff00000000ull; } @@ -453,7 +453,7 @@ uint64_t HELPER(autia)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apia_key, false, 0); + return pauth_auth(env, x, y, &env->keys.apia, false, 0); } uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) @@ -463,7 +463,7 @@ uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apib_key, false, 1); + return pauth_auth(env, x, y, &env->keys.apib, false, 1); } uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) @@ -473,7 +473,7 @@ uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apda_key, true, 0); + return pauth_auth(env, x, y, &env->keys.apda, true, 0); } uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) @@ -483,7 +483,7 @@ uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apdb_key, true, 1); + return pauth_auth(env, x, y, &env->keys.apdb, true, 1); } uint64_t HELPER(xpaci)(CPUARMState *env, uint64_t a) From patchwork Fri May 10 01:24:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163812 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1737718ilr; Thu, 9 May 2019 18:48:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9uWraf5/02scvxvCmDRqGJL7LGYL/bRj98izaY9otktQEEdi+c7iPyDHrWCybnkz88Xwu X-Received: by 2002:adf:ce06:: with SMTP id p6mr5536214wrn.278.1557452900541; Thu, 09 May 2019 18:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452900; cv=none; d=google.com; s=arc-20160816; b=TYh2JfZKbpulN9JQYuaY77cmjg5o5eR7/9p31YoSXs6/JlzRgP0fGAlH3Pa/v4zc3p eZCne1Pl7ZJ+et2qUtHWpaZwabFWZa8sWxb03gnio2XOQXD8+OvrCWmDlFB0bdaXX5Y2 TynwMn2VwjufLqOU+TxhfQ1hnfAIezr+RJ5PJZ6IDTa1RpAu/9F61L0s2My5KXieyqpr AcStdiqKHz/iQ37+yUkTthox/SYNHae9cEi/2+AsuMR0bLF1/CdCJ2RIDkjDs0qbxjVG oO786ONAX3iwRldcFGFxne6tSmSm23ZPXugzoVUNYjzpD8iG7EJwTdziO+l9exK4yUHT dUDQ== 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=6a5iGBwRtD5hTTLS6rzCG4hSulwi7yefRB4mjcj/bzk=; b=NhR/1Ke8KuPY4imPZfDfcnzma0xiXu7qZybSovtUyNrAiLYODBGlwzbMbEHE4pZyR5 +nwjN95xQmb4x0jj218kfnlixnOrDjt0+pVvtXGmYPl9C/AdfYNcKcXm0fN0FMWrtvXZ Qrv+V2iLJgbS4qzNL6Q5nE4eI5Nw2TzXy84aDnhBt6FLZ9lsqRz0JTPzhW8dGfjUZqbN YT2oWcBoYWi8ugMAJR6gdZR5vmcoHGr1YBQzh3ySngYiv7ulUhblfvdWRl/Gg4TpG8zB ThmTw7joSFHEnwUl4QNWfLL08wWxlNYjxkqo4FVbeUQlUHiS6xtfZdPRdu2xZxzI7Xmn KRsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uBPl2xjN; 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 a3si2934029wrm.296.2019.05.09.18.48.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:48:20 -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=uBPl2xjN; 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]:35305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOue3-0000SZ-K2 for patch@linaro.org; Thu, 09 May 2019 21:48:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHy-0006TX-9r for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHx-0001Pq-8C for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:30 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:44641) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHx-0001PK-2Z for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:29 -0400 Received: by mail-pf1-x443.google.com with SMTP id g9so2244747pfo.11 for ; Thu, 09 May 2019 18:25:29 -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=6a5iGBwRtD5hTTLS6rzCG4hSulwi7yefRB4mjcj/bzk=; b=uBPl2xjNQdlFp1d6IlgqDxsR/CXuB/2pc+qELra6ukOQq81OpdorQYN2Y6Ip9JhnhX vgfcZh1UHJygFhYKM0NV44O60dIbwVcjjuiOICF74Vw6l1ZIa5yDV1SY8+nRGBFZEMz9 ozzSXJy3Wh5QVM9GyS2RU1CSsvtgFmPf87TbC2g5oUIih31ebSpW1Heu9fQrqxNaKjGh jiH920xo0vySE85FRBVkk7IMj+dn9C8qELkM2nhjgTqd3G4HXitFauLFc8ViNNhMuQzA j+hfTWNCeT2SoG6Sc7NEqKv0szrMhR0PFGgSCMe+rjmK0cahE4CtR+sUXsYVH7vFd3wq kFRA== 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=6a5iGBwRtD5hTTLS6rzCG4hSulwi7yefRB4mjcj/bzk=; b=X9+WrDr+HGO05sSyTUI/+Ur0CWpId4fHJRZdL2OT/vXdCZcfle4Uzo+ox/4Y6O8WCW 2QEPRFKcox2cPrrdcpm/mjn5TzVcjzm0zW4NgAOQzd6e6PmTtXLKCkqu1qq0t7NamZDm PC+h0cYqeWtP25+Ia2QmnAvEGZvjUXOUnN0QsszA7/0sijeeoEJSJBRfMd47AeQFNyx7 OlkuRFGk/FoEnU3xbD/rODuRWPH5BHfDFocUlscKgQRQPK+BrK2QecJ1WBZGUW9+6yNg 5ot8w0GLCpdFJN8Jbma1RcPmP+liBJtcxVsA97AdJPYrhn9G8SZogAtsAKZd3H9z2tCP NXeA== X-Gm-Message-State: APjAAAXu1HNmHReu/SEEgws3mVDiWnKg3xIRPAiw5DQFh7h9xnlgMWBG WvNPLh5vE7rexPbXfkydrv4lD/yat6o= X-Received: by 2002:a63:cf:: with SMTP id 198mr9672036pga.228.1557451527252; Thu, 09 May 2019 18:25:27 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:56 -0700 Message-Id: <20190510012458.22706-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v5 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 Reviewed-by: Peter Maydell diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 892f9a4ad2..c34207611b 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3521,6 +3521,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 7e88b2cadd..9642070194 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -22,6 +22,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 */ @@ -5746,6 +5748,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, @@ -6690,6 +6731,9 @@ void register_cp_regs_for_features(ARMCPU *cpu) if (cpu_isar_feature(aa64_pauth, cpu)) { define_arm_cp_regs(cpu, pauth_reginfo); } + if (cpu_isar_feature(aa64_rndr, cpu)) { + define_arm_cp_regs(cpu, rndr_reginfo); + } #endif /* From patchwork Fri May 10 01:24:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163795 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1724566ilr; Thu, 9 May 2019 18:31:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqzr7lsi8dZMuMmXwMJZFTKSsRMTO7LbLoB/t8ftTtxYJa5mmRXs9+IXoogjTWZVu+8rrCuB X-Received: by 2002:a1c:a550:: with SMTP id o77mr452319wme.28.1557451892459; Thu, 09 May 2019 18:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451892; cv=none; d=google.com; s=arc-20160816; b=e2VZTgT2uaJ6J1epyGbJfPp2ju+EoyR9Ql/TC1bhYy47BBiXfJPCe8QgM8jCptZX7F YqaaslIGfazMTdymlQP8EJRDwWtM4y35lP+HYKyLUPekEI0huMXL/y8QLnAWy9XRRUPE Hz7up0aEVs+TowEQ8QWn6VvF2LqeIB49wdXwVVPnW0sZLO1wAV6v6JFf/1DdXQJUNV8H RO1XhefpeRBGo1qAcNU1nj1Qw9H/g1kHMOYyiV1gtlNOqerKj7lJGndpRxt5Rq4Vnu+h rhbtV8S4np2ty60i3roGkq2KqOapBrZ19n+bCc1yOX/sAE0u4UAiN4VtO0gZZml189AJ 53dw== 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=dA7IdM9XxYp0KA0mciB9Wmn94LeseL1766ubkiFpUuY=; b=i7+l8UFyLsI+edfPtWLUXoM2QZe3ZWJL+sJ+6bNywy9D8/j1KYtxABNxUAjoviSREa qsrScxycrs9b497IUBfN62wq4kmGQY0WTOr7iEu7FJRE+LZjvekecASUKXcy0YpvbE/o XoBnY6jeMc7M3mQc3jQ4THNYTcvcgjQFhIIhvECowbXBaV8tCfzKwf5zhRfPL3ucnzst SOTkk973DNMEb7kuStEw0qPRg8bu6xd9teH/ZsD39HHwJJK/YljTriFaOZOuDKyNDbM1 QqgRD6fBGCYFJ5sLVF251tmghZ+fOHoW1UatuTGMlFz0IydlCCCgq3yiaRjxsBKtbJQK nWRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R9QrGTMb; 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 a12si3383961wrf.357.2019.05.09.18.31.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:31:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R9QrGTMb; 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]:35090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuNn-0003mo-9p for patch@linaro.org; Thu, 09 May 2019 21:31:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHy-0006TY-Ee for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHx-0001Q7-Ib for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:30 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:40871) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHx-0001Pc-D8 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:29 -0400 Received: by mail-pl1-x641.google.com with SMTP id b3so1992003plr.7 for ; Thu, 09 May 2019 18:25:29 -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=dA7IdM9XxYp0KA0mciB9Wmn94LeseL1766ubkiFpUuY=; b=R9QrGTMbhpFv2ooDE+rHY1/EyvH3DxR/YxJSC/g2s5Gs6Rr70N9h6O+6AU6/5WBRfC U72/8Oa50Lb3jN6+s1dizVR/WJfPz/mCAcOOefsqRuNoQeLmWoPnVf8DAka9HXfnEHCA Q2N+OMuQ353YW+xHvdX032IyOWr9b0EoXAfyERsO7N15QDd9lIdyygdvxRzGmGCjSfP/ 2sO/ytnNDccHpuILQ1Vo3xizTzd84J6FuauNfCJhiPp/DKI9cv2yJ7u+EeAHGsezZEJE PNfLcEHkUg7zAHrv9zo4FONf69Wk8aTbjuW6Pv9VCwWunqulpknwewDqXNua8gsztflC 1qAA== 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=dA7IdM9XxYp0KA0mciB9Wmn94LeseL1766ubkiFpUuY=; b=nIBGEZzhobfw2AwAD4Yqa2JuPGO1yZooQ7pEBQPdJ7QnMZxqaVl8su91mqE/hJM/v1 GNOspaQWja5NQFKxocteeQ6cX1VXfMfOFrImthGmj2dXMkWD9YbV1u4kS1hV5LR9WB2Z 8/yBINcPbRj51CWjWI6q8zP3R8/GTpNgxOCG7xe3aaBZGnvrkPFestm1OQUPrzSLsonJ slHW3XuTUXTZD3kb1zL/Hi90kX95Lm01plPHUM3hYC8A68cELrM/OapBA3zMrixi3bws CCMMZk9brPKqQmrnfcSv9L00GlBXhdPloojo7BJc1VmfmGfYDH6tgxi/u9TuRM1/H/5n zyNg== X-Gm-Message-State: APjAAAXswqowxkGDn0toRC9DSA4MPTBkuIN/jed58dFmwPxhW7FxcaKz Ew6mMBx61yLAVu4CDUwWh0L7LHICoy4= X-Received: by 2002:a17:902:b202:: with SMTP id t2mr9102123plr.69.1557451528176; Thu, 09 May 2019 18:25:28 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:57 -0700 Message-Id: <20190510012458.22706-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 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 --- v5: Do not loop for darn64; use sizeof. --- target/ppc/int_helper.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index f6a088ac08..9af779ad38 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,38 @@ 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, sizeof(ret), &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; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + + return ret; } -#endif - -#if defined(TARGET_PPC64) - uint64_t helper_bpermd(uint64_t rs, uint64_t rb) { int i; From patchwork Fri May 10 01:24:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163798 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1725014ilr; Thu, 9 May 2019 18:32:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzq5kD/Jruafej5+DVJFeQcqn+ZTkCFn/lpwg4q9ryezD3AyKlqSL7lCM8+qaFRaVBtYZjN X-Received: by 2002:adf:8567:: with SMTP id 94mr5649213wrh.286.1557451921613; Thu, 09 May 2019 18:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451921; cv=none; d=google.com; s=arc-20160816; b=LUAgeB9Dd17PC9wPAHaQxLzlsk70QK3ZVYJw1xpz20LovHEzioCMoh8frhTSakzLXw LcyinW98ZSv4WUuAPfDNDpXND0ikoITBFzWs+Veo/2fJTEjeX97d0LlqIP192yLwXXJY KiW/8GVAi98UMHYQlEBKk95mE8AdThQHTQBYytGoCSs3HA78lWMv42HV+7j75StnzRCW 81Cxm1T51YNjORZew8OQvIGt6TABapezh/J0Z6Duu3NP+nm2HKsS1fu68hCMseCdL1jV sXdAxZdN1Dw9M3PEugixwFDlleBhaiCqRw/7EDLCjmNKFcEvUYhzkpTNDGLgTNEjSLRo q2WQ== 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=Zy7Bl/NY6R6WV/KALAMj7Mld2mS+F9Ia+hHvDF6MXjc=; b=YKz5mKk6QWKBHCja6gFFPbHpG5ceidobSAdykma9j1oI6C7g12OCeFw72K5VqDEwrB nfb/cJdMf7LPd2ltlAUjLvB4+xd9x+0UgWS8PHpm6mG+o3AhsB0+n2UagFc9BBZHr6pG eqNesGTN23+u5rmC/hSKeJGUn8bv2JHz7ddG1zeSuD4v5OkFUvHCUR0TooQkxjXsfqYS HAoLpL2qI16K9tF/e+smOjSx3ufAEk2igw41U+NuqU6xKvCmPEWEO2Y+ulcU7xT3nkOZ LDri00wqrXMe/9CkJboHjeq/WPwmMGGqmzIk20XonIXljr7v9BERozgQy/Ydj3tzG62h qi/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=m3XLC8XW; 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 k19si3449726wrg.360.2019.05.09.18.32.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:32: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=m3XLC8XW; 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]:35092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuOG-0003rT-Cs for patch@linaro.org; Thu, 09 May 2019 21:32:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuI0-0006Td-0W for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHy-0001R3-Tx for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:31 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:44292) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHy-0001QY-Nu for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:30 -0400 Received: by mail-pl1-x634.google.com with SMTP id d3so1979954plj.11 for ; Thu, 09 May 2019 18:25:30 -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=Zy7Bl/NY6R6WV/KALAMj7Mld2mS+F9Ia+hHvDF6MXjc=; b=m3XLC8XWpdIMgME4VXjsjRL9+9ZdEqWuDnPdFmEFMv3EG4Gh1FR5YVZUDwtH5VlIlo 1BCrxKVPOWAoYPZNHd5aCXStA3rOMJ5+4f8YZyIfHu1mhwtrVeh9dGbUns/ouEFpfm+t l5cLWY51p4EmeGaHfGQHmlSa6KRMLdrrhmEoUl+4yQm8sB9xM8MojIh2eZlIO8uR7w9w QQzyiYGi/bhb0YfDaGipW5plgKJztDymSvNzJ21zcj/B9nawQKCcpmbBUuLHWnMgqvTi xs7QZfMpwAsEqM4a7jnJZYh0bJ9l3vERaxvLy2sliTLXnNp+pbUYHe6GovCZxm4wcJAs AV/w== 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=Zy7Bl/NY6R6WV/KALAMj7Mld2mS+F9Ia+hHvDF6MXjc=; b=kcGvWWX1u+6+o1ToSpLlGikCM/p3A6JIokL1xakGPEsySLZ8iu4DmLuZ5JWA61f0wy fxV7Mije3a2Ba1nZPJqyRCZweZ0vuimddEsV0e/f+X78EE3EjS0nYdePIWx3HgUc+sMs b2OhNOEYIHlwDx6HlJsCAWfbefS+IR6vwsdqNo2HBsb1RqmZJc27rGPzXPunpX/YhK2W Jvs7eHSeeJqBoqehMXOJ4A6sB2162SjnWDwFho3xoSSxVEs0G9nx1Fb72HM4ejhlmOwX La+CQ1VZybdaGihJjj1a5UuPWOZhsQV4Wy344VrbUrxZmoZJuOu/oBPUzJITm/gfCDvB T+cg== X-Gm-Message-State: APjAAAVVSqw55gQ2nNF/RvAGQ9VhAkhO+4uZDCCam8sTB1MIdeavm9ka yvN8AJsdpumlse2rC7T3YYG3UQKyVHY= X-Received: by 2002:a17:902:29ab:: with SMTP id h40mr9335922plb.269.1557451529423; Thu, 09 May 2019 18:25:29 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:58 -0700 Message-Id: <20190510012458.22706-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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::634 Subject: [Qemu-devel] [PATCH v5 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 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 Reviewed-by: 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 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; /**************************/