From patchwork Wed May 22 18:42:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164882 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1251814ili; Wed, 22 May 2019 12:26:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzU7D0WY/drZEkUS3sCdnydRKgbHGFX6zKx8QkDlnTVbchzdKRZV9rCkq8CC2/7YO0Je4GH X-Received: by 2002:a17:906:e9c7:: with SMTP id kb7mr35935768ejb.259.1558553177535; Wed, 22 May 2019 12:26:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558553177; cv=none; d=google.com; s=arc-20160816; b=EXR96r0iGhntC5XYDxYNp5+cGhWzca4kC8oBvklk2+PcEP0TYES04DmuXCRZwHtPq+ 2qFxlr9SqbMn1BLH7zxOh3r5wHbWw6cNerRY+RJrZdg1moN+Rs7qNQ1FzBBBn+Peh7wY cKaJxWEHXHJGuko6kqo7bvrESarkqm7FWsuN8s7qnwAMXJHtusqfkjFhpgYrUn2U7Yl6 x4/N6Kw0bfDxrOI51E8WMCUflRo2YvKVDSvG4sKt1xLhSdYqvRd0kngCq+S3F2PGawwJ BQgcCTH0qJ6sAa4bizoxw83RmRiO2kxSchWg6cENixNoACTUXMPNdYk8KyBFZz3KSKTf ToeA== 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=9dAwC0S3G/OFyRgp8E8i1RIZB4naA10HcRt0yDU2T20=; b=MbFWNRI0avO68aK72mej8hsdCQjlJaa6fJbxBH7FMLlazuU55coxWx5zhwIyYUax4l ycdWfPq5v0D/alU6fv+QOBx7trvDA3IsXbK5tpQOYNR5b58XzUY/DOoidmFaS/Np6kke 3WP3JUye8GNMLysjqwZ4ZcZVQ/aH/mOT+z1chQqmIgnAYAtkgkU98iIQjLO1EsxBLL+S toZ7S7762pMiSAGNKZC0Sp399+YetsPw9RZoeOmtr3pS3kpdIkqiMoakkBD5xh9ubGkV G+CtjZ5VhMcPhbqPflYGmIxcek9TtPZUZKfU4SudBl8blAM4/lrXlhQSMtLDFb6VQRy0 /92w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LYa5PPQM; 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 x47si6508966edb.353.2019.05.22.12.26.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:26:17 -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=LYa5PPQM; 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]:50102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWsS-00022G-CC for patch@linaro.org; Wed, 22 May 2019 15:26:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOt-0008Eq-7n for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWC6-00080U-97 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:31 -0400 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]:43108) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWC6-00080L-43 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:30 -0400 Received: by mail-yw1-xc41.google.com with SMTP id t5so1232445ywf.10 for ; Wed, 22 May 2019 11:42: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 :mime-version:content-transfer-encoding; bh=9dAwC0S3G/OFyRgp8E8i1RIZB4naA10HcRt0yDU2T20=; b=LYa5PPQMjqAQwlc9/adtwJJpve/N0/a8ZNAdtgKWrLFDagkdPwQrMxI6hY75aCkaaF z0HOpjZ9c1HQ+L6TXYfyGmJJi407J7R1pxpQ69mp0oL9Nl4urdzgsaKq5PnQ81BY9t+b x14XEvjY5L9YpUTd68XgawcXCwAWH8UQrlbNPIWcHiRVqCKetMmA/c4KC4Dw1P8xJxUn idGd4oPoWmdV0tncwe5lRICjyFkKSywsPZdtOyJt2JAp1gZbV6srbJgBNrCgymoTiY4K Kdm8CBp1ptBEgCRQ8CSr5oLLEAWONlNs6ZseTDWZwl/PnH+aAH7aTbN/voW5nG4BvwEu 4G5g== 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=9dAwC0S3G/OFyRgp8E8i1RIZB4naA10HcRt0yDU2T20=; b=Al8MvI7nJcmNMDkLU5teuD2qM4nsJVG0YLGw9b+M4ksr1FjCdWDcN5R8QWyJFMzb0J 9rUd7kjfJlUCRWkkw2ytlHgacytrirJq2ywIIF+ACZeO4OENJdSbiD+p2Krgywp3fN6+ SGos9WWjRvO5CdB1T2/ybPdCqCCDfCHZbqxi87t99dTUiLJcBl1ZZFiP5+P1OnwMxGmE xKKSluztghZvTIGYGj+T/tR7xIBmP3hXffvAgQIUg2rhOgX1OnXRp+HSKijiO0f+nyB9 PopnAs/I0DBR/LZFF69/jCbCrYW/xW2w2U7AwXK2CA9qKkq8DAC9PzHa8PDKLT6SduK1 DNpA== X-Gm-Message-State: APjAAAWWtBKOZcuuwS/VjvXrcG/WKNSXqacuQkt2E3wVtqHYFlEKOTom M7uWFB+7/41IJ398zzy6On+OD6jeCBI= X-Received: by 2002:a81:8606:: with SMTP id w6mr41845008ywf.344.1558550549179; Wed, 22 May 2019 11:42:29 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:02 -0400 Message-Id: <20190522184226.17871-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c41 Subject: [Qemu-devel] [PULL 01/25] 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: , Cc: peter.maydell@linaro.org 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. Reviewed-by: Daniel P. Berrangé Reviewed-by: Laurent Vivier Tested-by: Laurent Vivier Message-Id: <20190510012458.22706-2-richard.henderson@linaro.org> Signed-off-by: Richard Henderson --- configure | 72 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 28 deletions(-) -- 2.17.1 diff --git a/configure b/configure index d2fc346302..571dd94ee2 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 Wed May 22 18:42:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164868 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1237568ili; Wed, 22 May 2019 12:12:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQgGa4MQQSI4bn9/QA6ByTlEYd91/vlCE/QR8w23HRuMM0sBktG35mpyUJvWWajU1iongc X-Received: by 2002:a50:e79c:: with SMTP id b28mr89990330edn.277.1558552324317; Wed, 22 May 2019 12:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552324; cv=none; d=google.com; s=arc-20160816; b=XKspv3Sj+/6nHSIfFGxEJIowG89yUhNuZ2NVdedFrNiJXRDLK33nDdAHRuXF3q8SO8 RYybooj5ArSjrJMv2ULc8IbkeegOiLda7e6fnGehHa496xCv9BHlkWYPbikZ2lCoplkL 1Y54TxOQEeX0u0BLxiRUFJWUVt1NWsArt4InywNpg1DuCrOWaZmrtQI/a0OtoeutmXqw lrQTvUUTKoAblKL1KZP1uS75FjkPsazSoz4pZr0TaI2joaiZXo9KTRPM2W0R/92SkcRZ jkKPHzcgwwQ1YseqIsk2kptIEMetITPIO9WDIoP8qlPVPg9L0Yx7C+0RZgt78z2893k8 qMvA== 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=i3KWRWimQh5hv++1F1wzio+dP9yFcGqKmqdoYeXPACQ=; b=NFhd2IMJq3FZN4FcSvfE8HucL19M/cenDe6YKc3+eYTIvH6K5R54rRrFxfiWRlIOEU ohW0JbZq2BeZnZfsE1tEVUmT42p6BF8bCmtMuFiaRAlbSTVgMl4T7ZNC2sVO6aWADPvJ 9L1R/VacvV3rXO8Ingt6nQhMHtpcDkZOsHVm8HSstcvpe+HOUe5b/MzJokQf1Gymdafa 1a6sFQ/JoozdWeLMZb3SkPT/E9LIjvQfN/9O4LGUvPkbXWN5tsX/ArxJvxNHCPGmwEz9 jnm7BVTuvFXUBgHNXrKA4rGTJpjz3e9U6DG9ONZa0x0OlWvbF2D9rChWqLtcBiPpTI97 W1yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=EY20sgin; 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 os8si6318806ejb.57.2019.05.22.12.12.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:12:04 -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=EY20sgin; 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]:49867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWeh-0006YV-5X for patch@linaro.org; Wed, 22 May 2019 15:12:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOt-00086f-5x for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWC7-00080s-5L for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:32 -0400 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]:42439) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWC7-00080m-11 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:31 -0400 Received: by mail-yw1-xc41.google.com with SMTP id s5so1236491ywd.9 for ; Wed, 22 May 2019 11:42: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 :mime-version:content-transfer-encoding; bh=i3KWRWimQh5hv++1F1wzio+dP9yFcGqKmqdoYeXPACQ=; b=EY20sginGSANyyQGWpVnz88xzaVI8p1N/CE5IO6cvsAohKVfSeLPJnUf2AwbrLFGJ+ 2rJNjlxwswchdn05UCtFM+of1bthCMjgAkfX7jiQWv+RbapxPopt2g/OXtaRCPzcQtZx u6SFCqWVYHv9HaxUzVvOXoX8JX8vL/P/61/EPpEql+GYO3XIFfjW8RzeRVfjFEFVOlUS v/g/2AJHg3SK7HSeYYevEgRmHAmtSzlwgp8NNYajLxtxeyoTTM/Wshd/Txs38Mwl6nf3 t6Zon2ZhyVca6yuRJApDQ9PyZWCZT0WITOgOYT+akJ8eDDyAy0b5DZZeA4mMeV91fdun mmZw== 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=i3KWRWimQh5hv++1F1wzio+dP9yFcGqKmqdoYeXPACQ=; b=grSVbW0nrl6lfQIlLbVHClOchKLCdcKPOxhAjScRZzh2bUQn9/dhMTqj0K3RrfceIz Miot5zEIgVwh1rEwHN3tM+QWQ8lTFnpCdhSvVo4CVRWA/U4JyJlsQNFlyXx7AMEa3m/m lv1ilkjeoLEGRvu0y8n9/VKUr6svnCSFDw7P+fcDcFehmaDmJ1Dpol1Y6xB+Xz+eg3XA 9zWJ/dVziQwtfTEfwWroM/6xTksd5vP3eaatYHToZJrVuqcUXho3+GJR0gjVWef4K1gl WeHKzkq3JEfhFJtjTdKBRq0fcnQcQdl3YFglQU3KQYISnDQMeBDuxE+RH8vr30J4r3hz TyHQ== X-Gm-Message-State: APjAAAXtZ586Gvq7zoxSxlhZaLM88hCC4fP4DZDxIBlA++xm9/IFVTib M5dbRUnjX/nsDFxsRtO+FrO36lTldwQ= X-Received: by 2002:a0d:c707:: with SMTP id j7mr40724434ywd.250.1558550550226; Wed, 22 May 2019 11:42:30 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:03 -0400 Message-Id: <20190522184226.17871-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c41 Subject: [Qemu-devel] [PULL 02/25] build: Link user-only with crypto random number objects 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@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For user-only, we require only the random number bits of the crypto subsystem. Rename crypto-aes-obj-y to crypto-user-obj-y, and add the random number objects, plus init.o to handle any extra stuff the crypto library requires. Move the crypto libraries from libs_softmmu and libs_tools to LIBS, so that they are universally used. Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- Makefile | 4 ++-- Makefile.objs | 2 +- Makefile.target | 4 ++-- configure | 9 +++------ crypto/Makefile.objs | 11 ++++++----- 5 files changed, 14 insertions(+), 16 deletions(-) -- 2.17.1 diff --git a/Makefile b/Makefile index 155f066a20..3dbe82a9e4 100644 --- a/Makefile +++ b/Makefile @@ -412,7 +412,7 @@ dummy := $(call unnest-vars,, \ block-obj-y \ block-obj-m \ crypto-obj-y \ - crypto-aes-obj-y \ + crypto-user-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -486,7 +486,7 @@ subdir-slirp: .git-submodule-status $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp BUILD_DIR="$(BUILD_DIR)/slirp" CC="$(CC)" AR="$(AR)" LD="$(LD)" RANLIB="$(RANLIB)" CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(LDFLAGS)") $(SUBDIR_RULES): libqemuutil.a $(common-obj-y) \ - $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) + $(qom-obj-y) $(crypto-user-obj-$(CONFIG_USER_ONLY)) ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) # Only keep -O and -g cflags diff --git a/Makefile.objs b/Makefile.objs index 2b0793ecc9..dcba4429c8 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -25,7 +25,7 @@ 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/ +crypto-user-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 fdbe7c89f4..4ef4ce5996 100644 --- a/Makefile.target +++ b/Makefile.target @@ -180,7 +180,7 @@ dummy := $(call unnest-vars,.., \ block-obj-m \ chardev-obj-y \ crypto-obj-y \ - crypto-aes-obj-y \ + crypto-user-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -189,7 +189,7 @@ 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_USER_ONLY) += $(crypto-user-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y) diff --git a/configure b/configure index 571dd94ee2..54fa78c4dc 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..7fe2fa9da2 100644 --- a/crypto/Makefile.objs +++ b/crypto/Makefile.objs @@ -19,9 +19,10 @@ crypto-obj-y += tlscredspsk.o crypto-obj-y += tlscredsx509.o crypto-obj-y += tlssession.o crypto-obj-y += secret.o -crypto-obj-$(CONFIG_GCRYPT) += random-gcrypt.o -crypto-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o -crypto-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o +crypto-rng-obj-$(CONFIG_GCRYPT) += random-gcrypt.o +crypto-rng-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o +crypto-rng-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o +crypto-obj-y += $(crypto-rng-obj-y) crypto-obj-y += pbkdf.o crypto-obj-$(CONFIG_NETTLE) += pbkdf-nettle.o crypto-obj-$(if $(CONFIG_NETTLE),n,$(CONFIG_GCRYPT)) += pbkdf-gcrypt.o @@ -35,7 +36,7 @@ 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 +# Let the userspace emulators avoid linking stuff they won't use. +crypto-user-obj-y = aes.o $(crypto-rng-obj-y) init.o stub-obj-y += pbkdf-stub.o From patchwork Wed May 22 18:42:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164885 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1254164ili; Wed, 22 May 2019 12:28:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+VE0JOEwxJWJg8BP79sQ2sC71pOoSfCczsT5NkryjKAWXdf9Lz3QyMgFQit6X8dJ2wiEE X-Received: by 2002:a50:b68b:: with SMTP id d11mr91772171ede.42.1558553323888; Wed, 22 May 2019 12:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558553323; cv=none; d=google.com; s=arc-20160816; b=hldqrFyFCeWrh/t+iH3fOsWgpna9Xx0Yhf5nvVeVOsf/3vg9LwDwW6kfbBJyMfrdQl GgpaZnQ4lyPZ8i+ItwTwjSjxJnR8UkYTMLHRvS+YNgA8b1iL5qPwjbf55xJ3yXAQo+IC cDs3f6XOYe94W9Dpgs7XyUn55ZdOk1anh2sYjzzJjDaO1TIgugF+BVKbIl3uGETH7bSH jysKjMevmta6lavHmFQFw7DcQ08PT6HViLLeflk2qrzgTsWKId7oqOoBNfpIZrFH44v2 FDLnAim5XsGlZfIRNvNY0/ns545qzWRmTKiqYp7A10Sk0HjZojqyDw40Z+cfPSbwDyw0 r/Qg== 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=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=bo735OSxFE828NpSjVcXceC5VQkMn/wo0pzFwWOQFT7qmMDQBQJqYpSdQorOKqnMxi pkYid4EvOhF0TXu5V+iATiOJk/nsKtOJTWbhdPaW3Id8tbBU1HhZw82Q4E9cCquPQ8m6 4hWBw6WDyQa278Ej3AgYQPx1d29qSYw8eFOWo9UQCoRRANcjfedssqnS/3SGu/Zx0593 A86SsIeSxai/7W2hPCpsifAQZYQrpQqtm3uTe09od8jIqvX46p83frqiNcSrh8rHhyWz smR+Upqo5hmcmATW4KYeIXZKb/4YMIDKbVe0cfaqprbX3HXpPP97H/uMFPlQhy8C8WaY 8k9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WqoBSRUT; 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 n5si3172492edn.356.2019.05.22.12.28.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:28: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=WqoBSRUT; 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]:50142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWuo-00046d-KG for patch@linaro.org; Wed, 22 May 2019 15:28:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOr-0008P8-BW for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWC8-00081S-Eh for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:33 -0400 Received: from mail-yw1-xc29.google.com ([2607:f8b0:4864:20::c29]:35728) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWC8-00081D-8o for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:32 -0400 Received: by mail-yw1-xc29.google.com with SMTP id k128so1247876ywf.2 for ; Wed, 22 May 2019 11:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=WqoBSRUTTGnpLM+sdJxTl9/3hxQssulEWF+W79mNBvMYMqcWZuIYbo0rmAqiUMlwOG 79hIZG9TUAIpN6S3PVWHtrEuAmgmnNzdaQhfYBmURM2ZAtKtfEuf9bFu8DpK/MBNpiM5 d9nzvej5A+Dk/WKjDK2Us/E5OkQZZIaY5VcQ2R+m1O9rhH//DmRk10OBTXmEVFq/r/vI gTKDDOXRiSR85+1nRpqC324Zr1b92Umjv986mx52tcPnf6vV4khqYNyiyLuj8Ug8VglR zAFS1DrYn9xpmLn3zo1zua5BcjuCmbo5CJJuPhM/LfEHNZuDIIKUSl6b+CoYcrhcFYcj ED7Q== 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=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=TyYVEsMboPyieAIQNWz8uMynB7ltamqjOhoMbT8w1AXomvObdzIkX/IExSZfJyqn0h pBbgiW5s+t98WJqhincv2Rir2UsCdkMLteCjdAk5W25EtIpXtJNQKvN8EMhzrPbHiDcN 0uj4YXWupfjzpKS9lbK57x5WXr+umtPxRu6WKVhhtZ3Uy1ukH+lBK3tvXJIbN2WcwDmj wtGRgKTAm4g/ZFJLqnsd0A29wFUZb+Vd0Ylys1P/kOqGJJQJtWC0VVW3Ag55lbLNhvlJ n0azSefn4Sls15e4+52osfjuEhfDAReTARcOZiSh/aZ2ZiuqFyFeK9xdJ24I8oegM651 S3Mg== X-Gm-Message-State: APjAAAV6+wjbirf2bagGl2hmmEZ7sVO9dMDYk7w9bkMh1VLJCkk7kyEk uKVPSDd7A5IEADqgVb65XAkg/knQ2Cc= X-Received: by 2002:a81:b84:: with SMTP id 126mr41880660ywl.257.1558550551317; Wed, 22 May 2019 11:42:31 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:04 -0400 Message-Id: <20190522184226.17871-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c29 Subject: [Qemu-devel] [PULL 03/25] 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: , Cc: peter.maydell@linaro.org 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 Wed May 22 18:42:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164886 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1255699ili; Wed, 22 May 2019 12:30:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJXkILsUwI7etglbrAuas4YseUJKW/4TNu5d9sLLOvS7Hb7CKhqn7XKy4LT0x9FOV27S5S X-Received: by 2002:a17:906:9609:: with SMTP id s9mr20150165ejx.35.1558553429281; Wed, 22 May 2019 12:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558553429; cv=none; d=google.com; s=arc-20160816; b=EUJzDaLYOJzGyxXSJ2D6OLHKW5JnXGu3u6I2f00zyh3Cjo+d23T6+Auaibgn0akq4D 095UDGQXYWUirEJrgEykkGMNCsBy3VErCIcuGIQ8ShUesPX7KudnbVf6AxxJFLp/dmtg THiz28wiGCGCkLBqBMns9Y5Refxq04iie+47eejyzLXtGPpiqLmfgBiriSd4bfoBrp7k X3P3l8G7+4lELSQxMejzqlxY6s9wf1xfLe8IvzMv89277xI0gkhXO949sYk3YU++n5Kt ZJU59SZcwcnK0iP+rFfsHXaQOpvgBvLUzsD9FY+bgg2a3ZxoKUIJsim/IloeDHkTTkzi b/xw== 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=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=Ct2XdYUsevvBPN9ERxFvwqmQKSUq+4G8hBX5sxmF4ZVZiIeOqcJtjmnsWvZbda6Zl2 WcHzcUSMPLMMSpf3kKpr1DzM6JFmwEJgPj1MM74iHvyrdqihJDzJ6fpHpXpatg5zcdEG Sxdqix34V52P5vkeHaOC9xsxhHQAyPlsTn8slbAFOuyU0VvVwz5PWPAMfwPs2sTZ2ogH n1cZyyY6oJp9SUPz6ne/GircuG/RFUEOzT2xIdxSTmkNufxZSYS7mWB6xByyTjMkC2o+ KCmzr+tfYYm30B4mYs99jOVTBbrFRJjuFEKZCxijTx0dOD/NfQTjczyy0wHBX/71hh7a o+OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=C2fXkltt; 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 6si2278115edu.147.2019.05.22.12.30.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:30:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=C2fXkltt; 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]:50188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWwV-0005Od-Uv for patch@linaro.org; Wed, 22 May 2019 15:30:27 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOr-00086d-Be for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWC9-00082C-II for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:34 -0400 Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]:33820) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWC9-00081c-CR for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:33 -0400 Received: by mail-yb1-xb43.google.com with SMTP id v78so1266115ybv.1 for ; Wed, 22 May 2019 11:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=C2fXklttaFB55rJ9U5Po24wtMKgUXJCFBv8eyRy82xHDen3Y67tB6R0FHjz+XIxhMf TVbBFlEUBGn1mwgOeIZL/Z5mWUeY6SXf3L2gSVrD2L4Gnp0/1Icf6W1+MExagrXiN/12 wU/NZ1W3Cc4ROgH8/iDeGkNrbYnZGzpRk49VISUf52ZbwxMuN0MZPTaFQFbZ1rxLi+DY XCrAIpwqUveEhfbZ/Oh9p/7EgU1UYTCUzQHAZGlkFvYKEj/MPZrnncqxTvn2/pPKEHks 5ZvNIjd5vcVHdRoyHQo9RB9bXUAnemWYvxIXTqQLn961ErKS79Sju/WZyruO9q3UaUK3 7sUA== 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=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=lEq42MIfoHqVnkhYviWu2BdIcbJrzk548BHCuxxRYEPMqhcB4kLrmiORDmYw3J3Uxp hbezfEl+xoIspqnCT9WtcyK0+Q2E+zsW5EHjuh4z14SARclsZZL57SYWiuTDgKqspsQC 6r24atuvEjciKoyQhvTwVBulwwG38J0yH/4l+nQ21ak/5Cf72WN2c2o4raYzMPGUa5xY xf/ed1sykS4yXRjtPbry+CtH2C4HM4PehgsfKWPZRqgjeKQI2WxgzJLiOmCbl/D16RjI Iz+YOMVlPwTdNvamqsNxxsh4t8mcn5UAvhbJthAE1AYY4mq7s9obK+NPz59E1T0NklfF 3dNQ== X-Gm-Message-State: APjAAAUgKOZU0xZscQUDRXzqWtIMnuila7MbAzKRWYqpDpy3T0vO1ESZ efMhX5awJpmM1CsczcG4vSbuekcBkEs= X-Received: by 2002:a25:ef10:: with SMTP id g16mr10101072ybd.510.1558550552342; Wed, 22 May 2019 11:42:32 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:05 -0400 Message-Id: <20190522184226.17871-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b43 Subject: [Qemu-devel] [PULL 04/25] 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: , Cc: peter.maydell@linaro.org 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 --- 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 Wed May 22 18:42:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164867 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1237499ili; Wed, 22 May 2019 12:12:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzGM0pt1E9znVWeWAUR+jeGdrGe5s6nLqXTWYdJnDgx0cpojDa3tvKkWR4DRacrVOkTlf9 X-Received: by 2002:a17:906:7e57:: with SMTP id z23mr41653224ejr.62.1558552320608; Wed, 22 May 2019 12:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552320; cv=none; d=google.com; s=arc-20160816; b=qm5yCxOfGViWCjSKGG53UUJUAZR9z4iAUOjuQlf2klKsdFzvk5W/3LZPSHs2vW+Jky pjMsvAvzl8mmZYqNoPLnDm6jaBoZTMszyfq648+uF6qAl7qn6KWsxxW8M1TPy7SXP8AG tRkK2aOKvz4PGRxHEtiCYReZjawMrhsA9USSVQOQRJLs17evpOgTdXBzKXvaGuuCc8xV hT91ZhA+ZaA1dUkHu+A8zIgog921+JUwjErZcROsXVy38FC1Lo5jeON4MC7LydLNgJxp gfB9U2+IM54/CvX6Fws0n4NT9QdeP7jTMQi9h8fyTSxesWKcPgjkKbL5BSPBkenqrzgf 5NgQ== 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=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=dx8gNNmuMIEpFhNjiJQdPAyGQ6XRJB7vnXhxdjovM6bwLuquibU6B5U5FiIIEXwxf0 NJsPe/pECw42aS5y0D9VtGz4lrL3AMKHJGe/FWdyxcjrcs4dCQ80Ym4QjupW/gTh95df ac/zaURcxoNWjRqSRDNoyyekPpetulNq5r1bF7UmMrGtjwihbxwH0Mgh3tVXU9W7cAHO rQzdJYk5We4+mGR8Qw2Yb4yzr1cLVDMcWWl6rY9Ns6H8vQFqXTo7DrzLbfuuIeRb5HSP KCNEEATORvN94a3dr1n3bNZKtv+zYuFO1aDClvvzsWZKCnJnbMhXyxFeoj3xGbkbK1Ld ERjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=OBFpmPi9; 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 a47si5251135edd.409.2019.05.22.12.12.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:12:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=OBFpmPi9; 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]:49865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWed-0006VO-I3 for patch@linaro.org; Wed, 22 May 2019 15:11:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOr-0008Lh-Ag for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCA-00082m-GE for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:35 -0400 Received: from mail-yb1-xb41.google.com ([2607:f8b0:4864:20::b41]:44893) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCA-00082T-9q for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:34 -0400 Received: by mail-yb1-xb41.google.com with SMTP id x187so1239402ybc.11 for ; Wed, 22 May 2019 11:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=OBFpmPi9AWbdbtlYgTZidrE4QnXMu+xB9Qsjq6MUEiJotntcRpE6196p4t87OpGn+w tivMWHcZP1f/68eWfkTp0LXDzPcZJUyc09KvuhoG9+nyYzBW56wpJTlM6FJO9T2+0r4p FD+8m5+R4gaVVJ30i0UBAu1RGbdbEUErxX3b6QEPzX72VuARHtLrucetpKP3LpnXXOfj lZMnOJtEv17bB5VqpFK40bp9zNs7XONIKYOQKXB6NsMZM+6MJGC7Y+j8SC4vk6Yogrws zyRgs6+gEBExms0b+JgU5qHT1hV5Fx5HhS3j0Af+MhWUH8Xtp3tPv6Kx2CkdjK1tsQ/s RDKQ== 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=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=MnajBEt6gqhu4Fzxl5kO5YSoiNOzN4S4rmEZMqDOXkLwLs52CKFH8+SA8FQ1Un97y+ LsO9XpSzN2fCrLmPvKKcjM/YvEVqnn16nGSpYdwVXoTZiLspfNmz7fH8EcLgsVcsEwOD SIuzwa0cuZbSTw3qfxPGZ8Kixk4H3FNgR1PoKRUNm+IZjNkoQhDmrM/WtMzkxISDfvDo BqKFaDN2UnikFPE+RDqQ+8LjkXHVrNGf6MxdgwJI5SrL8l4U7c7plBCKWm0zspShYEOQ 2higDRMHC/Za5NHRmd2/8Bz31yaD1hVoDjOIcLW19iTTWDyuxGVtdR1O77hWMNcrUwyX Kwvg== X-Gm-Message-State: APjAAAVuYIqPWBjG59/+EWfRxaAfwlrSaZ8Qc0oKE/wjSM4oykWvW01+ Y4OzJMYQXSlfFy8Kg6KofCb+mLi+FSk= X-Received: by 2002:a25:abf3:: with SMTP id v106mr10653436ybi.123.1558550553422; Wed, 22 May 2019 11:42:33 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:06 -0400 Message-Id: <20190522184226.17871-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b41 Subject: [Qemu-devel] [PULL 05/25] 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: , Cc: peter.maydell@linaro.org 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 Wed May 22 18:42:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164880 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1250727ili; Wed, 22 May 2019 12:25:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRi2f1u9+qgleZQqXGIfMFXcPQB0KkD7SY8NlUCLK1n0W2ZYrj099IYfzMyMbxCH9H0wK8 X-Received: by 2002:a50:8808:: with SMTP id b8mr62869352edb.202.1558553101290; Wed, 22 May 2019 12:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558553101; cv=none; d=google.com; s=arc-20160816; b=ReEeSE1QDCor7Sj753PySYTiiZK9pQXCuw+ZDmX4svNtSZfyNmIuH5dyHiu6tEaccR D1N8hdDLvfZKPJtke6bcPM2llp3a2o6U1mZS9nm0b3s11VIlnu1BrxLUsbBxtmiEkrXi g9weJdP8XUX7gnoHkkTQIAuilj3sfBbYLi7HYUGHT4K+guwwcJ1QxsRvBAQl2rR74UaM ocdTxcxvPujkqEkUbT9C+xbTg3l/P0ENK7eq6xKH1tVIek5gjRSgcUFMyOO+pHuP/+VH 2JScwU6Y1HAV48URFLDJdiIxF/7iDC5s3qS8I+o81ByHti1TokfYo+Nxt1XuuND+EdtP 1dgA== 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=C5yUHyNINPBjASzQcl4pblPDsyyBX7i3Ae47r1N2nnw=; b=GBeSY1Ogs66L5BxJXE0aYxLP7XLy8+XZjDy3zrLJRzutVeI2yb4R7glXX7emnDuUgK /PJIZUJX4m4tFiHd9llRL7+5VEWV6u00KMq9i0uyDhK/9sAvAZ5H4MHTeHo+RZqxg8qP RJIaYeD2iV/gEYuqkQoF7Mb9hMCSgwQyrJNHHlCntdv+F7JJhgl3ww7PnvIC5qcJet9w ovbZYyp9QjCom+N8InVW4cEQoBh21V/1kO/2Eo+87KbQf5XSKNDAyVkNxEj2CpLqKsy8 nCBevViiRAMcrUtwaHXrg6SdNh2cl68XaLyH/LufR66Sc8/xzpoNL1q10v3FJcLbLyxQ eGxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MO9ov4iC; 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 g18si8327921ejw.9.2019.05.22.12.25.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:25: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=MO9ov4iC; 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]:50060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWrE-0000yZ-8K for patch@linaro.org; Wed, 22 May 2019 15:25:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOr-0008Ln-AP for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCB-00083L-Mj for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:37 -0400 Received: from mail-yw1-xc2d.google.com ([2607:f8b0:4864:20::c2d]:44154) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCB-000831-Fw for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:35 -0400 Received: by mail-yw1-xc2d.google.com with SMTP id e74so1231708ywe.11 for ; Wed, 22 May 2019 11:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C5yUHyNINPBjASzQcl4pblPDsyyBX7i3Ae47r1N2nnw=; b=MO9ov4iCjqTqWRSLRa+MMwhyhfNR8J5CBshBSM5RXUHwcsALhRWX98E3nGvBo9ftIR pzkUS6p6DRHN0OOGS1rjffopEnc3uPbHnrmQuZn/lu/HFcK6fdkKn1CP4lWTtvsP8ISb nDOn25cLJMB9WWompAIarJ8XnHwuxKggFDnkRCMmrz9o6q/hrToATasb3VxYRz8choc8 G4EYHNBIyQ+5f1oDNWsAjJAw6yt7vSijU6jmdEi6nvw7EtG8GWYC2zFkGICS9cXI4B2g UrmI9Hfn+0F0aUZyE2ZndPZuAlhuDw2twcABIgo3wWssj/BsoPyW3kVr3dXMBtks+Yay y45g== 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=C5yUHyNINPBjASzQcl4pblPDsyyBX7i3Ae47r1N2nnw=; b=rD2uCK3OSdzIw0PggGYZl6yH0MzY2QeFmrx2P62X9i2rP5N+4STxmgGZvk1NV2cj3n Lw/0tHkqnPN/ECYponP+xSfs2iKun/WTg5LDS74ib0xi8wA9UBwHg+ckY3H916+/uEDu jgrc0VNFkTj0O+pPX82pReUF20R8di2s4LuD5fljxTbyjYVFg+P693X1CEch/lcP62jy /u6lOQCsI2UlvcVuot/VjmFe0hn1e+51LeWRvP1dxjGUGHVJMW2NOCQSAh1jWl37oWus TGc5j9kxQEaGd0xDfl2W030W45riGc+sTVluwv5HxVa3dbpkxXbAXQ+z1uz2/DfveTIJ 1/dg== X-Gm-Message-State: APjAAAXLpiFCsIPk4EbPZ20BtzHwc1A1lVqNtIwpKZEeEdWuBc9zbeoT nZqIwf+tGNi7uBeAN7fV3HwJewJ6JCI= X-Received: by 2002:a81:7246:: with SMTP id n67mr15937514ywc.423.1558550554455; Wed, 22 May 2019 11:42:34 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:07 -0400 Message-Id: <20190522184226.17871-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c2d Subject: [Qemu-devel] [PULL 06/25] 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: , Cc: peter.maydell@linaro.org 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 --- 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 54fa78c4dc..f3526a5bca 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 @@ -7204,7 +7218,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 Wed May 22 18:42:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164878 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1248498ili; Wed, 22 May 2019 12:22:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxn3Qi/z/IZ/L9qpmwPsPQRrWJAEVtdL9hCwjtfKc+BDm7xUgayYlEtOKdskRgSzeNmibwG X-Received: by 2002:a17:906:118b:: with SMTP id n11mr27695905eja.291.1558552963202; Wed, 22 May 2019 12:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552963; cv=none; d=google.com; s=arc-20160816; b=OfrySn1T70h0Fe7tt0LtCwf+y4vzOFJEjik5PcyPVDkIHYj2FKUm6rfen3ijGusqla Es/2yzMcC6oOG8OGwz9m6qBZ0lRlGp1keB82gEQPwp6CfysQt+uuIYs/QFp2filjJpvd KYXRZFaugAy6dLFCg0qG0kb6sRcsFnll2nSbOD879J3EGDrtQvUmtDLH0hnK5eDzjbvY 7+cQ8ebiW0U1FgPlhVLWbxFfyQRF3xstPUVr2X0/wZ016MiIewpDFohBtLkGln6ugsxi K3W/7EOSNuvU+OdpBkmKj9b0n0yWAyHpmZ/LpEl4iN1feokTRRHGM9gfG1cgFUbVCFGx wNKQ== 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=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=VFR5w4bRXw17sWOCjM7weKx/zF2Twt/AYZIgW1L9qs7iAJpBt0n/cOnyGxlXyua2CD Y2dU+GFIZjKxor4YrePpLywczZEB/xsqHaRMYk3dX1H8R9bAIY9z4WpeuPWoPFtUno+C U3FGvKZ52PR/Ssrm+u3yLnk7gEQk9LiR62dmSxSd24hMU7vKfMqu1ucBjyOMOcHQPV2I tk6JNmuu5tpUTbJ73IZ7WQthgHyapAaVQik3CpF2oUSL9wSMU+UeXG7ujF4ZKctQ8BRG TMht7YebP0843Fp6pTsJGkglBwcbtf07u//Jpey9Vbh+nYmkEmioHlN/KwEnE8njf77u p/MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=AdtUsywC; 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 s3si7221990ejq.40.2019.05.22.12.22.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:22: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=AdtUsywC; 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]:50038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWp0-0007gF-4s for patch@linaro.org; Wed, 22 May 2019 15:22:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOr-0008Eq-8a for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCE-00084L-3I for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:39 -0400 Received: from mail-yb1-xb2b.google.com ([2607:f8b0:4864:20::b2b]:45668) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCD-00083b-Uk for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:38 -0400 Received: by mail-yb1-xb2b.google.com with SMTP id e128so1238772ybc.12 for ; Wed, 22 May 2019 11:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=AdtUsywCFarbxNYqrewX5Po7UVveY81UBDxGa+6hX7qZjmyAQLpmsOAIiQ+/l3OcWo UzJ5vyffFccwB1+HbqZkdmX64Gn7T5DSajnAayzDOYi/MTcC9r3PH7QdlhsXPC+BRPa6 30wvqhT4MXq2lPg/bVrNscj+fQzZy2pnMs2z4Sz/wpfObmwKh0HLeJMqSX55bkwtGe1/ S7mdAtvoZ03aAunGwKwzTPl1CHvFAQSE31/gKOFBf1vTHwU2cxvShhoL0LGy9j/H+uLx 640Ie3MZPeX7OBCTElgC9CKlqo0CVRCawbszF4VRPubRIIcvP/uQiKm0W8dN28RRfyay KNaA== 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=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=q/D2I5C+CB7TT//syXKuQMP+OV6CR06f6Es1COEeLbRj70O2u9IpItukWKvE9MQcUZ /UJm+RlgloulytVk1ELn1x+V+jcFwixsrXjQUYwsPT8E9RcPqIBLOMTjIdSDzhB7sDng UlNFiTW1tP6CAB67PIR/IbvNwN7fmo48aKK0ygJcb47wS0G1mTklWItYp36erD7EMiGy FSf+oLxTiquhzVqp8U5nDTA2bigSltGiFwdjLk08ywK6D3j5/PWoY20ofg2Wu/w7LFMR pytkbO9T/GLhuJJgzfKAH8RO2dJhxPXvKV4qXuvz1Iq14Ck5u56K7Tz8jwuxKNB5nuQl 5fJw== X-Gm-Message-State: APjAAAU+0enkcwNSOFQqqpZerC7Ktr2xZF78e3HgWFq6N3zWeLK5+1/Z 3M4IBLlNbwWhJfmms7l8wyg/SsEee4M= X-Received: by 2002:a25:4041:: with SMTP id n62mr2455760yba.388.1558550555780; Wed, 22 May 2019 11:42:35 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:08 -0400 Message-Id: <20190522184226.17871-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b2b Subject: [Qemu-devel] [PULL 07/25] 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: , Cc: peter.maydell@linaro.org 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 Wed May 22 18:42:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164881 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1251411ili; Wed, 22 May 2019 12:25:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDdy5XktZqEBZknmiJSWD8sZZY8nXPGcVpQzJsDrK1yPDSYhj/E6Amb9y8NQqEcopY6LBW X-Received: by 2002:a17:906:a94c:: with SMTP id hh12mr20911885ejb.143.1558553152479; Wed, 22 May 2019 12:25:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558553152; cv=none; d=google.com; s=arc-20160816; b=ulKwZ6TB1JI8yp/HlLufKz4p/0G5WiVz0PtZzm/tmGWfIV6EbTkLlngl0hPQ22uTaw gzLsmv/2bD369RXL1t9VTl5jTK1rg1q1N4D5m4rCy3aorYfDZJH1/rUJCA9CPO7jyDK1 0UKjS4LqopVggZrIAOamnyQ7R2vi7TT/S4OXaKGW07Ybz3GEVn9EKvczr3Oyr0r1/j27 vlqXTimEjThdJhqEdMuP01jHihMJu/DA3GmGFqLjFhHTuYPLh3D8zD+0OnVGMgphkmyM Jp+jSXmKSTla5PaKmBi4fFgCnPbwdHLhgg/ddXVYQ8nBhJZdCY45/OtZfrBeeGz4Sy4P 3S0g== 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=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=l2z7mq/sowiXZ4T9MunbhDcnt50u5kTax3oBDt9HAyjsSSH3WIjO8bLqwBOeok1eD0 ujR7Mc+mxTfldhKBEMQvVETqG32Ls9WTltKVrxredi77ellCdoROg0sbdXReSk8XckiS MNiwfBHPEwM1th20DCjn8mdwHUEjy6dLsBjAKIFchnx9DfqmPtcqPV5pQTImbwEU5irm iAFBBnxjstHM1GvA1xqf0LIeeichRf7dxa8QDjtOKaG96Q3bYpG+qIGav1ev8YPvcJX6 OYxysYzlDO/3wUODUfxQTVP6bb/SruAnL5oBqXBPHOyFrC2B3WBqieZVz89Fq17zVS5i eKGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=buz8zzBW; 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 g4si6153978ejw.305.2019.05.22.12.25.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:25:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=buz8zzBW; 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]:50100 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWs3-0001yS-AX for patch@linaro.org; Wed, 22 May 2019 15:25:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOr-0008Ga-9t for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCE-00084h-NJ for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:39 -0400 Received: from mail-yw1-xc42.google.com ([2607:f8b0:4864:20::c42]:44705) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCE-00084B-3Y for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:38 -0400 Received: by mail-yw1-xc42.google.com with SMTP id e74so1231751ywe.11 for ; Wed, 22 May 2019 11:42:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=buz8zzBW8+fGmmxjgk6pFxcVeQ8mDCKNmPovFUaM5dBh/03FFMZjutDleauPoWTv/h mXNxnUnWPNz5+cVELkiJIume8PzXHMBxXFzV64XzAbeh/zWa5AIpQZv+g+8lTgsLV/Gi 5Fmb+blYFCyvDeiYLS3DVPGNB+E13l185tUTd+OZec6mij4suQ+JLUp8H84RRmWIDOYm j1Wef8H501WCFHlOyUeb5XQCizrHz/0wphr5Gxvk08qWPKM8dXYsJp9F7MNAm4hBE5iq nouCjgqzMxg6L+5BElqCvwHuvZH12nB0ZWp2IuZS2EyHXJjgKps2e2qCioX7oKoHQBJl 1ejQ== 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=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=MTXNrx1wqW//qUi7fzgyfPxY/HdlLlSw6Uo3Y9+YRor57Xa1IJ+ASrAqgKcGwD7jAi aM2eMTxKvMLYNHAfeEomhCPFbp6Hr1UcIEQoYUYGrP7EUrOdqYc/U8pKFFRyV0EDmcp0 e5EOaYUMkXJ08HgQCKg+FN+obMNjPcPMdgPwB++aSInujdBOG4w7XSIPxflNqw16Wij4 ehgCFAApDaW2lfMNnutAQabBIV04X3OswIHZoSHLfohQwTWCOrasQUFHYwoWJb8YlqAP knHqQElH5kosnGtQ+RsqLEuMmNTuqAg1X2VHvjKspBmOH5A6kIzfZw+zvPsKLztd7MEd iy/g== X-Gm-Message-State: APjAAAWqi6DvMslHa4By23f0eZNXcElNbJ1m5/cysITlLPFveCglA/Fw NoTMm6PUVZrMOT7K/f/bwv3a2ELxOFk= X-Received: by 2002:a0d:e584:: with SMTP id o126mr25630935ywe.81.1558550557014; Wed, 22 May 2019 11:42:37 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:09 -0400 Message-Id: <20190522184226.17871-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c42 Subject: [Qemu-devel] [PULL 08/25] 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: , Cc: peter.maydell@linaro.org 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 Wed May 22 18:42:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164866 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1234319ili; Wed, 22 May 2019 12:08:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1l6w8QHm9JGVn0BSyN0x0Vls0Kkx+LSRnZ8ti+m1PUbk13Yjgg/OvYJGbxPwy4BVKIxGY X-Received: by 2002:a17:906:b250:: with SMTP id ce16mr59385065ejb.99.1558552125020; Wed, 22 May 2019 12:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552125; cv=none; d=google.com; s=arc-20160816; b=cYcOSwoy4B4pu1xLnhPjkQa6BaKSyI3AqtC38xNmf1XINkm2f+n1mkjLvgpS26MCR5 I8dRA/kaYKAL+bxrpPMgTvSIuOVPtqgkRM7TNN+OsK+fN3xbeB7JOlUfJCQIQhtV310m GJqOBeFCuThLyQZ6I8Li1pOpeYowT9Awbh3HoqDUBj/mo4Q1CO5rFQNaTa54/AiiRoU9 AVk1BdfYn4IE9JjCrFXUAYSbOPoCzlhKTuTWErDVkGcVYqjajtJMgErJSQKTX9XtHAGq 0vRlgwAgUJ5ZPf2RMKJ8lUtCil2y/7///YMzxIt31vCD0U/xXsQgFYPhqfRucIK5bk1p 2bSg== 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=DHS+azgDjOz9872pwx2wjM+spw3T8bEncaHuHvbQJSc=; b=XZ8RTKXIiwIclbBvMCB3TQrTZ041TneUAFznp3KKWGzwl/CABawREil6f1u2W67idr ELzJl4WLQXAbV6wCA/IhJitKoHjVMyXS9A3NumbonWi7BLKfaL9je+X2R6HD/nXEJ5u5 TJXkzcB3G5Gj0BgcsjR4vE7cBztXDgle0+8O/iIfv8OwqxAyBy1ZEZCHcpLhliEZ3Y9F iuua5YRHBFFpm17H9mZ8t+xG//5qGN8QmqQ4epLEDhSxiEofiif+ugGHsBzcWky0DRcX wYNCYClQJI8NmVBRhYodE9K6HQiGeyVxJdx1BCyReiq7dmLs9Rt9IYW/jyYJwB1WfrLR kxSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mPRksRww; 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 r28si12717551eda.140.2019.05.22.12.08.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:08: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=mPRksRww; 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]:49810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWbT-00044t-Tc for patch@linaro.org; Wed, 22 May 2019 15:08:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOp-0008P8-TZ for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCG-00085H-1R for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:41 -0400 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]:43335) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCE-00084Z-Rk for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:39 -0400 Received: by mail-yb1-xb42.google.com with SMTP id n145so1243674ybg.10 for ; Wed, 22 May 2019 11:42:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DHS+azgDjOz9872pwx2wjM+spw3T8bEncaHuHvbQJSc=; b=mPRksRwwbN/3/077MRePyAeJDUS6P0OM8kpNYghC9BDh8iqyPbzDpUz7JyfVjKF2r5 PzO+ThcVIwNj4vkL+MISSptc13xDpdNrnH2Kk5xY7t6PsX1/Tdq+NzArtxpU+ZREwmOO avkBpZoy2WjVvfrc3sBnqDBrq/IYeXnX/7CF+VUbqx/v99zpLgoi7q6mQkeNa4FwvJe3 H/oV4yTJVwuPrWIAH9HMV4cqfTVDyVuVQ87KG9GpLqSLiS3Xl0VUmd4ppqayRC/mZbmE seTaha8kwb6oqvh0s753pOFFXw3cBz5Yu3n9gQe0VtrCyVokCIPawT8yycTe+COfw1Bo NzoQ== 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=DHS+azgDjOz9872pwx2wjM+spw3T8bEncaHuHvbQJSc=; b=Po3FnGmjc5GL919yeILDl2C1RbBHnA7KU8hpxDvsNhwuCpqWBmGde1jyI9r5lU/bCg FHEMW+WQI+t9UsgcwIl8bV1RUwDznNXjyPdRFujCP2txM/uwDeZS11W+n1gIxCZen2Hn 71Dm0ecSi1fVelz1GUKqsEnfYCWZIn364cb3RQ/DA94TrkVwZNzkOgf8SxbY7HbHBcOP qvSYlBhbOxvn8UUO9+1gsMuR2pMl9KI/SkyN1ES80L+cMNY1Po0hDqQ9Gix67np62Uld UJL7KoCn1aoDSx7W3JtX+J33V5W52g9O9Nz4eppZZ++zBJeG0bT3FalmHc3FetquOgJh W41g== X-Gm-Message-State: APjAAAVWLJ4KhKY+ih1P066gnANICVEQiW19SlGf3jahUeTJCW98c/Mz AWyQJ2UpOFi+KIu674enXKnkeAjXcwU= X-Received: by 2002:a25:b18e:: with SMTP id h14mr8631012ybj.18.1558550557978; Wed, 22 May 2019 11:42:37 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:10 -0400 Message-Id: <20190522184226.17871-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b42 Subject: [Qemu-devel] [PULL 09/25] ui/vnc: Use gcrypto_random_bytes for start_auth_vnc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org 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 --- 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 Wed May 22 18:42:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164877 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1245992ili; Wed, 22 May 2019 12:20:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHt8EU7ARFuLYMEwmbNPZ/hlyGqsmoAkrAUd2fBsEgY7/ldTzvz4MQfVsxrm+ZR0lZyx9A X-Received: by 2002:a17:906:6857:: with SMTP id a23mr64919061ejs.280.1558552813079; Wed, 22 May 2019 12:20:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552813; cv=none; d=google.com; s=arc-20160816; b=BS2tJLY+hEk23ZzDrRwbwxhHw/laWDpd5otqx9P7+3ZdIxv8JvgJPsLnM5Xk9pAJ1P dfatJRu5oMpTbuwbr4brUqNHQryeb4ut8SNhjeLZgyiSZe0n6VRl30HLfbxTmqe1BoTu BBF5wBF87CdNbwDPP+WlReJtQXf8J5nG4ht3ZuDSvYa29DZ0pSdxeBI5roielkcCPeJ6 m8VFQ47FATsuj3uhoUVcNuFmldrTXg6ps+FzBRFYPZtPwrm6Qwg3QRgKrqusCohxznGE fRMmwOmZxykEAxO/PTIdmrm9U/MSgKa/OffQPdKPzxDO+NMjHvS43zZaspcfWZofFA1V LFCQ== 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=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=e7WyYOaZ48GzHt3MwtTcprlHJOe1bMPTSt8DtpWYvT6MDCUIfbV74My0wLrhJjsfTT 5hbTGKAl3fs18CF1MqbhN/vhXiUB78OuhwWPuQhBjX1IZuko2f6eFeLRtA0Czip6UYtk SpjvEn/x8IAElAJ5/MptWlAixQCSdC8anvjU6+xt6WcOi+rEkDH41lwRWidZCImRZStJ bdflUBDQ9X/F5hlyGLPAY+9Ga3G9ZXjiXBJWytueUJHfr8gVvW3tpqbM83WYygh+lsrU oaUnH8SsdQxsZb8dCqZiWStFFL4yphPWQM9Dy/hxPLKybtpYX+CpdaX972PN+xcVIJL3 AfRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GWEK4DzL; 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 s32si16483860eda.374.2019.05.22.12.20.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:20:13 -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=GWEK4DzL; 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]:49987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWmZ-00055U-UF for patch@linaro.org; Wed, 22 May 2019 15:20:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOp-00086f-Ql for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCH-00085r-QZ for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:43 -0400 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]:42440) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCG-000850-E5 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:41 -0400 Received: by mail-yw1-xc41.google.com with SMTP id s5so1236681ywd.9 for ; Wed, 22 May 2019 11:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=GWEK4DzLuwRLDSn4ojJp4HgoMS+aCUenx69mtZ9UAPaDFezyZWQQE5toJEykcVwt51 yb4+JhiRiPn09WrsTsq2aWtMlgGY4FBKiCLJSzz2SLvJHn2Rf0GPqlM1cjmBGb2+iMrC KIdjat/vwGiLX012TEJuiRmUM1eFngZuPeCrGupstP30HL8sgMiHZB223TkR4RIR9GDz 2qDSnzaqbRy1eRE+TGFRjecjGlsFGLr+a36b7akQceZyPtXf63+9Ip3aMkAXLOeEBXqG BS12ksV8qubrTFk11ugxerh4VuScgAFE1e7U97RlaXCnZLS1O9NemwCi2AHONfYDC53+ 1sRA== 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=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=ApNiOvRAbDlc23/pVOAeH7An7yPMKh1QOWcDQJILtObseTKgFEKMCYS5SRwrCTkzgf bhwJWRsCMGr5KtrCzJce27r7GxuwbdZZVAem7D3pAQCZLSAVTQkqOqYiQ1U15qjdBMp4 HDI38dyFa9zzMhSYRTx/IN4ZlLCKxEBlhwaq2EmeC0RV3cHorix/NeDX3DHIl3N+PEkJ 9JVMyhB2YkGyKuhcBawH21yhxxSxTXvmowG3EzIZRmMNP3rfkJv80M0Qeh/HawlVAxDm qMs/INPtnMhID8SZWFsKOq5L2fq+ASDwLsQ+GH3vpZgx+rapepwxzTC4kIMcrRiIf2c3 RNBg== X-Gm-Message-State: APjAAAV8TyjnK4G2CSumobOArcS7FTKV3OuqpM4JUrnOyMTwGOi8QXWr Y7ulZxckEVL+r3rFmbaTY6heAzE27NM= X-Received: by 2002:a0d:eb90:: with SMTP id u138mr22470698ywe.196.1558550559046; Wed, 22 May 2019 11:42:39 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:11 -0400 Message-Id: <20190522184226.17871-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c41 Subject: [Qemu-devel] [PULL 10/25] 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: , Cc: peter.maydell@linaro.org 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 Wed May 22 18:42:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164876 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1245423ili; Wed, 22 May 2019 12:19:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDHgEN8r8LKQ3QgUQxSynEMXzMTMzDYbRZG6pO1GoQ2dti43dUPz17mH7qf1Mwy0iXFm9c X-Received: by 2002:a50:8e81:: with SMTP id w1mr91761253edw.271.1558552782891; Wed, 22 May 2019 12:19:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552782; cv=none; d=google.com; s=arc-20160816; b=s+kblIUb0oYGKijwogDU5r94EO24e7wtrPzrcfF6ir53VTZ2+tLV5Kvfu1xJIAKe1S NVPCze0CBhPGRG9wcwFx6XKBqsjz1tlu2lYHYPWe72Twt19W6U8rZ6QrggisonFuhVpr Q38eSlCsJSet4FQwmmjEgIPl9WTczDpALU3lqysdT9ZddnuamENgJ9x3i0gNhX0xU0jV rs2xcqnMWFIQc0ZqMEeRIrcJ4bpIHrpPwcN8zCTntBkGij/+yL9EQl1faO/AfYqcoSnG Ke9G9U4gqckGQWL/yYzjM/WLbW3U0Z/+1NlbuB1fQ2KPhCejsWtYh7DQ7x8b09yzWaGB wElg== 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=ooMVwgAp+U7g50/jmMWyVcKo6lX9ghcSSdE6Ahl0IEA=; b=REAWn2TAS08tOGaEOyElAzgGUmHZmI2EdPkiJvJiunnpxUJdPGIhZ++8MHtSgGU4pJ aHBo6Vkho6VfB7bXRkrRII66kwPxpk1K38Mdax3kEKDhpWjl98g7r2BY1NBx+q0vFm45 bWzqZEH5mpSYP21536b9RL6LZ7UQ4QwnYGd9Jvagt5FAog8FUdGuYGFcYf+9+7jjt0Vm 5krbHV/fI+xDTosRPAMZVihilOZU+ohYcTGyv/gnU2uT/r1wCscEIrmE2OkJ5Z0k2H/Q lSRYSmVGjnvYYgiln5jW+83ThnuEzNZYJXGwhkGFnc06/Cg9SdvGFs/MEjCoig0YLZ36 pylQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Al34NMFF; 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 b56si7461337edc.450.2019.05.22.12.19.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:19: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=Al34NMFF; 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]:49981 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWm5-00051K-OS for patch@linaro.org; Wed, 22 May 2019 15:19:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOp-0008Lh-J4 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCJ-00086c-Ok for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:45 -0400 Received: from mail-yb1-xb44.google.com ([2607:f8b0:4864:20::b44]:45287) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCH-00085b-QA for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:41 -0400 Received: by mail-yb1-xb44.google.com with SMTP id e128so1238846ybc.12 for ; Wed, 22 May 2019 11:42:40 -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=ooMVwgAp+U7g50/jmMWyVcKo6lX9ghcSSdE6Ahl0IEA=; b=Al34NMFFwEg5EiVi2K6FEftXDJw4RmI3y58uV7JjVoeXT2YQzGaA7a2sI8uHT1Ufab U2oeO515vhz01R8i+RXsiywWmqInSvMYEr9Tit10iSzdDgc94MbrDHL+XikJ2SAb+hlh 2CPBsFB5vjp+QvMc3C4DLB9l9llXgBXCD/EVmAEe3phGSPIXX4flxGM8sZKFMW2Ig6qC czN43c+45twodRlBzvQ/0MS8nFHyYcY9q5rGCtcRmgo4IxZrrKT+CBwVcZx3d5bv4LIG M0p7m/sdKYWZ2ESbM0ozrzRDMxjL/BLTa8/EfCPbCXljYKg/JKHCcnhAl27Dt7rtFg7c HbWA== 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=ooMVwgAp+U7g50/jmMWyVcKo6lX9ghcSSdE6Ahl0IEA=; b=ueE+2qgoAh83Cf1K6q9KFzJyAUBrLtEbp6TlIA16N122ASdhdZ/7Vp3jqcAJeQFiAx ic/EzkaKR/Yesoqt6jAnPCyfSv0jIPmBfcNfUeGZdBBnT8EEJWvABCP10ypOKRMEhvhc zQ+W75PqFDV2VTWjXv/cA/zhWMoQGKmW+s8Ay+X2/rXYSGmKZClXQmTWTZRj3Y3fk1Gi lGZFyDXftEwaVnWI1BA7uDE0hlRC/FmRc36F8NdlbaDq1bcmo8rfB358lkMGN+NCe5Xc yeOLBanTUhKdL8dPQsV5jtROoviQYdqzABjCwYlVUDFSgOtZcb9AxhHvNXJ0YdyvA+F6 3AdA== X-Gm-Message-State: APjAAAV8ixJmhiqH8fK/bzaaPf3SH3x6gwxED8GauLv5pgMJVD2upB5q 07OvqwTVLnY/PbqzH+hEOAx4G0H5YkY= X-Received: by 2002:a5b:c8e:: with SMTP id i14mr5679911ybq.12.1558550560144; Wed, 22 May 2019 11:42:40 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:12 -0400 Message-Id: <20190522184226.17871-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b44 Subject: [Qemu-devel] [PULL 11/25] 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: , Cc: peter.maydell@linaro.org 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 32983f27c3..98e12d914c 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -375,6 +375,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 201144b162..5550bd7693 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 @@ -3349,6 +3350,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 5daa5a8fb0..7ae3373a00 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3641,6 +3641,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 Wed May 22 18:42:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164872 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1239437ili; Wed, 22 May 2019 12:13:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwEffhWtb8UjLGXsCSVZsbRLA7P9l2JjOnFmsREoA7AcSa4OeQ7UKnghztvdKa1QAWjr7J X-Received: by 2002:a17:906:6545:: with SMTP id u5mr20094215ejn.102.1558552432288; Wed, 22 May 2019 12:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552432; cv=none; d=google.com; s=arc-20160816; b=njkGFC7aDo/ehZtvkAa/IMktYY+Gx/B7dWeVGINloQgYA8Ec9JON1uQyLv60vexkme vTLRxCPXTlj/x2kR0oM3SdKE2ZZijXxgOsbtsqaNAbC/gcrCos5CMJB3heiXeEZfG0zm mlpKKt9f/t7nehMcBKtIaFo3pVOyseUOgaUrj5VCaSia1EJdmyTQQnTTrX+yF3b0eRcS 3apziMQOv3gci5O4i2vRF+Yyjfqwe2JqvntAl/kVByYhKgQXRStX3wzi6hArSMoqEva0 hiwPorTsqf/pm12nEfvoj/zS38EfxvNSUtE4rDDjRL1knF8Rlr6G4TFQdZZ7adKTXcyt 33Ug== 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=2ZOvSlCVstHsIxkY3rXu99Q7piqIwzQbJ9bkZ8lPHXs=; b=U68oisDPPMO/xFoOyV4e88JWFVrCucx9jp5zEkLEmI9DhoxGW49ypTnz2qCfIul6wf uSx8Uw9FFVOy11goNR+gtWd2IGrYD4Bh+Y7XKmbO5gg3B5VaNB+zn4YJTArjZcRj77uZ zx1gxToxmO/iNitKYJ7M7lI0Ov1sV96VUq97HT4RIbxUpa+xtay76wq6zGCG48CzUuty XJ0L+C57mPb6Xnlbopft+H5Am8SDSCyRd0ODqf1bct19HmJAScbVFWquETjw5ckslXpM hbQFaPt+d87DkWjPPsX2SYTPsWmTFbp4rNOO6MQD1Tsjmb+zSYO66F4CztyXzXowDieQ Ed7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vNQKJAXQ; 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 o5si4421281ejh.34.2019.05.22.12.13.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:13:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vNQKJAXQ; 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]:49887 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWgR-0007br-3A for patch@linaro.org; Wed, 22 May 2019 15:13:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOp-00086d-7L for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCJ-000872-U9 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:45 -0400 Received: from mail-yw1-xc44.google.com ([2607:f8b0:4864:20::c44]:41715) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCJ-00085w-PR for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:43 -0400 Received: by mail-yw1-xc44.google.com with SMTP id o65so1240637ywd.8 for ; Wed, 22 May 2019 11:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2ZOvSlCVstHsIxkY3rXu99Q7piqIwzQbJ9bkZ8lPHXs=; b=vNQKJAXQml5IIJRBkmHYQ+UeFXIUV8TEpCEEKufTkfAsYrCezZrlQQ7OyRa1ywZUzM DULL2P7etXtYfwO7wxNAeWIhNqoBx8xw5ADTYEMnOCGjetRckZ+wCLI5Br6CO+8cVSTH od6/2OafJLl6h3ALRkMVK8+LRH4z0KxRuGdCRat1DWIhWHv9VpJhUY7e9OAVtrqYNDXW CiSeYCggnbilXbk5l20ia7okflcyv2w+V4+8aQKAp/2unbX2XX4Yc8+T5IdMWUZPvri5 r8rQpEk2qSitgCvMmrma/w13tBWHJgTgiYKCAxJLO8g5jmDbjJPaSAqOVYRZIVAc6qkr Cu4Q== 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=2ZOvSlCVstHsIxkY3rXu99Q7piqIwzQbJ9bkZ8lPHXs=; b=T3o9tkhOKEkFN/mA96wTIbUQe4jQ9Q0RgNPvhrcu0NQmgAYuBxA/VgTh8Jaao5ULus jAiJJiekExUPfcwXounSTKWyBJQKqWIjvqE6sI3X3f/BZbbde3pebD5HDN3CkihrYF0c 0nWJArEbv8agDe98og4xU0GKdfDnjmQ+ROgmANnga1vjhpqrhqWGVuuKoUpbBEUcQ6Ko 9SP6ZY71tZETuB12N92rBjjUG2mFy9yCqtXrzq7dh22/fXell2RcV9eZx8CDBBqbi0MI YvK+ilqKJZwZapDO/fIyaQZlRtHNky3kmSMlFz8VW4PlvVNhYD83EoXMPrz50jutrLI4 j1tA== X-Gm-Message-State: APjAAAXG8JV5EhXqZTE//gyrNzQa7UOz7IQEpbvOKoVl1wkH6oTaeab6 dvUy2b0EuipygzueXVsZCrOAFO93fKQ= X-Received: by 2002:a81:9294:: with SMTP id j142mr15313237ywg.157.1558550561235; Wed, 22 May 2019 11:42:41 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:13 -0400 Message-Id: <20190522184226.17871-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c44 Subject: [Qemu-devel] [PULL 12/25] 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: peter.maydell@linaro.org 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. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 30 +++++++++++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 22 insertions(+), 11 deletions(-) -- 2.17.1 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 efa3ec2837..f3ea9cac21 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -107,6 +107,7 @@ #include "uname.h" #include "qemu.h" +#include "qemu/guest-random.h" #include "fd-trans.h" #ifndef CLONE_IO @@ -5482,6 +5483,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. */ @@ -5568,6 +5570,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 Wed May 22 18:42:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164862 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1230861ili; Wed, 22 May 2019 12:05:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+t5Tk2VnksW4Hlr8tDfI4nW1Oexrnh/hkixKZ8SkMgUao9O8eLPzG52iHQXP02HESivgH X-Received: by 2002:a17:906:abd9:: with SMTP id kq25mr56209464ejb.30.1558551936290; Wed, 22 May 2019 12:05:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558551936; cv=none; d=google.com; s=arc-20160816; b=DWlbJC0efGvcD/W1obnTuCg1gM+LlvJEfRSSlBgSMkAfxpsQoHoJ/86rTlI0AtzC5f eTx2VydGqMZma+BluoBJamDVBw671jj9ybbDG6U+yx2xTPbNbwAcXGDRPXhKLuFjdMKq mKfQAPI3eWzs7K47kU8qBF28GImyiUhT193L4H3orZibqrtEpuG0HaooskwRlMJzOgK0 A/nIoT2rq1gbo3D/8O5Tw6WC6rtk2L0c6N7qt8lmwjnOzKdQV8kdB3KcozmHA77hnon9 5ns+5N/MOUCgIvC1qhcG5SbRa7TCyVjST0sxHix6wZ4Ix2ccTwQ958Kf2d0b66nFFnQk xWkg== 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=XXhAPtYvtMlhkNiiH6cZEQQTlmdpOKHdKg1FRFOG4Is=; b=oCL7q4sR1DGeZC9C1IC/SL/eKKLF+tbNRJ4jo1RKPQpA2Xkb4LyOeJK46ynKlR9lyj KdM0CHUbAwY3zi3sKumSHFy4qp7TAa7W/78TYjZKm5VUzahlNkWJSoSwgxsVYSTZQRKQ LUZlpX6NVt07xg0DOye4XTRqd6auCQ8f6wylu+a4CSM7UuSscKEOLbN1GmMI8NrCfTED cqdgg89LTGU2w4VnO2GteuE/m8rIyC1HuhiPf7t10Jy7BR6WBPVcKAZJRsccrP4hX5cf /Mx9FUI1KDJYMpKAbBkrpnoVEVI2JLVVmO4o3llX0uxjC9DuLZa8QOKXaIqsO3h/WKRx zXxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dvoJpqts; 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 e36si2304942ede.438.2019.05.22.12.05.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:05:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dvoJpqts; 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]:49782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWYR-0001JT-8W for patch@linaro.org; Wed, 22 May 2019 15:05:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOp-0008Ln-6q for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCJ-00086w-TM for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:45 -0400 Received: from mail-yb1-xb41.google.com ([2607:f8b0:4864:20::b41]:38879) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCJ-00086K-P4 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:43 -0400 Received: by mail-yb1-xb41.google.com with SMTP id x7so1256969ybg.5 for ; Wed, 22 May 2019 11:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XXhAPtYvtMlhkNiiH6cZEQQTlmdpOKHdKg1FRFOG4Is=; b=dvoJpqtsvIHw/G5jCKu4zDmr94LIm25PGcgVGME+GVWJJwUFHZbmE0WZVi5vWE2hJr bJMpWvPhU+X1OBBmyx4dL0/kONrpGaHE4IpoQDC5DzVAB8Q7MVOOXRSPLNUtIGoPIS9x 2TdKAdFxIFt2hySoIodgi3W5s+3ce3tb5GZJhXAz2eQG9+l6VPzF07sFnzxpZUC9TVQx upow7mqruQfrvfcO/+DEfUEvxSJTjNbsFQV5r3+uZFvLSM2cgWWwmdiwt46bvXHDByeY zEd6WRFBcig6J/8REHZ6ksDHji0r/8aiKS5ZQuVkfNi9uNXRvThGIyAxhHe4oqv/Hmsg r1lg== 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=XXhAPtYvtMlhkNiiH6cZEQQTlmdpOKHdKg1FRFOG4Is=; b=D4eoxiDKNauOcUyDouDupJ9Us3rtzaCeJTYvqG0BIRwjFFl4hMMMijhRQC9yfsWJ7M OwYncX+aCroE2P2fMcxTJmF+OcMcP8nnUb8FV8/GTsiLDHLqM036G4veiPuxJIwFZSOq leanezmPvnIBauqJfkTL0yBmwRHTaMaEniQBw1yYmSIOyKFLg8niZwenI2JmkG95e65S OhQFlkTXM4OkOAWEqdQUtRjNnuWlNb3ZTIbkTWcOC2xRwiEDHwsn3BJL6kMTuKZPH3sp m+wYnbPZHQ/+DkuOHEKsiWTpstosTmgV5SfmXyLt3cdpBQn1/LeoFi+uLhYWZFkfYoCZ AxDg== X-Gm-Message-State: APjAAAUQIv8gaZf10lUpC3wZljasMqxYVVRKOyHqPHsRwk7awAPhX+o/ 6jKCXhG/lfblyPTh1W1/EtEW0SNDOj8= X-Received: by 2002:a25:8109:: with SMTP id o9mr11702248ybk.132.1558550562385; Wed, 22 May 2019 11:42:42 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:14 -0400 Message-Id: <20190522184226.17871-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b41 Subject: [Qemu-devel] [PULL 13/25] 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" When not using -seed, we will use the crypto subsystem for random numbers. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index 7e704845c0..66c909a1a6 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,26 @@ 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 { + 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 Wed May 22 18:42:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164859 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1223046ili; Wed, 22 May 2019 11:59:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUiMPtrIij3yUG7YJfos9+uFlnuqfvRV4wQ7WbXjQrO3fSS88PFWnIMOu2HGY3vrgBgI2w X-Received: by 2002:a17:906:31d4:: with SMTP id f20mr30384579ejf.275.1558551540457; Wed, 22 May 2019 11:59:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558551540; cv=none; d=google.com; s=arc-20160816; b=PCHrhqmCFQSqclZcpe+cIbqvn18IAL2kVtK+SZtysrJcUdjMxO2V8DyyNCflEbou9p KX0csjzp0QZ8E5F6haVqZyWE5ilp5+cPP0idc6bpVIUpg3u5MLuiY4oQvEIsMLky/Zf3 /5K3PKWvs1U0Ko8taH/f9dx3BSuzmsiJJsEd6GNEJQBKTfk/tl7ygQUofCXXGoUlo5iz dVQcVJGpdpy2hHH+GzlQp/VvVzxgoXs86nXXhRCYnShGQA9L1Vc+De4glvdBMFvClY4g iCj8Iumg7/srML06/mIT6uDrPWu2/mLpUDVUYYbH4IUlJmhisQARwQlqhNyFUMpOW2CX aqFg== 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=LA1zmsYxmzBAEiSSaTbYsFeqnklh9uk6Ygv0EHqOLtQ=; b=D2pjtEv9BU9+/+t8K8oK+NYAtp4KmXnhaZIsuKeC6pa8rMjO3xMYAB5FY2m4FJDjL2 X99oJ/TzsDI5EmD+kZcQhKcRLOcc29o3YiIRwoRt+rzKWOsIu5piwfVNNaZjjpuY0XD5 W91Wko2J1Z0LpGvCHddjWO//IGR9YnAvaydlfDJC95XzWwqtpoVCEt650OTf9fxKqTw9 8o+GrOpqiMOl3aF28lT9BdOIzNHPYw297dRfNbZjo1ZyXIuiYJPrGsGfjWtB8FxIF4SD 4HwAEKAVdNiuOQYPLnIqizMi9qOrOLrizhJU0HZkrIa2P/BUiunl6avQAQlRglhpXIO8 fb8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wlPqZaOb; 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 x22si15668051edx.1.2019.05.22.11.59.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 11:59:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wlPqZaOb; 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]:49667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWS3-0002z3-CH for patch@linaro.org; Wed, 22 May 2019 14:58:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOo-0008Eq-TQ for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCL-00087x-Rv for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:47 -0400 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]:39835) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCK-000879-61 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:45 -0400 Received: by mail-yb1-xb42.google.com with SMTP id a3so1256401ybr.6 for ; Wed, 22 May 2019 11:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LA1zmsYxmzBAEiSSaTbYsFeqnklh9uk6Ygv0EHqOLtQ=; b=wlPqZaOb4ijRuE3yZISM8x6gUnqRkZE2hXEFLBmosSPC4Sc6e8SlftA3Gxpay2eFzt 2ZHnDRIwfk+IgqhK2Q0Art2CCvn5AyryHoloPKjpOgkxNGEVNvwfiPyHUYI14k1l4zzM Iz1O3itt/XXnj863xOesyE+WxpmYGC7H1JiPOHQzxkVL+ZGJzGSl+Oiw0I/RyaziphQh c2qsAT0Ucd3mMkF3FaX869tLLn9q0Xw3v5N3QdEzwYz8oOPNX7jMGSZm2dP7npMMh+7G lSU2/BVLVYtjhET4vedF1/9SeO6P8JgtDqqsu/q0jm5y7bGZVWuZYs61YNqaCr+xX1jM i5Mw== 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=LA1zmsYxmzBAEiSSaTbYsFeqnklh9uk6Ygv0EHqOLtQ=; b=e7q6aa3kV+v94R67+xfzI0GPEABQ7b0LFL9Xk9XJz3mCQ2IhOdpat6kN8fTOuj2sF7 RrkaBnlhxqVqkz3E2Xc/aO3jGbJPo2O5F8619t7EaXvVUt9Sq6jD/Tk6xnXaHCCHrZhT DfOABkplF1Zz1dWcXIr3rXP1WS5DN8da8VGcNDsJi0kPpLMSLAouRYzCuVrgIeMi5ca4 bWvOY9ADqpYSd59Q1yEj/mBLSxfovB2ekTQkYaJBQr9itQ/2HBHXt0HhlcCUaNQczzpS ydGTnnKJrdjtGvsgGH5HLvYGBtDDmtFwbrUsEGcPb82fTwNn2jZEMlarGwj56MYNH1pO RQ8A== X-Gm-Message-State: APjAAAWV9L/zQXMPB/6B5QQg7o/uAI+dR9fRTzxHscVM8TFn1C9riEhM EwTGFrKXWVQzLznUUJgaYftBjjdv/A8= X-Received: by 2002:a25:2d42:: with SMTP id s2mr16062056ybe.476.1558550563421; Wed, 22 May 2019 11:42:43 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:15 -0400 Message-Id: <20190522184226.17871-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b42 Subject: [Qemu-devel] [PULL 14/25] linux-user: Use qemu_guest_getrandom_nofail for AT_RANDOM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org 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 ef42e02d82..1e06b908b7 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 Wed May 22 18:42:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164874 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1243987ili; Wed, 22 May 2019 12:18:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+4nus1l0SZsJZAXsFvTxUbT55GOmRAaDce4+d0rVqzI+L0rmy9wmRDH4X+jDdZ1Wgf4X6 X-Received: by 2002:a50:b56a:: with SMTP id z39mr91987240edd.91.1558552697018; Wed, 22 May 2019 12:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552697; cv=none; d=google.com; s=arc-20160816; b=P4PZPIWY7w8I7NgmFxfXwJMKqC7LTPP5i4k88nrXvi8MiBQ3Q2cM6q/udrIWfrhYyf jva3oAY28VpgYXvxf9sSJ3bIUfxuaMomLIks/lTm3LsOxTZHG8FzqxFKOqeEL7Xf4wmb +BzDLJQu53bQx7K5GnviHTqX/Hi482Ddrfkv254jGsQtf/Jt0p6JX3KlFtBoq3A/4o48 HY1tl2fWrVGXKfW/xYhPvOlKRQkGfgY8fLi2L2c3NAsvH0z1zEZDWqr6EmE7yY/q9ITp 9dOjEDceCxowiJbu9C6iJGfGASONcy5cVzNkLJVz4wbUt2NjpwGKQcFvablygvJbLueE fkGQ== 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=e2SNlmxHFtsdM0b0itsXkBL9sAk67p5UPbLq4CDfjKQ=; b=B9PFjWbTEBidsbLPDZGWtTrOCpy1UYJ//fvmvSC48fFkY/dRgdxCLNPJPuwZGDy6FI juUazvwTZktwj+7RBhoLw3msJj3uc4D9OsgCIs7px4AobU5mJd2kWLZC9/dvIguIoP4q McGKSvg4CfcKcdYkpH8uYDqvFLqdgY1m8BGOXtYlKIDD4JtL4qCp8hIPWi4JdUjl56Bz GX4aXq5xqCBvxijfk8Ib1r2e+iU1TsqeuYF+PgvgVBaQz//w+iKlH6BnYpRe5hx4n2yA zUySQI74EFIFh70O78WdbJO4fx/AD6tZX/YHZ1YuE+Hd/C6yCq/wDvJX2Jy9r/UPcehD G2QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nAmWZDxB; 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 s53si6691800eda.46.2019.05.22.12.18.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:18:17 -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=nAmWZDxB; 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]:49967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWkh-0003bJ-S5 for patch@linaro.org; Wed, 22 May 2019 15:18:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOo-00086f-DR for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCN-00089H-SX for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:49 -0400 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]:46556) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCN-00087Q-26 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:47 -0400 Received: by mail-yw1-xc43.google.com with SMTP id a130so1226205ywe.13 for ; Wed, 22 May 2019 11:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e2SNlmxHFtsdM0b0itsXkBL9sAk67p5UPbLq4CDfjKQ=; b=nAmWZDxBw1LBKfn1t5DLJXcQyC1eJezA6t27t6jn6XshhMWmiUp9BUU/7eG8JDku6h AUk4ejyCNobPPEgPhuNIALlf8Arf9CS+DLsTB+JlCZEqeFbZu7V2zj6OzvEujqeFsbHU 5nr5lxRPYIdSSCHEs8wsNEwUn7V2bq/vrTf2SjmDxGubRnsTbBrovjCtBOjcDjtlK0ZP HZ/ve94BmBU3Vo+oyOv9bo+IO5gBNh8YsrnZUXyir6qWc58snKQCNseAH+AFBZP64vRI wLb9pdGUaisrCP2y8w9z9772GtZHZaUbou2L9Ywc18np6jHXdKg0ebOmTa6SLz6WPz2w Ps3A== 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=e2SNlmxHFtsdM0b0itsXkBL9sAk67p5UPbLq4CDfjKQ=; b=pmZ7AXyvcm55p9Msyf4SxrsO/TmO812eahAjaC9KON0tXt3iMRygu2Hu7SeWsfXfem ZBulJ0nLaaeooKcZs3RZ6nFdVu/XfdWz9xk+QzvdQQeeE/cTfmJ+tGhET20OY1VsuTGo EiiGX9f5iCa12/2vaqj3vb7Y1p/+S4gAdqVLs6fRPrXhR8FmDugWkbBUnNsr/ITIMCrZ Q/Iqb75evHR7UmhDlvANto8mzYVyGIF+QEc7/ifOtTH9elXChWbh8kyziim6Aaudqp8n qQ0OVcMGxuPy86OighrIg7Cl0KFF49rxPxDzztJ4CO7QLWBYJ41SEClfmIM2PPVWyihu 6J4Q== X-Gm-Message-State: APjAAAWtWvcNCT8vjj4nGAgplCq5qxh6ObX561lrBbxUwuY2apY2maLb oAA4fEccUToaTRxRq1tOP2yw6pxvh1Y= X-Received: by 2002:a81:6a03:: with SMTP id f3mr28238704ywc.169.1558550564394; Wed, 22 May 2019 11:42:44 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:16 -0400 Message-Id: <20190522184226.17871-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c43 Subject: [Qemu-devel] [PULL 15/25] linux-user/aarch64: Use qemu_guest_getrandom for PAUTH keys X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org 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 f3ea9cac21..72e43b517a 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -108,6 +108,7 @@ #include "qemu.h" #include "qemu/guest-random.h" +#include "qapi/error.h" #include "fd-trans.h" #ifndef CLONE_IO @@ -9765,25 +9766,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 Wed May 22 18:42:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164875 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1244711ili; Wed, 22 May 2019 12:18:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeIUkZow/1VXmejH1SDGxBDjV68eNbryyIgaVfXvgYMx4vs7pbS4j9t2gA0MwnYSwFgOtQ X-Received: by 2002:a50:95b0:: with SMTP id w45mr92755524eda.221.1558552738622; Wed, 22 May 2019 12:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552738; cv=none; d=google.com; s=arc-20160816; b=UdfcDrypN1Ws+f230XVShWjhajRp0by1uljgy217Lh/WhIoVTyAsEFal08BOomQQ6v Y71mXBdzjeAFmuTArd9AUkmjW9Ayi5W0RBugttKgvcHMXYHj+sHG5CygQI2p8Dp870Z7 EF9BuuUoNZKf0IwQKP7q4V2L+N63F/mw+7McZmOEXYgeTEo21FKkgq0gBRKjXuNsCAFK F1e8Yc2AX+poYptwrk3RcWG0Jb3hOb2gDbv9+5IxA8WoyMgRPbSiIx5guCVHjj8YZZUx cnTxqv7G22HvpenvuNu0Wx+NyNMtKeevOg3Tqu1w1P9BeEl2S4KloDrtqRTVe1wkwxAM Zn7w== 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=cAffAFBxa4y/VVbarNUiRFSP9To260Z9zDP/Ls36OfI=; b=UQ11n8SAI+EK6fKsue4LdlAJuUUxuhlltetc/T6IPNgAalLtDL1XiInT3p0EFy9b1/ 5rEhX7mdt4JPXEXQtSRJEIIUXh7uZjQVfREkES8N1nWkEzjQggC1QOWFy02u62kXI1HI mnmnxEZ5PPJRDwrLrifBgb/rNX0w08yMrZE2hoMd4mGw0KzamG7hnAtntP+xhG3aOi2Y nQionNS8czxCXJ0YaAY9jJYZBlx3wf6dsEQKTcv2+kGIx2xdJyFR/iWZClOoedMnpdwh KjdbTKNUiG9MQTKAjM+4jnc0cyA8h1sUQIgxC6ZgjEKn0iHGpBVThcoVsVfxTG7MBddB r4wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aFbsH48F; 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 m18si6496741edm.173.2019.05.22.12.18.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:18:58 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aFbsH48F; 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]:49969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWlN-0003gE-Gj for patch@linaro.org; Wed, 22 May 2019 15:18:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOo-0008P8-Oe for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCN-00089P-Uy for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:49 -0400 Received: from mail-yw1-xc2f.google.com ([2607:f8b0:4864:20::c2f]:35734) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCN-00088A-PY for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:47 -0400 Received: by mail-yw1-xc2f.google.com with SMTP id k128so1248154ywf.2 for ; Wed, 22 May 2019 11:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cAffAFBxa4y/VVbarNUiRFSP9To260Z9zDP/Ls36OfI=; b=aFbsH48F39Xybci721A/f/XujFCOPwXRHQJY0y83RsgL3CsRY7y4Bx5W3NWKKmdiVE 7JaMgeXYGtwj1ue/MlqLlofh/eyF7gyc6z2jnPl2mtzHJB0Z4DQh98S9iqRHM/dYcINP JZVXM+YykQwCEap5W59L4mlv3bHTP7Lh8WbfVir/o+nGvNyIRFMJulCbS1wba9DUFJVZ EB3uryMoGvrUmUGarf7Kec+z8V86Z65zkc3/rmplPZyI3o0LGEoo+bK7P91hvwk13Pjj RnQ7D9SB94vC2arWx0AiOjKHMH3G/W0M+vzDEYhf+y7y6bbj1GMMDDcM4UCG9UhoCedk lp5Q== 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=cAffAFBxa4y/VVbarNUiRFSP9To260Z9zDP/Ls36OfI=; b=HvZ/UmBcRyp95HvExuGZpTu48HuCBRfUZS0Psf5WYziJ1njrvLA60Tj67IR6VWbSMh c+Rkn8M8p/7xZuhcwtYch0qNbzpBs5/VydeTrNTkcRDt+JP5/gRJsvnOY95VIB0UeAqS KvdhLHv5QPo7A24DoELIeL7HvAkUxPrhmnc5udVbAtGOzTt2GoLuYxvGob3+Kto3xjmc 5yXiy5Pf+3sVhVtXmuQ6lvvO5mt914t7hUYN14eTwFWyEUC+6BbubnstpkhseLr0LkvG mHGtQdM6M5xeyOVoNuRoSUcxNyh0zaQespAAXV1pFRUdzIS+TL1euymrSY6JH8+kMW21 SCOg== X-Gm-Message-State: APjAAAX+A+dXpuHlOn1IFNwbfFyiH2+m0mvhGKGwrKnmHKPWy/QkwwqF f3uHvtnZddTwFsQM9SvIVEZz1Bsbnxk= X-Received: by 2002:a0d:dbc1:: with SMTP id d184mr18034660ywe.18.1558550565413; Wed, 22 May 2019 11:42:45 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:17 -0400 Message-Id: <20190522184226.17871-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c2f Subject: [Qemu-devel] [PULL 16/25] 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We no longer use rand() within linux-user. Reviewed-by: 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 diff --git a/linux-user/main.c b/linux-user/main.c index 66c909a1a6..689bcf436d 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 { qcrypto_init(&err); From patchwork Wed May 22 18:42:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164879 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1249527ili; Wed, 22 May 2019 12:23:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwW7h/OoFwT+hSLUIayRGLwy8+5XClx+4nCl67oO06u9+gApUgYX5W9gPIfxQF0WNQRmQk6 X-Received: by 2002:aa7:d1d1:: with SMTP id g17mr93080233edp.19.1558553021875; Wed, 22 May 2019 12:23:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558553021; cv=none; d=google.com; s=arc-20160816; b=NQxzP849YXClEBygQ0obKskV5GvjbPS7ok5BZ0tQvzNW8YOcqRu045mNdG6wDvRuz9 90nYX0fpHNj5x6PxDTnMYomrFc3aDTdTDqiKTaKhNZe44bp3dBOYXnXuPZMjXo2YY0FO rTF81gn9XErq7czwwDGLjEebDo2p7aLZFGf2o7+2H69tRpLZaRe5/vuHij1CBuzq7hLy QjSwOVaxFPhCzKryHMLx1iBKczgyiwc2ZiI0FmCSA0Y+yCHDN65XrL4LX9L7cL1NRi2f DyifMpvCeFCrriApzttaSZzo6EJ7xH4Rsc9iRA/zu/OmS2K0tt5Tn8kNEqohNt0uSVMu 9Ieg== 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=gZNiNYQQXuA93bC9AkQ3RkBuv003My9kgUQccuqjr10=; b=jpXlXNY0x+M8BkY++1HPIyXcQVBkivpIqY1fuUmKmGkLl08HbFyS1ns2v+phQCsP8a sH5HhjW6lvLbOcLZTqULO9d3Ut8atMNuBjfNZNyZsQr3eGoSx5HRkrLvo8Y0FhyUKeBI AM7+GGCpYAVdNlxsuKm26uuUgXljy6NDHSTNj6fy9LxRk7p5bgYhzwxed6aHKzRBGBUM wzY7z5k27hE1ZmFilXpLcacHF7EV2IpgMhbInPRlqHhQ5MuzNlAysD4TY11cJ5+GeTYV lg1LwUaDfihEWAAmpl0iKSZ3rExFQ/z7c3/qfL8+408Ek+AeGcm3OypW6j3JFaBoH/6Z CSvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="B/PcVJ5J"; 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 d21si7826078edb.358.2019.05.22.12.23.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:23:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="B/PcVJ5J"; 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]:50048 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWpw-0000BY-Nt for patch@linaro.org; Wed, 22 May 2019 15:23:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOo-0008Ga-QJ for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCN-00089U-Vl for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:49 -0400 Received: from mail-yb1-xb44.google.com ([2607:f8b0:4864:20::b44]:35241) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCN-00088Q-Qi for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:47 -0400 Received: by mail-yb1-xb44.google.com with SMTP id s69so1085143ybi.2 for ; Wed, 22 May 2019 11:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gZNiNYQQXuA93bC9AkQ3RkBuv003My9kgUQccuqjr10=; b=B/PcVJ5JaoLFNLP3h/Y5MLrwQgrFOMJz4Nle0d731qT/PhTmK4OHsMjnEH3BY8zA+U xtiaTZU8swftv8jVV9AXxlY4xxMJEczk2CJf7s8VhSkRU4uuXxnUSE+8T7UaoBivxq2q RESa/ZuGE7xK+49GUAbv5u92GRVL+FS2ANCCHO2RrE62MRkGBsshub+9rINGYC1NmYEL iD2a0nrkNHO46kzsLqk+oNDdMIZdb0g1hGsSq6lsOBJCi2R07691mMRlg1ghxpkr5Vc5 FrwEfZUKQDUm9IMBq1Nc6fsPesZ/btYu8+MNq28dR0hx47T2rvYxDzPFLYEJXilqmrfe pRCg== 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=gZNiNYQQXuA93bC9AkQ3RkBuv003My9kgUQccuqjr10=; b=Rb7OjTBVOpljbu2yPJEsu8eJ07XUUZTrvk9YDioNNj91M9P2bM1ND3/F4YkmX5Qd2D xYVw9Y+EQu+FBBS/f9RCaWzvhkEFAUbJ2TdjlYaEFo1yyz4pDjrBLZ0JEzYQgRjHgoE4 c9NC43rwNWnlGdVutyO2HHAqa44IkOG5oYU549i8c8w/1gImyqCqLqOLo5cV5tZefHqf JXVdqkbfaaFvO478/ocwF+rGndI96NV4XJLbRXY9XnmwEXTZcSswBL20EI0TXiws71sg It7P9VyFbkK6QT0A9BdjksR78q0YtTKhhmlUtwSPtY8A4/7a0WUSuyEBjxJ52cKlkhfg 0MGg== X-Gm-Message-State: APjAAAXoMiBb9XmG92txaCoq9WAl+/ppAGab3ZPm+UOs14y4/0uF3cYS qgujCTMum7rv4BxoWEe9oRewHmXvSvo= X-Received: by 2002:a25:7502:: with SMTP id q2mr22098191ybc.31.1558550566459; Wed, 22 May 2019 11:42:46 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:18 -0400 Message-Id: <20190522184226.17871-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b44 Subject: [Qemu-devel] [PULL 17/25] 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: peter.maydell@linaro.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. 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 Wed May 22 18:42:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164864 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1231492ili; Wed, 22 May 2019 12:06:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzB8lhFlGcbwu82UjQRgWyXXXOeNbG/cyB7jPAyX5ckbKRUR73Bvzw7oP2EIDzb4fKjmVSZ X-Received: by 2002:a17:906:699:: with SMTP id u25mr35047687ejb.245.1558551970036; Wed, 22 May 2019 12:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558551970; cv=none; d=google.com; s=arc-20160816; b=g1Um7HyljGYjxccv9CacF+G2y51rlmr4lTFplA4/mjFOM7sgcLhJ8qJl7ZH2h2pzOR tNj5uYwgB6aX0+LqpICzU2w5kMLnCljo0GOwrzlyHDU0EuJ/mMK09yxPbYow0ao4cua9 cIeQ2Y84M7p8BG7yoF3sDfHx6ekt43DqohixBgmjoq2HaDrgteLmnbzYXczUoT1msIlb YQeDbNaisXKYNFW85Z/xPX+knkyWmBXlPxz7AWCb/eD751QaojbTGAU2N8oUcfBjzATx KH35YDMV3V55FZfQkf/5rL2NRKA/xAjSsJxAfSWCQmnnx5omBq5CL2EDjSLMpu3mLS1A OCSw== 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=zHL5/dOLNq3cxnvhnBPOBazkJM0pmZq+fc+P6w38V4s=; b=G2XnbLNnHqv1qkzorRaIRLlrNjWns+FDNl5fucuNDkJMfh2TnN1mOpioEAO87hj5cF crz1ZX7NTjnzFbhSLzq5wVoYCsEIw2avRZrEo74qqRPxbqdJTEI6Mej5NJbiPiR93Jxv rsdf3O58+nEGjbPmhVLCjla/biIbFgzIYnr7n0nBJLxg/d7QrSTwOOAwWS3uP3bNRIew qnJRxtapkyphacQJ/Ul6LID3P9hHcIQhZLgsTLupVjApBZiwxh1lKh3LLtjwuOdUP/+P xa8KPW4m5cXfhmoadbE4LxrcBX/ZRiaP9VodXKUEqtKoDcaQrrs5BZQ57G5pAC6F2Jtw u+Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="I/RgZIqw"; 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 w24si7555323ejf.95.2019.05.22.12.06.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:06: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="I/RgZIqw"; 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]:49792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWYy-0001St-Ty for patch@linaro.org; Wed, 22 May 2019 15:06:08 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOo-0008Lh-9x for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCQ-0008Al-0d for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:52 -0400 Received: from mail-yw1-xc44.google.com ([2607:f8b0:4864:20::c44]:39304) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCO-00089d-8E for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:49 -0400 Received: by mail-yw1-xc44.google.com with SMTP id w21so1241570ywd.6 for ; Wed, 22 May 2019 11:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zHL5/dOLNq3cxnvhnBPOBazkJM0pmZq+fc+P6w38V4s=; b=I/RgZIqw0PlT8WEjXXx/SNicpUQAAw/6516CBgMzR6eXFNR6Kf8kKEOfp8J/smmNnF NYg0VFjZqE7YnqcGyMrYeaQnIQQSZN2I3LKLyVTjSph6ojnD66TUsunKXwVF8FPcCcUf tvEjcIPRZ1kDI1WZXMFSb+v+lJ6HipC9sCtCrfKUT1nEJgrMjPhUuFpihrc3BnECxHFH f+JkEFKaF4AmwjWEw7LEaRZ6JCyWjlwPo8/QpZ993o1u8qpXE05I7p21HO02psxA9Ep0 Jz3OlFzAfnW2ITvFDk/sJTYDfgFPkJDc+nvrR+QciOjR5/6ahKWi20hdgF1n4Rrzfppr O+4Q== 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=zHL5/dOLNq3cxnvhnBPOBazkJM0pmZq+fc+P6w38V4s=; b=lza19VRpnh448KKodFXzc+exvfJkW+GpNfYeBkFipADzI6qVelrePMJR/QYzyDeobk hqTMBV+miOUxzgYBUTuadnKXOJrnXbB5GyimQIoedtaklsmKDRYL/pV7gLK0GhS9OoN4 h1bOG1PNuEF/MxQveDrn67XBaxNGrT1DYsYfm9GWYQM6l4bTMMHVi21NE+6RzvTCDMz9 W5zKI4/XLAZ5m5vHzhh1pJM4AtVZXn9362JVHrpgMpNs2n4vrJceB4EUkhWgBywIQjqh w7D5PBkCea1BCRkVvNvhCnb7hLHpb/5VvMwp4dOGaW8CST39ShNtugIJtrMpCxMFRZ2O rcXw== X-Gm-Message-State: APjAAAV8777qDC/K8trMZ2pyFUEmhbed5n3dq8FoUNZH/pYc4ZncSYP4 5FIzGEu99L+LStESm0CvfwCdz9zQ21c= X-Received: by 2002:a81:b717:: with SMTP id v23mr42621851ywh.120.1558550567474; Wed, 22 May 2019 11:42:47 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:19 -0400 Message-Id: <20190522184226.17871-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c44 Subject: [Qemu-devel] [PULL 18/25] 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: peter.maydell@linaro.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. 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 Wed May 22 18:42:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164861 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1227407ili; Wed, 22 May 2019 12:02:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZoLJh4Iif8uwe1SFlinO8TBem3rwVQ3gRPqwvGyL+03pTqzUG1p8+c4LsEWqph7n4lGsK X-Received: by 2002:a50:896b:: with SMTP id f40mr91804692edf.152.1558551762121; Wed, 22 May 2019 12:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558551762; cv=none; d=google.com; s=arc-20160816; b=LgsEQMbawv4NoHwMeNrZD+FGUTyv2xccUwtin8Pn7NzPEAo5v9/kux/sVVQh9LoGRn jlx3TkylSeFAVryfNgQ6bbmgpd41CMdqryPfEmSpxTadzbjCqcP5+lPs5WSoYd2tvs0N OEDqA5kehdOPRsuWcqHybY6qLNzlvo122kdVjGpZVPixu9hT7+sGgdiWrfxHct+EtuTr gqb67mlM5JuS05nrzPoi3Yqrfg8IWAr6OzT1UAt9lm408ZnLLCcB9unxJsFNAqr1enf5 hIrBBD9B6WYfTShd6Qm3tIjWxOHBQYHcnBuRCPcsqt5RWp528GKdWtQ2WVwplMmqWCgv z1Pg== 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=wKy5ep5gzBeVJvdgqxMAwC/EHW/NEI1i+sUaPM2vsGg=; b=xX5Sq/fnvJXk/U2dim12UrZgYGhHnb5zK0ie6tu19bUxzIM/zRqZnWQL+E9k6xBNrk bCwxrbJ+yBOXtGpzF6mPJjMeFW7k/PorDDZMej5+70zaWV7umDOcriFLvIDWIxx+/aZz 5L834v7Qi7Ht22ZVwyaw1d8nw3eJzk0Zc42XNBxTzlaW/4AranKbBf4COA7mOAmSrHaz rJXJFpdFxRBzy7JPZB49BkxaRvYWvj0zEivNLurz0u6BOztNhnUF8S47IMrST4nhbb1N 0WJh0VcChX8dgvKryUs4mB/sF4BY5s0/qOs+5+np7m5c7UvsTQFoetUoxK9sGLo7Jxb5 wd5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=D6Au61lO; 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 w11si7018034edc.148.2019.05.22.12.02.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:02: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=D6Au61lO; 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]:49737 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWVd-0007Vi-43 for patch@linaro.org; Wed, 22 May 2019 15:02:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOn-00086d-RV for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCQ-0008As-3b for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:52 -0400 Received: from mail-yw1-xc44.google.com ([2607:f8b0:4864:20::c44]:46557) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCP-0008AK-Tu for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:50 -0400 Received: by mail-yw1-xc44.google.com with SMTP id a130so1226271ywe.13 for ; Wed, 22 May 2019 11:42:49 -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=wKy5ep5gzBeVJvdgqxMAwC/EHW/NEI1i+sUaPM2vsGg=; b=D6Au61lOK217c6i5LElq05rVyQKQbmn2pNey3boFrtxtSEThXVHUu3ot12gV+CkRWd 6UQAxBzpWOy9ixwBm/LAaJy6zViddRGqqI7M1zAVESCGxT3sleVAvUkHfXM5nlrnr0UT JOyIyfv7O64xd7l8E+0RdOLxGYLWbUsx4NKle+UvNquTt+vIoOK8SYzauVVYYRAgOsvL cP9z+zQUd0HRe7AE+mCWDT5AY7OTWUd5leOoyBgFNa81UZtgmKKCgpr07GYE0+PNXKCe lbb/1cbsIb140iath7U2DEMxYpEXtidHLQEeWIX8/IZ/4PKV+qeRWRW+Pspbp4V2xRQn pl4Q== 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=wKy5ep5gzBeVJvdgqxMAwC/EHW/NEI1i+sUaPM2vsGg=; b=Qq7l+iZs2UxPf82rZbf38TgFIvcHkMHXJEYWuIOAPVM1H6iojjckq6IbHWa2blAuog ssCa2NWf4TTNWoSMd69c8rDRCbdXjtNSe693cD+9UnA/b1Hmrnj1f7PHoohs66LTtye3 ExHoaXwb09t59evxUXjBUCRHfK7832WiFNMX5pHW9q6WzhEgC5zQFRiv560D7WRVha2f nkOaxIIe1mha3IJ1Mu973H10KJyDttgZqMn9uy1wgRrqQbPml1jOFwaTTIDkWcrQp3MA EhCgygfVZopkBVuh+76mRqzsPxFHEVnY/rkB6doTT0qrO+wbwyKT+AlbGj+oJbzuSWa5 Z+Og== X-Gm-Message-State: APjAAAWhnRO9YL7DA8OaMQcaDjhvq00h1A3cAFqxTwxtniPesT7MAqs9 VmojBXabfW6JCptjPBf5uhkfg1WGA+U= X-Received: by 2002:a81:3c13:: with SMTP id j19mr24625854ywa.483.1558550568683; Wed, 22 May 2019 11:42:48 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:20 -0400 Message-Id: <20190522184226.17871-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c44 Subject: [Qemu-devel] [PULL 19/25] 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: peter.maydell@linaro.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. 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 Wed May 22 18:42:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164869 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1237582ili; Wed, 22 May 2019 12:12:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0UApSL0YBxnVqK0PbxIr9VNa/mzz9lEoDIwudJucDVMrx6ZQyMilxRZg0U3Zt+4BC2/V2 X-Received: by 2002:a50:b7bc:: with SMTP id h57mr76069108ede.77.1558552324986; Wed, 22 May 2019 12:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552324; cv=none; d=google.com; s=arc-20160816; b=TDwVYS9r+y+YRin1n8eXsM93v8slAB5ujyGOoHpHJ9TG7kAsPYSQ10HjkuFU6huAF4 f7k+AmMzlGIVYsGjxXEIcLiccFu8+FbEsD3hTWYp1zDYqT0lkefUJfVjrrk1yeArzXr0 9rPDl+P7KmyFkuo9zzvhLp4xlbd+bF1fzalS3NjM1HQ6qJz6Unk99LDnCrovHfa/xoaR FOcrh4jQnw9BbT4d9bVfvfinVqNG3BaiqjaaHKJbrBdp4t2dboXg/yeo6S1jVPLdIvkE jpm5n7QXHEU+V6mKVCJMGttI+UZOtKF6kLScgZNcN7nl8ZsyQXVbsT5N2HhLOvZjTBmX IQBw== 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=/VWGaUBQJcHRh8ZCol9Bt7n9p31zv9AWS8bL9WKxKYs=; b=ac+wz0gN1dppCKO1bbJ+hFYiEjK5moFuR+YblJcNnpx2ymeAxLXUIKMIPITlasfXvB 3g1NuYy/owMmwWJZ8Tg0RfQvvyR50O2f/kORylkkX0BgiOcB30QTS4W4LJs762B3up3i b6pvuZmpRc4CjYhY5kTRI989TWQTxx1xMcf0FtHjz7I92KPT+ZCYY8n646WTPpsds1Nz gO17sWhyC0nC4I0O0/cdUBDcrCCkd5ky1i5RxB4IQQ211hm61UGO5ehQFcnmK9ozQp2c rdy//ObnzkSCqLbUkV2OZGwP2HNStIrTEAypnWbiDvweBuZaQh3hmfJwwpliB3xPD2IE mxyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pIeas4e2; 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 k9si5042834ejp.58.2019.05.22.12.12.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:12:04 -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=pIeas4e2; 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]:49869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWeh-0006Yz-Oz for patch@linaro.org; Wed, 22 May 2019 15:12:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOn-0008Eq-Gw for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCU-0008CI-1u for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:54 -0400 Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]:32786) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCS-0008B2-1G for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:52 -0400 Received: by mail-yb1-xb43.google.com with SMTP id k128so1268603ybf.0 for ; Wed, 22 May 2019 11:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/VWGaUBQJcHRh8ZCol9Bt7n9p31zv9AWS8bL9WKxKYs=; b=pIeas4e2eGmoShylW72dz3I+fq499gQC5L5yzxJlyyc95qlsW42IE94fKa3YpY1u9V WCio4iCMHCRVIOsRLpq/f3OiIfkycpcFeT0mhBSu7t3l6saUO1KtaEpQDYDmlUj1Nw+M 1eASOtVyS0YSVV29yxiCs0ttGAS1CPQEZFM2Y+cMZ+yECIpAsoedS+SBsFz9UO2yWQJ3 B+pwbDpB2vna94DhRjPpGJpzT0CwIYWHXOAF8TMmttfU6cC5tUUHBzRBmCAcmXI/dPzb /8cviERkCdPeqq21PvFmno4zMSHPGMywPt5DGL5WLhVu3HrcCJpwsBvg7fvqVnBc62zv sduA== 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=/VWGaUBQJcHRh8ZCol9Bt7n9p31zv9AWS8bL9WKxKYs=; b=Qbqe3sGESU5hH0yitN6CycIhuvQHzJvvf1/VPm0/pUAZp72TGBzLKosW/D6uur7UPT LxiBzdtpzw/K3G/ipK+bKAvjavzerWWCA0fb7SnYafOatesMzmUZvDE8glPCpaDPw9LF ZF2HO9jVqg519t7HblzC88UgnvrZ48EBEV0o1xzBCCknmSObxej8JPelMWkPn6vqURze fr/oMMtlRmSUlVZLJrr+E3Wdr2sb5UEDTc3sJ7mRePakUnw1f57Km3cfBHHFaiIOcCVX guW/Mx/IaezjsVryTTsOi/4aciuFuRhrmhmfRA16olWt+kMVlYXyFGFpLdeIrrwVZ9K1 wseA== X-Gm-Message-State: APjAAAW4tRnQEgr3yN8YvvbGbuifw5ay2l9WbA7BYgtYqhRs5zUXWtbp IdJ8n8FSvLMqxMAHYm2uF3x/L061+CY= X-Received: by 2002:a25:3c9:: with SMTP id 192mr15663764ybd.223.1558550569701; Wed, 22 May 2019 11:42:49 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:21 -0400 Message-Id: <20190522184226.17871-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b43 Subject: [Qemu-devel] [PULL 20/25] 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: peter.maydell@linaro.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. 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 Wed May 22 18:42:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164873 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1240750ili; Wed, 22 May 2019 12:15:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+NrKWi6x4Xt25XSmN4uv6GJ6WuvWTy7TD6lxNkqoUjc7PdqikamLgQ6j/YGdwkth2fCCM X-Received: by 2002:a17:906:a2d4:: with SMTP id by20mr42723217ejb.72.1558552507487; Wed, 22 May 2019 12:15:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552507; cv=none; d=google.com; s=arc-20160816; b=cs+WOVlAreRDlZAoUP/qz5Vf1Rh6N9BioY/T2e8l9zmd/9zHum/I6UHZmxHTcTHEDA 4LLCPua1CS8snJXd2/SdxWbqX6j9oRDB/al3/sk8mIf6Yj9DqFrHGMB2+0VkPBTxWHAP 8gTlxjEnI4PZv/xNyDxK3nIuhBLRCbHU/qB8Ic6UaVHTn7RxmC+vz6d+H03s9PX4FsRs m34eG8+l51kLAWC1Jjor0PGJPgIUfNpipeRr7JK3lQ1z4JVlWp6Gd+W2OjIP6eSX0EjI Fm8OvI5a8BrhnNF0atu3qEjq2iEzVTf3/8PiOGLNSeHsBkujL8C1HJ+jDUVSR9SK3UTu iByg== 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=91uu1aUA9Q1duAfeofMBsz4QGLzYWym0CyS3yfCCEtA=; b=YubIe6jmJxTBIyldKnH1Sb42mnyAwCLypryU9/iKT8JFzCuUr9Ykj0Z8lX44Pejm6f GD7RbIMOM2ebXIduXFJ3ftHEllKN2JKM2oeAU5kegCgMZLrq5GGE40xjCTc5P6t92gIB d7cYh8+ruYsvspxWpdKGxPqu4gLWH6W6zPogzNF8WUEpU/JY08maKIvtJqV/8Lsl9FnF fPavYJ5EJtgpfKml3JmplMGcwLv62kcY6PScMCMMKL7sNzHroXNOXtKWc82v/iMj7L0u wPaVuLXTGjccuE/AJbwNQ3AWo78nIgGBsm7R1+BqlFBMwVdv3IGwFYA3G4p8XitoGihR hyKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WUzmFOKa; 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 ck16si764533ejb.318.2019.05.22.12.15.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:15: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=WUzmFOKa; 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]:49904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWhe-0000SI-C5 for patch@linaro.org; Wed, 22 May 2019 15:15:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOn-0008Ln-4x for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCU-0008CO-3H for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:55 -0400 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]:33874) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCS-0008BS-3V for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:54 -0400 Received: by mail-yw1-xc41.google.com with SMTP id n76so1254439ywd.1 for ; Wed, 22 May 2019 11:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=91uu1aUA9Q1duAfeofMBsz4QGLzYWym0CyS3yfCCEtA=; b=WUzmFOKaaPmzf3hF3x0DaG9GKdGLaS1So5frVXQSerJUkUZeDx38/vI4FL0MtJ5707 hOknTDKjRKrJwTLz0IZ5dqWnz+EskpRYtRHa5llCfQcXw1UGMBgATB3BLQeD9onpHhxM mQfKs5FdQSdwTB0+X3P5RmPTsMqxw3ZR0Pc7Rhe0z1j+4o9b2Lo5cLy2jNwPOhnWkp4j 3ch4ux4GWmHZIf2LhGvzMuU8XhpXeJvJC8RPoaMx/EKH1CfryWztHf+aAl4tgjebneSk LdC4pIc9FU5RDxm0VatQg6dxoD9I1/6d6plp/bT8lOROsLOA0aAZaaDbK/wB6jwuCyET HBkw== 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=91uu1aUA9Q1duAfeofMBsz4QGLzYWym0CyS3yfCCEtA=; b=KoXBLX28wzq/sSCgTlBj2biLh6zB6MUHa83dop1fOL5UjCvk9KHbAgBGGhJfs9IHKW R8hEKS1bDm8bO9+X3KjDG9QN0ry3YisdWX0bFxUbhnsnO+9GhtqD1axtzhcXwg+pqrLl ZdOxxqjdqHogSxb7FyueuH1Jy3JlKbkPfDfPE8/Y6swq7kIwae0MHf+3urELM9j8dNSh aZjlHul2ExJeZ3d6cJRtbmF64XFgpOSMonkTLS+mAjZcZY+a4kN1gWpAV9gHoLCRCwrs t9EB2zcfvcYank/EPDvOYVbERei/8I/F9CpjXgCSYwXw8/3o/ySjAu2iWdf/LfcO+Mbs Iyng== X-Gm-Message-State: APjAAAU9C9vGXP/4FZVFcjBq0W35ImqkZhmqTEBx2+Iv46n765kDKTny ZlmYh/5uGjA2w9N/d6vWUtFbZyDZUBw= X-Received: by 2002:a81:2513:: with SMTP id l19mr35956533ywl.299.1558550570781; Wed, 22 May 2019 11:42:50 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:22 -0400 Message-Id: <20190522184226.17871-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c41 Subject: [Qemu-devel] [PULL 21/25] 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: , Cc: peter.maydell@linaro.org 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 72e43b517a..3de792a04c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9775,23 +9775,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 e2d5c8e34f..6b91082b8b 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 Wed May 22 18:42:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164870 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1237741ili; Wed, 22 May 2019 12:12:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsnWSXIOUuoFRtEX44scNl3dbMNXIAA9NAMwihGobhVYlGz9OQucevnMWRO3IkFQzGymrC X-Received: by 2002:a05:6402:550:: with SMTP id i16mr46470801edx.212.1558552334294; Wed, 22 May 2019 12:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552334; cv=none; d=google.com; s=arc-20160816; b=ef69/Wqu+okiivYckX5qTbVcA/y0rCa7xp9fwZ5FgLRYA1wn5UWyWILeDFq6VvQUHI /j+rDsUebI2Z+wKmLOlBhvW+ycAPmxJ2W7KuMU96NAvGyJjyBdVsVBxhCB/im4yKhGPa rvgcZ1qLZfKnrAuU8jqutDKnzWYbzMl65MNFB28hdthIN89C/AtZkP5d4PEppDRcVSXD ajDW/rMatTbUTy5cFIT5ruNGSPocWHW9rxyvz45NOpzbY7UVMHgxfPjDeDSr3sip6YKM 3YxcVMopm1QXvdb2aR+J9CBvmiDPO538juX4AXnyAgtCXucGFmJMmbzDKCP0nOgDLjwJ dUYA== 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=eQF1EgwSKdQ+jEilzLu3oc5jnuWVHN3zq38+Bl8lFmE=; b=oJgTy6+gXo4mG435hfbhAMNX/M6pB/vki8WmQ6rLWfLykXaOSETdRbKmtnBitX6VMs HQKoARFZtdOWDPvpVWchvzHJIoYyzbSA/OnWrEY7P53QErfRvE0ehZN1/ClBegE93Wro X57/qf2e//KVCDRDKR9vpZ/PMPkdT7uSA32EapM2Rp0WDUfk4/MEOzjEm/hmK7+rsUo2 7N/jdfVRIBl8cm0bx31u5GDXaeO36asO1UO4hDq2Aufj13ADKJsLQDgp3uUMQw03DhG/ ymfg2VvVeiD6qGh0HonpmJrOxngLNt7/24jtPK6woiE6HrO8tH8JqBkM6tjndXBS5G+I JcQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="HSh2u8/D"; 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 a7si9698342edc.327.2019.05.22.12.12.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:12: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="HSh2u8/D"; 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]:49873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWer-0006eb-3U for patch@linaro.org; Wed, 22 May 2019 15:12:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOn-0008Ga-BX for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCU-0008Ch-8E for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:55 -0400 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]:40638) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCU-0008Bk-3l for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:54 -0400 Received: by mail-yw1-xc41.google.com with SMTP id 18so1241479ywe.7 for ; Wed, 22 May 2019 11:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eQF1EgwSKdQ+jEilzLu3oc5jnuWVHN3zq38+Bl8lFmE=; b=HSh2u8/DWaOXOeGfFCromNcDpKZGo42mmhKZKJaXRRO2/rWdn+CJvChECQ2ZfKCKTH PDGdHY9cmkTnRh51F2vzo81xvDADZ9FjjGUmjZUFtFPklj46UBr0X43fQdcXYcGmv9XW QtAH4L+rb4MIDhni+4BqQfOeA3d+FRWPWfeY38rU4WWtuRlwvZ9f/4obucFjb3zkKtgK exC/i22lcCBGQ0FymOqMLL1R/XpQZeGL8USh4adZ4Q158ZGsVLS3ynsr+3qL8QeWtgze cg4qjoOH6VVj4bCJJlIZaC+81BZlyDAnd0YE50kTZ94+q/qasfyyF3Dtni/pf9xpODAR qBtw== 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=eQF1EgwSKdQ+jEilzLu3oc5jnuWVHN3zq38+Bl8lFmE=; b=UOFas/ZbtpitvZTI/OJNFtwGL+8L3n0Lnx6GPIvCZIrcWpNhennUujM02tOxGilHh+ lNddCNEWg2BJVxlU4AzYXa4fRfw/pzfI14ZX40wdX9H45MWJNGoyQlPqI9PzSwO/Kf60 fJFgpUfA9WZQeGiLLwYEkxIDp8Y4v0DXdWigjf5sCUcNHL1NgbdfYFosTLaxjuuchMSJ GUKFivNlE4LKuoLpTLu4NRc7GmYG5CAg/PjNPB7zjp3rgyalSXcVM6G7+rFNzmmZE+xj KBcn2mRwf6sW3TZdRP6R7rZXVZLgP3LXgnqlUy8JbegTKqXlQ6LPSOIHZRcdIvYJB9fS +sCA== X-Gm-Message-State: APjAAAUr5RC6T98kabJFd6Yj7sRlRSN8FZco4fgo/Atc2Lgbi2+DCMF1 eYbFL8rnT4TEqtfZlhK+6hCGAMsQzkE= X-Received: by 2002:a81:1ecd:: with SMTP id e196mr40520973ywe.356.1558550571662; Wed, 22 May 2019 11:42:51 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:23 -0400 Message-Id: <20190522184226.17871-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c41 Subject: [Qemu-devel] [PULL 22/25] 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@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use the newly introduced infrastructure for guest random numbers. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 5 +++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) -- 2.17.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 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 6b91082b8b..acd23c53ca 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 | ARM_CP_IO, + .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 | ARM_CP_IO, + .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 Wed May 22 18:42:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164865 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1231517ili; Wed, 22 May 2019 12:06:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyt6c7K0PCJakJFJ/ONbyrsmeqRmxUtQwg4itQcOnJ/39/L5NoCQUJBbDms97F/gU6x36RV X-Received: by 2002:a17:906:11d3:: with SMTP id o19mr53885898eja.278.1558551971320; Wed, 22 May 2019 12:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558551971; cv=none; d=google.com; s=arc-20160816; b=vmVzb4oVI5mCwWi1hsEya0bCulhapC/l6y6+q/a6ixl0HRYRDBxJSsmk09saaCwk45 E2j5iGZx4mm4qkqPYISFteq9L90rQg+PWairecY1xxKTHwli9v3I5B4odyiAbpfb2IUI VCFxVOmS3/5NE40yabVv0mFIQebcfxscbDAhIxY24p+uVDac44mZ8OZIdwPXRJ+Yo08G LB/FOOtHWLRAT9jYSEBWx1tEglfjp0ltVLi0wuylqMDMAw9dAvdWkgx/jcm5M3YNY1Ke gtAIBPARlt/QsmZQYsTAub0m1uVPlbDbmvH6MpzQnGrjAEK32jRlkiNb8cVxP5cM6phX Qg3w== 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=jubgcMuTGNSY5TtGEwh0c6OxeP3qp5DidyhAq6jVSSw=; b=Wv0Z/Q6bW8eNQdw6wjqWYSNuYz3COH79/8sxBsFnZAPUZK79cTao0Q6G+JKzeSRB4/ zrg6Xf49UHcbSh9UhWrEhWMcUOfxYGmTHj+3HqPKlATygKsUD/G1GzNWconm3FlwVJol O3j5nWhJkJ8NWfZtCCTf7CohVYCRYHrXRnmO111NJZIQqoRGdhvQ9ALJTe+ZeUFe1EQT G1fee5w7Y+jf/szTOpQASpZPedx5B3siWj/6IVetcCGCuN7MDIqP8wWxwv9vlFqqbr/b TKZzXokByCcoFuw5chXM5u49bXCCa22CxIwSfyYW2XIO3/DvkKsvyQdlbNpXshnFheHd 9qQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=f1PZ2iIn; 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 h17si9568969ejf.169.2019.05.22.12.06.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:06: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=f1PZ2iIn; 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]:49796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWZ0-0001Tu-8w for patch@linaro.org; Wed, 22 May 2019 15:06:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOn-0008P8-Gi for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCU-0008CY-5n for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:54 -0400 Received: from mail-yw1-xc43.google.com ([2607:f8b0:4864:20::c43]:33509) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCU-0008C5-19 for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:54 -0400 Received: by mail-yw1-xc43.google.com with SMTP id v81so1252036ywe.0 for ; Wed, 22 May 2019 11:42:53 -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=jubgcMuTGNSY5TtGEwh0c6OxeP3qp5DidyhAq6jVSSw=; b=f1PZ2iIn9dsO3VMKtMvskBrGiJK4m9OrtvCaexOuwm0hu3vKwY6EmmdZbFdpr8Bj5q etomMpuqZXjetwUr01u5T1/ScbyUjCW7CDEwkLYroNgnJTVSwuBpsYYh+ru9vP+FqZp+ wVCWXZtZaSpJJY1kjH1sjfDMyvsMaqdJPjbhNl/jBG4+Sy1OcYnZlriRf1+ey2v7zJk9 EpgQYgYiY5ivG//HsHY7r0PTVJ6Mm7738DOhgvp439k9URnpX3XvL/to4YSfjO0BahFx cF7Qf/NpeSVILfSlFIIXfgQQAJmHuGYX/VP0h60jFBF5KXH+zUAlr7zgILWFbdPqkw+4 CrBg== 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=jubgcMuTGNSY5TtGEwh0c6OxeP3qp5DidyhAq6jVSSw=; b=M6yV0Jt9z0x57FaQvAn5NXEHx8zw9Vn+j+LfI1RQEXKtTyMQi/IEd7D0v2JrQq8bmx Li8E6uYgIWe9g35i/3gGOO0NO/nY+9ZpfRt0ajfGrrLrpz5lAhkoA9EyIJTw35YhtI84 4sB5VVSvIgnwGcqNAqLq8ETuKRGmXQIm4P7LlOYLoZYE94EUS0LY1dimox79vsRgQkuT v19H/JRm44EA6Hx8enfg5phZajUa5K4IRsI+uET6q2LIgMkmVy/baH1V/ERN81QccJlF mnSP33Ds8o8MBBneruwVmC6nLCo3g4731UqplMs2Vihklr+RBi10uri2epwoM6Xa1pOm MUrQ== X-Gm-Message-State: APjAAAVLFuFGB+31NuJPCOcxrdiHI/MjxAxDRken2wvgrFx7ddnYjkLV oSvmmvBnru6GDXTiP4toHG8si40x2tY= X-Received: by 2002:a81:3088:: with SMTP id w130mr42322592yww.63.1558550572691; Wed, 22 May 2019 11:42:52 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:24 -0400 Message-Id: <20190522184226.17871-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c43 Subject: [Qemu-devel] [PULL 23/25] target/ppc: Use gen_io_start/end around DARN X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Generating a random number counts as I/O, as it cannot be replayed and produce the same results. Acked-by: David Gibson Reviewed-by: Laurent Vivier Suggested-by: Peter Maydell Signed-off-by: Richard Henderson --- target/ppc/translate.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/target/ppc/translate.c b/target/ppc/translate.c index b5217f632f..4a5de28036 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -1847,13 +1847,22 @@ static void gen_darn(DisasContext *ctx) { int l = L(ctx->opcode); - if (l == 0) { - gen_helper_darn32(cpu_gpr[rD(ctx->opcode)]); - } else if (l <= 2) { - /* Return 64-bit random for both CRN and RRN */ - gen_helper_darn64(cpu_gpr[rD(ctx->opcode)]); - } else { + if (l > 2) { tcg_gen_movi_i64(cpu_gpr[rD(ctx->opcode)], -1); + } else { + if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { + gen_io_start(); + } + if (l == 0) { + gen_helper_darn32(cpu_gpr[rD(ctx->opcode)]); + } else { + /* Return 64-bit random for both CRN and RRN */ + gen_helper_darn64(cpu_gpr[rD(ctx->opcode)]); + } + if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { + gen_io_end(); + gen_stop_exception(ctx); + } } } #endif From patchwork Wed May 22 18:42:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164860 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1223071ili; Wed, 22 May 2019 11:59:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMY9zJmk2NTBNLoJwDTJVlSx3NfdYneV62v/+M6492xDz4A3UcCSD1RuzFUFPmpNm/dmiX X-Received: by 2002:a50:d717:: with SMTP id t23mr35242167edi.248.1558551542533; Wed, 22 May 2019 11:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558551542; cv=none; d=google.com; s=arc-20160816; b=WnDU7q2eNeogwd5yFG6qptp9zoJDEIQIROOARhzHj4FqIA5pNImA1bucTcO1BjG4Wu 8u7n0aJI0FfoVX60feA+apJBZcsS56jKDTjC+ABqJ9bIEW5tajwsKz54Ljzi4DGCpn/+ lWuVn5XNhsnwUW0QFx1pbz1z3XU3kbioEK9x6IiIj+PTrJv733kwyeWdNVGkAKtGAGdU aykCQvhf7KK3laXoj/+80tuV4m5phft0o3wp1K+QGbVUiW9aIbMlZt3JQfzAHlf91YFv oVonX1A8UPmfSJih/ZeeOk09bzQUnqx2EJHqZMCVfRC9TmXC7RnIdpM/puW/HSg76DJX Ds/g== 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=bpjcbv60JSWpD1TbbxFv9kSVFeLonJbRE1N/VVDdCYY=; b=JUL7J18Xe7WiJFQvayfbTVzVb0VV3mcrakSFzteDPqsad98Dv6Xol3vtjFo9YLajqv jST17NKRV0TbdMWEiyE+berUDxLxAnUfeRUhdy9F7MXxDevjgDDkFiQNFHoizdn8WLlv PnyCIztOxpTJqgKbttIzY9zaa9+kasrf4hT+p96Mp+jAbOR+Gp8oi+eTtq21S25sQQ6i UvmxKep5lrgJ0qGnt5UaqtIhJij0keA3kmJNq7P5HN8h/xULkZ5J1pso17FagDxIpMKP VsAOCHWKPFpIBxCziIgkyC02ISoCXff9yDYjVTZ3pqLZ0rDrQkx9wz224sx+7d4Ar9Zu ms1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=obXPQmve; 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 t10si6797370eju.219.2019.05.22.11.59.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 11:59:02 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=obXPQmve; 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]:49671 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWS5-000318-FX for patch@linaro.org; Wed, 22 May 2019 14:59:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOm-0008Lh-RQ for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCU-0008Cz-NV for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:55 -0400 Received: from mail-yw1-xc2a.google.com ([2607:f8b0:4864:20::c2a]:44152) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCU-0008Cn-JK for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:54 -0400 Received: by mail-yw1-xc2a.google.com with SMTP id e74so1232055ywe.11 for ; Wed, 22 May 2019 11:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bpjcbv60JSWpD1TbbxFv9kSVFeLonJbRE1N/VVDdCYY=; b=obXPQmveNKyNSXpvyCvQgGuL84HmN38d+ocQ4xu6Hy01Ako0r2YNybJi3sRWYgL+L+ vwdcq9wugcF7ZN1vN1Sro1ztACdStOwROqJYX5n9Kx7PHT3tne4Pm6I5qJnq4fuAW7eX 8syO7oe2HUAdAHIFe+fNyMGHHtU1vUpDVZmeYHB6O/oU8H/oUlro/vl+A8GGP7KZk4DI Z+vu0eg9D42r5+pS6S1fPUTUDu1RfDNTZAGf+ttHjebL1EpUNAO0RT9OS7RQDDNRwo6H ycmRoNuq3sRHPNsovVxSMUSJbQ9Gr50NTbAIc4zSH1otjeUSzHPPJoHRmVMoOayrI0/T Remg== 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=bpjcbv60JSWpD1TbbxFv9kSVFeLonJbRE1N/VVDdCYY=; b=a0eCcq1tzvUHZKRmTvBR9v28no1C1mx8aa3bDZUuozTsjq8rSe+DYDZ64JDk0RB4rJ 31areLsoRuOF1pzdGvCdFRMcjM8SrRDx1HhrbN0jKoAfGcfPdoj3qUaxU/4bn3oedsFh Beg0XV5Z1NXkuTxUCQ9VNhDfQf4+uvnEm+JoxwOY8pD9WGtPabBpJQW6aYegZFMzBKqa e/Ls1sUTbuJav7ezN42anCbNHii6k9d6OlNT1jjEgh3GU81/a+ehf8LFd1S2ohMihou8 PKfIhxUyBUapMfQ2JLWYc00sg9FL+pVnYt2K2hxOTs8aZKK4ER90hf2xNDY9fw+/gTvf Xd7g== X-Gm-Message-State: APjAAAWDjyBTDqA2+/nAPevy8vDPYPyB5qOPCbovTEyXFSL379oothyI 63JFYN31IXVa00IqWD/zgZwXxu+TkIo= X-Received: by 2002:a81:924f:: with SMTP id j76mr40316861ywg.199.1558550573715; Wed, 22 May 2019 11:42:53 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:25 -0400 Message-Id: <20190522184226.17871-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c2a Subject: [Qemu-devel] [PULL 24/25] target/ppc: Use qemu_guest_getrandom for DARN X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org 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 Reviewed-by: Laurent Vivier Signed-off-by: Richard Henderson --- target/ppc/int_helper.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) -- 2.17.1 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 Wed May 22 18:42:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164863 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1230949ili; Wed, 22 May 2019 12:05:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkSHZbkJ77SQMUc0DK0rjuvW4LzBpaeMbsv3VXavAjDewvf2gy0SPzG2PN/8BswDo4fifj X-Received: by 2002:a17:906:a354:: with SMTP id bz20mr46500833ejb.209.1558551940885; Wed, 22 May 2019 12:05:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558551940; cv=none; d=google.com; s=arc-20160816; b=h3m/spJ+dbJARbvF0/CXZd7QxFe0vew/KTEQcquWCrFdaYEAHfq2l10sOYwfpQGUxN BTN/iKmW3UhZlWJBprS8/ffnDZEf/PvWChMIH4bxLVbp8gS2CAl3VP4F9t8wZZkr8BR+ u3hiZ+vDjherxmx6qQmAPMPkYCRDopvZYsS2vSogGovM+Y7sYKMEvfMKkgeivaazmjIf sDOK7Q5w+llNi3lJHCoPBk/I2Yjn505NLifWM5UwshCVvd8mQT1FSzebqMoi2Bj/pqBS leaomYHmVMV1vMUBIkNoBh5jb19Y30GLZ1YLZPASKdLByKDLpvpNCg7lWwyUD0NfoLbq QXvQ== 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=GpDCiQN8/aZvZ+AXeAAwaFQMM4p0yaXjgzSjXp1WzGU=; b=SNe1R9oqwgQRq31FBdSQH3qN5yagGHTqtPIJXVMdWVmid/d51MQfaMo9BCWcnCsmkg 86gwFvDbVwjkv4VCZLKGkXX332kieqKPUumRmQ/5mqZz1iCooYlz9Bl9BcaZDXycyHig uuYMMvNnlaXZefCcvKfbocVEkLue1zj2NGg7pn59eB77jrHRGSi6rxlXen4zfqNbi7xE MGpbdwkuUEQ1+mmffQjgzxkvq+JYSABR/kl0pZ3gAz7vvCOFhUN8l1ct13ZKB+hdLJPZ hpqb48WCeCeU0EgrhRIhjhrJ86bpaD4DwSoHpSOL+d3JWq4TtBVi+46tQX1ITeBZDFyv wm/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tunQmnmf; 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 s29si7350098edm.225.2019.05.22.12.05.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:05:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=tunQmnmf; 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]:49788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWYV-0001PC-Lc for patch@linaro.org; Wed, 22 May 2019 15:05:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOm-00086f-OQ for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCV-0008Dm-Rq for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:56 -0400 Received: from mail-yb1-xb2f.google.com ([2607:f8b0:4864:20::b2f]:46137) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCV-0008DO-MX for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:55 -0400 Received: by mail-yb1-xb2f.google.com with SMTP id z22so1237577ybi.13 for ; Wed, 22 May 2019 11:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GpDCiQN8/aZvZ+AXeAAwaFQMM4p0yaXjgzSjXp1WzGU=; b=tunQmnmfmjy9xX7MhYnbid1kucG1KYVHbJNaY9b1xAq2m0EteoLPV0LGI3SV/XFWcS fTt5mVJDu65uROeWIBs0fVvDVkABwdm2PL3xHQlqOMWosbzx9FXrHGBSNmk1DLlMqzE2 c+tQ5avOPrNlWkk7OUwiLVK0fVHRXLSUMAmItCcuoP/z2B9ABNLpwPlK9Daa6ce6zkei NVGlCJIN6qQTd/GZsEeRDy+cLtgifVcwPSFL8xUqP8ayDIEk6Wq1VcPKeyWrWrcCcb0S SOsCAylOdYFDDPUX71RcSge/HJEBiCYr+DTMlGVPGbzVEDj9/4hQeTsyvyqHqgt3KcIr Q0dQ== 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=GpDCiQN8/aZvZ+AXeAAwaFQMM4p0yaXjgzSjXp1WzGU=; b=r70g/YMOcfdcmP4dpai/0f2LMFNGNNpMWsTNdl6IeUT/aQVclhVWbKzrBBwi4V4mlG NvyfBbVeQqJG/Dk7Dlx/Py6VpRwDaPNLvi7gFU2zsJviUchU9hp5ehnQ+Batsw27heCA 1+6KZN1RWIXuNInUiaOFhLXLcw053BvMhl8AYam6Gd88Sjq5nHDUKzW2zYSax/G8wT3q KoMn19eBtANwxE30tEWnKPVDrR8gvVg/G2H5+ef7dMg0mVgoEZaE4DwZBDqarYmJ+dGB Ce3L5LGRuYJpQ+Yah2Z+4Y8Rm0+rKTDEy4BVYvqfFmdgP9xYt30GnifRd3hKFiK58oBG UMZg== X-Gm-Message-State: APjAAAWr4jrF/UAZpyMLA8gwPzWEBsE77Jm5lc1qzrXEgi/TQEy/SZqX 1UYV0NWaIbK6FUPm1+ET+gTDVhyDC5s= X-Received: by 2002:a25:33c5:: with SMTP id z188mr12793969ybz.359.1558550574685; Wed, 22 May 2019 11:42:54 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:26 -0400 Message-Id: <20190522184226.17871-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::b2f Subject: [Qemu-devel] [PULL 25/25] 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We now have an interface for guest visible random numbers. 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 | 62 ++++++++++++++++++++++++++++++---------- 4 files changed, 73 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 2df56fa977..357d3c43a1 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..03150a86e2 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -5332,31 +5332,63 @@ 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; + } + if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) { + gen_io_start(); + } + 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); + if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) { + gen_io_end(); + gen_jmp(s, s->pc - s->cs_base); + } + break; + + default: + goto illegal_op; } - set_cc_op(s, CC_OP_EFLAGS); break; /**************************/