From patchwork Fri May 10 17:30:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163907 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2669671ilr; Fri, 10 May 2019 10:34:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyp3cbYsdcDa7ncEMUTmIo4rAnlpoabzF4D9aqrTUIHqXZyXvX9+GcaqQ7poy5/gGNXmOyl X-Received: by 2002:a17:906:b2d3:: with SMTP id cf19mr9969360ejb.8.1557509665398; Fri, 10 May 2019 10:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557509665; cv=none; d=google.com; s=arc-20160816; b=rAgtsVoW+eJA4VyPqBr5pafwnfIIDBzMKZfwOc0m6lPr6dID8fkTAsHqx0j+5G4BiV xzSvhg9IOdOGS63IyJXKGAFXwF8UK4TbRR873xSu7lkRu6iMXt+kyq39P0yaeUql/S7f r2LgkfIVDo+/HySxO1kmWRteF5f05OVh7UuksPQ7FGaZcH4l6CLM/wFVjy05u7rTHscA TCzK9hea9R0lFo0AxUfgtTRekZKY2JK6CW70B6fOnmQc6JhwXUSBYXYdsh0i+dsJzwyI gbOAQbLzy2E64UiJiCPfQbjXhGJ2hKRu8qdRpdaHvJj+gSst9umK45o+S+6n/iwbnuHX Z+/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=p3cfnV5JbT6H/nwjKGY4Kezh5D3MhbPkpcQaspyBazo=; b=ALSISzUHfHbjYjWPRVnU7VP1rDjNfbBV5PLvUjW9x9s5tkL/YDKdcXmqpj8yajI7v8 JkzG5qwqXeqMiuczw41SQ97mlQmHR/m44wNBWAubSRRHub19di7LQsMPFMlqNbSYgxG+ ouwXAUW7lvtLHC5dnlRTrmayxQrB/EcNEVBAAnvTpLANa0x7AsLFLjJpwq1mumvpg8Gs NbV2YkrCbjoooxo3MJk3qfh3FRY9Y29eK35vpRCvGwxUnQWeR3LTLjydknJ4+IE+w7LG 3qtplV40FpnaUGBwbkmqVHLpdyPcO/u7moOUQ9yHe+jDBOIvjLByrKHJAe0LoWFprRVz nS8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Xv1QtOJy; 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 ot8si1933120ejb.275.2019.05.10.10.34.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:34:25 -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=Xv1QtOJy; 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]:47500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Pc-00021F-5L for patch@linaro.org; Fri, 10 May 2019 13:34:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MF-0007IC-Ci for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9ME-0005y4-3Y for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:55 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:42598) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MD-0005xX-Tu for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:54 -0400 Received: by mail-pl1-x642.google.com with SMTP id x15so3127194pln.9 for ; Fri, 10 May 2019 10:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=p3cfnV5JbT6H/nwjKGY4Kezh5D3MhbPkpcQaspyBazo=; b=Xv1QtOJyGKmPVc5wOfKNqKuFiKfEoYGPwYdml96HohiJdk/ZKN2BjqJn2iT3b52BYg jADBwofGV5ksLI6TP4E1x1osCpftbDAX7ld9yK2znpfGwI+nvoXJm56iMcezni1w4zJE SFhtsHob0ooKXnH2uR5p0vb1G/NhtOXgk8WW044lvQOyRvQDdrsz65heiQIf2nHpKhD3 tPKfzQZdRs6PBiPHb/755Pn5GGw9Mt1zVv/eYrgw+jTBnjw7I10U5M+xIc0X5ItoCMET h8H62b0S2Z1D5QdqMCfxdbZEZhvPqzeA92urnqUmBxLI7JbDJbRnkUXLIwOfmFyWbTf7 CzXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p3cfnV5JbT6H/nwjKGY4Kezh5D3MhbPkpcQaspyBazo=; b=bvbMwOn9ZQHIak3ZEmsrTBkdnD2kQp/FtCBcmW7JfKAD8YQmixvwyNuReUsG1KXfWL hifDG73xXeRksOXlZwBgpsWem2YNFnTDA38nk8Bwd2HURGz1eOdlQJI3uvDsPx1nFWm2 EhPDZzB4Eul+bAdeFG2BJqS7fd1j5WQAG0KBFquen34VfzVKzuPNwgr11+YHUpshbR3W eCwm9PU8o2f5tqLwl1SgQlAx5jPRtR8WAqK/mX5YqEExZKknugvSnBj3HZS74ljTrsAy mx11ZzOzk5TjoWfH8cL/jQ8lsiubHsKP00Wj9mqH5kHOgmNU+U0ptutj7j0pjHUXcS5h oZRw== X-Gm-Message-State: APjAAAVFNK79vo9+ahMuX7m5f+l26fiUPVAQDsTRYGftciYA3B5vJ9lJ SPKp+T0+bZ5UV90+W1MmcE8nkK2Ufh0= X-Received: by 2002:a17:902:263:: with SMTP id 90mr14917245plc.257.1557509452590; Fri, 10 May 2019 10:30:52 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.30.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:30:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:25 -0700 Message-Id: <20190510173049.28171-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [PATCH v6 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: , 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. Tested-by: Laurent Vivier Reviewed-by: Laurent Vivier Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- v5: Include nettle, gcrypt. --- configure | 72 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 28 deletions(-) -- 2.17.1 diff --git a/configure b/configure index 63f312bd1f..c4f27ed453 100755 --- a/configure +++ b/configure @@ -2784,17 +2784,24 @@ fi # GNUTLS probe if test "$gnutls" != "no"; then + pass="no" if $pkg_config --exists "gnutls >= 3.1.18"; then gnutls_cflags=$($pkg_config --cflags gnutls) gnutls_libs=$($pkg_config --libs gnutls) - libs_softmmu="$gnutls_libs $libs_softmmu" - libs_tools="$gnutls_libs $libs_tools" - QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" - gnutls="yes" - elif test "$gnutls" = "yes"; then + # Packaging for the static libraries is not always correct. + # At least ubuntu 18.04 ships only shared libraries. + write_c_skeleton + if compile_prog "" "$gnutls_libs" ; then + libs_softmmu="$gnutls_libs $libs_softmmu" + libs_tools="$gnutls_libs $libs_tools" + QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" + pass="yes" + fi + fi + if test "$pass" = "no" && test "$gnutls" = "yes"; then feature_not_found "gnutls" "Install gnutls devel >= 3.1.18" else - gnutls="no" + gnutls="$pass" fi fi @@ -2849,43 +2856,54 @@ has_libgcrypt() { if test "$nettle" != "no"; then + pass="no" if $pkg_config --exists "nettle >= 2.7.1"; then nettle_cflags=$($pkg_config --cflags nettle) nettle_libs=$($pkg_config --libs nettle) nettle_version=$($pkg_config --modversion nettle) - libs_softmmu="$nettle_libs $libs_softmmu" - libs_tools="$nettle_libs $libs_tools" - QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags" - nettle="yes" - - if test -z "$gcrypt"; then - gcrypt="no" + # Link test to make sure the given libraries work (e.g for static). + write_c_skeleton + if compile_prog "" "$nettle_libs" ; then + libs_softmmu="$nettle_libs $libs_softmmu" + libs_tools="$nettle_libs $libs_tools" + QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags" + if test -z "$gcrypt"; then + gcrypt="no" + fi + pass="yes" fi + fi + if test "$pass" = "no" && test "$nettle" = "yes"; then + feature_not_found "nettle" "Install nettle devel >= 2.7.1" else - if test "$nettle" = "yes"; then - feature_not_found "nettle" "Install nettle devel >= 2.7.1" - else - nettle="no" - fi + nettle="$pass" fi fi if test "$gcrypt" != "no"; then + pass="no" if has_libgcrypt; then gcrypt_cflags=$(libgcrypt-config --cflags) gcrypt_libs=$(libgcrypt-config --libs) - # Debian has remove -lgpg-error from libgcrypt-config + # Debian has removed -lgpg-error from libgcrypt-config # as it "spreads unnecessary dependencies" which in # turn breaks static builds... if test "$static" = "yes" then gcrypt_libs="$gcrypt_libs -lgpg-error" fi - libs_softmmu="$gcrypt_libs $libs_softmmu" - libs_tools="$gcrypt_libs $libs_tools" - QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags" - gcrypt="yes" + # Link test to make sure the given libraries work (e.g for static). + write_c_skeleton + if compile_prog "" "$gcrypt_libs" ; then + libs_softmmu="$gcrypt_libs $libs_softmmu" + libs_tools="$gcrypt_libs $libs_tools" + QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags" + pass="yes" + fi + fi + if test "$pass" = "yes"; then + gcrypt="yes" cat > $TMPC << EOF #include int main(void) { @@ -2898,12 +2916,10 @@ EOF if compile_prog "$gcrypt_cflags" "$gcrypt_libs" ; then gcrypt_hmac=yes fi + elif test "$gcrypt" = "yes"; then + feature_not_found "gcrypt" "Install gcrypt devel >= 1.5.0" else - if test "$gcrypt" = "yes"; then - feature_not_found "gcrypt" "Install gcrypt devel >= 1.5.0" - else - gcrypt="no" - fi + gcrypt="no" fi fi From patchwork Fri May 10 17:30:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163911 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2672781ilr; Fri, 10 May 2019 10:37:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqymATiYQCTf3tglHNGGlPeL8gbOM8wVWMbywR0hVjIOdsK8VhGTB1l92fQNhI14ACWbWJqw X-Received: by 2002:a50:e79c:: with SMTP id b28mr12163533edn.277.1557509846140; Fri, 10 May 2019 10:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557509846; cv=none; d=google.com; s=arc-20160816; b=GLqys8sMwdEUeuXuPo9bjnDQu2rAa5s5THlOMUioVaGg/eEzj6V88gy3lKSA558FME B1665xdVodnRf0SvG/HZITCyyO0qQuQRYz2AnIWiLxA8jRIK3Feh1k/bD3UBlDY27yhv T6EGOe+LL6Rk1UxHsU1gQiK+Ky4DleMh1TSCwdOgP62f3gIQ5Ew6aTWpHMPR+bzq8VNp V4rl0fbboIuZnbfsO2P74FImoqbIHippGqaDKri7U88WI+sTM0KVCMIz/glOzyWdSeq4 x2SWVipcKcSxOqVvj+bUvFjcBp8ekkvtgoC6rpNgp1aIwTghqrhXwdqg0MtuvucMRQBM Gtmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=oNLcNEzx1AVg7pEqaHg2NYbCmOShRlwabHt9Wio1gps=; b=s/az5zpRWLoH9BfC6KoDCZvaydIjjlxHXPGaTJxS6lItX5FZbaLu04Eg3vAkfYbrlE QClZ1ueLMnEIgFScfi8xEMkedY6QwoM5WiKT0ZnJkoVGS2KamAjYu9VI7AmZiKFROWgs YJckbxBEciHHMzOn1JCXdsrZAaM4vIYYWIgBbt3zKtveQLubvD2okcpMzWKQX/Gbi9WU p7ObTZt+1P9uwZJMpJn0Cdsn1oV5ciOF/Qmt1wSasib/YUUPTW8OcgtiAjkEkXdsbfWI madtLFhV3ZRjA2GRNvsTItc3N5wQ0D9TAefJP4adegfafOMY0alDaUNHJash9mm7VjaG ckHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ra9jDxTL; 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 w14si1667469edw.79.2019.05.10.10.37.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:37:26 -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=ra9jDxTL; 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]:47556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9SW-0004vw-Vv for patch@linaro.org; Fri, 10 May 2019 13:37:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MH-0007Ie-Ck for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MF-0005z5-MM for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:57 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:37468) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MF-0005yQ-EL for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:55 -0400 Received: by mail-pg1-x543.google.com with SMTP id e6so3334537pgc.4 for ; Fri, 10 May 2019 10:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=oNLcNEzx1AVg7pEqaHg2NYbCmOShRlwabHt9Wio1gps=; b=ra9jDxTLNuYDLE4J3yl9KdiHEBJGrDx7pjW0tLlJVVdcBLy5LZBEkAYeOSLF2wjnVy Y8kolHTu5n4okpuUwx/w1MflqCDGZi1xDb0LLba4RR62uygPHcFux/v974VByjgo+dgF IBwOlD8yTbr6EzaswuoxJOvSdu042Wir78Yn/s8jjo4QLhgT5sAofakRL6gNzKgSMEFM x7sknDvhDZgF06XQaEwtplmMW4VLe+0HGTHtcZ2P6YFTDu2mat08+ivsO1bCr8fi1LAg TP3jTvxST8GWGWqL/he32neiI5T6Ep1/HhnxDba9lPSFWJ1381Jl13NL2ZQ4YZlFt5qu RZcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oNLcNEzx1AVg7pEqaHg2NYbCmOShRlwabHt9Wio1gps=; b=J1XxxaZEogGN0rHcEJVv2wKSyDH7y4mvegO8wUVtwFjJHeDfOwUnjiAXVRd7oMDufd M+t3zZmVx1V1tl9uTKjhVf7VXlDfd8pRDkWTbh1/aXOxMN+lHK7j0YQb3EuGgGC7FIzD 0Ua1qco7WgCjevZMa29WjMdfAURLTbuSF0EwnEiKeDVbE6kyDxRoqQlPBXcxPrEonWSP a23EIDpJv7FeszOSZfHXUnVbbDjdp9Qa227fdsrOF7q/6xe4Y6vQk+epeXX64s57o/+f fRd81gPQpXMFLaqw/3d4E5BG35+FHF4GfP96JUmosH+cyelM7KTc8H29j+fA7eRjWsXn NagQ== X-Gm-Message-State: APjAAAUReWeXks2XCWPe+a8ayUrzvL/ItJ5MDRAYXv8PdpEaCxR0kuYk cv1cs70RB4AwzIzixIPqB19Kwzb5Stk= X-Received: by 2002:a65:448b:: with SMTP id l11mr15097201pgq.185.1557509453909; Fri, 10 May 2019 10:30:53 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.30.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:30:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:26 -0700 Message-Id: <20190510173049.28171-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH v6 02/25] crypto: Merge crypto-obj-y into libqemuutil.a X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We will shortly need this in the user-only binaries, so drop the split into system and tools binaries. Remove crypto-obj-y and crypto-aes-obj-y, moving the objects into util-obj-y. Reviewed-by: Laurent Vivier Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- v6: Remove a stray crypto-aes-obj-$(COND) -- (lvivier) Remove crypto-obj-y entirely -- (berrange) --- Makefile | 14 +++----- Makefile.objs | 8 +---- Makefile.target | 4 --- configure | 9 ++--- crypto/Makefile.objs | 77 ++++++++++++++++++++---------------------- tests/Makefile.include | 3 +- 6 files changed, 47 insertions(+), 68 deletions(-) -- 2.17.1 diff --git a/Makefile b/Makefile index 4a8ae0ef95..acf13f5eaa 100644 --- a/Makefile +++ b/Makefile @@ -409,8 +409,6 @@ dummy := $(call unnest-vars,, \ qga-vss-dll-obj-y \ block-obj-y \ block-obj-m \ - crypto-obj-y \ - crypto-aes-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -446,7 +444,6 @@ SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES)) $(SOFTMMU_SUBDIR_RULES): $(authz-obj-y) $(SOFTMMU_SUBDIR_RULES): $(block-obj-y) -$(SOFTMMU_SUBDIR_RULES): $(crypto-obj-y) $(SOFTMMU_SUBDIR_RULES): $(io-obj-y) $(SOFTMMU_SUBDIR_RULES): config-all-devices.mak $(SOFTMMU_SUBDIR_RULES): $(edk2-decompressed) @@ -482,8 +479,7 @@ subdir-capstone: .git-submodule-status 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) $(chardev-obj-y) \ - $(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY)) +$(SUBDIR_RULES): libqemuutil.a $(common-obj-y) $(chardev-obj-y) $(qom-obj-y) ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) # Only keep -O and -g cflags @@ -511,9 +507,9 @@ COMMON_LDADDS = libqemuutil.a qemu-img.o: qemu-img-cmds.h -qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS) @@ -524,7 +520,7 @@ qemu-edid$(EXESUF): qemu-edid.o hw/display/edid-generate.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap -scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(authz-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(authz-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) ifdef CONFIG_MPATH scsi/qemu-pr-helper$(EXESUF): LIBS += -ludev -lmultipath -lmpathpersist endif diff --git a/Makefile.objs b/Makefile.objs index cf065de5ed..4875b6f2e5 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -1,7 +1,7 @@ ####################################################################### # Common libraries for tools and emulators stub-obj-y = stubs/ util/ crypto/ -util-obj-y = util/ qobject/ qapi/ +util-obj-y = util/ crypto/ qobject/ qapi/ chardev-obj-y = chardev/ @@ -21,12 +21,6 @@ block-obj-$(CONFIG_REPLICATION) += replication.o block-obj-m = block/ -####################################################################### -# crypto-obj-y is code used by both qemu system emulation and qemu-img - -crypto-obj-y = crypto/ -crypto-aes-obj-y = crypto/ - ####################################################################### # qom-obj-y is code used by both qemu system emulation and qemu-img diff --git a/Makefile.target b/Makefile.target index ae02495951..ce02924ffb 100644 --- a/Makefile.target +++ b/Makefile.target @@ -179,8 +179,6 @@ dummy := $(call unnest-vars,.., \ block-obj-y \ block-obj-m \ chardev-obj-y \ - crypto-obj-y \ - crypto-aes-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -189,8 +187,6 @@ all-obj-y += $(common-obj-y) all-obj-y += $(qom-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y) -all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y) -all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y) ifdef CONFIG_SOFTMMU diff --git a/configure b/configure index c4f27ed453..68b34a93eb 100755 --- a/configure +++ b/configure @@ -2792,8 +2792,7 @@ if test "$gnutls" != "no"; then # At least ubuntu 18.04 ships only shared libraries. write_c_skeleton if compile_prog "" "$gnutls_libs" ; then - libs_softmmu="$gnutls_libs $libs_softmmu" - libs_tools="$gnutls_libs $libs_tools" + LIBS="$gnutls_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $gnutls_cflags" pass="yes" fi @@ -2864,8 +2863,7 @@ if test "$nettle" != "no"; then # Link test to make sure the given libraries work (e.g for static). write_c_skeleton if compile_prog "" "$nettle_libs" ; then - libs_softmmu="$nettle_libs $libs_softmmu" - libs_tools="$nettle_libs $libs_tools" + LIBS="$nettle_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $nettle_cflags" if test -z "$gcrypt"; then gcrypt="no" @@ -2896,8 +2894,7 @@ if test "$gcrypt" != "no"; then # Link test to make sure the given libraries work (e.g for static). write_c_skeleton if compile_prog "" "$gcrypt_libs" ; then - libs_softmmu="$gcrypt_libs $libs_softmmu" - libs_tools="$gcrypt_libs $libs_tools" + LIBS="$gcrypt_libs $LIBS" QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags" pass="yes" fi diff --git a/crypto/Makefile.objs b/crypto/Makefile.objs index 256c9aca1f..8fafffb048 100644 --- a/crypto/Makefile.objs +++ b/crypto/Makefile.objs @@ -1,41 +1,38 @@ -crypto-obj-y = init.o -crypto-obj-y += hash.o -crypto-obj-$(CONFIG_NETTLE) += hash-nettle.o -crypto-obj-$(if $(CONFIG_NETTLE),n,$(CONFIG_GCRYPT)) += hash-gcrypt.o -crypto-obj-$(if $(CONFIG_NETTLE),n,$(if $(CONFIG_GCRYPT),n,y)) += hash-glib.o -crypto-obj-y += hmac.o -crypto-obj-$(CONFIG_NETTLE) += hmac-nettle.o -crypto-obj-$(CONFIG_GCRYPT_HMAC) += hmac-gcrypt.o -crypto-obj-$(if $(CONFIG_NETTLE),n,$(if $(CONFIG_GCRYPT_HMAC),n,y)) += hmac-glib.o -crypto-obj-y += aes.o -crypto-obj-y += desrfb.o -crypto-obj-y += cipher.o -crypto-obj-$(CONFIG_AF_ALG) += afalg.o -crypto-obj-$(CONFIG_AF_ALG) += cipher-afalg.o -crypto-obj-$(CONFIG_AF_ALG) += hash-afalg.o -crypto-obj-y += tlscreds.o -crypto-obj-y += tlscredsanon.o -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-obj-y += pbkdf.o -crypto-obj-$(CONFIG_NETTLE) += pbkdf-nettle.o -crypto-obj-$(if $(CONFIG_NETTLE),n,$(CONFIG_GCRYPT)) += pbkdf-gcrypt.o -crypto-obj-y += ivgen.o -crypto-obj-y += ivgen-essiv.o -crypto-obj-y += ivgen-plain.o -crypto-obj-y += ivgen-plain64.o -crypto-obj-y += afsplit.o -crypto-obj-y += xts.o -crypto-obj-y += block.o -crypto-obj-y += block-qcow.o -crypto-obj-y += block-luks.o - -# Let the userspace emulators avoid linking gnutls/etc -crypto-aes-obj-y = aes.o - +util-obj-y = init.o +util-obj-y += hash.o +util-obj-$(CONFIG_NETTLE) += hash-nettle.o +util-obj-$(if $(CONFIG_NETTLE),n,$(CONFIG_GCRYPT)) += hash-gcrypt.o +util-obj-$(if $(CONFIG_NETTLE),n,$(if $(CONFIG_GCRYPT),n,y)) += hash-glib.o +util-obj-y += hmac.o +util-obj-$(CONFIG_NETTLE) += hmac-nettle.o +util-obj-$(CONFIG_GCRYPT_HMAC) += hmac-gcrypt.o +util-obj-$(if $(CONFIG_NETTLE),n,$(if $(CONFIG_GCRYPT_HMAC),n,y)) += hmac-glib.o +util-obj-y += aes.o +util-obj-y += desrfb.o +util-obj-y += cipher.o +util-obj-$(CONFIG_AF_ALG) += afalg.o +util-obj-$(CONFIG_AF_ALG) += cipher-afalg.o +util-obj-$(CONFIG_AF_ALG) += hash-afalg.o +util-obj-y += tlscreds.o +util-obj-y += tlscredsanon.o +util-obj-y += tlscredspsk.o +util-obj-y += tlscredsx509.o +util-obj-y += tlssession.o +util-obj-y += secret.o +util-obj-$(CONFIG_GCRYPT) += random-gcrypt.o +util-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o +util-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o +util-obj-y += pbkdf.o +util-obj-$(CONFIG_NETTLE) += pbkdf-nettle.o +util-obj-$(if $(CONFIG_NETTLE),n,$(CONFIG_GCRYPT)) += pbkdf-gcrypt.o +util-obj-y += ivgen.o +util-obj-y += ivgen-essiv.o +util-obj-y += ivgen-plain.o +util-obj-y += ivgen-plain64.o +util-obj-y += afsplit.o +util-obj-y += xts.o +util-obj-y += block.o +util-obj-y += block-qcow.o +util-obj-y += block-luks.o +util-obj-y += aes.o stub-obj-y += pbkdf-stub.o diff --git a/tests/Makefile.include b/tests/Makefile.include index 60de085ee1..96bf071992 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -496,8 +496,7 @@ test-qapi-obj-y = tests/test-qapi-types.o \ tests/test-qapi-visit-sub-sub-module.o \ tests/test-qapi-introspect.o \ $(test-qom-obj-y) -benchmark-crypto-obj-y = $(authz-obj-y) $(crypto-obj-y) $(test-qom-obj-y) -test-crypto-obj-y = $(authz-obj-y) $(crypto-obj-y) $(test-qom-obj-y) +test-crypto-obj-y = $(authz-obj-y) $(test-qom-obj-y) test-io-obj-y = $(io-obj-y) $(test-crypto-obj-y) test-authz-obj-y = $(test-qom-obj-y) $(authz-obj-y) test-block-obj-y = $(block-obj-y) $(test-io-obj-y) tests/iothread.o From patchwork Fri May 10 17:30:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163906 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2666507ilr; Fri, 10 May 2019 10:31:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqwOawSi9IxRTnNJvX+jTiFyYOx2ty3jCGdiKvll6wAPt6450dCrhfNQWHHjgR7pEWnyfxst X-Received: by 2002:aa7:ca54:: with SMTP id j20mr12496488edt.23.1557509497033; Fri, 10 May 2019 10:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557509497; cv=none; d=google.com; s=arc-20160816; b=Q7UKNe/BvSEGSnflkFzPJQGNAwdk9EoIIFeowTfoedF1hwCn1gS+qH755evQ9laQUG X6WGAjqNFsq93IoCSlINHUTG2YBXXTz/F/psnmqPrx7OKnTGwFBrBPqizA8Q7ruu/Ql9 6t8+dswKe9P514khuYn4q/jK/TQSlF4r5fcekB4Ur+hJ+JgeuXZv3L0/2ocZj23fJO2C o1Lfu7L6vKPYDU2J2uXc09iJfWMEHCXFQVBl0HFQCA3MOhPSHueKOW3WA8Lo6fVoZ0b1 Jd/OXqaMHH9ygiVMh3PkxgcHelEdv7ngrU5cYVoantlcCFo+WXuTB/f2ehmCzZiKJm1h uEyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=BV36MdOMTrafrM+t5HT5T1euoUepVkxDpJZFXMkwXbHN3pOx1UK1qiUiRoiYMXNaY/ sNmlgPdRsvLnLwWei9PZDyrnOfS1m6mlSzVnU1zUTDHIFI+zCDTrY7vWoH/Qqhtku/hg dV50vusQokS0/c/NzOe4PtxRgkJ/tWkFQIdQ6dC/+P0wxOGhShFd/NLITlU4UzPL2H5/ fsOER5OA1ORuV61HSLeCcqhrg+ikVZThJpkgu02RgIyBSwou9XYLMZ8r3mTqyQ2+dRtN iEWfswNCmRdpNWXVAYNp97LGcLI5WPNnE8DZeKr3SBOLZfu89i3KnK0pHB08+uJhEW/+ Fibw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xAjEu1X4; 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 r12si3286043eja.193.2019.05.10.10.31.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:31:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xAjEu1X4; 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]:47486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Mt-0007L8-TJ for patch@linaro.org; Fri, 10 May 2019 13:31:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MH-0007It-Mo for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MG-0005zW-Kf for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:57 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:45948) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MG-0005zH-Ey for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:56 -0400 Received: by mail-pg1-x542.google.com with SMTP id i21so3315306pgi.12 for ; Fri, 10 May 2019 10:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=xAjEu1X4VlwRNknwmCYR+OOCLDvWztfWn8u8HXL2EOv1yj13dUGgXj20X7w/OaSivF rNvoEyyBkHTS2a723pigY9zxxhaJ6uqFF3oTOF498ZLQSqGXEQkujln9Cica1O57I/wb HJzBcqNke4rvAV74vwV6rMrwnYt5YImMGdOS91S1bvm1lCe0iBwnmYqOLUaJKadk9vma krOvoxFt2kdGlamxH2HhL2tqJZxNYyTzm4tPNhCu7eiwnZtaoARcBBnrkLGly/wz4ZB3 2JCPBGdj3CmePAXZTmz/qbR2Zb3JNAmvewTtX8HRxgrBhC+F6MA+9OXsdAB5Bi9wrVb3 cy6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=H/37sbIeO7BUzawcBwbkZZq9yavTeATFKy5etOVKQHik5NBGMZPEKCIgO+r6f/Nzs0 UuZo/Fa3WI4SX7uBQnmL65NvGrdblgb5vyDepC1bpc9v+UFJsQODuSCw1VpLWZDNeP5F DmyOp+CKzD9j3g9MGQrQyUm717OBpJzOvv7RKwrdCMUjlF5yGikskv2f7RaYUIvdHDfw u1qKw5rqmkQpSI+tTB+3r36DY+IRb31EUnNQbQ50+EiuzVjWfy8iMRVI3AdHvj3Xwwcu e8F526Qo5Wy9oDhSA4yAaNiFBHCQ5fduOInoRFsdakwNoYUr/Hf3D/Ee/r8P/ytsTHnw E4lw== X-Gm-Message-State: APjAAAV8DnsK9eROcTsGz+N2Dad5XM2uby+OrkrVPGvWCJUQcRBx2b4k tUBYitjG8IRQd3OynkVi/BenFcToLUk= X-Received: by 2002:a63:2c4a:: with SMTP id s71mr15157285pgs.373.1557509455148; Fri, 10 May 2019 10:30:55 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.30.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:30:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:27 -0700 Message-Id: <20190510173049.28171-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use #ifdef _WIN32 instead of #ifndef _WIN32. This will make other tests easier to sequence. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) -- 2.17.1 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 7541b4cae7..f995fc0ef1 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -32,7 +32,14 @@ static int fd; /* a file handle to either /dev/urandom or /dev/random */ int qcrypto_random_init(Error **errp) { -#ifndef _WIN32 +#ifdef _WIN32 + if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, + CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { + error_setg_win32(errp, GetLastError(), + "Unable to create cryptographic provider"); + return -1; + } +#else /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ fd = open("/dev/urandom", O_RDONLY); @@ -44,15 +51,7 @@ int qcrypto_random_init(Error **errp) error_setg(errp, "No /dev/urandom or /dev/random found"); return -1; } -#else - if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, - CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { - error_setg_win32(errp, GetLastError(), - "Unable to create cryptographic provider"); - return -1; - } #endif - return 0; } @@ -60,7 +59,15 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, size_t buflen G_GNUC_UNUSED, Error **errp) { -#ifndef _WIN32 +#ifdef _WIN32 + if (!CryptGenRandom(hCryptProv, buflen, buf)) { + error_setg_win32(errp, GetLastError(), + "Unable to read random bytes"); + return -1; + } + + return 0; +#else int ret = -1; int got; @@ -82,13 +89,5 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, ret = 0; cleanup: return ret; -#else - if (!CryptGenRandom(hCryptProv, buflen, buf)) { - error_setg_win32(errp, GetLastError(), - "Unable to read random bytes"); - return -1; - } - - return 0; #endif } From patchwork Fri May 10 17:30:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163908 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2669744ilr; Fri, 10 May 2019 10:34:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkJ5KIqzIOH7NkCzA5lyYNrUOev710GWBgKJytoObpDXiB/Ula/Uy4O+0WM2pW5bH8qMgT X-Received: by 2002:a50:97d6:: with SMTP id f22mr12402206edb.115.1557509670434; Fri, 10 May 2019 10:34:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557509670; cv=none; d=google.com; s=arc-20160816; b=ISxHORCoRN0q32F8aMYV1atZPCoFlDvoJJ45IVnQKq0siSyVyzUjHEjaVCtPALDepT MAxD/3PXxL1DTXSCTdGifs3DIGbVrsQ8nfN+4SPKlGbd4jJ1lC+kqKPGb+z6DTpmjz0G f7Qkjh7NIzGHhrTb4yyevzSK/Ha0TPaOAIsIrrlxdJbHhA6gtOnZD6HrYMQYK49qxN8T TSdMG/yNZAmWuPBA/AXUQ839yqO9Bl/D0LfouqM0oA4lPmeOOh/hxN0chQJha84qqoLo mKJS6pl7iP17594Z5jQ6uaaDzX/JXUy6r+5ptNasTKVHNmTwUKMazSQbs3oM056VpnNU FBOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=8Bh7531eyDC2/9D2e9XWW3j4XTcdT7MvDIqTNSwlf4w=; b=cMaj1npZIHVTDaemxhnjYWdQie5K2007loAd+BStQxHxU3as/12aIORC91ljjlmihE OJ0hFlTCFUUxVOMHpCYj8d5NYQHaLkRio1AbtiwrJBm2M1VMrsosUI59xCxTwEy4Rnfu mBsm/UBYkI+o3JRnrv1qsZOI5WVMm4uW7k/l019jTxwJfUUU+m4mms5lc5azVD2OO7No P1gU/Nd/T3gGfwIZsugfj50Zonb5LX+cdB2ugYDPkQ9OD+xArmfFVXvgDzwdrBKCV35w hJQoq4+J+sFsCIBlk+AW7vfvl3Xvuc+CZaffJ60gaE+s4jdxpJ5iPESl1n8HR7Ywn2yW nETQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="rqRq/qk3"; 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 a3si3339502ejp.64.2019.05.10.10.34.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:34:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="rqRq/qk3"; 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]:47506 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Ph-00024Q-8q for patch@linaro.org; Fri, 10 May 2019 13:34:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MI-0007Jf-MZ for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MH-00060O-Ok for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:58 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:41870) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MH-0005zk-IO for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:57 -0400 Received: by mail-pl1-x643.google.com with SMTP id f12so1118456plt.8 for ; Fri, 10 May 2019 10:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=8Bh7531eyDC2/9D2e9XWW3j4XTcdT7MvDIqTNSwlf4w=; b=rqRq/qk3z5LDC9iz6nYAtBTgYUsQzGLpDUzuUnkdd8e8U47ENPNnTjWZlAyVXFwBat whBGTBdYMfEFgqXDuKGEjd62qQlKYonCB1snwzTL8P6S2M+hDDqFxS85MjKn4NuP4hg4 wIjPLolf6alu4O9/6T+qQrjVORrAIQymVRh55XESRP2xgi5F5IQearzkRGBfVjDnSBLC z73MKP7jYqWbkBUVmUq5JGEopAw1TeBXUTLW8JEiALiLsLayMqNpa0qaaH+UiyNJDznW e7i3n1GHfqNc5T0zYctCx8WdfNvvU2BiCKTAgMrKtoBJLpFot0CWF7uQGagAWGcQ3qt/ Xv4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Bh7531eyDC2/9D2e9XWW3j4XTcdT7MvDIqTNSwlf4w=; b=QMYELBOMefFjXbMJOVuVeaEcKMev01nOeepIeE2vl8suTqaRPMPdO92ID2E44E54f5 +ZYaEeCX3B6BwBLT9gAJu5YBcmwvIV9wFv18ypQ8xP5GuZRGAcaN96Jg7nlUbZRfhnSr f0q5eaj6VDvAY5p0x8E+KbK3ZVjxmLThVwINXNJTH/pIH7NLys09tEjCYKu8jUCxWu2y fH9YSN/L+U+HwiJNL+n6u79YkY5GEbHJq/JfypmcPAXLE8XlQw3bnTRH8JjeqgVOFbwu nFNKd+iZouf2VU108HSE1d2DFAMjD+lt6I4AXrGHJhommhPgei+hDLfXHdzMlv3ME80L mK7A== X-Gm-Message-State: APjAAAVdpV8s3cUvJ5J6Kpa+WZR3NO2BvyGcp8Li/jEPdI8s9TKiwoUz 7RR9mLWtMzy1uWCWw4OG93zBBPfRMI4= X-Received: by 2002:a17:902:bf44:: with SMTP id u4mr14546915pls.171.1557509456326; Fri, 10 May 2019 10:30:56 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.30.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:30:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:28 -0700 Message-Id: <20190510173049.28171-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::643 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We can always get EINTR for read; /dev/urandom is no exception. Rearrange the order of tests for likelihood; allow degenerate buflen==0 case to perform a no-op zero-length read. This means that the normal success path is a straight line with a single test for success. Reviewed-by: Laurent Vivier Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- v3: Rearrage the read loop again. --- crypto/random-platform.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index f995fc0ef1..260b64564d 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -65,29 +65,23 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, "Unable to read random bytes"); return -1; } - - return 0; #else - int ret = -1; - int got; - - while (buflen > 0) { - got = read(fd, buf, buflen); - if (got < 0) { - error_setg_errno(errp, errno, - "Unable to read random bytes"); - goto cleanup; - } else if (!got) { - error_setg(errp, - "Unexpected EOF reading random bytes"); - goto cleanup; + while (1) { + ssize_t got = read(fd, buf, buflen); + if (likely(got == buflen)) { + return 0; + } + if (got > 0) { + buflen -= got; + buf += got; + } else if (got == 0) { + error_setg(errp, "Unexpected EOF reading random bytes"); + return -1; + } else if (errno != EINTR) { + error_setg_errno(errp, errno, "Unable to read random bytes"); + return -1; } - buflen -= got; - buf += got; } - - ret = 0; - cleanup: - return ret; #endif + return 0; } From patchwork Fri May 10 17:30:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163913 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2673283ilr; Fri, 10 May 2019 10:37:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6spiI6DuGv5TQQyP1Ux8GNvom3YSFDVCY90ob+ekc6YbnyG2vhy/MNJfBZeV92asKWyon X-Received: by 2002:a50:a5ed:: with SMTP id b42mr12222986edc.178.1557509874408; Fri, 10 May 2019 10:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557509874; cv=none; d=google.com; s=arc-20160816; b=pD5hy13v5B4coTLPC2jiVt5cNAWzSY9Yvz53HoCLpAaCKFW5uLKv+VFklcH8cGp4km uqqjGk0U6cJV+JmWkpOkuyR3FZK6AQF4ho15Sd43CCLdq25/RXHSzd+RN31YNtpmjVSR P/EZ8gLeBsUj20XFRJVgMV5Sa3BOljuJ/Wk7kyxJrPEiazBLRyNCyVtK2AEIpqXS2vNe phxy+N9+KSrfxTtnKlE2wvDzObNotrHBiQQr2Cv0BaPOAyp+AvlX+b3QS0daaEsuis42 hJ1UkX4R3Y7m08wc26UaoY9e6UpWxvBUhAeOQzf/M9TM53q+pEplQ0p1yD/k+jPaGcVi xsVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=LdhmXsWtKCIoVxpPYup4td/+S8+wQOPuaXnT2ZYWSOwOX+/1P6T/Xt3lsr3Fm7kAMK 0XTHnjh56WM71an3/x8P0m6+iWyaLgjgsWQn6yzkJABGVB4i3RXyBlBQ8XrTM2B5isXZ /xAVwbK5JeJFXw8oWcZzjKyb/lwKXhbSQ6W0KMSrgUiDt9RI0zrOIvOWFgycC0vGv/oz mOsIccNRyHqXccsX5hz/22jMGEvbfzCVObgqyIg/X094EApDNZ+Y5cpdZcqbgTVci1An GWsFJu1nA2F1SXgNUXPxQgAR3SUS7Hq+LYM+Gmo2SmKB60KXwOr0FeOUQFwSG5a+FWt5 csVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="LtT/LEiz"; 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 l4si3411341ejd.366.2019.05.10.10.37.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:37:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="LtT/LEiz"; 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]:47564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Sz-00050p-A2 for patch@linaro.org; Fri, 10 May 2019 13:37:53 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MJ-0007Ka-Mh for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MI-000612-Tf for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:59 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:42221) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MI-00060c-O2 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:30:58 -0400 Received: by mail-pf1-x443.google.com with SMTP id 13so3575779pfw.9 for ; Fri, 10 May 2019 10:30:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=LtT/LEiz8o8zZQG66+lyn31ggveLygkwoxdavL7ktPh1tyYPRmK1hIc4aZIyCEW9C+ OBowa7uPF2HK1lhsIX8q2WSzDubSznb+XQtAcgQbTVpYBLTrNBnwHYxbHuAMfLmYJ8+r 86vbw8svJwSbsugVfl2GoZm394SUdefVT084ocDxYGGdObxsAZPoTo6A7YDNf86UahwT JhHRb2jPTClkKuNQ7Ea+lM3+0L3NhEhNtdD0c5OR9GLx7yUXTQ3yXAkjaCbA7XY3sihS VQMlGvcDkev8Q+r7qPu8RgoHkAXVwhIEEWtvkbFNlMwJK5e9lYakLkJIBhHk08bVt0NX UYdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=NuZXZEzxPw/ZIlK3i+COtUyd9lLOHnHsAZcvNCWHUaLzcyHaYqUY6WXqSBG5Xrg9Ja w9yWNySyjVpLU/cqbSWuNvDoGEAAlPUNlc1idLQuIgL4yNl2zIzKSwUB/UB4IyW/dpi4 ebZJ2QbCTkkwlrcQa91U9BeNJj6dJTDNYK5vWJSuXst8gz/EFNU0hDqDO1otYH5Mnbhz 6wUyKdGzOqfLO4t3t40IeZ4U4d+8JS2wXTC1BEZuGkNlptTzhYPTZ103JrpZtIQBSl8n pf1V7L42lILEM8KHPW+wyorrrjFyVFHfIQoZfNJC0pYjC+6M1tRozOx1M9t56nDQAbnc KScA== X-Gm-Message-State: APjAAAWfCjXrBxHfR/Tk/jTiD+w6gsBEHzoE67JWMuz1KpoA4DCaE83g 4JAL8i75t6W9PD5KzrBTvEyPFjs85LE= X-Received: by 2002:aa7:8212:: with SMTP id k18mr15939374pfi.50.1557509457381; Fri, 10 May 2019 10:30:57 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.30.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:30:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:29 -0700 Message-Id: <20190510173049.28171-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Avoids leaking the /dev/urandom fd into any child processes. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 260b64564d..6df40744c7 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -42,9 +42,9 @@ int qcrypto_random_init(Error **errp) #else /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ - fd = open("/dev/urandom", O_RDONLY); + fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); if (fd == -1 && errno == ENOENT) { - fd = open("/dev/random", O_RDONLY); + fd = open("/dev/random", O_RDONLY | O_CLOEXEC); } if (fd < 0) { From patchwork Fri May 10 17:30:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163912 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2672790ilr; Fri, 10 May 2019 10:37:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFEBgCEyK7EczlGPDZIjmdgJyCcdIpkGb1HKMPBmk6u7/SVpEamzWE7xsQgKxDmOoPqqh/ X-Received: by 2002:a17:906:4bda:: with SMTP id x26mr9805418ejv.176.1557509847114; Fri, 10 May 2019 10:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557509847; cv=none; d=google.com; s=arc-20160816; b=q77AJFYF8RugbNalhL7DVnP0h7o5PoxriqnpSTNaNfchvnYLyabD4hA5fWlustHVnk zm1XjhEnbrhi4kiMcsFcbMeSmySBQj1Sd1JZGfL7kYakDUC2uX2RTRe2D1lzhz+y1Fub Wq2AFtszOmGMQDwvDinR8jqUSW7Hf7yuRvK1avIljfRUPzCkW/ukM33QvYUdlxl/8mHR oSEMAdTfsmOYuxizuhUMyo3zV/n0lWD/gluMlpaCrckaKMUpA7PrKZBa/CShiUoPpYJX 3e01rvIUSnMii6VRZdTDp7TQ/t7lgcTDsstFQiY/BuLZPzqd5kmcqX1RINNTFKdDlFGU rSKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=BFNXO+CSJUIyB4vBsJmwl02buO19GtyllxlmqyS+gn0=; b=d5o0vjDuq8NPhL2OyygFm6O+Cj/AaH4BTE9yKjYpLhFYShgHgLceykcHyVPdeQp1kD w9ZSQL0h9Xl9CRYuFYGi9Y9BQg4JlbrmAS5/Nf9lHmiELT4tlIATmcy/m6Y/PNZtgFjI 9Ez0lQ9wROOn+8kwZ3kBLNrFv+N8YBcb+Hbmy9UIDVjMrV9caAN9RvRQRu04bcp3S75B Bug9+wOurRq1RUYmD1rEIWUwa3WjhRfZKi4fz6gKiMChqjn6STNdatZhpJkQRoGgGpax QiHxwnKXEkPHUOYRm2E/WEJkfWa7Y3cZL4zuYhIM015agSl7fEPaRi3LEqVovHiKLH2L TcRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IhhRql27; 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 u2si3493077ejb.88.2019.05.10.10.37.26 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:37:27 -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=IhhRql27; 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]:47558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9SY-0004x0-0r for patch@linaro.org; Fri, 10 May 2019 13:37:26 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9ML-0007ME-CP for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MK-00061l-9d for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:01 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:38800) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MK-00061H-45 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:00 -0400 Received: by mail-pf1-x442.google.com with SMTP id 10so3578648pfo.5 for ; Fri, 10 May 2019 10:30:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BFNXO+CSJUIyB4vBsJmwl02buO19GtyllxlmqyS+gn0=; b=IhhRql27JRpyTpKfyfhwNCPUptOiFzoeD9+10SAJh5A95Z8lTymnQeV1bPsftIp2HX 8W5OABaR5iVrDav98FDzHRUFonVtXkDcs/DzwXGUlwSfjatxMbLH19Q4e9AwaeHYkiJN 5AUpHouyUc4aWTelIDU6Qls7BdriLu+jnH1MeebHhI+31YWvHEw5urjcv9bgYPc7i8a/ sFhlLK97oijZACujFMdj5i3yD3fDlv3Wn8W0JmnnWYds2NlSJK6DwPlZJU5BnvOk8wKR eUhhsBJE6ltRGp0mUpUXbbj+YyAOiOgKMxvMD3dFtqblmnlfyoAR6OuuUOtGkXl/+DPv ibEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BFNXO+CSJUIyB4vBsJmwl02buO19GtyllxlmqyS+gn0=; b=Rrdyw9tADA6qEDBznNNutpXTTUvVma9f4EnssaTdyLQyLXKq2Y4kAZJ9SiNfhaJNiX oYBY7fCzw/1NvvoKO/wI/7cXj5Liv6neNbnhuew+HwjKFyGDYlbmqOtiRqYmYKNus7TQ M6v5CAWYCniSneTCaK84HRL0Y5PhCtdbD7c+bxh/jk0bCbxfMEOSatwFrFfBAwI71t41 SVldv9PVkNQC3+Ka99k6p1DuLENAd4Wf/Qmi6dv61obrpYhp0M6Hck7O0UNOfsHPexKB HqhY0SByt8KBLOYN48vsc6+UvrbMQx5yphiqG/MUioMQrRHjZOHgvH85gjeTxFG2Q9F2 uc+A== X-Gm-Message-State: APjAAAU8f9X6AGOiK+1pxc2l3n2wQQxnc5Xxd5mtZEamIgR4/vwtsRff UjyuD1C+woUKv+2IYQey5r98zmUiQwc= X-Received: by 2002:aa7:8383:: with SMTP id u3mr15829769pfm.245.1557509458728; Fri, 10 May 2019 10:30:58 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.30.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:30:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:30 -0700 Message-Id: <20190510173049.28171-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Prefer it to direct use of /dev/urandom. Reviewed-by: Laurent Vivier Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- v3: If getrandom is not present, fall back on /dev/(u)random. --- crypto/random-platform.c | 37 ++++++++++++++++++++++++++++++++----- configure | 18 +++++++++++++++++- 2 files changed, 49 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 6df40744c7..cb3ca1bc09 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -27,7 +27,11 @@ #include static HCRYPTPROV hCryptProv; #else -static int fd; /* a file handle to either /dev/urandom or /dev/random */ +# ifdef CONFIG_GETRANDOM +# include +# endif +/* This is -1 for getrandom(), or a file handle for /dev/{u,}random. */ +static int fd; #endif int qcrypto_random_init(Error **errp) @@ -40,15 +44,20 @@ int qcrypto_random_init(Error **errp) return -1; } #else - /* TBD perhaps also add support for BSD getentropy / Linux - * getrandom syscalls directly */ +# ifdef CONFIG_GETRANDOM + if (getrandom(NULL, 0, 0) == 0) { + /* Use getrandom() */ + fd = -1; + return 0; + } + /* Fall through to /dev/urandom case. */ +# endif fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); if (fd == -1 && errno == ENOENT) { fd = open("/dev/random", O_RDONLY | O_CLOEXEC); } - if (fd < 0) { - error_setg(errp, "No /dev/urandom or /dev/random found"); + error_setg_errno(errp, errno, "No /dev/urandom or /dev/random"); return -1; } #endif @@ -66,6 +75,24 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, return -1; } #else +# ifdef CONFIG_GETRANDOM + if (likely(fd < 0)) { + while (1) { + ssize_t got = getrandom(buf, buflen, 0); + if (likely(got == buflen)) { + return 0; + } + if (got >= 0) { + buflen -= got; + buf += got; + } else if (errno != EINTR) { + error_setg_errno(errp, errno, "getrandom"); + return -1; + } + } + } + /* Fall through to /dev/urandom case. */ +# endif while (1) { ssize_t got = read(fd, buf, buflen); if (likely(got == buflen)) { diff --git a/configure b/configure index 68b34a93eb..346f89ea6c 100755 --- a/configure +++ b/configure @@ -5815,6 +5815,20 @@ if compile_prog "" "" ; then have_utmpx=yes fi +########################################## +# check for getrandom() + +have_getrandom=no +cat > $TMPC << EOF +#include +int main(void) { + return getrandom(0, 0, GRND_NONBLOCK); +} +EOF +if compile_prog "" "" ; then + have_getrandom=yes +fi + ########################################## # checks for sanitizers @@ -7202,7 +7216,9 @@ fi if test "$have_utmpx" = "yes" ; then echo "HAVE_UTMPX=y" >> $config_host_mak fi - +if test "$have_getrandom" = "yes" ; then + echo "CONFIG_GETRANDOM=y" >> $config_host_mak +fi if test "$ivshmem" = "yes" ; then echo "CONFIG_IVSHMEM=y" >> $config_host_mak fi From patchwork Fri May 10 17:30:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163909 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2670217ilr; Fri, 10 May 2019 10:34:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhoLSFGuprbrGjw2tDM2gKjJcLze488/7124ReHC5sVbLjDVQc9Ga+T4s7hML+84j+9Fd+ X-Received: by 2002:a50:e101:: with SMTP id h1mr12788949edl.180.1557509697144; Fri, 10 May 2019 10:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557509697; cv=none; d=google.com; s=arc-20160816; b=VQuCH0yKjiJsmmBb6dcGbEQ4mqMCz9eVFFaxf0a6VxvHfCMXsju3/Is7QdUDleDQGi ljTbdaSWwYn/l+kf0aa6hjfqhnjM6kJXpkMVklpVEeCRdnL8UvfPAuQNg2tKE3Y6TUeh Db3zwOp8dGP8rgqx/xPt3JJhP6zT9OE9U5g1yiKzbl8xsvcPdtZizsg9jSM6yqz14v5l AAMRTFH4wkxAafAKDU4exuSky+47UZFZG9WnNk7OaFIgCUd6TUDVcJR41YF8uPeUU5y5 UZa80E1irO1dIrf7QWr58EcKFSw3sYTx2mJa4VgHPon1ZBWbkKNXlbBxVianC2u6/9dB IfzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=cbNU9dtv8Eql4LAVzyhdSs0LNwm5NYbmY8ZCf7IDwxCx4YaCXdiavg+nKSyFn5wJLQ e32RY0f77fKJWk5IbpLqicNLtWau5EqLPwFz7tDPGgXxBUdfpO5NtCaWdFUyX4kbDAEm xvAvVfwniQk06VuhbIOcip9uWcJynZTnbsDwBNp6nBupgWuO4g8l5P8GUe3pfHH6ctku WZpiaCGDtAM56Y8e1LUCaC0Avlml44Cz+QSD3wVH+vzltwWStVfCDT+2vT5rPsN2zDP0 hvfCaJIa8KmiwFFj8sdMoi3vvcydeKlxPg3MM+lsZi0X9hKgPYyrPiFBh3MwzBh+sPbR QCkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=j3X58ZE1; 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 r47si3713150eda.363.2019.05.10.10.34.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:34:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=j3X58ZE1; 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]:47508 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Q8-00025u-3U for patch@linaro.org; Fri, 10 May 2019 13:34:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59031) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MM-0007Mt-7F for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9ML-00062F-8d for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:02 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:42232) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9ML-00061w-2q for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:01 -0400 Received: by mail-pg1-x542.google.com with SMTP id 145so3326791pgg.9 for ; Fri, 10 May 2019 10:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=j3X58ZE1k7hy5YSY4BDHgwcCYZD3EhMDS84VcsG7JsqgUAFqVeGU42oVDvrITnrB8H 5vDR+S35M/tU3ca9/dbv5x9qFGWivH4Dk3W54Oz1gdKw+LqRVM4oXGxh0g95w+3xz4T3 m+ongJtMi+ZGN3TKijgLFYU1JudIKbnmF14IO74uQfLkHs5HaaosdtmCYKEMpbcStM5P MHw2/Lvh2L9dHR8IEIIruB7TcxBCt/gUk5MG/g6RnkXCRBRCDhVcNwswn0x07khxV1UP 1d8tYyjn3orljsVlnVcJ3Ly+0DCaCMT+LPFyD8zn88gQppRRmzqZtkznDIeEpi9jmJck jW0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=TQArVo5MjwkLw6hNzLdilmwlQK4lqlntV+/qqhpHiHzhwzWZrm6CCcr5bD/gmJhVnT 6qH8SBxve6u8BTvlcK/R9JWSX+zbl+Yt2FJdLbW8Oe1+hCSwGnKIH7FRkBBxHswJ90zw WPvYc5pyUpQ8dl8ucbTdIQUT6yc/iF2JNoRLQwzmeie6i070soOWgmB4qF3X6bN8vmSF 7n1lNYWS3UaW0xGS6BskckGtYtv5RLFscXeevVEdEc9AiI5L/zXkRqu0OvTzjHm9YZYh GNlaeYLBLkqvV7wNlcQv5Hsft6O1yHrND39mrkYfCivOF42zPjO9SMdrgeKLBQNbX6h4 SxoA== X-Gm-Message-State: APjAAAV/beMcNeDEfmTCqjTQhoLvmj6QNAmclQps8Gi+9hovdJymHMYz O1OBJ6NRYKdVUhiMRL6D5FAyFj6lyQ0= X-Received: by 2002:aa7:842f:: with SMTP id q15mr16120205pfn.161.1557509459887; Fri, 10 May 2019 10:30:59 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.30.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:30:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:31 -0700 Message-Id: <20190510173049.28171-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Using uint8_t* merely requires useless casts for use with other types to be filled with randomness. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- include/crypto/random.h | 2 +- crypto/random-gcrypt.c | 2 +- crypto/random-gnutls.c | 2 +- crypto/random-platform.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/include/crypto/random.h b/include/crypto/random.h index 8764ca0562..fde592904e 100644 --- a/include/crypto/random.h +++ b/include/crypto/random.h @@ -34,7 +34,7 @@ * * Returns 0 on success, -1 on error */ -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp); diff --git a/crypto/random-gcrypt.c b/crypto/random-gcrypt.c index 9f1c9ee60e..7aea4ac81f 100644 --- a/crypto/random-gcrypt.c +++ b/crypto/random-gcrypt.c @@ -24,7 +24,7 @@ #include -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp G_GNUC_UNUSED) { diff --git a/crypto/random-gnutls.c b/crypto/random-gnutls.c index 445fd6a30b..ed6c9ca12f 100644 --- a/crypto/random-gnutls.c +++ b/crypto/random-gnutls.c @@ -26,7 +26,7 @@ #include #include -int qcrypto_random_bytes(uint8_t *buf, +int qcrypto_random_bytes(void *buf, size_t buflen, Error **errp) { diff --git a/crypto/random-platform.c b/crypto/random-platform.c index cb3ca1bc09..66624106fe 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -64,8 +64,8 @@ int qcrypto_random_init(Error **errp) return 0; } -int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, - size_t buflen G_GNUC_UNUSED, +int qcrypto_random_bytes(void *buf, + size_t buflen, Error **errp) { #ifdef _WIN32 From patchwork Fri May 10 17:30:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163916 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2675751ilr; Fri, 10 May 2019 10:40:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwtXb0/JwcAQnFw770ZwGJ58h7M3rmogWLH7iY2BsF10wA74QIWuEe+Cs47dIpxNl3APoF X-Received: by 2002:a17:906:bcc9:: with SMTP id lw9mr9772499ejb.83.1557510016927; Fri, 10 May 2019 10:40:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510016; cv=none; d=google.com; s=arc-20160816; b=XySAHFaXVS4XH/qMioYh989ArJemQvvKbHUrvWmpABCkbk00xoPrMFQpsLYIJh9DFb 9k91uMvQpu9m96Wey515uwASM0nlcSl93PlJvxYl4MouzzHP6ujHwnMKwi2v4YZCyNVz OLG7Sj7lTySMbcF1A35nKBkxdbHna1rJ6rbmTtgE3a23Ayq4He5oSU/7Dc9uxBPuY5iD 7Z7tCH+9tco7nWEp7e8FcFKhprVsIpHD6jn25RQ13JrYuVMOlzJfHo0Jzzmz2GG2De7U 2LHWy8waWLdVcze3HH7ACDoY3juLB4BQEjQA7tNQ6qNHZAUKj68SicHsVLtrmtddNDAi 1D1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=GDkR8KhtSWI6QZ6+Vzj21ewmxycr4VQnGlbvnf72fXyaIivY35gMtSk6i1bVvcXo28 j7fRuTLW4Cfs+xf3NqJQC/eIsTkMS4PuTK5XN0X+jiiKH/pSAHnl7X7lgTbhGW4dNocf mLlh7rwUPULdk3/nbDMEoT9q2RwUuOOeona9rADAT+p/Vh1lKUJGw2DzbY4xqeOQAcOr WMGhVNeoxLUFwoDUXVdUWA59L7leisX27ygJpuqqxRPyWAtWAQ6VO0suCO6CeeyO5OYS YWFg9oGB+XCt3DpJkWueBl1Oe5TlGvJpqlg5WDPps/Xo3dnrMKDaoPBZLxdlJZoelowm PAaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZkucTqx1; 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 t55si4491482edd.123.2019.05.10.10.40.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:40:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZkucTqx1; 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]:47612 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9VH-0007Ie-Qm for patch@linaro.org; Fri, 10 May 2019 13:40:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MN-0007O8-Gi for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MM-000635-IY for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:03 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:46841) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MM-00062e-Cf for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:02 -0400 Received: by mail-pg1-x543.google.com with SMTP id t187so3317134pgb.13 for ; Fri, 10 May 2019 10:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=ZkucTqx1ygwD5C7Hj7PhsTB7jxIMlQ6e2F/EH6+aLcbGpH8Lak2jiwj+iX0sjdFPK2 v+tjvLeqFnN53/nOHpGuIJ+zNdtZpEUabe8zw8WkItXLIt0qlNMkV8pPBgTDplvJH8N2 R4KdhQfH4Snnhsw6CC9NnfXxLiucvRsPUAikqaeUWnWTfy9Cj3RipAXKXohkQrV105dB bF/2yFL/yE/LXlQjBTPDBoRln0PGeevBO+BvGbIKBoHnMla0CMtwdpP14b88GjFMsqZU zBOp6hnXGav/NKaoty5Et1ZQ8wZ579pKYezO97/EvOGEXgJIda+F5xbMJ33g78m67Zoy RzSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=jNYA32t9dFW+QxWmsYjqFaPS7jQQ6ttlZPHrR7ADfVkV5qPeMUIlT3zmXpz2INnosT Pcj59oKQwu20Q95zuzFfpx2JhOWiNMGgj4uhdQmGnxIInKxcRhgykc4jBiFZBECuFzql JorXstLW07cH9M/8peNF1Dp/tvTkee6QSYqzRH9TbqHNj/QtZA7ZF7CUzodfI5n8SSLS 89qf1+OgUaEfW0OostbKd80e4G36+Nz4CNzRcl7FXTkOHwnNj/i1w0jP165a4XdNcO9q uGn1LMhoP5/Xmw2uXjChnONgQIvLoKBz7VWstrp+P3geW424lIfUTmXw+Z3AnP263z2i dOfA== X-Gm-Message-State: APjAAAXwy/TFm+LcMdkV7eGUh2Yq6cl5gCp4AG0b1BAuqB462VQCsETd /tUnXWUL4HfC73eRC6k5e2LuLAazEy4= X-Received: by 2002:aa7:9356:: with SMTP id 22mr15760191pfn.188.1557509461094; Fri, 10 May 2019 10:31:01 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:32 -0700 Message-Id: <20190510173049.28171-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" There were 3 copies of this code, one of which used the wrong data size for the failure indicator. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- ui/vnc.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) -- 2.17.1 diff --git a/ui/vnc.c b/ui/vnc.c index 1871422e1d..785edf3af1 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -2535,6 +2535,18 @@ void start_client_init(VncState *vs) vnc_read_when(vs, protocol_client_init, 1); } +static void authentication_failed(VncState *vs) +{ + vnc_write_u32(vs, 1); /* Reject auth */ + if (vs->minor >= 8) { + static const char err[] = "Authentication failed"; + vnc_write_u32(vs, sizeof(err)); + vnc_write(vs, err, sizeof(err)); + } + vnc_flush(vs); + vnc_client_error(vs); +} + static void make_challenge(VncState *vs) { int i; @@ -2609,14 +2621,7 @@ static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) return 0; reject: - vnc_write_u32(vs, 1); /* Reject auth */ - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_flush(vs); - vnc_client_error(vs); + authentication_failed(vs); qcrypto_cipher_free(cipher); return 0; } @@ -2638,13 +2643,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) * must pick the one we sent. Verify this */ if (data[0] != vs->auth) { /* Reject auth */ trace_vnc_auth_reject(vs, vs->auth, (int)data[0]); - vnc_write_u32(vs, 1); - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_client_error(vs); + authentication_failed(vs); } else { /* Accept requested auth */ trace_vnc_auth_start(vs, vs->auth); switch (vs->auth) { @@ -2673,13 +2672,7 @@ static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len) default: /* Should not be possible, but just in case */ trace_vnc_auth_fail(vs, vs->auth, "Unhandled auth method", ""); - vnc_write_u8(vs, 1); - if (vs->minor >= 8) { - static const char err[] = "Authentication failed"; - vnc_write_u32(vs, sizeof(err)); - vnc_write(vs, err, sizeof(err)); - } - vnc_client_error(vs); + authentication_failed(vs); } } return 0; From patchwork Fri May 10 17:30:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163910 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2670266ilr; Fri, 10 May 2019 10:35:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+Y2bHVfMQSHg4MVFxHO45QHxikYoTtvvRRkjb7QTMALO0bMVbC7G4a6QF7PsQuxYE7cft X-Received: by 2002:a50:a3a2:: with SMTP id s31mr12478767edb.254.1557509700228; Fri, 10 May 2019 10:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557509700; cv=none; d=google.com; s=arc-20160816; b=VHggPFLUuQvZjuRrHcdHPxVD9mIL/i/C5ZN7V3za/yeYAZHc90dFvACKwM/HgYc61o /4ozDUweg6PpEo1/jQNwoGFcrCeSzQ4Unaeqp695QP7/R9kCTRIL3sS2e1Fmpj/RDqqb t8LUc93rGvYKFH6aQjiy7/fuOeLwaD3s3SujaNEY3fsXTZ94bXQAqv4GD7NdDxZoXLK2 n3PepwaMWZwlThQPdkXJCEddBRCRixzqVwcmnYPVgfVXCBFQtpm+GQmqEw5JWopgPYNT +YbO9q7pw+wLyQZmnI+gM/Xmz7yTrbFbuqEz2cXjo3Zfv/6tQIhsvuSlmXMlc08SJst/ Om0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=I5rf4UZO5M7jzIf5OuYrD0+OIAqPeyA8/gMGGOaGTrKvKy/3C+gXR0dpRMiny5/wd4 Kl2kYLKY0COUgK8VPhdIAkrymf+BNGwZtwEvuwzh+jluppkH2nukN2ugXy9vUxLCmCxY B/p4ulKxEyyksL4Ynf7UIRHcn2lWpR5kQ+bldFUjs3j12z1TLss0lsxVIi7yMGefxUYR VpKQeHqAlna7pnM68ZEvSfdxxXgRbuty6gtYqToOuiaEXu2r6KTb3Co85/IfEyseEP1A 2fVdfxZnKtNEXC4v/09clUJXZur3JsuZaIn3RnAueWbVkodWHDIhOGanCf0xaoyELM6s ah7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=comklrI7; 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 z19si3641513ejp.198.2019.05.10.10.35.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:35: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=comklrI7; 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]:47512 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9QB-0002Be-43 for patch@linaro.org; Fri, 10 May 2019 13:34:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MO-0007OC-T7 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MN-000644-V1 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:04 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:38802) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MN-00063b-OR for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:03 -0400 Received: by mail-pf1-x444.google.com with SMTP id 10so3578722pfo.5 for ; Fri, 10 May 2019 10:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=comklrI7vJRFkDR9OWFu6hwuKVFU1zNt6vn/glu/slrjyzVypYPxPtSUORzW9gLIjW mGmGbPusUItMMbzgTQ1Ki5BgWQatG5y5+NxnZ1NtwgD6VMdLDhm2GN7qyoUa7sOxchnL ydwFyWN3HHpOKZP3mVO4/+BbAsELB6j580cGVQdhzipVPUsRjycy6qof1ezw9p6TpNiJ 0fVohOg38OnEhJdMhrqvMlvWOXW9JqLUga0M6mzDZqGh0IycE3lC9rPLFJHuJjAo23Wu u1Q/hMhIi7fAJqKtr2sgHiOhVYph+d7kOdVqidz80CcK9lslw+XxMHprd+XrJMCgNQdX Is/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/ZYAcflQLE8QxLnv1PzgjeCpnaQ2OAMJAHbK0JDJ8Y8=; b=lDLXbCvlRvBCM0vPp37lL5zqv2oKc63cGlQG/Rl3nSvzQBzx1WSegWg3GqCz11CEbj 42L8MlkjqRIcNUm0tMLgHbGbzcalUkil+4r/0p9+tUyxhoFTwmRKIMqYHfZwVfCOU3z9 FtFkWcKP6bt5oByoqqFf9IxMjW0Mj5zf1wC4UMhEjgmZ442iVOHniOnUs6guydy0PoRc 8Z/KLqJ4jX5e+upesZYTSQWEF4THFyX5LfWTjVHjV+dhy1jX3Mkpd5wsAoYX+Yg0IYQg aAo+a5grCUbHdsQANGjICUWkddW7eszFVX2OZG8ZbK/HT8B1klCNA+TkwGbBgC1dxKhw s66Q== X-Gm-Message-State: APjAAAVcN/24vV/lApcXj6CZ4WiTentXeNDE9h49GzEyczhpwGhpaIl4 CCJHMA3tnH0Brn0mUyyvnDHpg8L67jU= X-Received: by 2002:a63:7989:: with SMTP id u131mr6596432pgc.180.1557509462453; Fri, 10 May 2019 10:31:02 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:33 -0700 Message-Id: <20190510173049.28171-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand(). Fail gracefully if for some reason we cannot use the crypto system. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- v2: Use qcrypto_random_bytes, not qemu_getrandom, as there is no need for deterministic results for this interface. v3: Fail gracefully in the event qcrypto_random_bytes fails. --- ui/vnc.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/ui/vnc.c b/ui/vnc.c index 785edf3af1..d83f4a6ff9 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -43,6 +43,7 @@ #include "crypto/hash.h" #include "crypto/tlscredsanon.h" #include "crypto/tlscredsx509.h" +#include "crypto/random.h" #include "qom/object_interfaces.h" #include "qemu/cutils.h" #include "io/dns-resolver.h" @@ -2547,16 +2548,6 @@ static void authentication_failed(VncState *vs) vnc_client_error(vs); } -static void make_challenge(VncState *vs) -{ - int i; - - srand(time(NULL)+getpid()+getpid()*987654+rand()); - - for (i = 0 ; i < sizeof(vs->challenge) ; i++) - vs->challenge[i] = (int) (256.0*rand()/(RAND_MAX+1.0)); -} - static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) { unsigned char response[VNC_AUTH_CHALLENGE_SIZE]; @@ -2628,7 +2619,16 @@ reject: void start_auth_vnc(VncState *vs) { - make_challenge(vs); + Error *err = NULL; + + if (qcrypto_random_bytes(vs->challenge, sizeof(vs->challenge), &err)) { + trace_vnc_auth_fail(vs, vs->auth, "cannot get random bytes", + error_get_pretty(err)); + error_free(err); + authentication_failed(vs); + return; + } + /* Send client a 'random' challenge */ vnc_write(vs, vs->challenge, sizeof(vs->challenge)); vnc_flush(vs); From patchwork Fri May 10 17:30:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163922 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2679444ilr; Fri, 10 May 2019 10:43:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlp56Cl+RPTIQHTJnUffdjsEdLlJzspKK39GfL7MSWJBbo5vnm+90xoKtCo2QJMjjXZFXa X-Received: by 2002:a50:94a1:: with SMTP id s30mr12827880eda.4.1557510234489; Fri, 10 May 2019 10:43:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510234; cv=none; d=google.com; s=arc-20160816; b=BhAOg3VPFrYTiRGNaZnvZkzxUFno9+vciTSCUBnMwDdxFGQvAsJ1wOu7fmB59uE0Pl TAMMhoz4jmG/nbOoUvNMPfUnKWALsj5ATpIYvDkRraxeQGMpn5TzXYjlCyfxZW2ECUmT TkO79fw2DKaNmFT6s5s8VjZ8IGh6oRmixbDTdPPFvsZvvkTG4KyYx7nxYmRKT27G79AY YTycpU3hgVfnF88SAWeqy9pfIJYFiTMYJYhTQzssR121GOj7+i5M/Hs3NMzZldbxNbXz X+TkS8FhicYXvZr0VdFf912+kd8LFQWkZSNFj18mOaCdZ2CA4Nu/ueOTl/CUCWCDUo4Y R2JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=cmKdBgs20unEcgIbaIqRl7Z8kEW7cKQMCoDS2exFxFhOyZyn7fgCPqheUyUUoMUPm+ RDjHerOqKbseqebr/4Y3dlTar5j6IVNO2AUeP0yl9vkHteb6NnPhKs9GzAMup9wD2iku +fU0KX1SAUdFc1CB+b9DCTgSwaqiiW0gDyR9jZ58AfAp1pOYzj+TXpEb2t3tWxCPFeRn bwpPbhnCx23Nxmf5Dhqctf51q0n7OKI9pwdNGcEBVSJy+7EfLijL+Jee3faDbdnx7zY/ KiieuU9VzeeF4YHa5Vvw0ymK2H4G6ds1XWRHGHMQZeOcZm7nDHPcrQtcxZvuz2yV/8g8 /D2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="ie/EHeAV"; 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 d34si4530217eda.58.2019.05.10.10.43.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:43:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="ie/EHeAV"; 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]:47651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Yn-0003Xe-Ap for patch@linaro.org; Fri, 10 May 2019 13:43:53 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MQ-0007Ot-Cs for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MP-00064f-0k for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:06 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:46678) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MO-00064I-Ql for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:04 -0400 Received: by mail-pf1-x442.google.com with SMTP id y11so3561168pfm.13 for ; Fri, 10 May 2019 10:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=ie/EHeAVA9pSgYM5Z78Xp7IJywF6LnvPfcK6Q+HzrN9c3NbJqdfuQbVRG7TJ0N+n/U zvUbQn3vJNhxFb9z/+iGQ7DWsK8L0j5xhvCDIJXtzKtoERAfwDCC2tVrawLHrAajEuLZ eJxIag5wSG/GMWh2OLc/O6BUH4KkjoPtshchdMYDS+tw8FyOYdsccGmdOvtZclNygRmh n46FESvA2g/FYg0Y3L4ef4yLyZPsUorSnZVHTciyCdybmeIuNsOwZ8c2QNv13Q5TiCU+ RaHu2V+8d/ue5EZbgObRBcJsOKCH71JN6qNxzpLzM9pGnkv4HjKEf0lLvIkxDRtTzbya tlHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=iVyYMI7pwh/6jzqEfTwJN8MONeulSpKZMkxWz9wT9KptcF+EWa48guSBS2lqJ5wNYo s4JihFFvQcKEcV9cvXqlCJCB2NclgSj0i2fCVeGt5w3SSHp+10bp2RkUrg0u6I95BuqJ lylsPa7CAy7tgR3T6Wl71Fka22Eu4xXQccq5SH3gICysUCQKG8y3TBGB1pMbSscb8Jmn 4pI04MMgajLXbCt5gKhdVI05h+om0On7ApIvYaaPgeiP4q25nQT8uk/ybXSEP8CMJhWs 54ubY+cyqjBrEeJ5u2fvmZP+rUBHpJ4M8rCu2OijzgBAox5JUkxnA70Fu4veqTBB6tH6 2W+A== X-Gm-Message-State: APjAAAVSWyYTDFHLDwsulqf/DKDCUjlfbgmb7VxVETO6YvkcQxaRmHEp bhBSfyn8e4cGztJPuj9ek7BDQnqrn+0= X-Received: by 2002:a63:f212:: with SMTP id v18mr14316410pgh.231.1557509463551; Fri, 10 May 2019 10:31:03 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:34 -0700 Message-Id: <20190510173049.28171-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This routine is intended to produce high-quality random numbers to the guest. Normally, such numbers are crypto quality from the host, but a command-line option can force the use of a fully deterministic sequence for use while debugging. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- include/qemu/guest-random.h | 68 +++++++++++++++++++++++++++ util/guest-random.c | 93 +++++++++++++++++++++++++++++++++++++ util/Makefile.objs | 1 + 3 files changed, 162 insertions(+) create mode 100644 include/qemu/guest-random.h create mode 100644 util/guest-random.c -- 2.17.1 diff --git a/include/qemu/guest-random.h b/include/qemu/guest-random.h new file mode 100644 index 0000000000..09ff9c2236 --- /dev/null +++ b/include/qemu/guest-random.h @@ -0,0 +1,68 @@ +/* + * QEMU guest-visible random functions + * + * Copyright 2019 Linaro, Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + */ + +#ifndef QEMU_GUEST_RANDOM_H +#define QEMU_GUEST_RANDOM_H + +/** + * qemu_guest_random_seed_main(const char *optarg, Error **errp) + * @optarg: a non-NULL pointer to a C string + * @errp: an error indicator + * + * The @optarg value is that which accompanies the -seed argument. + * This forces qemu_guest_getrandom into deterministic mode. + * + * Returns 0 on success, < 0 on failure while setting *errp. + */ +int qemu_guest_random_seed_main(const char *optarg, Error **errp); + +/** + * qemu_guest_random_seed_thread_part1(void) + * + * If qemu_getrandom is in deterministic mode, returns an + * independent seed for the new thread. Otherwise returns 0. + */ +uint64_t qemu_guest_random_seed_thread_part1(void); + +/** + * qemu_guest_random_seed_thread_part2(uint64_t seed) + * @seed: a value for the new thread. + * + * If qemu_guest_getrandom is in deterministic mode, this stores an + * independent seed for the new thread. Otherwise a no-op. + */ +void qemu_guest_random_seed_thread_part2(uint64_t seed); + +/** + * qemu_guest_getrandom(void *buf, size_t len, Error **errp) + * @buf: a buffer of bytes to be written + * @len: the number of bytes in @buf + * @errp: an error indicator + * + * Fills len bytes in buf with random data. This should only be used + * for data presented to the guest. Host-side crypto services should + * use qcrypto_random_bytes. + * + * Returns 0 on success, < 0 on failure while setting *errp. + */ +int qemu_guest_getrandom(void *buf, size_t len, Error **errp); + +/** + * qemu_guest_getrandom_nofail(void *buf, size_t len) + * @buf: a buffer of bytes to be written + * @len: the number of bytes in @buf + * + * Like qemu_guest_getrandom, but will assert for failure. + * Use this when there is no reasonable recovery. + */ +void qemu_guest_getrandom_nofail(void *buf, size_t len); + +#endif /* QEMU_GUEST_RANDOM_H */ diff --git a/util/guest-random.c b/util/guest-random.c new file mode 100644 index 0000000000..e8124a3cad --- /dev/null +++ b/util/guest-random.c @@ -0,0 +1,93 @@ +/* + * QEMU guest-visible random functions + * + * Copyright 2019 Linaro, Ltd. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/cutils.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" +#include "crypto/random.h" + + +static __thread GRand *thread_rand; +static bool deterministic; + + +static int glib_random_bytes(void *buf, size_t len) +{ + GRand *rand = thread_rand; + size_t i; + uint32_t x; + + if (unlikely(rand == NULL)) { + /* Thread not initialized for a cpu, or main w/o -seed. */ + thread_rand = rand = g_rand_new(); + } + + for (i = 0; i + 4 <= len; i += 4) { + x = g_rand_int(rand); + __builtin_memcpy(buf + i, &x, 4); + } + if (i < len) { + x = g_rand_int(rand); + __builtin_memcpy(buf + i, &x, i - len); + } + return 0; +} + +int qemu_guest_getrandom(void *buf, size_t len, Error **errp) +{ + if (unlikely(deterministic)) { + /* Deterministic implementation using Glib's Mersenne Twister. */ + return glib_random_bytes(buf, len); + } else { + /* Non-deterministic implementation using crypto routines. */ + return qcrypto_random_bytes(buf, len, errp); + } +} + +void qemu_guest_getrandom_nofail(void *buf, size_t len) +{ + qemu_guest_getrandom(buf, len, &error_fatal); +} + +uint64_t qemu_guest_random_seed_thread_part1(void) +{ + if (deterministic) { + uint64_t ret; + glib_random_bytes(&ret, sizeof(ret)); + return ret; + } + return 0; +} + +void qemu_guest_random_seed_thread_part2(uint64_t seed) +{ + g_assert(thread_rand == NULL); + if (deterministic) { + thread_rand = + g_rand_new_with_seed_array((const guint32 *)&seed, + sizeof(seed) / sizeof(guint32)); + } +} + +int qemu_guest_random_seed_main(const char *optarg, Error **errp) +{ + unsigned long long seed; + if (parse_uint_full(optarg, &seed, 0)) { + error_setg(errp, "Invalid seed number: %s", optarg); + return -1; + } else { + deterministic = true; + qemu_guest_random_seed_thread_part2(seed); + return 0; + } +} diff --git a/util/Makefile.objs b/util/Makefile.objs index 9206878dec..c27a923dbe 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -54,5 +54,6 @@ util-obj-y += iova-tree.o util-obj-$(CONFIG_INOTIFY1) += filemonitor-inotify.o util-obj-$(CONFIG_LINUX) += vfio-helpers.o util-obj-$(CONFIG_OPENGL) += drm.o +util-obj-y += guest-random.o stub-obj-y += filemonitor-stub.o From patchwork Fri May 10 17:30:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163919 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2678293ilr; Fri, 10 May 2019 10:42:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqznqo458k3mkI5bvN6zqd0yAqoxDDGCGjWEs/brRiJL+0F5aZgbAmO4ahi0v+6AJqbeu3hq X-Received: by 2002:a50:ed14:: with SMTP id j20mr12784643eds.84.1557510169170; Fri, 10 May 2019 10:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510169; cv=none; d=google.com; s=arc-20160816; b=zUnY/qZrwawdrtkjL4pPQT57iYgdKZfGzJwpTktuPJak36oKi+11ed7E6KtJnqxjGP ogPdlitLjds3vp2bwvvAUnyzgyBoZI6NAGjcsIAjC1WmOSgvTCGNOLuDaRgBoj9jp0zA Qr40hAgP2/NDe66n0MGqNIj0KR9e1upM05m7lHziAfk92DU1/NPVCMiPtALWN87zYjxi XfStM7Kd/13HOnowLFZu+/7Kx5XdA1tvSL56HTSnHBAR7uafHKi9ThvmTaBY7vdHbx6v 7jhXbwmaqBjWMFf4NEuUTGJ7tjtjH6helnmeOJrRHx+9VoaCfW6AHjnVJ6yuNn4OAZys vjdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=oIDEuqyIXXAdXSBpywI+3D7Q/lmqC0qVHQeXrw+41sD2urhS3kzA5gzCTRhiJIf6GX d8MGC8BEpg8Kb3DQmGvW2unvGygfhAfmUlFtP6IUQty0xhDrz/zkxN319HVoycwThhAN CJhwLn7D97UuKmqj/rhWM8uCU31V6im1u158Kg+3KgkNrpuC0I81Qzsuu2KgaEVF/VDp O2/FWZrnKBqx8oVA2vLpn+RYuFjmeY8vxlz5Tdb5ekbjpHsOmV4fIRQbUJsq9oSXUeZX GNwvS8Xgz+RckLUe8JSNlZb6cohxq9C+R4ygNt2MDiyFAw6sC1cMiELTO064PwBx5Q7W VZTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XhA+pXlR; 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 k3si3456595ejv.154.2019.05.10.10.42.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:42:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XhA+pXlR; 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]:47637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Xj-0002c3-RJ for patch@linaro.org; Fri, 10 May 2019 13:42:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MR-0007Pg-CV for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MQ-00065I-5V for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:07 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:37843) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MP-000653-VI for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:06 -0400 Received: by mail-pf1-x444.google.com with SMTP id g3so3586230pfi.4 for ; Fri, 10 May 2019 10:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=XhA+pXlR8e0RNUXPWtWVNimjmg3Im0ATqmR7L1NDpEcJFBVuCMDLyB+9tdR1cESaJc klGlyzU6AopnoZbNqxUG4f3T/lKayuqZB7r/ud0Wn99QDfyK4/xNtnsolmBYODXLsgy0 a8gths3Pz6XLS/kbvrlH49ry9+51SZy80svCFITgsgU0JWJCHXNSYgWKYhEjkdR+4Fuf y5pBBi4u9OLJ3l6lL+WNUMlEkSrDqrWYam7cbQLRMN6N0O43A/SeLyJ7FJ4SZWE72aF2 RGoZ0A+VMiypiEc5gz6wDOjsS26LpUXf+cNK6JDsRpLFyUPTyUdNk09UuBozIZoxg1dL InnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=SNdjOtyEV1X5CwrV7U0nB0XLkYlDPyZDQor/fDofa0/laHpgZhPEGEwrddPO8e34vw N+db8Ljb8hDOv7kxZZHXUIlzIEVS50z0WxsRnX8QAY3/qe0bQULgWrRqyBiMTossZxRh cBuh8KR6ifBgtGL0UYzVE+6cv4Ab0Dm9BsOOjPxi75Dk9lB1bdeMnsoIQjOOxrxInBU0 F4jMTBIE6D1mBAmBuAnvI5R7ZvhIvaj7VLUapjuCfNtSouynIw9CLqSFmNfuwXTxy2QN V4RD4JOlj1OIYeq/v94DKA6nic82FcWyzOpxznj8drFZkzCQyV94/yv5V2icBlr/EN3D dXmg== X-Gm-Message-State: APjAAAXxJNT9RmJOb/h7fbMehwuWK/Ek5zUJgn0pHpCzR5jrV2gElOHq ESlKGiHC0kuKtbu38SAf03ouvCQROJI= X-Received: by 2002:a62:604:: with SMTP id 4mr16094082pfg.38.1557509464762; Fri, 10 May 2019 10:31:04 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:35 -0700 Message-Id: <20190510173049.28171-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" When the -seed option is given, call qemu_guest_random_seed_main, putting the subsystem into deterministic mode. Pass derived seeds to each cpu created; which is a no-op unless the subsystem is in deterministic mode. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- include/qom/cpu.h | 1 + cpus.c | 9 +++++++++ vl.c | 4 ++++ qemu-options.hx | 10 ++++++++++ 4 files changed, 24 insertions(+) -- 2.17.1 diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 08abcbd3fe..9793ec39bc 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -369,6 +369,7 @@ struct CPUState { int singlestep_enabled; int64_t icount_budget; int64_t icount_extra; + uint64_t random_seed; sigjmp_buf jmp_env; QemuMutex work_mutex; diff --git a/cpus.c b/cpus.c index e58e7ab0f6..ffc57119ca 100644 --- a/cpus.c +++ b/cpus.c @@ -50,6 +50,7 @@ #include "qemu/option.h" #include "qemu/bitmap.h" #include "qemu/seqlock.h" +#include "qemu/guest-random.h" #include "tcg.h" #include "hw/nmi.h" #include "sysemu/replay.h" @@ -1276,6 +1277,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1319,6 +1321,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { qemu_mutex_unlock_iothread(); @@ -1478,6 +1481,7 @@ static void *qemu_tcg_rr_cpu_thread_fn(void *arg) cpu->created = true; cpu->can_do_io = 1; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* wait for initial kick-off after machine start */ while (first_cpu->stopped) { @@ -1592,6 +1596,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg) hax_init_vcpu(cpu); qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1631,6 +1636,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1671,6 +1677,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1724,6 +1731,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) cpu->can_do_io = 1; current_cpu = cpu; qemu_cond_signal(&qemu_cpu_cond); + qemu_guest_random_seed_thread_part2(cpu->random_seed); /* process any pending work */ cpu->exit_request = 1; @@ -2071,6 +2079,7 @@ void qemu_init_vcpu(CPUState *cpu) cpu->nr_cores = smp_cores; cpu->nr_threads = smp_threads; cpu->stopped = true; + cpu->random_seed = qemu_guest_random_seed_thread_part1(); if (!cpu->as) { /* If the target cpu hasn't set up any address spaces itself, diff --git a/vl.c b/vl.c index b6709514c1..e1d75a047f 100644 --- a/vl.c +++ b/vl.c @@ -128,6 +128,7 @@ int main(int argc, char **argv) #include "qapi/qapi-commands-ui.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" +#include "qemu/guest-random.h" #define MAX_VIRTIO_CONSOLES 1 @@ -3347,6 +3348,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_DFILTER: qemu_set_dfilter_ranges(optarg, &error_fatal); break; + case QEMU_OPTION_seed: + qemu_guest_random_seed_main(optarg, &error_fatal); + break; case QEMU_OPTION_s: add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT); break; diff --git a/qemu-options.hx b/qemu-options.hx index 51802cbb26..0191ef8b1e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3601,6 +3601,16 @@ the 0x200 sized block starting at 0xffffffc000080000 and another 0x1000 sized block starting at 0xffffffc00005f000. ETEXI +DEF("seed", HAS_ARG, QEMU_OPTION_seed, \ + "-seed number seed the pseudo-random number generator\n", + QEMU_ARCH_ALL) +STEXI +@item -seed @var{number} +@findex -seed +Force the guest to use a deterministic pseudo-random number generator, seeded +with @var{number}. This does not affect crypto routines within the host. +ETEXI + DEF("L", HAS_ARG, QEMU_OPTION_L, \ "-L path set the directory for the BIOS, VGA BIOS and keymaps\n", QEMU_ARCH_ALL) From patchwork Fri May 10 17:30:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163914 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2673378ilr; Fri, 10 May 2019 10:37:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9S8JwCpxqZpnuesrqTT7DyCn5IyTrFFH07U0V3MyJx+wvZKOkV+fuIRZlaVrQAx2ybPu0 X-Received: by 2002:a50:bb24:: with SMTP id y33mr12420454ede.116.1557509878712; Fri, 10 May 2019 10:37:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557509878; cv=none; d=google.com; s=arc-20160816; b=NzgCxpAXaarpJPww4ZiL1pfpYWbgGveitdbdD22r59g4suWLCZUzKu9LGcM4if/ZFH m79NUi9fRM7+Up1QJ+fXR7sgo60ntdWwCnUYZ7KECe5eFsFSqIx6817uhSTOnroflwYr Q3ufvlJ6kZTCSkgTGn8g4P4A4YzlqrefVtQ8I76AMEbZ58jMk/6a0q5U2xFzKWMPQ0yt HiZf/DPxkwWHhXLbFdCOgQLZEzyci/hbCU2wMswvMfZ0QJt9XbnPiv7BcP1g7Kw2oQzU NgE+1jbFtoFcfhYNIfsUNHtw8oirOzM80OoZzNpCFOQDfO4QrG3ts+u7owBpDAFOOV9W s/8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=ceT2r+izts3PAZf3K2FbPyiFmzlKg5cF+haJm18PT78=; b=0NnBuQPNmrokkGPP44cXTbFsjv6tIrlQ3xcSOQTkIkrMjlxsXmzoU9h9OLNkpC7cSO RawiGzY3RDfin4o79KcWYZRlYY/2haGUWzyWl+gy/ZHztjg57wM34bsKmZOe+mKhvALz 1VVsTqTy62nUKZc8EbKEOHJqN79qctIBh5GLJlmeoimt9VbPS5HiWWUKB+nISzOEPNN4 xuYnTQHDNZf+slviDfkM29aq+VrhlzRR7jwVSJTnZwVLkVEjRaxju21LewQl4KZ7UMet sMRY4iKxzsCG39gGypPqBgH2+OnxgTsB9sj1nwUFkzuUXDVgZAZYaiIIwjz2VMa+zEgp hmSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GPF7u3U1; 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 x26si4603719edm.106.2019.05.10.10.37.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:37: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=GPF7u3U1; 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]:47570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9T3-000543-Fu for patch@linaro.org; Fri, 10 May 2019 13:37:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MT-0007RV-5g for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MR-00066X-Qy for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:08 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:44171) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MR-000663-Kp for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:07 -0400 Received: by mail-pf1-x442.google.com with SMTP id g9so3564953pfo.11 for ; Fri, 10 May 2019 10:31:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ceT2r+izts3PAZf3K2FbPyiFmzlKg5cF+haJm18PT78=; b=GPF7u3U1LVBVDG6A5rXKtsYXh8+nXr/1DELjYbkrEtTUnrIco4/YzrXTE3q2l4rtgV +xlrrDeJPySMHxSICNsvSwqPR1kWsJq7M6jfQrCdGdODs0TWhpl90wj2OCqH42TG6Bes oIG67b/oeNe/LPY2cR8i2wZ/ATmie7/aYc8DbfjxbBMUjzZdsqblMYSiLIEuatqdR0y1 TIKz/YF7b5cfTmbKR8cphfOC7RqaQSKdNg3P5Px7sJRhrl8b+S/FzJV2tck9DZqvNuO6 foHmxL0w7w4PyNUQNCo1km6NeSOU7cdhX86YUKQpeWJKkJG9Ew5NJOUOa/4Viv3H4uP0 /a7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ceT2r+izts3PAZf3K2FbPyiFmzlKg5cF+haJm18PT78=; b=bg9x8tDkC6UOFZH8vjLEDzaEUGIhL1LaS6IoAcAVaXW1eHmL3iEdtSq4dYb+U5eTte yxUNN+sRg5i+jZmcpm4c5KAY4PqM5WbgVruw2N0SKMR85pJ2Vg0tNklGl08SMGrqZAwP f7YCV9eh9JP2ymGIcu0hQG8nGHDvbJjczBQwt86s3tUW/pxCJqNA9Dzxpo53wbS4wRjv HbnZ7p1olC8mHU6CI9CSw8kfzamewHKSnNiWriINcI21Pd+t9Nfd0CP4oNsUxeVRTkjb +nlDl5WGeF2Avt9PCfzjvgkpcTtciodeaagK/nM7ep1ZmZ6ov0HMvzj7IfwfLkM7Vjfs WsxA== X-Gm-Message-State: APjAAAWG0pR5OHN3AGC3Mn8zRZsb0V+onmZ/UfnoXa+CfMoOHOSHEDai GkfcDMkpPrgmbs/UU522MPTROM7JZgI= X-Received: by 2002:aa7:9148:: with SMTP id 8mr15706393pfi.176.1557509466384; Fri, 10 May 2019 10:31:06 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:36 -0700 Message-Id: <20190510173049.28171-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v6 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: , 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 --- v5: Retain srand() until last user goes away. --- linux-user/main.c | 30 +++++++++++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 22 insertions(+), 11 deletions(-) -- 2.17.1 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 f5ff6f5dc8..96f20886ce 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 Fri May 10 17:30:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163920 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2678453ilr; Fri, 10 May 2019 10:42:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxk4BYSKBFxoTdL2TZ7jvKEIWLCT9DJXIM67i85qL9ayzAikohGgJ2ixRJ3in/Sd0U1HLlY X-Received: by 2002:a17:906:314b:: with SMTP id e11mr9685050eje.259.1557510177744; Fri, 10 May 2019 10:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510177; cv=none; d=google.com; s=arc-20160816; b=Mq+E/YMSSmm4NFjH9AaR+QvD/bXjdgKgtIAq2rF9SGi1+H/nsEHEp0WxXYJHkPF/BO dVWelmVEzWCiR2xd25Carcb/CM6EzmJL4jT+R8NkRVZ4/1ou0lHULYO+sLtE0FiPWJId nOpe7wc8XKVq6T9qZmdOR+KdgB+CVrSoVhMnv7Uj0nu9nIXS+ZN/GvcuhEdc3Mqe/tLk 872SD8K2yK+XNBAL4Mv7HKC9wp9UdVzXKSSU5icM7mtWGeJLZwclhpyysJY61/et5z7p wPfeTywwgqgZSo7tJ2dIucRsw1Sr57fLI9nMr+T9qd31l6/risJEKxgA/MzmKKwUz+Cv h2pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=fAXpZvlDsepPUFQXEdmtR99aNvFnqvXET4zfpT6bZ/Q=; b=ZoOkrsJXCsNSbHHKKs9stCZNqw70WS8Y4a4/O7AmuRZkZx5hWMJcAcgqRwC5EZ/H/7 w/upaoE5NiWS8/iFf0ViAIQ93bcggrJcxXypovXREO5+SJLqDSPtsjym1NsBDo7NWp05 pcSJf6kKye5DHobpADbnFvS2+lf6bd5BJJjW36XcaxCQkcyvhUL/eaTpgmHVB37+2ozh Csp1bdS1x1KbNIvJo5HJtbu4t4/6XGfh1iMAkRtMclheEbJ7rCr/tdvZTZ4PNKSNj6PR nnshl4Glk4hIEl5xF3ICMDXqG5Z9T6ZcY9sFI26xsUWgOalQmOMccMRPTlWBq3dPGt3u ytWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qzAQeB+R; 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 a20si4370710edd.180.2019.05.10.10.42.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:42:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qzAQeB+R; 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]:47643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Xs-0002jH-Lv for patch@linaro.org; Fri, 10 May 2019 13:42:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MU-0007SI-0U for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MT-000672-0W for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:09 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:44199) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MS-00066i-Qb for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:08 -0400 Received: by mail-pl1-x642.google.com with SMTP id d3so3129847plj.11 for ; Fri, 10 May 2019 10:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=fAXpZvlDsepPUFQXEdmtR99aNvFnqvXET4zfpT6bZ/Q=; b=qzAQeB+RIATfRdck8iCJFBZ5cOBmMRdlNXKP+kiT0oaPRt+Fmi4QG9IFqEhHUXbHBQ 5fLlQMW9PKxqIPmW81yLXaTzRjgpsor3L/CQeX4Q0MiKSufnwSpBO2P1mpYSw5PIxDSX N6JpSgHv5NBG/2zKOvfx8ZNtpPBRtNZcsnV/DtU8/St5qDIY0SDoGS+G/sJEkl8ih3uo sRKq5/icAOkOkn1WN53mVritvZnGi0rYUpUV95HYWfjqs5J2b0h5DuQVfSThH6Jmzjg3 JHnWCSAHuKQInQTe/pVVv+geVzMZ2TojV2STVtk2rGhcp6BeZKn7l3vbsmDvsEE6qTH8 YErg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fAXpZvlDsepPUFQXEdmtR99aNvFnqvXET4zfpT6bZ/Q=; b=R99T7L4XTcSIsx0jm4hl3AC3ffLtS5UcTDC7uia0NxYA2afNMc02hUnFsGrmriK7kD WCXmEaAVUJQ4viPCAw7o+vKv+sbDrW9YzdrXSGPdRaDxGkOiqZsmIT8x1XJX3FZfx6ew +juH7U4uDUDb2jNpsjGKjdiUhBL/coUA+arTCkIsutuh7lMvTYhBAYpGoEoHBRTczch2 8NuXDPXpSvsRdJOGv6BFBhk1J3w2T21RUJs+v2kSu91MDLqXrZfMsPuT8cC/vQrjSLEV A+4sLRwOPFaeHXkrO9WOcJWX4bbq2gUAgjMF6yxg47ah/F6re2v7Y6NiovEPGxbR+8/1 qKFQ== X-Gm-Message-State: APjAAAWebavP8jEFJZrScpvYeBnj7jR5IC5IA34rDQwFgTg5ryWKYhXa Bp7b6dpSwzZRQhiB7qgtmPWbiAaFwGU= X-Received: by 2002:a17:902:9a4a:: with SMTP id x10mr14592810plv.113.1557509467521; Fri, 10 May 2019 10:31:07 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:37 -0700 Message-Id: <20190510173049.28171-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index 7e704845c0..e455bff1b7 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -39,6 +39,7 @@ #include "trace/control.h" #include "target_elf.h" #include "cpu_loop-common.h" +#include "crypto/init.h" char *exec_path; @@ -688,17 +689,27 @@ int main(int argc, char **argv, char **envp) if (seed_optarg == NULL) { seed_optarg = getenv("QEMU_RAND_SEED"); } - if (seed_optarg != NULL) { - unsigned long long seed; + { + Error *err = NULL; + if (seed_optarg != NULL) { + unsigned long long seed; - /* This will go away with the last user of rand(). */ - if (parse_uint_full(seed_optarg, &seed, 0) != 0) { - fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); - exit(EXIT_FAILURE); + /* This will go away with the last user of rand(). */ + if (parse_uint_full(seed_optarg, &seed, 0) != 0) { + fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); + exit(EXIT_FAILURE); + } + srand(seed); + + qemu_guest_random_seed_main(seed_optarg, &err); + } else { + /* ??? Assumes qcrypto is only used by qemu_guest_getrandom. */ + qcrypto_init(&err); + } + if (err) { + error_reportf_err(err, "cannot initialize crypto: "); + exit(1); } - srand(seed); - - qemu_guest_random_seed_main(seed_optarg, &error_fatal); } target_environ = envlist_to_environ(envlist, NULL); From patchwork Fri May 10 17:30:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163921 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2678928ilr; Fri, 10 May 2019 10:43:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4MR21bleyN+DTzXQLM6bCXNpvJY7vhlmYIoJr6YbsRF0fGHOb5O620qxGB9O9xwaccT2n X-Received: by 2002:a17:906:a414:: with SMTP id l20mr7316793ejz.255.1557510204944; Fri, 10 May 2019 10:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510204; cv=none; d=google.com; s=arc-20160816; b=yxe9G0f4cX87hmhb3+w0rW82wTlu1o6xsHSY076cafSWUiGpoPdzfAMJi/OXRlts5/ yRlgDkHUatN1n1AMOAcNgozz1Kipqjr//1XSQz44Ozhvcsks7x2C3gm6RLb8YVeBB3T2 pn2Wyxd9Ina7uHsoBXyIL2vBtKasHYvRAHqfyqA/+eMurzyoglg9+Yni473WOP4G2sbx 8WG8lR7CKupsUDy7EGEJ9xq54GGhbYQZYBFVxroLjNHtkEXSTRtNA/VkWe2ftf0m4gmx rjF2gA4Y/xsgKoqnvyGnY9eVuGXkIy4F9QJxHjfv0zFUIBB1qmaRTtYitM+c6qx/TC5V lTiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=LA1zmsYxmzBAEiSSaTbYsFeqnklh9uk6Ygv0EHqOLtQ=; b=r22YRLaqPQduGLJzYXpjAfUhdat9ZHG5rXEFQPWiU83NkXjz+xif9feN97rq4YRSB6 gDlkxrwSDCLBLoxoP2BQkBKnTbNi8/upgjcpSsZbOExrL8qPxc5Ir7Pm6nJtvdei4FEt HnGZ33RB5cuY4dFPkBWNHZ95/kbI3ZqSg81eZ49HT2gGYCrJ1f1yLffULdu2ojglvsJJ tFwup3B88fDvn7OM4VuVsRaBLzYOTefyA6Q1ANAVYZI3S8KD8cROWu47e3Qp27zejRIo LYz1klH1ikngMzG+aIqpAJzV8EEzFMS+VsUJg448zveiTH+SUo+ca/YtoJ//b9d0R7En ylWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=FNPH219O; 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 gr15si2244347ejb.272.2019.05.10.10.43.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:43:24 -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=FNPH219O; 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]:47647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9YJ-0002nk-QD for patch@linaro.org; Fri, 10 May 2019 13:43:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MV-0007TX-0g for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MU-00067t-3x for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:10 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:40333) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MT-00067S-Uu for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:10 -0400 Received: by mail-pg1-x542.google.com with SMTP id d31so3331433pgl.7 for ; Fri, 10 May 2019 10:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LA1zmsYxmzBAEiSSaTbYsFeqnklh9uk6Ygv0EHqOLtQ=; b=FNPH219OQ0b5NQFTLYr6qpuNP/ia06SlQEpUiIzLc3TyDA5TWvjGWa1re+Ocdw+oN3 XY8VJIv36iFk7zFNJZ2aiLd+zCPWke+1ASbAw7piHG8/uhA4VpC5gFji2+zKfzSS6Ur2 1QaMnFgn6lc8YtDNa8zDc71DVvQG7tzFND10aJrnlOXWkjDcNnZeCkXAs1kdIgF4mUOq IC5LMWKfCAlXRZbFUQnCuieTTF/9x0MU7w58Gqcju1nc3khvPQhOB1xVSPWCgdknS8u9 ar3wyyjkfKMWG7gUdePlY6YizDJG5ijb8GC+k0S85x12F3hZYcn+o+n4RQV/CvFU16gM BpAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LA1zmsYxmzBAEiSSaTbYsFeqnklh9uk6Ygv0EHqOLtQ=; b=Dml8TncuL3rmlDZ/Y3reJjcdsQMZoQ9mNgIDKsgSrFAc/Z5+9UM9O/PT+62VSsvUTp uVyu08ATkPHMc0eMC3jin5kanGNyaXvsa9R4ckYwgf7k89CABv+J0q1R+t9KgQP05UKI hbKbba/cMVUXMBFPmICBK1XACnnEWnd3EbdEQj51tRPWOqvbEdE3NHx+qLa96GwCD0np Zd9lhprHy/lZg7AYkRzfj5mTZkzbOTDy8U1j0YGqvFbRiHw8Is75qg9FG8R+Q038JdBW S70c67VO60acs+fpmRv4fCqdky+fvKjs3+QbDDQ5ewOKAdUZpUAg73vmn7Jik7y9cVaV ttXg== X-Gm-Message-State: APjAAAVXBTEaT2PZ8QaAnNOSZqm4bwKGoCMm6V2bqhLoU0oh+zszKUt1 b3+ndbELhIQHcS9QTFZXM2fqpRfT7qM= X-Received: by 2002:a63:1d05:: with SMTP id d5mr15173262pgd.157.1557509468739; Fri, 10 May 2019 10:31:08 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:38 -0700 Message-Id: <20190510173049.28171-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH v6 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: , 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 Fri May 10 17:30:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163926 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2681864ilr; Fri, 10 May 2019 10:46:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxQYbu4aUsN0VbPlRLaEp7+xJ65JGP7ORPDkIN9OYGd5f8Y5vwKMgYlAcIq5FDarjeZxa9b X-Received: by 2002:a17:906:2ac5:: with SMTP id m5mr9921830eje.71.1557510373878; Fri, 10 May 2019 10:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510373; cv=none; d=google.com; s=arc-20160816; b=fhcQCsO2G8/Y8OiGNAzaPq0L96JSsH3koAVZj5cfWXsRYQPD5QSLvAH2TmA/pLQ9TE 7Q1ipPeiPL9le2GRm/ZBWD7zdJ4Yr7XrIG9szRpi0O2SeXssQrSRiMJ70eEWsWae1hOe cE8ynSOgeBZ12PtVQ5cW3kIr1z5++POwPh0H/crrBnn8k9TD8fev0qaEbWcAwIMaXNn2 chJMDXAGoxbbfYgN7BepvoYQcI3a0m76f6Zf7IzKGxmbRz2urp6nWNXHxC+MCtG3qFNf YrjGdzq92xm1Q8eo1tl9muyGj0dAEXybZkgFDKWVv8gbF/2A0d51uzfa/DX0ZNozGTRR xpig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=yE70JIuqrA6MJdI0/JWiVeD/16stq6LybzVtzKfjj1Q=; b=T8Pcnu0XEN96Vi7enm+/JbemzlJnRvo7ebTXKcQhgoPg5FMv2zNAaOZ5EKB+643xte px1adTeEWGIMIfSKhfa9e7ViIIhEWIm3vY2fCd7Ly9w3buRbejRrbtNhMuC8SluKqFOa G937aBCMQaT2LGH3UXhEc6TEqzNMjAM156HkMnAN4BHlaimikqk+3RzpHRwcbzlc+yqA PlDxK78K4pv9qi8v1NpO+B//8Sjl6HcHkQVfLIRAXWj4D8u3YCCSGnU6k9imn8hQxd+d EG2B26rtbDRbtF2PHcDv7RH+iCv7ez7V65z/ENlY31iHrwJ5/Y5FMayt9rAMXUc0q/UN mGkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=gs56dEN1; 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 z10si4510817edc.287.2019.05.10.10.46.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:46: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=gs56dEN1; 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]:47702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9b2-0005Dp-Jp for patch@linaro.org; Fri, 10 May 2019 13:46:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MW-0007U6-Tb for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MV-00068Y-I6 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:12 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:37921) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MV-00068B-Bw for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:11 -0400 Received: by mail-pl1-x634.google.com with SMTP id a59so3143650pla.5 for ; Fri, 10 May 2019 10:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=yE70JIuqrA6MJdI0/JWiVeD/16stq6LybzVtzKfjj1Q=; b=gs56dEN1jv8sDVDblSRkxhfhLlFzsPjwrd0lLyjjQEYlCjdkhRtK8yaOVHcLlynpZw HZQJ9BcGP9o/Gi7kx90hFVDlSdAau+dV+Vb9eqeYUU4mypZ9vBUH7jT6f9XDUMPmzlBE DaYOa0WsCxQlZJWCNYEqOMm7z/A9mLVdVSims9NVXrlgJ7tgcpiHBFnZ019e3QMBq7B3 FC1P8B210AXqPodJcffVWSIGuBBKTnGKE0jHGCSFeeCY8Zz6HsIpVIxTfUbj60nMm9Cd 5Z6Gm0yY0YGYZEoNOJAWe9+STAuO31t9EEFonH5sBf7tVWU/EN+OZocy6Sit++JAmm+3 FX9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yE70JIuqrA6MJdI0/JWiVeD/16stq6LybzVtzKfjj1Q=; b=pzY/Pbk00f9atCcEy+ZaxpUCHG9gdVguzN/M3eubccG2dEP/oXWyHLJLTxS969eUxl cKNiKVVVH2S6CPH5ghx0Cw/ZOXmzO6hZE/d62aE+BPj9xmOb9imS6xTi1KW+eKr9ziJu X1xvuX7oBM21O1+23+gnfbD6g5/JWk2QPrIsXvSvC5+71aPJV6FX95AQknHxTxBSjPp8 IQU/EcHR6bUyyXIF0h6mpQQ5LrUfziXzlC5K+Dd/aSrsnYCv8OxvFDDRjsRSvm1p2abR V/SOh3U6uQOS14TRNsx5CltE2WWim6v2uAhmVIXD2gg//rlqQjn+FZaghhfDYEZ6kg7l E5yA== X-Gm-Message-State: APjAAAWxo56ZRg1awXto0s/HoAZT/lzISp1WVsNSX4ji/CPnn6XnEGtH 4Ig9jUaC5nHkM/tvM9uzg4llPV3QCxs= X-Received: by 2002:a17:902:aa45:: with SMTP id c5mr14515287plr.144.1557509470020; Fri, 10 May 2019 10:31:10 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:39 -0700 Message-Id: <20190510173049.28171-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-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::634 Subject: [Qemu-devel] [PATCH v6 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: , 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 96f20886ce..8c17b14d51 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 Fri May 10 17:30:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163928 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2687779ilr; Fri, 10 May 2019 10:52:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxslN4ST1jwGujbYgp9nELI3MzIFK0ESdtx3iU0Pvk/6TJStnEeLUAxLzGnFx4M+7j1vBXD X-Received: by 2002:a17:906:264a:: with SMTP id i10mr9021093ejc.294.1557510721344; Fri, 10 May 2019 10:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510721; cv=none; d=google.com; s=arc-20160816; b=aOev8FmB7tmfQW9uCCiorekN7AmB4aCA4EOSDttjbjzGAU7NRUCTejcJMlOJPywjx4 kU+ZhzF+GtIYeX4RUzxvUo9DY7hoHeEvXmsfPJ9xtLkLIydQv375CW4TM3WSyfvG2+9u No19CySthPNLE+DeagxanSjPRLGmqXIWFmsHE51mPtyL1jbW9BmRqEqqEWU1Iv9TIh/q r8/2ubRfdUx97hTajK+W1jVvlGqXq86gffeytwl+PYECDe4c1ckV6AxGeM4EY/r+HyiC 3YIp4hiWfpwIOa7aMGNiB9dT92P8PR40AtOny57dinwp71IoU+uqUHkgQ5hrbP3UOeOn OA4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=V+gOkII+X0gMY90Is6MzBXqbkDPGTCzHgSN8abaUrU8=; b=d4yYN3j2qbqF4NRzFyjF0XuUaJYjGi7YOrB2rUOaYcqC3s9YMNehdLc4HGVmdRAkIa 3wRxT45xoZEVD6GAcevjdLXEWRGSOIXQ1CYsTZwHemnicSs2DEWd8bLIA1QvXIWeDBGs M8/FDnBYwBNsD3aLN6PnWHE7qFf/OGI2Fs02fnScC9lUZII7ePNKCObAtN7Bs0iaS3lQ e+DsrV63XfqnK6lhle/7T38A7f9tKpfejRFmb8CJq490lPKf7yop/YT6QDCidOtWeaUq 71FDpOWTdv8ibw8xRfWl9fRBmpA2KKErEwlsDP9uTCUJrFN7Ft7cmbjNAVKNdKeP62/I JnMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h6HYYZDw; 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 p38si3186249edc.348.2019.05.10.10.52.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:52: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=h6HYYZDw; 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]:47789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9ge-0002Vg-7z for patch@linaro.org; Fri, 10 May 2019 13:52:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59164) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MX-0007Ud-LK for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MW-000690-Pn for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:13 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:35796) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MW-00068j-Jt for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:12 -0400 Received: by mail-pf1-x441.google.com with SMTP id t87so3591573pfa.2 for ; Fri, 10 May 2019 10:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=V+gOkII+X0gMY90Is6MzBXqbkDPGTCzHgSN8abaUrU8=; b=h6HYYZDwby2Pv5b/wP2xRw4m1mLD22hQYqzLyORS/nCjrEUlf246slfhBflJpEF7nr jPNkP0YJmfO7j7a0EiDGVc91JuLdDrdkzJlkuYiI6ntDcDk00L9d9Vj9okUXvlpiuT4+ qQY/BEp8Ij6EZIUGBrMbBhIGsYrzgDOTdoq9fJSlG9ybNZRvlqnYmDwCBOG45OPHvepP oJRD4z+klAmTUe0pweO+so1/0c3U6yFZbAo1VtFC2/DyFMpB5/f17ZdL4xj7xis/4B6+ wi5xBIiE1tAULX18AdDiT4uzaXAJzmMU3i0WR24YLnCZ+x16j1PkCXzU8g8MuqAZ7EiJ YNUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V+gOkII+X0gMY90Is6MzBXqbkDPGTCzHgSN8abaUrU8=; b=HwRILyFyT8lMhBisgbodvPmdJuj12WldkYIPdZbVxIvzFabeiLCuC8jG8EZTd/AKnu tLsocysjQfwXjuxO820lxa35v2wtWaYZ6DGbr4aVsCuTl46KJPGDLKo4pUrxYhfIIWjD /rzdfgSuHvubTSWwZ7nxa4ZvueeSqKs6QSeUQMiBqPqrZHW72XZZrDBxDtykHO/YGu6y UzHZLdxKUeAB30sSe6Sow9tAmqfNvov/gEnjzynK6Sr3r9+nn9JYgdBDyHKpVlUh3Dod MxOi2CwQ86lax6ry9zo3q0UYunCj4cs57vIvK7EbiGaNwDs6Q+5nbOmqdJ3SWVyhLEhI VdtA== X-Gm-Message-State: APjAAAVmt39VYtpLalBOKPLMqWfL1/dzKb1YIr6paLgx2ZEjuJEqpsRl qDyu+QmkFtSB/q3WFv4d9Wip+adbjTE= X-Received: by 2002:a63:6a41:: with SMTP id f62mr15367573pgc.392.1557509471274; Fri, 10 May 2019 10:31:11 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:40 -0700 Message-Id: <20190510173049.28171-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::441 Subject: [Qemu-devel] [PATCH v6 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: , 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 e455bff1b7..5d1c6a115b 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -623,8 +623,6 @@ int main(int argc, char **argv, char **envp) cpu_model = NULL; - srand(time(NULL)); - qemu_add_opts(&qemu_trace_opts); optind = parse_args(argc, argv); @@ -692,15 +690,6 @@ int main(int argc, char **argv, char **envp) { Error *err = NULL; if (seed_optarg != NULL) { - unsigned long long seed; - - /* This will go away with the last user of rand(). */ - if (parse_uint_full(seed_optarg, &seed, 0) != 0) { - fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); - exit(EXIT_FAILURE); - } - srand(seed); - qemu_guest_random_seed_main(seed_optarg, &err); } else { /* ??? Assumes qcrypto is only used by qemu_guest_getrandom. */ From patchwork Fri May 10 17:30:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163925 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2681448ilr; Fri, 10 May 2019 10:45:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLCPg2ggSRgD95A+1FxvuJ6wbTIyd9MYWpWZf5RZEgLoo5ly0WpO6DRGPApjQrzHKG9LAw X-Received: by 2002:a50:b3a6:: with SMTP id s35mr13091497edd.220.1557510348977; Fri, 10 May 2019 10:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510348; cv=none; d=google.com; s=arc-20160816; b=sZekGugXF7h5VbuCLf0VC0mrmlUXeqHjl9E3evxgfkTwvPhCEtKKmn9tnBiO/LAqpI UtAbNkHAELccxDsV5YJmCAAASGzeieyfllf5jUF5mM1uqF6BZm5dtj6ybIqhVei9Yluf 48cj639k3Ca1roT+5NK6pO9tFxABV9aiYofuLT5wXa3/mDhvnpHBsOwMvzTpaI0Abi/Q s07qC4UxrCcdjAN59CntcyfLymBzYdgf2splxTKGrmM/G1EL+qX6oC47VZaobTCpqDgk jvLIRQpHmZqpgNguR2Y1Y5UWNKKM84D5CMTg00sJquURZR8jXT4kK/VCFcaXhK7ouRu+ /miQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=NqFQGLUWEK2q+OruuYLxByccY86fvPfXVx23TDmISjI=; b=G/ZnxO/BArzo8/l966715TSZ6k8J+3pqMBVKcZ/tv5eKIDM65PXxBxstvUW4ggxiuS PE92GwyILdCFmZnMzo37MvdSptYS/m/hwejGhR/SFaIIR6GnA1XgmeQHmvEOVEPFrT5s m+75TxykJeTFVwsPth8jvTqJE0/Ci8cgUAAUusn67FFtvCMBpgAcbCAFwNotONmWERwO YEjzkdebulo+MMI+O6yuUWOGK11x+cE2nuyGs03ZzBDqhNc32kDa8ZMiAHlIJ/LbW9X+ 3uGE8qHUmLSqozi/IVLmGdOtcHRFabqi4EYMDhJTnxohLoGewwd3JJ7uVLXvwARRxJRU 2UiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Zu8XjrqU; 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 m47si3659432edd.311.2019.05.10.10.45.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:45:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Zu8XjrqU; 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]:47704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9ae-0005FC-0C for patch@linaro.org; Fri, 10 May 2019 13:45:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MY-0007Un-Ty for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MX-00069d-Q2 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:14 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:36068) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MX-00069D-Kk for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:13 -0400 Received: by mail-pg1-x544.google.com with SMTP id a3so3335124pgb.3 for ; Fri, 10 May 2019 10:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NqFQGLUWEK2q+OruuYLxByccY86fvPfXVx23TDmISjI=; b=Zu8XjrqUMrWf6XQgZqoSlfd933QyJLsMUJQuNdp2L7GFynd9RDOEw1hWF8yxnOzvlw i8NC2LAfv2ISDvMhlXDqvvmU0yyNejuABQKu/L5M05RTWlIlo38v5VuKLPD1Pu/RCtBH c8dlidgMdExoOB95L+z/Yo/VhCdJBDf1HUUwfs1nk7FBtaqp5MVzgz6x4Yms4pd42Ry4 gd9bqMWeqHjidCpR3gO2ShzKlVYfr5Cg6IS2TAVFEtwPplwynNDJ4Lku7nltwjQivkUN qUaOPK4OXKwO3LMyBGDkF6Cr41X26Ya1fWH0nf++KBfnx5554yDEFiOn7ls3xwUHcPRu QFrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NqFQGLUWEK2q+OruuYLxByccY86fvPfXVx23TDmISjI=; b=FrJmfpIb7stKljxVT1lbZNxIQAH1aQcgoIUI6li/oK6JzECbkObRbAF90lx12IRG+1 LvfTutMO++dJ3BLEMXcV7KZ5PxBENMizUlw4m91iOmOOsUH+y/G/pLHsWpimXBwGPo6G ildeS4z13Xool6tJH34myS3yZPu+v6DN0B8grCMvrLB5suTYWSX2mw/FMTC6k84+8ZI/ 6WqKt0Vc6Md3g/6N6YjHkMzD7fRJvZ7WuXQeukHKDTVcuumbT+P3f/3Voy7Xzhh1XdWk aL5AUavmxBIH+8cUuON/Zaod/jKtlY2krfsIXIHg1jzqx7y9/iqq9oufRFdTQnbCmI0F j4Kw== X-Gm-Message-State: APjAAAW+437024M3rkhBF4ve6Zvu9XqNV4tmOgK8YlPR44lOJ16OS780 bbRMEsQObZW7idHbRuCKdKw6I2uUTb4= X-Received: by 2002:a62:4ece:: with SMTP id c197mr16128216pfb.139.1557509472366; Fri, 10 May 2019 10:31:12 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:41 -0700 Message-Id: <20190510173049.28171-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH v6 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: Andrew Jeffery , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Use the *_nofail routine instead of rolling our own error handling locally. Cc: qemu-arm@nongnu.org Cc: Andrew Jeffery Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Reviewed-by: Joel Stanley Signed-off-by: Richard Henderson --- hw/misc/aspeed_scu.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c index c8217740ef..ab1e18ed4b 100644 --- a/hw/misc/aspeed_scu.c +++ b/hw/misc/aspeed_scu.c @@ -16,7 +16,7 @@ #include "qapi/visitor.h" #include "qemu/bitops.h" #include "qemu/log.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "trace.h" #define TO_REG(offset) ((offset) >> 2) @@ -157,14 +157,8 @@ static const uint32_t ast2500_a1_resets[ASPEED_SCU_NR_REGS] = { static uint32_t aspeed_scu_get_random(void) { - Error *err = NULL; uint32_t num; - - if (qcrypto_random_bytes((uint8_t *)&num, sizeof(num), &err)) { - error_report_err(err); - exit(1); - } - + qemu_guest_getrandom_nofail(&num, sizeof(num)); return num; } From patchwork Fri May 10 17:30:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163927 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2682370ilr; Fri, 10 May 2019 10:46:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpoOJx58Ep5xom1HXkgTzSlhC6CdIlft5QSs9QGeEuXzuV9FhR3ovKFznng4Yt5ITI7gnI X-Received: by 2002:a17:906:4d57:: with SMTP id b23mr9629728ejv.254.1557510400066; Fri, 10 May 2019 10:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510400; cv=none; d=google.com; s=arc-20160816; b=X0qY9rgntnZx1pXypNeRQ8x76OIWw00ti0oRlbPPDQNKNfu68glDx3f9XfTkGBXio/ iOqfRiXbsCMeKVDw2C1BByVh+VVp/+UXmzvlrNyajJPe/v/4fmSS3Fgc6GmmOkbWkrwa Gtq/c044CAwkk9YCJDcLMbeR7pIE6TrFQKuaN0gUfzhE+MYKtPtOahM5UI3uT6YAZ7xX noce3i7cnOYCn9R7aKjgeKCFvcfZROlLmk6bWFp7LZHMk6LgutWyHRfFYaF2U8yy0Nm0 hmtzj+2apA+n8lt1AE9oV9VUMY9GPa7/TlFDP6CAJDUshhRtkF+6446pNpzDIEKcDq63 5sUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=iRt1ekpVqMBTFPlbEkwvccpMEH6z9s1kPn0wCee76Ys=; b=hadu5DLgEuJYWwvKHMuRKeKVclRboJ5Bj6anFAMU0+62A4DQlkF+k6olZ1Oh89v8M+ rXDQKdFW4cEgjkw9LE7MBj1K+3d5oPrg21ePYbIJE5kPjdHG94T4ykLSfC+ZX9SeryoN kDwgCygbpHjneAYU9NR5EOscVzAZESumtigxTIZcGSzEpeZs9097qr/2UuAlh6jFBlVW VMVJU1AgE6Uo9ssNUxpcUxEwlGkomyD3538kALi3/oThzV/P6swFSRGZGyzt8D60fUq+ YiWKPu/4H1fMADSyxUwCugkD5mwWasd/DO2Lh1ltw5SXeFDL1UCnQVcDNr4Y+FgVD1Sg QU1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ehYp3aoJ; 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 c53si764956eda.439.2019.05.10.10.46.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:46: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=ehYp3aoJ; 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]:47708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9bS-0006T5-Vf for patch@linaro.org; Fri, 10 May 2019 13:46:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9MZ-0007Ur-Rs for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9MZ-0006AW-0P for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:15 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:43225) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MY-00069x-R4 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:14 -0400 Received: by mail-pl1-x641.google.com with SMTP id n8so3133298plp.10 for ; Fri, 10 May 2019 10:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iRt1ekpVqMBTFPlbEkwvccpMEH6z9s1kPn0wCee76Ys=; b=ehYp3aoJk6VPXB0pVCayxMCdYclH7yxIWbfUw9HmALoWfx1ww1+x8dh8NkU3Mm61pn qp0V/jNsvuDFUBloYorQnMIpz4cu9R88FlvMwFFpm3o4ldLmwjPNM/rKhZW0qGDTbyh1 Y7ooTEjVXBiFk/MtZSBVTfBP2IcOST+JwL6JKSmGFi2S6sgWiDT539/vwYyhtd/K7aCt VLsU5v/xqpNRC0NQFevLXL121aU+vNNHn90nS0gxQ8gpZpCW5FighaCQMRZnotwFtpf5 DrlD4bwdMgpqV5O8tXZaWTr/+1H3fjb5Hrw5EN8AVjXgfc+N4hsbqZwqCiLl2brwYjTh O/9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iRt1ekpVqMBTFPlbEkwvccpMEH6z9s1kPn0wCee76Ys=; b=Tl69pUUIiPt7ioZPqnVKyKb9da6pYEpQ1ANSTRrhkdxCh0ulearsGK9z5R5REf0Puz JRXdYTiPLDAab5nskdqnKucuEiDckOgdjK6cWm5h/hTYGAq8/JWatJuCsYN6xA4PURjN CHknT+4DtXLNw6lLORj0G4zGOtUAqaGC2v2Q88EyUpSe4bP1U/shfqNduYoI3YC45Hf2 uLdZNPVfvGAbSa9fZsWiepGkHTUryw4i28zj+1+kt+L64PKkuc+H7fKRVqCrg7tXZej5 cP2AiHVl5X4dWy5lmq+MgewMH+6Rwff16mgVSS6y7FsqhD/uS9sX8jVfBpWgWGfnqd9V AkgQ== X-Gm-Message-State: APjAAAWHpOIluPQlN3IAOnxzRT3B6VWAYSKbxD4Bu8sbNnDe0DiClWt8 NMegViKlYw4Gz8P9mw1ETeScb+93Xr0= X-Received: by 2002:a17:902:446:: with SMTP id 64mr14480345ple.322.1557509473495; Fri, 10 May 2019 10:31:13 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:42 -0700 Message-Id: <20190510173049.28171-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH v6 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: qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Use the *_nofail routine instead of error_abort directly. Cc: qemu-arm@nongnu.org Reviewed-by: Laurent Vivier Reviewed-by: Joel Stanley Signed-off-by: Richard Henderson --- hw/misc/nrf51_rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/hw/misc/nrf51_rng.c b/hw/misc/nrf51_rng.c index d188f044f4..3400e90a9b 100644 --- a/hw/misc/nrf51_rng.c +++ b/hw/misc/nrf51_rng.c @@ -14,7 +14,7 @@ #include "qapi/error.h" #include "hw/arm/nrf51.h" #include "hw/misc/nrf51_rng.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" static void update_irq(NRF51RNGState *s) { @@ -145,7 +145,7 @@ static void nrf51_rng_timer_expire(void *opaque) { NRF51RNGState *s = NRF51_RNG(opaque); - qcrypto_random_bytes(&s->value, 1, &error_abort); + qemu_guest_getrandom_nofail(&s->value, 1); s->event_valrdy = 1; qemu_set_irq(s->eep_valrdy, 1); From patchwork Fri May 10 17:30:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163915 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2675711ilr; Fri, 10 May 2019 10:40:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDNokqolE5JLkByzYehKFdW+WJnzfUzkSLXpYK5UEEPHKAQtzPt3U4cuNcnwABpVWih3ZU X-Received: by 2002:a50:91d0:: with SMTP id h16mr12576964eda.265.1557510014227; Fri, 10 May 2019 10:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510014; cv=none; d=google.com; s=arc-20160816; b=kBMZnnGZDQOQbP37wVZKpV9phavEYbaORht2EgUfp0+7OSeDgXrz/lNJaIS6lEw1B9 LCyc6Lb4q8/aZZD5aEnnPs7IieqxwiqGz7LnGLRdsHW7Jjj51Fbf2eb9p1LIT26xc2eq vIe9Ca5Xg27RhEZkBK9FMZ1J9I89u+Yfv1xzirGjAjwv1x/6v0EN25Aa0+SI0lZxtwiP t5MDg1BXr0YqF9wjPOoLrK8n2ARSMhvN5m0GXg2l2LzmGkTZDxzqlm1kcS7KO/4CAibi OBYvBXhvyZsQQNY915xCJGuDiODwCx9l8ZrMRKWIfN6wkdNy7ggCxJGWVqCmC/Yxjc8Z 0h+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=CbChhlXQdosoI4MWUK/zk2WTRGwUvizy4vwPQDmKAqs=; b=X7k/El0TPgLDEVxzuyttJAwl3Xmt/3UQypU/L313RZd9pB/yyT2zQWlgbwHJj3DWpb JNfXVGWu/Vscr59TCs7KHimZ2FrqGTwOxO+isOcy8VmDm095/S+aD/7uzffBBRZ8flfX ADKipO9/1hmtNKqjK3kiAPStTYubQjrGdYdrGPiXFcXVqhlTW7GF9jHfj0yyB4MbUc3M ZNuAVQ1Zfi+OZRB9IBfcYrfm4b2QivjbjyY0oWGPWEeEpiqXQqK9fZGuz3L3/mwOektS 2Lu9zE1hqvgTQksakHiwfGKo1ztWkh5bXXxGUPUCbd2NuEq8aVKj0xBBfPH2EYFTR7tG FFig== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RjeBll7F; 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 w17si1847777edl.369.2019.05.10.10.40.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:40: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=RjeBll7F; 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]:47610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9VF-0007G7-4F for patch@linaro.org; Fri, 10 May 2019 13:40:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Mb-0007WQ-5s for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9Ma-0006BS-4z for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:17 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:41832) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MZ-0006Ax-VS for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:16 -0400 Received: by mail-pg1-x536.google.com with SMTP id z3so3329166pgp.8 for ; Fri, 10 May 2019 10:31:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CbChhlXQdosoI4MWUK/zk2WTRGwUvizy4vwPQDmKAqs=; b=RjeBll7F2XfVW0Fos68V1JZ1XYmFQC/be0V6fR3mzqCne3S7j002nc6dhYdmOjQJ8w OYXEMa6OyvHaH31Pz43TCMnbl+S+Q6DgBitHESuwBq4AXKFZtqGqezx6SiT7Y0ZpL0CK 7lnLGG8yHmsYqd3hhS5kdFhPDXFrvWdcwWwUqDc1223nTv/6I8V5b4fm5QljfV5Y5yza 2Zxag66oHEFOMjDDizUiiwi2imuPuSDkCAWzzy5Vymo4pVXl8lR0tgf1NTn3NL5EaPGl bYRSzYsfzlGrYphoEZQ+btl0ZnRe7E+HVPZIGMSBD1t0zTEFek6Jp7d9ciSyxQRxKBSV 8O3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CbChhlXQdosoI4MWUK/zk2WTRGwUvizy4vwPQDmKAqs=; b=JNYc5W+LSqpRG4PWB/JgOaAtKHeteikdHp/EYibk96BHOYmouAXWHUGLupDA2MiXop O8z+FW2+XQOUPealcfdnYap01CK0+4RbvOrAbzjXm9NIoKrF8CvgR5C/Epgfyrkwcb2h LUGOnho+zvZ9zdNWRknXT/GG5BFOyjBoYQOXsuw6sGtEtcS8JxWAJnFR0xAo0XV5D0UT whQJUBuCRvFNZr3OHtDI1Bik8yJGmtIlT5g42dxbqHSVLHHiK3c9logMbwFNMNs8SHbz AIdLWYwDDtc4hX6Ys+7qoby7WrxwTcTA6iQpxcHpTpjBiLUkWcQTrTmPDs6stCHyq/Ud ByfA== X-Gm-Message-State: APjAAAWHEp9XfDUYqjoIbmZyjOrbXAGY1RDn3CTSpIhezpLAeggwIL+N Qvd0gvMhu041FXC66k78InvHJXgUuw0= X-Received: by 2002:a65:644e:: with SMTP id s14mr15629617pgv.290.1557509474699; Fri, 10 May 2019 10:31:14 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:43 -0700 Message-Id: <20190510173049.28171-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-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::536 Subject: [Qemu-devel] [PATCH v6 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: qemu-arm@nongnu.org, Andrew Baumann Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Use the *_nofail routine instead of rolling our own error handling locally. Cc: qemu-arm@nongnu.org Cc: Andrew Baumann Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- hw/misc/bcm2835_rng.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) -- 2.17.1 diff --git a/hw/misc/bcm2835_rng.c b/hw/misc/bcm2835_rng.c index 4d62143b24..fe59c868f5 100644 --- a/hw/misc/bcm2835_rng.c +++ b/hw/misc/bcm2835_rng.c @@ -9,30 +9,26 @@ #include "qemu/osdep.h" #include "qemu/log.h" -#include "qapi/error.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "hw/misc/bcm2835_rng.h" static uint32_t get_random_bytes(void) { uint32_t res; - Error *err = NULL; - if (qcrypto_random_bytes((uint8_t *)&res, sizeof(res), &err) < 0) { - /* On failure we don't want to return the guest a non-random - * value in case they're really using it for cryptographic - * purposes, so the best we can do is die here. - * This shouldn't happen unless something's broken. - * In theory we could implement this device's full FIFO - * and interrupt semantics and then just stop filling the - * FIFO. That's a lot of work, though, so we assume any - * errors are systematic problems and trust that if we didn't - * fail as the guest inited then we won't fail later on - * mid-run. - */ - error_report_err(err); - exit(1); - } + /* + * On failure we don't want to return the guest a non-random + * value in case they're really using it for cryptographic + * purposes, so the best we can do is die here. + * This shouldn't happen unless something's broken. + * In theory we could implement this device's full FIFO + * and interrupt semantics and then just stop filling the + * FIFO. That's a lot of work, though, so we assume any + * errors are systematic problems and trust that if we didn't + * fail as the guest inited then we won't fail later on + * mid-run. + */ + qemu_guest_getrandom_nofail(&res, sizeof(res)); return res; } From patchwork Fri May 10 17:30:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163923 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2679859ilr; Fri, 10 May 2019 10:44:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPPd3GdZOEZBLUvb9g67k6ai01qE+nMoR/b7MNwhu4ELuIGSZuprKMr7C1t0Zk3ikve6h5 X-Received: by 2002:a50:e442:: with SMTP id e2mr12074189edm.227.1557510261027; Fri, 10 May 2019 10:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510261; cv=none; d=google.com; s=arc-20160816; b=dHFj7HKcHrav66Lpj4ytVqwjiyNE9zwK4b82zvPfBbg1ocuTrH7lz8u9cOPPxPtTK5 AqS4zstlxty4mwmQIX12phUZdQntCwqm6yWAsVxOUrIupU5935fwvOq9lyKJzlORqk5U qkpTAHFlzNI++UqzYLlYIBAc1k2jd0GU1bqIbS4IDyRlAZX4b2nuZpBW12LTwi7SPt6/ k7xoroFennqWXJ0xmWbNRE8T1SaoBwab/G0zO879Bxg/A/FbHvIbNsy45xuGjdLm47DJ z6OmMI0qzL+oQcoj5q4fI2UpGXmae+trvS9yT/Zm9xeueqz7QWW9NIWdjO0tyCWG8HV9 k3Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=SUOVHO6j5bto5JT3YOaz6mzG9aMKtYONtCxKiBQvOSY=; b=we27hrEs0uGKqe9mHDzBcG5uysMQDwz1qbw6q8Oq6uVn4xNl/NzS3oyn032y9ivH7I x/oAYbVnpaaYtPwA9oHdn3+I/sSJi0FAX/Klsvg0J4Vedrt/uHfYeyk2sLouVc8zURhA w/aDgMVf5QwY2wNWK/7FSUtfofVDZdm9wc9Z/PNcS1skPb+FPNjZqINlOvu2osnRuHkr XfHtAilIlH7GPqK6bCHkjUF/tYiVJxrmh5oLsK8/jz0QDMAT6xNacZrg9gkjiT99I/EY rCJT8xuwBPwM67D26eJ+IywlJvnHwKCa0gXbMI478W+q6NrdjBicCigIyinetdFjhpug dLog== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LipXyzHF; 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 p13si3595160ejb.22.2019.05.10.10.44.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:44:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LipXyzHF; 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]:47653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9ZE-0003cc-0J for patch@linaro.org; Fri, 10 May 2019 13:44:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Mc-0007XU-7H for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9Mb-0006CF-8Y for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:18 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:44173) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9Mb-0006Bq-2x for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:17 -0400 Received: by mail-pf1-x442.google.com with SMTP id g9so3565191pfo.11 for ; Fri, 10 May 2019 10:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SUOVHO6j5bto5JT3YOaz6mzG9aMKtYONtCxKiBQvOSY=; b=LipXyzHFUhm484KKJAcq7BZ+BqYBjTds4vKoHfGYZlrvORzSuywhoFR4IMaLxNXb2m Ic9RP9r4CLy7khPIvhqp3yfu98Vb+svfMFhP0XLtBLWN4QJIA7vyV51pvzgmMgGX3lW1 lPKQiq/XpPBbXg5JTO/nA+gLemnkXwfJqVq5hl6NE03BiV/70s93liFNrfw+i0xPZzWl fvdw3qhmWZQ2CSVPf5ZtpVr9bdlkgE+esCX3DM7mO1Jmxv2kVGs6UzA164V6wcrIvgpN 1UwhDl8sOOSvmYvorRTpqfB7lOGvcVypUl7SQxQaBUX3OyVb6KVwfVlqUVVUotRxdiMs +8lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SUOVHO6j5bto5JT3YOaz6mzG9aMKtYONtCxKiBQvOSY=; b=c+J24mIN3ysg5W3t/czioky0RDvdZsQ+qUEGvUALP3nFAkt6MDfR+Vay7Tks+FhcAe 5rPKJFt9+ikfL5NlIc4Z8MNm8yVc1mx+rweowWQhzZ+f15DOdvQHRpAd638SDV+x8mI0 Na2wTxy4jQ10P4XhulHvaz9uiVZxaWTFbI0Z4+WVmIkrTclpLrVcjzb+tN3nHIJmUGN4 8VGk0a1B4GfqAc26kZt/Ya/mN5p9JzoPzOWnc03gdDBPyXO1jsfoeMCnyozMEHGkiRs3 0Whj4lcFrMtQDBi9FZtwbtgeZf1D8RvDj/kiW4cgmyMJF/VxOpOYq2tHBjZmWsO60LGP Nbrw== X-Gm-Message-State: APjAAAVrdzZPycUOrcgjsxDAzaMJrzbSnSb0Q6MiPwH8262muhYLXmjZ GUQKwJE3ritJXZ9p/joOZ0i1P6Oh+/E= X-Received: by 2002:a63:6f0b:: with SMTP id k11mr15135478pgc.342.1557509475903; Fri, 10 May 2019 10:31:15 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:44 -0700 Message-Id: <20190510173049.28171-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v6 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: Igor Mitsyanko , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Cc: qemu-arm@nongnu.org Cc: Igor Mitsyanko Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- hw/misc/exynos4210_rng.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) -- 2.17.1 diff --git a/hw/misc/exynos4210_rng.c b/hw/misc/exynos4210_rng.c index 4ecbebd2d7..0e70ffb404 100644 --- a/hw/misc/exynos4210_rng.c +++ b/hw/misc/exynos4210_rng.c @@ -18,10 +18,10 @@ */ #include "qemu/osdep.h" -#include "crypto/random.h" #include "hw/sysbus.h" #include "qapi/error.h" #include "qemu/log.h" +#include "qemu/guest-random.h" #define DEBUG_EXYNOS_RNG 0 @@ -109,7 +109,6 @@ static void exynos4210_rng_set_seed(Exynos4210RngState *s, unsigned int i, static void exynos4210_rng_run_engine(Exynos4210RngState *s) { Error *err = NULL; - int ret; /* Seed set? */ if ((s->reg_status & EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE) == 0) { @@ -127,13 +126,11 @@ static void exynos4210_rng_run_engine(Exynos4210RngState *s) } /* Get randoms */ - ret = qcrypto_random_bytes((uint8_t *)s->randr_value, - sizeof(s->randr_value), &err); - if (!ret) { + if (qemu_guest_getrandom(s->randr_value, sizeof(s->randr_value), &err)) { + error_report_err(err); + } else { /* Notify that PRNG is ready */ s->reg_status |= EXYNOS4210_RNG_STATUS_PRNG_DONE; - } else { - error_report_err(err); } out: From patchwork Fri May 10 17:30:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163917 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2676165ilr; Fri, 10 May 2019 10:40:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4IpwHDVFXBtgQCia9QB9umR+Shv61r+Pi0dGgVYv9NK1kEFbEJOIEAhyUKzPdR1iVha6A X-Received: by 2002:a17:906:e01:: with SMTP id l1mr9631414eji.273.1557510043260; Fri, 10 May 2019 10:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510043; cv=none; d=google.com; s=arc-20160816; b=bS7VpT1WWC3C19J8WE+OCIqjmRLqbHajNRwAHU6bizqcozUJZAvfyWJ670+AfswRrs TBFc1RMu6qUHOW/3+RGuiBWwauTMKtX+wr5aW9wZmfD+Nqh78cs7cz/vlFbAZeVfbjDf I3xDm2CjjtEUjxEtdFv0P3mzF3EMl1ER1wxL3+EbdHbmqewzaXIaC+mbbl82OgHTx1Yi fC2OALKnkNYW/5pFmhOXuOdQtmmiFTI8yPr1zc39iGU1vwIt8smN33hA8/vQgqr5Gqlv lU0HVOaa3bk6ZBM88tpYuu0+kfxBNgLS1GabXUQ9nnYqYMDj4mH6j9l9ACwZZc9HOlt5 ICiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=O5zIN7a5YhWG7ErE5cL09/UzOmkeLwtbGoogr/y9loY=; b=i/3R8t5cl/wGIiVm4KUzxnakNb7X5Tl+OcJbY3vknilpI5JbP1EGFqnW2gi9M+0kNx 0m3rH+H++V6g56vpufltD5g5CukCDeiVBHTJeZKhv2OGwXHWkpZsB+hktYcdo4YxuB6P ssXdzWYIgBWUz8euQZ86pLL6n0J/PbU5yoVLdxJkF+5VVqcK6y2vh7ybnQhNqPiJjyQL QW/DAfsalO2pYACjg4Ll8oa6YML7KuLE5rH2G6OoXXAUbxCN1gn7E2s6x62rKbYH8mc3 EvlzLIWKSd0Nmi40Op+f2bmlRlNDQVv1X5hYMQ4KnrBS3lQ3snugzJhh5zhXq1w3GmEC hhIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UhB1QSmX; 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 cd5si3278297ejb.300.2019.05.10.10.40.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:40: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=UhB1QSmX; 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]:47616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Vh-0007Kn-W1 for patch@linaro.org; Fri, 10 May 2019 13:40:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Me-0007ZV-63 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9Mc-0006D9-Kb for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:20 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:40823) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9Mc-0006Cc-D4 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:18 -0400 Received: by mail-pl1-x643.google.com with SMTP id b3so3138163plr.7 for ; Fri, 10 May 2019 10:31:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=O5zIN7a5YhWG7ErE5cL09/UzOmkeLwtbGoogr/y9loY=; b=UhB1QSmX9u4LhoRYrHBvYlO4LWx+feNVn6ZlJy8BHnScAKug+1/ZICVqENkz/UzMrX rPau/gtTK/umino9lT5aWCpUkpSb3lU01tvUVMjgI3xzSqH0prLSzn116qvsreG/e7A1 9rFSLpr4kNnjoAhgByRn0zmsXqzsQbpXQeF+UIQCIRmK8AJtzLMSl/93pl+J1OpK89F/ zmQN/B2gP/1/JmRwTsT1BqyMFeb0Z+4w9ryKcxl0KR4npKuLIMGHfkIINHpyGlOhR7xf 68Z0KEEgufVy+q7yzYABbSqDT3MNZHXS1v14gZoOdAHzvdKz/BvVs3z7kd0PhVS12QW1 JOGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O5zIN7a5YhWG7ErE5cL09/UzOmkeLwtbGoogr/y9loY=; b=ae6Iv3KZqwEy8a4yWyzvFcV84TGXsuE/Xebwni7GLRg8BOWG93yvrFC4kPoP45NqKq iOJrXO8UDSTiPQvnx9DuWdoStQtk7KD1EmAHTHAn4c6M8Vm/XV+ZWGv5y7CMMA4ArK79 +XhOWFsM+lfbIWhHPMenSwpfGUAAJOKVqFmxALBOiVlW39DW1uf3U/Y6A/rDUU38MY1t Bm8cKU80Fzdc1NtKWWoOtZBvHIsll49S6Axe/97mZ1Nmiaswdu0EvovAcdeCMqwzWaBw oHdvZniq5ZVGj8jTmzxg6Mex16brA26AJBunB5bJDRVL3AZ3cN1mcn2YCf5D8stQrGMn iThQ== X-Gm-Message-State: APjAAAUk9US29UlYRhJSFi/xXXvqS2REdntlzNAL8TJYO8sIOjF2Gzm/ tavJpnO5/V81YHD+P1zgj/DORO+HCjk= X-Received: by 2002:a17:902:b695:: with SMTP id c21mr15042675pls.160.1557509477148; Fri, 10 May 2019 10:31:17 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:45 -0700 Message-Id: <20190510173049.28171-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::643 Subject: [Qemu-devel] [PATCH v6 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: , 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 8c17b14d51..394b956b4a 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 1e6eb0d0f3..7e88b2cadd 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5707,43 +5707,43 @@ static const ARMCPRegInfo pauth_reginfo[] = { { .name = "APDAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apda_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apda.lo) }, { .name = "APDAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apda_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apda.hi) }, { .name = "APDBKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 2, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apdb_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apdb.lo) }, { .name = "APDBKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 3, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apdb_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apdb.hi) }, { .name = "APGAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 3, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apga_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apga.lo) }, { .name = "APGAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 3, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apga_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apga.hi) }, { .name = "APIAKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 0, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apia_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apia.lo) }, { .name = "APIAKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 1, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apia_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apia.hi) }, { .name = "APIBKEYLO_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 2, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apib_key.lo) }, + .fieldoffset = offsetof(CPUARMState, keys.apib.lo) }, { .name = "APIBKEYHI_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 3, .access = PL1_RW, .accessfn = access_pauth, - .fieldoffset = offsetof(CPUARMState, apib_key.hi) }, + .fieldoffset = offsetof(CPUARMState, keys.apib.hi) }, REGINFO_SENTINEL }; #endif diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c index d750f96edf..7f30ae7395 100644 --- a/target/arm/pauth_helper.c +++ b/target/arm/pauth_helper.c @@ -403,7 +403,7 @@ uint64_t HELPER(pacia)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apia_key, false); + return pauth_addpac(env, x, y, &env->keys.apia, false); } uint64_t HELPER(pacib)(CPUARMState *env, uint64_t x, uint64_t y) @@ -413,7 +413,7 @@ uint64_t HELPER(pacib)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apib_key, false); + return pauth_addpac(env, x, y, &env->keys.apib, false); } uint64_t HELPER(pacda)(CPUARMState *env, uint64_t x, uint64_t y) @@ -423,7 +423,7 @@ uint64_t HELPER(pacda)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apda_key, true); + return pauth_addpac(env, x, y, &env->keys.apda, true); } uint64_t HELPER(pacdb)(CPUARMState *env, uint64_t x, uint64_t y) @@ -433,7 +433,7 @@ uint64_t HELPER(pacdb)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_addpac(env, x, y, &env->apdb_key, true); + return pauth_addpac(env, x, y, &env->keys.apdb, true); } uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) @@ -441,7 +441,7 @@ uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) uint64_t pac; pauth_check_trap(env, arm_current_el(env), GETPC()); - pac = pauth_computepac(x, y, env->apga_key); + pac = pauth_computepac(x, y, env->keys.apga); return pac & 0xffffffff00000000ull; } @@ -453,7 +453,7 @@ uint64_t HELPER(autia)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apia_key, false, 0); + return pauth_auth(env, x, y, &env->keys.apia, false, 0); } uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) @@ -463,7 +463,7 @@ uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apib_key, false, 1); + return pauth_auth(env, x, y, &env->keys.apib, false, 1); } uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) @@ -473,7 +473,7 @@ uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apda_key, true, 0); + return pauth_auth(env, x, y, &env->keys.apda, true, 0); } uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) @@ -483,7 +483,7 @@ uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) return x; } pauth_check_trap(env, el, GETPC()); - return pauth_auth(env, x, y, &env->apdb_key, true, 1); + return pauth_auth(env, x, y, &env->keys.apdb, true, 1); } uint64_t HELPER(xpaci)(CPUARMState *env, uint64_t a) From patchwork Fri May 10 17:30:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163929 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2688674ilr; Fri, 10 May 2019 10:52:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOHRMOL7rjzPk9sZ38riMigCWkfk2CZjoZhhzvba55d2TAlL0volmTEpcuHDfdnBkQXjMF X-Received: by 2002:a17:906:4911:: with SMTP id b17mr4249851ejq.3.1557510770945; Fri, 10 May 2019 10:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510770; cv=none; d=google.com; s=arc-20160816; b=fG9a+I3CIAqFR6z6GS48Vkm5BCZeuH1jXAf1ocnFm9+wBQWAUnJVcE3fVZrLI774Y4 mV6wm9lCHId/ZVCUVodXJleYGkExhjAQ37dwGsDqEXaD0BnysRpHVUF66ukvEDDo+v6K 2NQPiBCRE5VDoxGcQ8c37bXuRF7gpa2IeSO99je0QVjmCiqJJf0oNPcUqGuYP+ioaJB8 BUn/tyrlqsbjfHVjlXYLW/Ppelq0T040G2NDRXB8Ws99FlGe9FcLiOKlhCKDegum29A6 8Fvd+uxgBHLJwyW1cjU3zBV850tYd8c0gAU+rRGIgJWD3ET1hGQJF7XJeDgdCF4WCor5 U5SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=SX/dz0O8302ZA9gggUBt45HSk3FSPauZ2uFWTG4hibA=; b=L+qonXmQhJ0ToSUZro7guP4zKVwYAtAy5t6BwvkhxfnpeMzXrxlYeOTDq8cP4AjrtH PFFE3aBLSK9EtLSOhsapVwWJzSSk4TnA3avJswwxyZyhhh1ozRIYBBnYS3A+pUo4JFgI mxQYct7uAEit4a7Vya0pIKyLM6uISibOaAKm5aHWa9KZjF6rsynW0qjFcd6WG5AWWd3j ilfaM6/VRGqc83X63FZtpTKkgiz8TsHQuSw08IgHs1P6uPl5JjtViKh2zNdq6+fWPfIL fReruY2B2sdvdTSCANEgow/XCuppNYhUWSwbihCvpv6dEierDOxkZrfx1IFng3VYGRGV 5abg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BWxEVid8; 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 h41si783728edh.55.2019.05.10.10.52.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:52:50 -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=BWxEVid8; 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]:47799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9hR-0003Jq-R5 for patch@linaro.org; Fri, 10 May 2019 13:52:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Mf-0007ai-4h for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9Md-0006Dl-Uo for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:21 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:37844) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9Md-0006DT-P4 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:19 -0400 Received: by mail-pf1-x443.google.com with SMTP id g3so3586529pfi.4 for ; Fri, 10 May 2019 10:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=SX/dz0O8302ZA9gggUBt45HSk3FSPauZ2uFWTG4hibA=; b=BWxEVid8g0IB1NkSu1PCLteNgYoe2HC4H0H23zw8WGcT/P/anQWho+6cYetSGuquZT Z/GlGnWmaKcHrRyrsuuFw7p0j6e4QdD5Qgc1HtZSYeiOpa9biiw9EvFIfYnCZZaGPMET sxJaI3mVSoLeMO9CM3MwYxGigN6W1xVLxb9IO8xpZW3TZLecPvQ2vgBwwHSCpnxZzHz/ Hhcgfgr/z27aOU2VTcBmtgrsS7U7md29HA/ouYN8gZ//cHjFbi/csGLr9zrbcF0QEaZ7 g1BVLyohX8Pr9BtX67hR6E6M6f4DJp1jzioMg/QcXlPB1Q7/Sv8UfVyoXhLi68v19sDR VbmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=SX/dz0O8302ZA9gggUBt45HSk3FSPauZ2uFWTG4hibA=; b=fnbnhN0G+FKgOFPU3J0fiG97catu+N4H5Rw/RYZZd7VhTYUNoSQo4xo0Q5kWzYUJcf yhK/JkR8j3qCPIJ1lhACOApIV90A59Yxw62SaFAta0Hj3JxjlppAWHAxwCmY+XnGzu/8 IlKlkwS8QhleUy+u9qcwhN1/lTT01AHdL3BNDS9CkcSh7+7VIVF6hgKdXhFxASSO7EEm UTEYCQpVbY+Z0TqCQ5te7GoxnRs2seMWVTkPmESKYJnqueXcpwk+tBkXhT0j2kYwP5zE qV71B6N0L/60shk/lXgZLfdd6HNrpJVWD/WxEKqIXvAw2KLfJeu/UecbimRDL9xlaTMf 2NXQ== X-Gm-Message-State: APjAAAUxOt/FF7d4JyX2XU8rC3iazHYz7SUpp14404vL2sHE0pYdQzf3 lTOK51Cve4fBm6Qtt40+e1ZfZTRMzow= X-Received: by 2002:a65:4489:: with SMTP id l9mr14968075pgq.1.1557509478522; Fri, 10 May 2019 10:31:18 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:46 -0700 Message-Id: <20190510173049.28171-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v6 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v3: Log errors with -d unimp, for lack of a better flag. v6: Add ARM_CP_IO for -icount. --- 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 7e88b2cadd..1e90f4d722 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 Fri May 10 17:30:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163931 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2690977ilr; Fri, 10 May 2019 10:55:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdzo7XE/OnvJAOXGQB35GVhcpHSL9nHp/cZ1VZ4yLxIliiz9hkMcceaBU8S0si0cKXXQ9I X-Received: by 2002:a50:92a3:: with SMTP id k32mr12615530eda.123.1557510910518; Fri, 10 May 2019 10:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510910; cv=none; d=google.com; s=arc-20160816; b=RjTD/op2Rft5xK7WQVHZeMS2cx+5giDJoz3EPxVhLh9zXHsCwbmL1bUkbb1lAWTzs8 i46gzchtlE6y8E3Hyps1YHoAc637c4kT7n1/YPq3rv9c7XD38RLMJNOJHnio3U31D/uO 0nRwzf0diOoKjcvh9cKJhK5VdVzpP52v4OXlJd3cJRU9dWRV3XkAwIAeQUkVJtojWHjX vxvKulKzM/IROSucE4MqRdnzmZG9osCD559EinaZf9rsCzDh3bunSfC3j77nR7hAKTP6 Z79vDY5YWSPJmm4BNwljYKF14fgAHa0shtHORytEITm4rZzoiU8jPfitrJh2+5Q4nHpN 8RJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=U7V1DU2sIBLR4xyyuIblisrMELcV0ZOXk8BQM7uyeGA=; b=lUH3WDC1S4RQ5ozVWNbrYeaKRlRYKz5alP3bulctPcEQfkExvKmy/jErg002YmMzq5 w9E/8Mean2QpB1wmp/c09RPBUU0NdrxCYN1lTrRtiOBtnTDb2OSvjK09hl5+PYuehaWS +C+TQ+0JD2NYs9o6jud/P7HnbHtpsa3AG6Fjgd8wFNqpIb9ylDO01kGpLwvfIEu4bWCV to1dZUQA3o73GOL24FE3wo7qeLIlv+MlzlzdQY13obxxDU3l4pUKsHRdTFf6lV0uqtba U9z+yEvq/8Qx6SzXTnvzY+XmDb8IX6BHDSNDxXcMDXapYhBq6jyJsXuDNrpJE0kY+p1d yOcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=lLB+U6uj; 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 t12si3565147ejb.124.2019.05.10.10.55.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:55: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=lLB+U6uj; 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]:47848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9jh-0005Bt-EY for patch@linaro.org; Fri, 10 May 2019 13:55:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Mg-0007br-3A for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9Mf-0006EJ-48 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:22 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:44200) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9Me-0006E7-UY for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:21 -0400 Received: by mail-pl1-x642.google.com with SMTP id d3so3130070plj.11 for ; Fri, 10 May 2019 10:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=U7V1DU2sIBLR4xyyuIblisrMELcV0ZOXk8BQM7uyeGA=; b=lLB+U6ujZVJ6L4XThI1HmZzsFwQkCilJF2kR0pCk0VB700ZOMTfW+27s5Lcr3dCz4o lUU7mlOdzzySUgVSVl6cJgm/3y/yoDVJdD+zgmYM/qwfqKWQVhYiWnbspflLxb3LQThX x2i32RAZncGat5Uw512Yv6XoK3sVBKo49XLawnjVvA0BFoDcT4qBkGDphdyb/cDcUJkm zH/0yTvkGHC0Qq5ujjkWa3K3+JBMLDVf6ERFuVfjFgMu6TR+JltjLkEhX3Bm+mmyFH6W epYmWhNCJFVi9ooIOVovD45qcxExbPAl8HQEPuWmHnFZmjmwuCIs5HuurcNmpPkIusDC Fk0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=U7V1DU2sIBLR4xyyuIblisrMELcV0ZOXk8BQM7uyeGA=; b=t8mx7XkjJCRJRSdNNzlRxod4v6QMChokG1cd410aStSbm6DvNhZ5EeHRhThBlqw+d2 OOTn/G7uqXp3N494xONLzZWjKDpqrJ9YZGTb9UuFGi0dkSqwAe0rnhj6RV0QTNYF6cfy 0RspP6X1l7xfIGN8ZM6DqVyp1H+yKeSmHcaBh2BnTvxL1Iom9u8kytcEB64EwXzhen1B DngnHlsrbAF3r5MpZOXbaDQwcW+8O5xITFpo44OTgfFoN8LSYzA36LXRcfdkd5lPbdaY NEKtTZyBF5FtK7a0E+uh9J/IaG5RnF1abAV6m4UxGsgqeHuhJ4LpRjPh638Rl6s0XMSL Ex6w== X-Gm-Message-State: APjAAAU6znQBfIXyHn2QgAldJrAxaI+SbGCEFN7FcVbAM2RcsGRiysa4 +aoueLEhpbsq63c7FSxRiAXpsUHBRos= X-Received: by 2002:a17:902:2b87:: with SMTP id l7mr10116770plb.11.1557509479776; Fri, 10 May 2019 10:31:19 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:47 -0700 Message-Id: <20190510173049.28171-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-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::642 Subject: [Qemu-devel] [PATCH v6 23/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: , 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 --- v5: Do not loop for darn64; use sizeof. --- 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 Fri May 10 17:30:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163930 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2689178ilr; Fri, 10 May 2019 10:53:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4Kl3Fgcrozxf42irlPeFMS8id5v2zOCW7HF3Dld7qLNrn6Ybj9Kp7PlY6ktMwpft3+pjB X-Received: by 2002:a05:6402:1214:: with SMTP id c20mr12436858edw.38.1557510800116; Fri, 10 May 2019 10:53:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510800; cv=none; d=google.com; s=arc-20160816; b=x9iR5fyi/mdhyinxH6pIyhJtKhsoPjqML6NPJVQHE7NzLmkDzBssHv7VwuUGeibU90 ZziccSPXitBMUPcZ6q2i5ggwBi2W4/5Ak/uZn1rV/ZFfe9tfiDyJiKvn8i6r++KzG2dq XsZXod2Mrz7WdIwlYq8jf6bVQG/BtcwL2LomEYrQvI/+0CN/IBkft7j+C9LxsGDEaG2b xiG8qReN6lyvLW1pQUo10k0x/KddmIz9nGgVQ1D338VegXtohK4EbowslZiNrRlSevzT 0z0LX6mFLZ2Gh0Rr9L7ul/fa1o29UGu98/2V/4mi8SZzc4mOtdzxCC7EcXh0g6YcI6u5 0QHQ== 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=3/XT/GNbTz9t3be4QG6qS3S59cCXuga8GczXPdJ1EMM=; b=yY0Qe0YKh+03L1j3U17698oevoxFs0eN8P0LBU7rRImdHqex2nEmxGo7qioS12IUfg Zva9sZkjvnymJBa4evNa2vIa908Zgo4rkwSgfrhBbqTanPaWr45Ujkrd1s7yVP0MdVmt Vq7Eugm2H/inAEBcQQEUn6K9R5RZgrpU2FR5pKBos+1++6xdldJ9WCs4U9LQe+EHfk45 BCqNLNurxUs0z7ExmH4FhPAhwHiRSoOAAOTSph6RB5sbmmG/LsrS4nE69TwzixznVtns HoNQ6dZSrcWAFIMS1s/MifSjZ8bqd+rfUu1wyc22w4n5ckQz1/0pLsmU1dpGngBHPc7w 2ixA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Fj0nTSks; 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 k21si1308137ejj.200.2019.05.10.10.53.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:53:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Fj0nTSks; 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]:47801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9hv-0003Rn-1R for patch@linaro.org; Fri, 10 May 2019 13:53:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Mh-0007cc-1B for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9Mg-0006Eu-51 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:23 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:40823) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9Mf-0006Ed-VH for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:22 -0400 Received: by mail-pl1-x642.google.com with SMTP id b3so3138221plr.7 for ; Fri, 10 May 2019 10:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3/XT/GNbTz9t3be4QG6qS3S59cCXuga8GczXPdJ1EMM=; b=Fj0nTSksTM4fN1HQhx5uGxgNCq/HKYp0ojeEbcEI65djDLBJWYutwPjsmKSw8WB+uZ VoFRNfzbIvehNcc8KgAKWcm1EChcnteZxXjtTnkpkMsrnaHMNQcc91SX1nD/7oD/UdcL zCmMQctVdb5AmiC6HalqkhPbGjeCLIEEWba6C/JxkjDYwyO7CKWRXHNikicEjCy0pdas a/ERAkmLB2ouKdtheeWUj+HbV+V70yCAOo+ifobiFk1SchHM4u4NbGreB2LLvGqW5A5f ISauxo0DZwOvz5no/1BTgH7y1JamXDBezY7WgrBXuIKOq4zLSGuONPVujG7HBMbkXVCG 2JEA== 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=3/XT/GNbTz9t3be4QG6qS3S59cCXuga8GczXPdJ1EMM=; b=FrM/Gq5JmwhafrNM7O7MxMRNNXHZXfhuJfmXRkKWKaTyV5xaeVQsVmk29bhYK2qYzz Kp8HgcrsL48mEMIzQCaP38eRi3tGLuDNbXIbenpDEPd9HWKVYktvClbFLEskhe2JfsSH kRvR3C33g2zoPA5ehdoYktKukpe/ROB2UH7mknmphYZQgsVxZOJ7OAHmoW9X4gVZqFtk JBfEqN69SNSUcGI2VLCf6o0kmah2eUiyRodHnynBr0MUjLLyZL97CJhNiFWKSx22BhSC R+bpJ5tADgK7JOEzIdGm1E5e6R4Xm5eIaHVxBi4fXTVxLPgUrX1M2X7qz1wi4x+DaDWE mD/Q== X-Gm-Message-State: APjAAAWSx4260p4o58NFcW94nIRV1PdbvyatsUnyV3FgKh+XyCB+NewO Y+if1gV4gDZBnY97Jo+y4idaWRosRVE= X-Received: by 2002:a17:902:8b8a:: with SMTP id ay10mr6272032plb.74.1557509480814; Fri, 10 May 2019 10:31:20 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:48 -0700 Message-Id: <20190510173049.28171-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-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::642 Subject: [Qemu-devel] [PATCH v6 24/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: David Gibson 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. Cc: David Gibson Suggested-by: Peter Maydell Signed-off-by: Richard Henderson --- target/ppc/translate.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) -- 2.17.1 Acked-by: David Gibson Reviewed-by: Laurent Vivier Acked-by: David Gibson diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 8d08625c33..76628df6dd 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 Fri May 10 17:30:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163924 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2681198ilr; Fri, 10 May 2019 10:45:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmpQ3eS08TQ17ry67mXFSsuTDEazjSslEFI+A4qak4eUMSR3L4xWLaei5B2dY2h+T5QjeW X-Received: by 2002:a17:906:1e89:: with SMTP id e9mr9653348ejj.161.1557510336571; Fri, 10 May 2019 10:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510336; cv=none; d=google.com; s=arc-20160816; b=zonMh5m8EAAIyBcsYVJID/+4FoOdMhZNn/U0RJPH3EGZI5Eu4lI4ft91iNDZm4OkNr 2cRpj/K1CRkZqIlt5GrTknr+GPM3HN2+86ATk7nAu4oN7F94gVSWSNeyH8ovOzBfw+k7 dgmxTnto8WGwK1PKigdJGc9MNlE96Gwp+SFrfEYUatGeZ3RyIIZIu4xZsyub44fSxvnf jyTBT7mKDvXeujK8ZWWZfQSjR6X3iMYly8rpEeBBn+xfMikWZlKA2J0gq3C7iJrhxzcx cNQa4WXxy7Ta2xdEV6D3WGNYJmaWVw0maMJuj3cpZQCQHpSVicYSSTabmgjqzfHrlNth 731g== 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=UWh6WQgwFaXoTdfyv00kbbEUIrTl3FpRNOTur6Egg74=; b=YdT5ihjLpszss8p6oP5nML5huNDJ/MFMDLXyl709FGrezx77Nm00w/sAlmKyq76SaB e4hnoDFexui0IDJ67LJrUOINbaSmKry7MMeXp2OwGNb0tBs5Q2+LbJ+Xk6MmYwPmS4eV 3Eo+9HnbtvyU9ZlQHbQw7t9mI+C2W5AFQIrb00ackJeONK3rb+1otuPSub/44UUErwcB /V3oFDZLyhHy8S+NVEe6meYAb+oyoe698b3o9tfkHJDRMo1er/9Wc6e+e4IKIosIOf0s /PJpsXE/g4T8EPuP2uqmWzS/0Z608vplKg4btqIdD/k+kKztP869aQD8oRcd5xEqJ5Mz aDVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eh4AvxOq; 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 t22si3162507edb.422.2019.05.10.10.45.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:45: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=eh4AvxOq; 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]:47696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9aR-00054V-DK for patch@linaro.org; Fri, 10 May 2019 13:45:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Mi-0007cn-Dy for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9Mh-0006Fj-8f for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:24 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:33850) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9Mh-0006FJ-2V for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:23 -0400 Received: by mail-pf1-x442.google.com with SMTP id n19so3589385pfa.1 for ; Fri, 10 May 2019 10:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UWh6WQgwFaXoTdfyv00kbbEUIrTl3FpRNOTur6Egg74=; b=eh4AvxOqrDh4W5UMdULNAvxVGhFICsbs4PafZ7zkHF+wUijkF1klUht7xO4iGNe/98 ge8baytdCPDsR/N60Ib6J9a3xF7s/uLKcaKuA2saFrWXOxY1FUmb8T0ekbTOVoHiP0TF kix1+Q6lkMMIiT+oq1ODSzcl+e+NzU/c8mQsO+BrxIQKRqEww0cbcM9B6iBBekeVz904 Jeer8oLjq8o+vzBLFkKlDmMfRezIimwu/++mo625jvEJnELcQKq1l6+pSE4I6yc3EGNO avsmiwRcB4UkWPhs12oYTIGz5bbFV6sT3rtns+YDrvkIMD5t58ZI6FwcvjWhd6fUAvQv KFpg== 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=UWh6WQgwFaXoTdfyv00kbbEUIrTl3FpRNOTur6Egg74=; b=Oi8B6//DjzgHHrKnGUAMsy7MTePjDdwd0M6WkZNDroCJshKDmkkPOSp/YwORmfUCgc +vQrxKCBaTK6uO1fVqpGpVp7dVuS2o+1cmSZVxTMuRtbDMl8y79nVILfV2eHOBRr2h8z JR5H0k92VNk0SZYh4uIBH1mtSCNme4bEJ8vf5GwaRG5A5s418UjzEgSNWzMhMeOlqCBV 7U0EtXjPAL8sDROZqNv23043kh9gP86rrgVvtCO4Aqg8HRB6FLArdVGRbLYJsBKjhLnm hq2Oh3sas8rtECiGBlQ7P2aYMrcCEn46K1bN5NkwSBSpxrm4ddq5purZ7+PPGGTPye/+ iG9Q== X-Gm-Message-State: APjAAAVteJSvqpgH8i0k73oY3ONgNcYvm6Jz5brLGkk3LJY0VnRNybYm 600L8KJ9S7UFanmkRdt2iPOJbYImWIg= X-Received: by 2002:aa7:92c4:: with SMTP id k4mr16581392pfa.183.1557509481869; Fri, 10 May 2019 10:31:21 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:49 -0700 Message-Id: <20190510173049.28171-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v6 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: Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We now have an interface for guest visible random numbers. Cc: Paolo Bonzini Reviewed-by: Eduardo Habkost Signed-off-by: Richard Henderson --- v6: Add gen_io_start/end for -icount. --- 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 722c5514d4..1386814957 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -730,13 +730,14 @@ static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \ CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \ CPUID_EXT_XSAVE | /* CPUID_EXT_OSXSAVE is dynamic */ \ - CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR) + CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR | \ + CPUID_EXT_RDRAND) /* missing: CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX, CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, CPUID_EXT_FMA, CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_PCID, CPUID_EXT_DCA, CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER, CPUID_EXT_AVX, - CPUID_EXT_F16C, CPUID_EXT_RDRAND */ + CPUID_EXT_F16C */ #ifdef TARGET_X86_64 #define TCG_EXT2_X86_64_FEATURES (CPUID_EXT2_SYSCALL | CPUID_EXT2_LM) diff --git a/target/i386/int_helper.c b/target/i386/int_helper.c index 4dc5c65991..334469ca8c 100644 --- a/target/i386/int_helper.c +++ b/target/i386/int_helper.c @@ -22,6 +22,8 @@ #include "exec/exec-all.h" #include "qemu/host-utils.h" #include "exec/helper-proto.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" //#define DEBUG_MULDIV @@ -470,3 +472,22 @@ void helper_cr4_testbit(CPUX86State *env, uint32_t bit) raise_exception_ra(env, EXCP06_ILLOP, GETPC()); } } + +target_ulong HELPER(rdrand)(CPUX86State *env) +{ + Error *err = NULL; + target_ulong ret; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + qemu_log_mask(LOG_UNIMP, "rdrand: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + /* Failure clears CF and all other flags, and returns 0. */ + env->cc_src = 0; + return 0; + } + + /* Success sets CF and clears all others. */ + env->cc_src = CC_C; + return ret; +} diff --git a/target/i386/translate.c b/target/i386/translate.c index 77d6b73e42..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; /**************************/