From patchwork Tue May 14 19:16:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164232 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3003701ili; Tue, 14 May 2019 12:21:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEDCxS3PdMkZJ5CXRclTXrr1Q2kQLCalWTxN4tbYxQ33lKgrcdeg+R+KAeyj7pWzpvU0Ap X-Received: by 2002:a50:ba13:: with SMTP id g19mr37718649edc.236.1557861667162; Tue, 14 May 2019 12:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861667; cv=none; d=google.com; s=arc-20160816; b=efgMtvbHk+u0tJ2jfR8ejk1ztuxfhYQ3NLatpH3U6WyZPi3b7QaKem1ryFqpbOsASM e6E8swt8Y3Wns1aRUULagPM8eJqeIUiMHwd/Ys4eAZGQlzlZ8OWYgxsFQC0sEG9P9gtX hslwOCdf3YFh9BdrGx2XnvrE1lPY0EjX+L1Xs4XaJ/7LBKJFNRVpHIPOTxavGUicnyq0 nSrOJx/P8MIl4OxCnEyz4HgjQlI/0JYUE5qhHXw1f+fdb8/d9jCKlaPATOP/BsXFLDcv lpz2BGyCH/dlnNjyN2oU79BdFf3DcqacL6WoRF/PXU97ELaCHEOI5XxDu3Jpw3RlkSsT vPkA== 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=av3lT3tB0E6MniPcJlUSedb9hAsWsyXtFxkAveRaX+4=; b=Q+rCbcexFt9LR7jbPOG7ACwS2JGpoovTvITBWFvk1436d6DciFs++hMGWSyvnqageM PzMl7o/FyduQCGriA7kL71Xq+0s4BGmy3ZEfZOfYpzEYNshKMd40K/oad8Kbbwuo0yDB ZGdV/2ZhtShiOJvp/dgiIb8vc6myp3+hXMrmhgtotL91/16hbzZvwUYf9sodlWO9nH5L bRmHeXocpTrx+M8yqu4OGlnRa+hqDoizesqy6F/9sh6B4Safq7p1YQv0HrbmCVLFTmS8 oP0DT7inNi2UJsKHnC7Y3Hh4DjpTXvpKkJLhjGAdsQo1h1WVl8D9tmgiuzV77YLxNLmq CvaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nvLzqvhn; 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 c18si4140586eja.379.2019.05.14.12.21.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:21:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nvLzqvhn; 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]:52973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcz4-0005SU-1B for patch@linaro.org; Tue, 14 May 2019 15:21:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcv6-0002Qk-4E for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcv5-0006Yk-2w for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:00 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:38182) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcv4-0006XS-T2 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:16:59 -0400 Received: by mail-pf1-x443.google.com with SMTP id b76so5105pfb.5 for ; Tue, 14 May 2019 12:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=av3lT3tB0E6MniPcJlUSedb9hAsWsyXtFxkAveRaX+4=; b=nvLzqvhnv+ElZBEAG1AOsTIF/YA3g1Fsm/33pqJH3O8JS4Yzkw0N3z1AL09mFKhtwk VOkqh1EytBQ79nQ5vpZzQ4pyiWxPglWq+cgKK1QaV324saRBQN2LQ+rdQ3Mq0xHAaUbY SGDaviQuX6/3TVR+Xh5IoAROzEtFb8+hu9nDt+Pw+rGhQQlBcDJGUZ5Y6u8roUxZqay3 6sbLDIcmq7iBqt9EIWVZl0c2r0TAag9UjwkBLRCwfb860DZaFb0LFdWQ9TbjV6Fw0axz 4PIc/jpOUfmrxIHMisxeUfgJ6OsrMjvJKus6n3jGpx6ghOR7zhqQFxyxAtKtE+HyrKVf u4DA== 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=av3lT3tB0E6MniPcJlUSedb9hAsWsyXtFxkAveRaX+4=; b=YJVFqfrBCAgiUB3haAn2zbC/CLjbL0CkkEFpH839FdTE5+NZc+ax7HVfgn+7pkYAsR wXwU8wcuXYUJA/MlOnFgI9tfOlDZTfuiGD0bI+r7wzUIquiIV0l65FhX9E1j2FXbfDOj xKE3x7/O1t55glKtzeJUmnOgOJFTvwsRmYyd6f0MW8mInv5o+YjZB0YqnAV2dyZrIOQB fZ13XX7U0NsuPqUrBXW93nTxT8DCNGwiA/dnGqSBD+YZ1+x7C8KMarjgQHaoTExT0NfJ 2dKsbTNYaL4m/SyjWgCcw0brqhJc9soLAHXoJABQQiv3LIF+WB9xYv+SpCXkQ4+kYQIZ yPsg== X-Gm-Message-State: APjAAAWPsmmDShrF01Tf0iWruGq7OjXro7UC6B3YDV0MJUpqS5ajLY4g HwxzFiy1xYYu6Z4nGdvrBbUB0Z5p7g0= X-Received: by 2002:aa7:8c1a:: with SMTP id c26mr42182591pfd.25.1557861417150; Tue, 14 May 2019 12:16: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 o6sm18682982pfa.88.2019.05.14.12.16.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:16:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:30 -0700 Message-Id: <20190514191653.31488-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 01/24] build: Link user-only with crypto-rng-obj-y 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: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For user-only, we require only the random number bits of the crypto subsystem. We need to preserve --static linking, which for many recent Linux distributions precludes using GnuTLS or GCrypt. Instead, use our random-platform module unconditionally. Signed-off-by: Richard Henderson --- Makefile | 6 ++++-- Makefile.objs | 1 + Makefile.target | 3 ++- crypto/Makefile.objs | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/Makefile b/Makefile index 66d5c65156..524f2f8a57 100644 --- a/Makefile +++ b/Makefile @@ -411,6 +411,7 @@ dummy := $(call unnest-vars,, \ block-obj-m \ crypto-obj-y \ crypto-aes-obj-y \ + crypto-rng-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -482,8 +483,9 @@ 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) \ + $(crypto-aes-obj-$(CONFIG_USER_ONLY)) \ + $(crypto-rng-obj-$(CONFIG_USER_ONLY)) ROMSUBDIR_RULES=$(patsubst %,romsubdir-%, $(ROMS)) # Only keep -O and -g cflags diff --git a/Makefile.objs b/Makefile.objs index cf065de5ed..0c13ff47ea 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -26,6 +26,7 @@ block-obj-m = block/ crypto-obj-y = crypto/ crypto-aes-obj-y = crypto/ +crypto-rng-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..4e579a0a84 100644 --- a/Makefile.target +++ b/Makefile.target @@ -181,6 +181,7 @@ dummy := $(call unnest-vars,.., \ chardev-obj-y \ crypto-obj-y \ crypto-aes-obj-y \ + crypto-rng-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -189,7 +190,7 @@ all-obj-y += $(common-obj-y) all-obj-y += $(qom-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y) -all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y) +all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y) $(crypto-rng-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y) diff --git a/crypto/Makefile.objs b/crypto/Makefile.objs index 256c9aca1f..ee7e628ca6 100644 --- a/crypto/Makefile.objs +++ b/crypto/Makefile.objs @@ -37,5 +37,6 @@ crypto-obj-y += block-luks.o # Let the userspace emulators avoid linking gnutls/etc crypto-aes-obj-y = aes.o +crypto-rng-obj-y = random-platform.o stub-obj-y += pbkdf-stub.o From patchwork Tue May 14 19:16: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: 164237 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3006199ili; Tue, 14 May 2019 12:23:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxdLJ/VRUHUMBWn0UVUteU5XTaUJffY0zfVU8Bfwix3MgfRND8r2EVFfLvlKvpbdUpUTJa X-Received: by 2002:a17:906:a28d:: with SMTP id i13mr29919718ejz.148.1557861839061; Tue, 14 May 2019 12:23:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861839; cv=none; d=google.com; s=arc-20160816; b=Kus/Po2dPczdgUrCWTEM69MD4g30zTjkOJ4/WzZii4LqnSCqeowrQSMNziVDX4R3nC RwjvOw1e9w9uCajOI/B0dHwJz/2NP/OLrWk6uR9i25dEg9wMKwDm5qAk7VYgcNxOx5KH xywNLXIeqG23gUQGuO7Tm114n6KS/fc1ks9GdE+dH7YMcLNvBeZxDmP+2BXp9Rksp7Nk BiYfdxOptna10FW9KRYUZbzeImrfzWXxQok2i6h8Y1HoeOlZuNxLjBcbkwwgo9FcMCO7 w/RoE2mqGAJa2PaRwHi8gYYaLo8S+9VISvxBWj0HpuBkjaSkW0BgKX2ZKeqav0TJz+O1 e2KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=MoDmwqqZS42MFNoDo+y2dA0Cnr8/Agpz1oVsc3N8fJ3BeqxYBCHCjpQU1RPI8lJWJh ib3UmTnRfJO0i21OL6TEBSyktDIzS4mcVipe+Rf5Y3QjvN+6tjCinkPh8R3W+vOa1F4+ XudMuKmnUMShEKT8KpOMo8Ytrmd1odUhnThGyGGX5fcbesVlwrwBw4WmZZayAz9RpL4N UVAlS/81daOWtiF5VDroZbAcl3v/1ap5qoo3b0GR+L/HBch5g1wK6JWgMH3kj68H63HE JRQhcGdDhupqyiPuvxRCPZQn8HeHsbbZEhTcGVYDafAW46zHx0YmnqDcdqO5XWAoYTlc sYcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Gb+xsA4U; 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 e22si3454150eda.365.2019.05.14.12.23.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:23:59 -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=Gb+xsA4U; 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]:52998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd1p-0008Bc-V0 for patch@linaro.org; Tue, 14 May 2019 15:23:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcv7-0002RV-MW for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcv6-0006bA-Ad for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:01 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:36047) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcv6-0006ZU-4y for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:00 -0400 Received: by mail-pg1-x544.google.com with SMTP id a3so51477pgb.3 for ; Tue, 14 May 2019 12:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=Gb+xsA4UIYZS7cwRNKCo6SpGCgSreXYfWByMU7/mA9nPjkwQxadgEYrs+xeJJRwj+p HNGJuwCiKp31mt8+sW8yHU3VPhI5m+VM82GA98KMPCb4ScXgK1tBtG9DHPTLHYD4X5Yg chW0MGy7d14uUDyqsFTiaw7u88J484/7B9XqeWCmTHy+CRRUWMr58lhX5iBb9rGnQwO5 w+Wm0woCLXjLkAKmbjoQBM9WdUZkxHLT9GhYgU76BEFh77r/GXhg5D4QF6aNKjKRKIXJ HKiOsM235FPdDUcc6A1ni0U7RYdBTUtl7k+cIFhmXPNa5kIwpDn3itHIeRHOoGtUlLKs 2MTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=kQkkUAQS157FF6LY1RAtGze/FA5gRRXp9LjUgvYYY8WHyFVnS4EmxR1llQmkWi/7pV 7f41sTShSKfJWkHXw1XR8PaxPvzxy12X3oFJCaSIZFeLkD1wNEv3qOjen2+yxJ+KtOoV mWPPe5vmk3pNWKdBhco4wIcB/fgzOsjY8mPj1smiFRQHQQqxqOe2U+zV0QPm6DWtyICS IFxcp69kqam20wU1gry5TI/blW8Lo7BqKLz+SYhCVqLF7poVSgqSl/DtJ7p0BIZd7WIm G/l/iOaqrnp+9qSFH+bUTvob5Nw+H6jLiXIrAy8EX8VxrWBW+tZpxfJBtSje/YFsvuk/ 7WxQ== X-Gm-Message-State: APjAAAVmrKVD5spIm+g0W/F4i3dguH2S0dL5ouVOEs1YPYfht1/YnA8T uzF5RAaxegonUMSj9rGcFwmHLDD8i8Y= X-Received: by 2002:a62:160b:: with SMTP id 11mr43761787pfw.88.1557861418821; Tue, 14 May 2019 12:16: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 o6sm18682982pfa.88.2019.05.14.12.16.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:16:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:31 -0700 Message-Id: <20190514191653.31488-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 02/24] crypto: Reverse code blocks in random-platform.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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 Tue May 14 19:16: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: 164229 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3000675ili; Tue, 14 May 2019 12:17:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvT3uPgZDkAFSkb5IMEM5Lzwoo2aa8B/6VYfo1tQJkFwvZiXrgV+6RvzRK9Jy6iyMlzGWx X-Received: by 2002:a50:f482:: with SMTP id s2mr38930791edm.44.1557861458554; Tue, 14 May 2019 12:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861458; cv=none; d=google.com; s=arc-20160816; b=MdXqTzcTi94Lc/5DNhDV9H4/l3xTO3eFljj5q+qcEXBcip0dPGGyQhv72LAN9g3LOT 5rpkdfu4VprU4Xfhqm7u7jMiHmuM2/mbWzvNzPxZDXrpKOV+o8hZo7M6LzoANKMZBBg2 7xqTfTece8dS25KY5xwQcOGZteuRUoMwHe4gtwdIwzt+6s+KKe4QFPlUWFCDTQ85mk+1 Kd5bwyWA+IRiQyoV3nRicxOVBRGR8M1TOC74T+5SKyH57AtohfzZPTS9swI39NPXOA/7 Pl9YB9i0yXYkcjPy7/rqROAwMRShpJ5UrFigKZVp5Zehp/KRhxmtZhoE79/7FkzLCmbj uZtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=F+DNdi8aZ9w72uvzmDc6fnI5IhfoZ+5jAzOsC1+FxuQB8b6euaxw3xioigoksYqgUF w5ZwUluLLrqv1wFvjQzkq3si06CSwxHIjMpW6IKoXuyPZkRIZaUSG9why5TMtOKbe2+b 5ZYbVYlq193nN7tyju+yzQGqYBRq3hngF+6/OSw6RKMRN/6cjTTkLlPeSlwI2+NjfTCo +mOOC3KH79/hnCJVWWf3EcOCLhPnTVnoyqvGMUOw0aeUvaPg88DKCta9x9ymQWJxJ2JN Q25ETAHibh7Xw12HwS7AQA/DA/r1XoyKXeiRJKNAe5NHnLBrVYxo2Na9KRsnKVQQ4z2J 93Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MV1an0vg; 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 b11si2506964eda.406.2019.05.14.12.17.38 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:17:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MV1an0vg; 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]:52910 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvh-0002V0-Fb for patch@linaro.org; Tue, 14 May 2019 15:17:37 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcv8-0002SE-Fb for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcv7-0006cz-HD for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:02 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:46217) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcv7-0006by-By for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:01 -0400 Received: by mail-pl1-x644.google.com with SMTP id r18so59138pls.13 for ; Tue, 14 May 2019 12:17:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=MV1an0vg/aEqlkOwBdnA9NRpAfsJuH1ukbkckmaIgldQYs+e8INRbWBqaMeKoFt/RH H3WtchNWEb3bXwtdWHJi9JvqgmzvsuQ2a/YCoZgqQpj9N/izR4jldIXaXmdPivg1+qtg R09ts4LpJQrvvpj2FRSGAdmBO/VsmL/ni0IakBhLSLFPcXadNvVDohPmvo1e6FxBpYm+ sI29s+bMRGnRVnsTckOg5sgSSywdrVRd+mvWhXDcULZ5uq0EVendavYO9AzYLCJclOy/ 7XJ0Zs24mUD597t8Ok3pUDInm8NRmJZyZKcjKeiut+5SQGbZ/exf2CsozEIh/5ho9TxH /zqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=rnZnGLZbU8sCUxS1cAaDvk8b1KABeIDgQk84u8vvDIujg94bDCpqjL1lN0VGDY1AQ/ 1AFFjcNUfLa5hJQMPHrk7g+Iucl7WKbZQtSXw7aSYZFu/7gBP60FUC2x7GqrziEJnJnE Uyehy1y/CbbJUnXBJ0Wxt/1qC9x5b9tVOl1BdJnq7ktXNmWp1v6zDkjX4QrBtpIB8kUW 9l7ebeI+KJ5VeVrkTH3mD3SHuFNWBI3Waphh+e8FUQawi534Sh4NAG6G8YAhBDxngtvU mPNKU+2qylyEmKs+yUx5+r1XteWPHG99NuI4CXtaSbHgIH3KmMhEKluBEpc8bfcAmGuU oduA== X-Gm-Message-State: APjAAAXGd+N4pzCN3vFeGGzzi3VxiZz3l6F7aJfCupenWjH7t8c2+58p 6EYqwy3IrYkKzeQd1xgkwnQyzzaMMhk= X-Received: by 2002:a17:902:5e1:: with SMTP id f88mr38615351plf.226.1557861420082; Tue, 14 May 2019 12:17:00 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.16.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:16:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:32 -0700 Message-Id: <20190514191653.31488-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [PATCH v7 03/24] crypto: Do not fail for EINTR during qcrypto_random_bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We can always get EINTR for read; /dev/urandom is no exception. Rearrange the order of tests for likelihood; allow degenerate buflen==0 case to perform a no-op zero-length read. This means that the normal success path is a straight line with a single test for success. Reviewed-by: Laurent Vivier Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) -- 2.17.1 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index f995fc0ef1..260b64564d 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -65,29 +65,23 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, "Unable to read random bytes"); return -1; } - - return 0; #else - int ret = -1; - int got; - - while (buflen > 0) { - got = read(fd, buf, buflen); - if (got < 0) { - error_setg_errno(errp, errno, - "Unable to read random bytes"); - goto cleanup; - } else if (!got) { - error_setg(errp, - "Unexpected EOF reading random bytes"); - goto cleanup; + while (1) { + ssize_t got = read(fd, buf, buflen); + if (likely(got == buflen)) { + return 0; + } + if (got > 0) { + buflen -= got; + buf += got; + } else if (got == 0) { + error_setg(errp, "Unexpected EOF reading random bytes"); + return -1; + } else if (errno != EINTR) { + error_setg_errno(errp, errno, "Unable to read random bytes"); + return -1; } - buflen -= got; - buf += got; } - - ret = 0; - cleanup: - return ret; #endif + return 0; } From patchwork Tue May 14 19:16: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: 164238 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3006663ili; Tue, 14 May 2019 12:24:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNc614QDmowHVe7b/xfFor7k89Iw6v+hGCJoW9823wWLACtciED6QmqvWcV7AafT2iEGgV X-Received: by 2002:a17:906:660c:: with SMTP id b12mr29705329ejp.299.1557861869019; Tue, 14 May 2019 12:24:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861869; cv=none; d=google.com; s=arc-20160816; b=e7BGeinZHhXpZ0DypSUQklVqAfGR0Sc4caNhGpftLnrEjC2PbCJTL/1vN+7+OTN1dw rwTgYUZmLejHOlYlG+0pQPSgdNtp6GQZ0FSlvYWyxSX3QIhm8Htd/q3BxN/ixQ78N3GX P+BiuEUikExuuP9AUTAQgFIFKRmeKCzZsA2yyYGMDyGJRxPt+orCXJnuLJn2fEu0hKsi m0TEfVgvqMoAbamXfAOpbkRxw8+/469OvJNYQ8ACqMZOMzdhavWykQOAtLTYAdZYAcfG kBaiNkBF1NMXxkuEU2zRPvpQ5jy16XxmB7tgelaxylTZzSHqChfZ6aLe4jzDW14t5mKQ CzXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=UVEZNnxxKSldodhV62UcTZQ3szFWSssfs8hwMeHA9r36SUqcrpEQR2x+YKumifKK+z vwZjFr4/pV+JmVwq4u0uocEmsGXPwj4X6P8w11XK4xFFPoZaP+9KgIGP7yladTaC2iFg Uy7C2/n9KJT+zPpujVhf3HMfQWTifyFKgMWUFWnX8EF624CReucwPywKA4xgXbO51MY3 9/hHrUYXjvOzuRKkqfvXkJZ2c2R5t1Hq+FflhO1WvUfPohCWaNerBHiCfAgNEtwBcoR7 8ZCai63nC3peHAPA52sqvYiyhQ/WvfmiLGvNMQmkh2M3TF0jVH/irnBATn0uqpXxH6EH jG1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=V27bejYP; 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 p49si8659097edc.249.2019.05.14.12.24.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:24:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=V27bejYP; 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]:53000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd2J-0008Ic-US for patch@linaro.org; Tue, 14 May 2019 15:24:27 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcv9-0002TJ-OJ for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcv8-0006fl-Tl for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:03 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:38783) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcv8-0006e9-OA for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:02 -0400 Received: by mail-pl1-x643.google.com with SMTP id f97so79423plb.5 for ; Tue, 14 May 2019 12:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=V27bejYPJ1d5Edg9q46vscEtm89bOnKxzU5r7sWIv8IilaDLnIMOP8AXYgW3Xxmbfw SpvIgUJF5QDDrzpY7eDH6SkqZHfgFRo9iC/F0BZP3p2SuyNGN0WYELh02fK8KNKPkzTV 77NabADkpyartaqjMMG1gZSrfKYsd2qg01kwjhEtfFSdYlr9J/Dv8/WmDvGOCe2Ug5nF SzFIAHLAqupumigka2FnjCWRAyN/Hci3xBBOR7CDqTrZcSyKpBeDLg9tY+Iw7WrijMhX CnsHMjfjs5b9A9yK1NJgABaM0qSjIHWVekLX6/8gBPa2a0RT+Lp01K+G3a3rAFwf9U3s YrmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p/AR+QB1/uCfqQ+ytrGBnYCYqwPtnBM3b7CBgieQEw0=; b=HnhEWc6H8lVna1qB9hEKz5J3KHrlVNHg7pG9QdtQnVRu/UNBogdHkJ89YktAHWd+0Z JCquR8OjsKWOk96vJdPv7uBzmQn9nK+M55VitaOOmKCeJiPXjxmjTyfk386LcQ3zgZig AHoj0SxDGmFZ57P4HmozaZzV9nx/7Soc3bXyuKcxKmrhg+9W7jpdMERij14CnYyjnNrg PdlA5j5LYdfjVWRg1/ARq+AlXw4PUCJfiRqXOe6C49GGQYNlDxutBnSPejXUCKnPuUj1 C1Blw0u1hJKALSJn715tfglOdBoYGUG2j7sypKsslILKOAlf4HLp6pj0BVp2m6Ia/xvv cufw== X-Gm-Message-State: APjAAAWX0724ZpCE2+ax3IAzk2mpppkut/WtguQirdiIWBJNHRGSEdPV dh5uP/8A/uSPm0rhJXufaIpP8tpT6fk= X-Received: by 2002:a17:902:8b8a:: with SMTP id ay10mr31193869plb.74.1557861421412; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:33 -0700 Message-Id: <20190514191653.31488-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 04/24] crypto: Use O_CLOEXEC in qcrypto_random_init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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 Tue May 14 19:16: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: 164234 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3005788ili; Tue, 14 May 2019 12:23:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwyZ3WuU53H5qe9gl2IwAVHHwVYZTV1UAk3ZqfTqNVMTuRBDs3f/uB9Sz6GaFW+QTudoy65 X-Received: by 2002:a50:fb19:: with SMTP id d25mr38513605edq.61.1557861805044; Tue, 14 May 2019 12:23:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861805; cv=none; d=google.com; s=arc-20160816; b=kdPXJ5lbl6nxFGnSA2kiHpqffpKn9xE1cwjjnDaTf/jQqqKr/cvZnXOEX6cdj2ooJ3 vZFp+iFxqQzZHrw7vgaNtV3WhUMSYhXRWpICW92Nd7Qn7+4Ibd0JDZls/cfz/LVk8e4X DiGtOQIhCJd/TsIZXRCQhSWaSyEf0p0g1UiPlVJ9yFfnmYggavQ7QJGVQWZS3lZfctJR V1szsfWdSCZzQlCPFEI9ojClXHYE8EvTqolvRi8ax6RwRPGB2uE8OrrqjkV9xt6f+wEW ULN7MWjink05XawlwN6h4yxpXLP2UUePL14Eykev71wKxB/+KMmrIfrq3aTydYb/6JQh 7F1g== 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=b42dIpKHYcMh2o6M7wOruwcfvv0uPGu8hN7+qTRYDSE=; b=yqqAW6UJcXY3uJxKCeUZ/KCD3vbxsFVR9nzOAASQzgdhOKQrcH7l7175L7EDet9g1L IiqF5PGNjsT38fTK7y3P6sg96xRC4YUOIDv9BIHM0XpbMDg9lRU+41bsOAmlR4tC4RBq E+j2/HDQ5LHXXe8GA0G+jfZnXNAavnSzHT+lxny8ez1u6YCIGSwmLHsmhlsB8DcCs6is FqW67g8L07HPI7XKByf80EFVlKPKLMTDEVOOYKSGhrnSJTxTeKpUTAzVbw4EBNKo43SV dhL3PQxExisw+Sq4DNVoYGw8S0EFoq/3OKOjkk30NZpZZI1+S1RY5poEYckG64NhWZz0 6Xww== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jdsxC1VL; 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 c8si9982636eds.136.2019.05.14.12.23.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:23: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=jdsxC1VL; 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]:52986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd1H-0007jh-Vu for patch@linaro.org; Tue, 14 May 2019 15:23:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvB-0002Tj-1F for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvA-0006ia-1i for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:05 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:38952) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcv9-0006he-Rj for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:03 -0400 Received: by mail-pl1-x644.google.com with SMTP id g9so76437plm.6 for ; Tue, 14 May 2019 12:17:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b42dIpKHYcMh2o6M7wOruwcfvv0uPGu8hN7+qTRYDSE=; b=jdsxC1VLgN0tfRuYsyqcgMMtnFn2rns0MUdiBSUqil1G9BwSYYcgE9X0mSutSFdIzZ OgCpj90j3LSCTIC8PPXvmW5sgeRNBuMmkKN6g6Tvs3PzVpHhFLP/Nf2eeoc+QiRn+vEZ 0b9j/yPzyXkO5D+FXBeB47fJnYIcKBg5IuZtLZhZNeMmdkrdhf1TnyqBa2qDOD8tpCoo l3DaHuKthgZcE8YW4rFWzcaT+oXmB3CV5Ymgp2LwhOrd5jAWxQMx46W8J6r2dQPq1r/i 9ZZyW6ImIkpLyUobMXaiTea3ms5JlEEzTikN2AD2nX/Fshsqf42bz1kxTS1Pb8ohAJLH cw/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b42dIpKHYcMh2o6M7wOruwcfvv0uPGu8hN7+qTRYDSE=; b=CMhqueF3xYnmrlwcpW7f4hpUGLHc5nP5vu0SmFhBfoZWiT5nlkfWb7lkadUTsg7n9Y caAKdEpqkLS7S+XHn8uzG8g9dr36xE5nysfw4v/MrBRCMP9XceUv6KHQYQoym4HhlgWv /mPsc49ZS580tSR9xBJCKEYlHhLKZsPCsr0z6sKuRak3ft3tCSIf2SQMj23YNYjwXP3e 2dNLZnh0pG0SJYgJ2HnbUZEzTXwp5R4BafNgDTbCrfFZ+udSdM60WUu6A8QXsQd8W7px Z5bV/sjDWXYWPneFjZ9g2pLeOJ9jrB11S3/11ypM+a8feyFFdRPBN92Ul6nL6AFm36Dk oy+Q== X-Gm-Message-State: APjAAAWSM5eMMHMXnqMKB/SxGuACtBjSOrlBnafy+NEVBgueAgbI7iWD h6leYPI0+kGGQJfww8V5s4lZz3iX+H8= X-Received: by 2002:a17:902:868e:: with SMTP id g14mr40284422plo.183.1557861422596; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:34 -0700 Message-Id: <20190514191653.31488-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [PATCH v7 05/24] crypto: Use getrandom for qcrypto_random_bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Prefer it to direct use of /dev/urandom. Reviewed-by: Laurent Vivier Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 37 ++++++++++++++++++++++++++++++++----- configure | 18 +++++++++++++++++- 2 files changed, 49 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 6df40744c7..cb3ca1bc09 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -27,7 +27,11 @@ #include static HCRYPTPROV hCryptProv; #else -static int fd; /* a file handle to either /dev/urandom or /dev/random */ +# ifdef CONFIG_GETRANDOM +# include +# endif +/* This is -1 for getrandom(), or a file handle for /dev/{u,}random. */ +static int fd; #endif int qcrypto_random_init(Error **errp) @@ -40,15 +44,20 @@ int qcrypto_random_init(Error **errp) return -1; } #else - /* TBD perhaps also add support for BSD getentropy / Linux - * getrandom syscalls directly */ +# ifdef CONFIG_GETRANDOM + if (getrandom(NULL, 0, 0) == 0) { + /* Use getrandom() */ + fd = -1; + return 0; + } + /* Fall through to /dev/urandom case. */ +# endif fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); if (fd == -1 && errno == ENOENT) { fd = open("/dev/random", O_RDONLY | O_CLOEXEC); } - if (fd < 0) { - error_setg(errp, "No /dev/urandom or /dev/random found"); + error_setg_errno(errp, errno, "No /dev/urandom or /dev/random"); return -1; } #endif @@ -66,6 +75,24 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, return -1; } #else +# ifdef CONFIG_GETRANDOM + if (likely(fd < 0)) { + while (1) { + ssize_t got = getrandom(buf, buflen, 0); + if (likely(got == buflen)) { + return 0; + } + if (got >= 0) { + buflen -= got; + buf += got; + } else if (errno != EINTR) { + error_setg_errno(errp, errno, "getrandom"); + return -1; + } + } + } + /* Fall through to /dev/urandom case. */ +# endif while (1) { ssize_t got = read(fd, buf, buflen); if (likely(got == buflen)) { diff --git a/configure b/configure index 8999698bc2..9ecec9c494 100755 --- a/configure +++ b/configure @@ -5802,6 +5802,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 @@ -7189,7 +7203,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 Tue May 14 19:16: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: 164233 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3003719ili; Tue, 14 May 2019 12:21:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYn0PFa0QlsLcPDJvUdmebZ67WNZX2upHhUfVkgwDVo2/NoSZZm2XW2BG7nCxx9RttZL16 X-Received: by 2002:a17:906:5252:: with SMTP id y18mr29510190ejm.186.1557861667841; Tue, 14 May 2019 12:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861667; cv=none; d=google.com; s=arc-20160816; b=j8KfrPYSc4GyhZ1YEy+3ORt7vM7ISsbq9PdVTiy2E7u/NA5D0RnGS7rQ4VF+aQeVMw 2iQlfyK7t63wH0SDG7r6d19Usi7ye1v8bIdzNFrspCj5csPy3HiEmuVf+ehvEv4mNR8r hqqaYKiu3gLS7iJguGqAaumMjMH9sLRhCq+b5+veMypBCz/yhyOKC80JnMRmItdaN1uW HTpWU/wOPtz3mK+WUQD14zg2Djw0aiAT+dPfzR9SOZg+lIU0SsQds8//waZFcGjn7W6s 34LfXpUKQL/ftVHAPO8VnTlemDK8WUMl7H8i6gP1od5uY52hiCxTIoWhHfjnP7To7hLQ nP3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=1CDOgYuHoAqMhYjjOZtAxkKPxAumJ/2gSv3OgwMByC9XTJU0x3UlCTZcnskSX/B02z JGY5fzBtv2pwrpF4rKJZWYAtC6EBgh3PFD6Ml0io/mI45Mjc5TI3KAP9yvnbF28M5NpU crCwJjbkqvcrfk8TGk/q/CECFU4lOwjvDOYwEy0CWAO6Ln2N2pkB0I6PFrOzTPC9NLYJ c49oOjhX7QDb8Ih9zO6j/HLy0AfL38TIe3SgTtChLz/ePHSk0sxMShpnWDKzHWhrbj+u i9w1cca/wsoknQlJ36qj5LkX8xkd6ZKfwlGGmyPu8PS2NoVEe2bYFFHCCnps8y+TRLBG Wufg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PJcfjnh6; 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 s42si323558edb.341.2019.05.14.12.21.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:21:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PJcfjnh6; 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]:52970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcz4-00053k-Nc for patch@linaro.org; Tue, 14 May 2019 15:21:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvC-0002Tm-CA for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvB-0006lP-Bo for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:06 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:46900) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvB-0006jd-5Z for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:05 -0400 Received: by mail-pg1-x543.google.com with SMTP id t187so29177pgb.13 for ; Tue, 14 May 2019 12:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=PJcfjnh6iCpJv/K+c7imTedknfYbTfCH5zIPH+iNkMN/dant7wWVqX4OTZctBOiRcY 6s/unk+w2w4glf6iFG5e2j0S/laU6TYrr0w/tEmsVWS3XOk3O93Cj48FtxG3nLRWUzcI 9ScnAn1HfhnoXEl/B12uF5OORCDbgG7Z9uJP6E0ordK4k5UlubGl9lOlauQHJif4k0I6 FnnaS0WY+4eN8QEtYcPixOcHEcE7kyCWS04QuV9KLv2D9t++MuDsx+o1VWSRLAEnzsHo 4t6/sfBMfjpXkawBZSNvJuGZyEYR/Icw457AL63JJrxYm3XmYHLDenWVYsc9OFCBZAfR HDGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z+TkCJ+Ncy1KMgA4q+7eFD+GiqzlCrNmhclplUZOTOM=; b=F9Dp7A89LpFMsh2nvlKvOLjmrVweBG/esjpyGiAqPvTV1aI0DlHCfgo9PwIrMhhOnC wZ+jTM4S5T16Hl6gUs7BwnF9nuARVs/OfAPzRoh3MV25ddc4r6PEnoJEmrgH4Dk8SulR 7AQ0OjLfcp29DsRwHC7wHG63SP5J3odmovCFbyc1NKgKxObP7hHfIYzNDbS6bZKU1RLM UqzHBVhKYTAdrepdkpKIc1DutR16TZmGXaSJgSATYrC6svIbbwiDAUGhoCB0MoBdxjDA yRR8d07q9wndclDIL9RfXy5XA1PoCRYrqFaYodlG0dVtlBsTeWLmiMlA5U/ezLkgCedD HSpw== X-Gm-Message-State: APjAAAVOTC/RDDE0PceztROgF6tklR4Z1ZE6wtxErxpPcXRO3zvpC+RO bKl3OZL4r4XJRm3VeA4xDvOq2zU7nlA= X-Received: by 2002:a62:570a:: with SMTP id l10mr42189212pfb.151.1557861423815; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:35 -0700 Message-Id: <20190514191653.31488-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 06/24] crypto: Change the qcrypto_random_bytes buffer type to void* X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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 Tue May 14 19:16: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: 164236 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3006126ili; Tue, 14 May 2019 12:23:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSKqVSGGh4Td9PHPGnEGhxzNZPEGXypob5U+CuT7DcjcPa2BcQvjLuhBoWiSMq0aTne4Y/ X-Received: by 2002:a50:a3b5:: with SMTP id s50mr38656042edb.149.1557861832709; Tue, 14 May 2019 12:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861832; cv=none; d=google.com; s=arc-20160816; b=LtISKwjB1qijltCjBWMFPzh0NPbjGIzKHp/Kh0jJwwe0rg+e3LzVpEDziOVqxIirT0 Gq54xKGEZnqOgHAZMuOdGX3wbZ7gjAWiGO6Le9L/SLidgvSC5hAhoR0tGKhgYx0xORuv T4CbOevOqqcbsfvMkJFaCYGd9L4Ij86GtNDwPsdTUwEHLI7glElk/I16WdgtqCQsQ4v1 wurvSQvnXGGNC/JUo9BNX9G0mBExAu5xKSQw2IJMhYeEJJpA6V40PfgU3KgeY7QuaB1f 5/dPQqg4PExA5b8gLlbBHnCAST5BmtnEsBwY8ElOT9Ohuuef8YUeh3su8JyAOjbrtA9h wrwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=Zk9SOp6Pha9nzBaMzMRTSzHK+A64OCZirpm2N3BEuKjAU0ocz8Ihb6eUGx+2/1sgfF 158ixfzk9u2+9C6tJlPTrtDvsyMzuxV7xbgx2jQyGDjj0nSSou9hc5WBxcCUrKk6ay9c i5VbPp/joP3+oHJHVNBAZaINMvV/OWd2NOkzChaCcIDTvBM4zgAES5JLxHpzheClUqih MzurJSVZoyu9fZD5kWeIoF+24m+08xNUPGjygOEQSjukNGQNewMxOkF+DcvuIbCzq7IV 9aGFC1B67JTzX/iE+eofTsl6oHv/+dutlGBWc7oTPKoII1Vuqo38FjqpGipIQpEylYbA bGKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HQN+QVb7; 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 ly1si5964333ejb.146.2019.05.14.12.23.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:23:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HQN+QVb7; 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]:52990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd1j-0007oi-H7 for patch@linaro.org; Tue, 14 May 2019 15:23:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvD-0002Tp-Ha for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvC-0006nN-H2 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:07 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:38184) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvC-0006mI-Av for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:06 -0400 Received: by mail-pf1-x443.google.com with SMTP id b76so5252pfb.5 for ; Tue, 14 May 2019 12:17:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=HQN+QVb73V3XfZ4T2T+jb1TZWUUTrJtTo3AsjOiBVKA23D71o/rGF4bDpSh9FGB1+X HpEKtIoyEqAcW2rLhJ744tUEAI/6dQGNyUHOSIS8UEUMrXapw4HfdBYld8ohrXI5+NDX uOzLLswjmuGbciMRtFebR9PQRhG+cTPjyGCNjgmJFi+7DudOlSCO+UEIIGsLO0/aT3rZ mwxLXZl7ipPbmh0xy+iwgCRvkwrjLqLgQ193cIbJsE5If8+vV18G1M8zIQzVtkwG5NTH zBj08pw+qPAmE3Z/Z1yKforLWnlTmtvQXkN8tFhEFr6cNC2/AWEVk+eTBoytadFeB8BZ OU5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zQEKMjfpCTDyJlIECnLYp610ugeuDB8/XWCLVFEbpkI=; b=sWft/Gn+FmuvpMxEMzzzqhw3TVuAybXwXBMqPr7wwJ1ac5qIHmQcPKblvX25rBR2pN jmYy0G9vu9MWMtpYIh+mhOuyvfIiAotjs/JbyWSNkXbEkUnz80JCgVL0mGIT0koEU6X9 L3BkZwu+2H2JDKMAwuFv1kuUBme+g42hHFMX+l7f8jMAU/DpGUZjCJXfZQlVshPTEl87 WFF5PvTc8WwJ7RARoj3HDxkTdfA75MHYbum0AqSAoe6XxbUFY9NKKxdg3j9kre/WRhj4 GOnBiyU64zzfQ6P+2oUvknFQ7yMDL/clyBlunrl9EAKq4QlNTJGySg+jY3GbsAEkRYXk ym6g== X-Gm-Message-State: APjAAAVMN8E//5OAbseF7ifSKIipq40/XqCYCLzlRdSdLClupZX9l4S9 9ewM4CRWcwf93AhVU1Spn4QReVuUJzc= X-Received: by 2002:a63:fa16:: with SMTP id y22mr17448pgh.15.1557861425083; Tue, 14 May 2019 12:17:05 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.17.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:36 -0700 Message-Id: <20190514191653.31488-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 07/24] ui/vnc: Split out authentication_failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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 Tue May 14 19:16: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: 164231 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3003250ili; Tue, 14 May 2019 12:20:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqz532E32EndTaU6fvGqaWs58cqG5iDSwTICmSrLPXbRJkgFhlsdla+v7S5SG6ZAqsx5AbdD X-Received: by 2002:a50:86c9:: with SMTP id 9mr37898228edu.216.1557861635801; Tue, 14 May 2019 12:20:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861635; cv=none; d=google.com; s=arc-20160816; b=wrJ7v6z1qiJjaV6GrGYmmk/npmzsjmcXBi2sIE3xnshmJfsBeytc3RSWVUiGBZTk3s P7HFCI/9Mzb7APEK2R9ZeZEzgv2mMZFAITFJINy9gMGIiJzgO+2cANpq5Ygx9TahRt0k MxaPddn/jKgl9PdktYOjJweUrafBS/iDGDM05cZFGnydqfx5tbOT1Q9D29g5bbCZ69O7 NOK0rSmzlxpsZ4h6TJeQnOK6+Qn9O4wDQWPDB5JCPXlcIJ1UhTXQ7fya6ATjQ7UWFyqq uWkDNar4ya99ED1RSbuhF8YECKKFg3nqSHKPjuqcbq4JdVa0Vm55HedZmQ+3PZrFTcCv pfdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=DHS+azgDjOz9872pwx2wjM+spw3T8bEncaHuHvbQJSc=; b=p11Np1nho9DaPOJQjV225e9BIfF9eu8Z8JO55oOZy0zbxdK/2xHmRKEXEc4arZ2dWk oW5v2sV+Kk+FwcN0uGwCh0jwV1u/yPxVZpFLbh+/r+mMhZjioUptjD66Ul+i1AkzdEts HgPUzLnkQXx5/rIehXhgUPDDSyFHZKmqrDAlAO6ME0ICN7Qzp29NvCZd1FacS2A1M/iP 9Pxo+0CiDI1AIXuj1h9xvplf0Xa1SoZSm+TwBGZsWxCp2vmc9hSjYxDN0TPm1KIhgSud HflSl3eWtDef/JerqrTsElgHnUgnkFiCAGOeod6LOBmx9XVBweA1f80wESCEPMKPJ6ee jdyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Vw6Ht19C; 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 bp18si9801281ejb.23.2019.05.14.12.20.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:20:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Vw6Ht19C; 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]:52966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcyY-0004vm-OG for patch@linaro.org; Tue, 14 May 2019 15:20:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvE-0002Tq-L9 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvD-0006oQ-M5 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:08 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:45593) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvD-0006nl-Gn for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:07 -0400 Received: by mail-pf1-x441.google.com with SMTP id s11so9612709pfm.12 for ; Tue, 14 May 2019 12:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DHS+azgDjOz9872pwx2wjM+spw3T8bEncaHuHvbQJSc=; b=Vw6Ht19Cc2d0O99O4y9E/m6n5DH1o3Gac4gmuvKoHF6mzIIIqJX0fcbmXRNwQSku5V nw3E/OYtCeUDzGZQGlauJfh3ObBRa5XThIIkw7XVaCifv6N6CLNJKu6Mp+h2goGyNinl lZMEeFM8jSPfw8c8iIyG3lXULeRpIi87TMKS2oGeJfjjPslGhwlRygEM14LuD1kY9PN7 9jp0fdmo0SX7RFvapzFktNuGurDrTowL15YtjQYGg2i8R/LVPycYvHlw9AC0guZf1co/ COc6R+1D8W6c9ksEa/i2VOsoUqO1VmFalq2O4PBP4oHdqEpGlpT2IYsbRh/O3KK7H/nS 1lWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DHS+azgDjOz9872pwx2wjM+spw3T8bEncaHuHvbQJSc=; b=uHcjQidl/Hh4sHhbFiYqnjeCGjtf6NVnQAKbDerakY4ULqDPS8QGqpc/fX60ORlo6S yL7IVU6UjL6te7PVIjiDPEI1NoNoSRrExRf6eyy+cb0n1V//djbNXeu+6qyWlUXHwnzG eMyC/+HMsuXp64Df7KODnJzkHL3I3j9kkTYLleTa4zBgetgS+jteoJPyJd1iksqe9Xes ZZJ4xiRGl8qZKy6PQ//K9z3noK9PpO1ElRMOHn4KeTeX58zSGUqnwHMd/7wpGfCacclO Mew8cG4Ta4vrIRJQDYjBzXYGo+GDsJeZBuFxAGj8l7fXMMkvxZMueUJig7004YLnrfZ5 r+aw== X-Gm-Message-State: APjAAAWh/UZ7tRdAdv4uQfGoabGfnDamCqvZpmYW0aWqxljZAn+6PC6v zS/uf8VdiInbYPfvgY/5bxAvi+5o8q8= X-Received: by 2002:a63:690:: with SMTP id 138mr39216636pgg.415.1557861426286; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:37 -0700 Message-Id: <20190514191653.31488-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 08/24] ui/vnc: Use gcrypto_random_bytes for start_auth_vnc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand(). Fail gracefully if for some reason we cannot use the crypto system. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- ui/vnc.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/ui/vnc.c b/ui/vnc.c index 785edf3af1..d83f4a6ff9 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -43,6 +43,7 @@ #include "crypto/hash.h" #include "crypto/tlscredsanon.h" #include "crypto/tlscredsx509.h" +#include "crypto/random.h" #include "qom/object_interfaces.h" #include "qemu/cutils.h" #include "io/dns-resolver.h" @@ -2547,16 +2548,6 @@ static void authentication_failed(VncState *vs) vnc_client_error(vs); } -static void make_challenge(VncState *vs) -{ - int i; - - srand(time(NULL)+getpid()+getpid()*987654+rand()); - - for (i = 0 ; i < sizeof(vs->challenge) ; i++) - vs->challenge[i] = (int) (256.0*rand()/(RAND_MAX+1.0)); -} - static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) { unsigned char response[VNC_AUTH_CHALLENGE_SIZE]; @@ -2628,7 +2619,16 @@ reject: void start_auth_vnc(VncState *vs) { - make_challenge(vs); + Error *err = NULL; + + if (qcrypto_random_bytes(vs->challenge, sizeof(vs->challenge), &err)) { + trace_vnc_auth_fail(vs, vs->auth, "cannot get random bytes", + error_get_pretty(err)); + error_free(err); + authentication_failed(vs); + return; + } + /* Send client a 'random' challenge */ vnc_write(vs, vs->challenge, sizeof(vs->challenge)); vnc_flush(vs); From patchwork Tue May 14 19:16: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: 164243 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3010474ili; Tue, 14 May 2019 12:29:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzID7VdhkkqjXja0OOQr2XUyPYs7jzVHNu/uZ39isZYQcYtz909petF3HLKWjxaN7xZ2RKG X-Received: by 2002:a50:86e5:: with SMTP id 34mr39004732edu.290.1557862161447; Tue, 14 May 2019 12:29:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862161; cv=none; d=google.com; s=arc-20160816; b=vib/NFKzBzBDkgLPwE6eOBCMJDoY7Bqz3sQJ4dpJSJGMcJuf9dpDduRwizkak7BxkA l4yE+AwFYg6QjgQl1dGPJC/5H3+9Wx5Nnd20rko8FxHI5lO9avDE2qwkyq2nyH+16lSA d6A9Vjp4NPm31e3wrnsWplw98RNzLf+HVK/3qIpw3ZcI1mbFujpYZtPbpouPb2TmWBbO kt4reGwkm+hFPqw1+f4Q5ZXeSRQdOXErffVxkVReF8M6bqcyPL01ow4cQvkwwIEZkuc6 5ilBWZsWmj5Fk0Gc72hnhQAQhjUM8iAw8xVldT4Fe6lWqDSFYEeHkI0y4uHLb//ArI7h +TyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=L9JwWL5aBwa53hX+vgKc9weThKisnmouzJrZWILL5KY35Oj19unKR2tq1uSRb86Oiz 1dvbg0kqChadi42K+0Yw9uZK41HdRYOcaFIZPAJ4hn5M3R8ZqIJU9NlX/wn1PIJ4Gl6V o646KmnfthzECS+TGh6iY4+FNpo/ZU79hynOfvP8SHd6nbL+ZyWGVUWoFZHXuDvKCbne Cslk9UgK8aZ/PeqsBjqlKEyRp91ttcQ9mhX/4AJF5dvkwgIOKrgfpmAONOyNqJ3JjQMn 3Tt0FRodtGP+bbNChhVWbkhc7JLmhB5VFwR602PqQh7HlVNCUQbu2DEIbUNrHKNfZaPv kbRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Lhi3bjFT; 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 b26si11422792edw.334.2019.05.14.12.29.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:29: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=Lhi3bjFT; 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]:53078 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd72-0004nN-8F for patch@linaro.org; Tue, 14 May 2019 15:29:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvG-0002Tw-Ok for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvF-0006qM-Cs for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:10 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:42945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvF-0006po-5i for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:09 -0400 Received: by mail-pf1-x444.google.com with SMTP id 13so9631937pfw.9 for ; Tue, 14 May 2019 12:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=Lhi3bjFT32r1L9f70/VFnAglrOjySbukTfUoGsiyENHbf3yn66vSSH2rV146cwakqO R+XTfSQq8xShD9Qx6uH4BxPxbO+U22srS+UVqKLQF7+rxRCW2rLrUKiFpAUh6/Xd6moe +A/FCgjFR8VhDPdqJvHeerGvArXb3yVbplvbVYJIpvNLL8sVs9Mi63oU9/GVTArSj4d0 ITxYfSvrYleB2LdEIiwqEnQ0VnQNLmleQqCNCCSQZPGK0nSH3ZPZyeX++jEveL0Tgqmn N4BWkgokfCeA3gJySg+p9amVjNJQe1At1VpNJXa2jxxRLNAeBN+Vmqnx6y2ZRSDfgDDy q1CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4MrsM8HWkl5HnptGJNmid/oZc3Q7MB8Exr59LxaGIMY=; b=hKC/+RF8oMBvhaTApUXunEvVc5W24ncYOIRzJwz6qBBCL95xa1A1KpJq83aVRTYRy5 hG/EKfIGsyI+AuTswk8sL7AJhhbVZz9oPQ4+sUYAJjaPg5MgXciWkgs23y31EE+jQrXE DfQ2TZ2jitaZ2AdP+1EEaHHXZ4/0Tfz9oPXKX7cLXvF/6U8DxWvisloBQ1X9grKv2AlO 1Ewrzq9rtMLM1TFKs0T+ZC6Uz3Q99g6vSDa2AGJOr/1eFxHoYIIpu4HBUfEsrNU41/HP BhIGpzNdv1wG5y4siA30lVb125FIO+t/22sURjJ9t5+zecClGgTdH6pfL9dJGQHjBZtm 54Bw== X-Gm-Message-State: APjAAAXPu+X+U0lp7sBXI9SzTW/DZwDlYvr00Ka7BEn2VfwwqxPtMAqb XHzZj98Fb3KNyGxSSbpfl+D8Sj94qQ4= X-Received: by 2002:a62:7a8f:: with SMTP id v137mr42687906pfc.243.1557861427693; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:38 -0700 Message-Id: <20190514191653.31488-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 09/24] util: Add qemu_guest_getrandom and associated routines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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 Tue May 14 19:16: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: 164241 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3008312ili; Tue, 14 May 2019 12:26:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyn2gafTRbPh/X5VrW/Gk7Vsyv+LIQs1sTBpUyGvy9HC1XUK0G2CHi6nZrKnJWCiwyPZ5L X-Received: by 2002:aa7:d1d1:: with SMTP id g17mr38961021edp.19.1557861997553; Tue, 14 May 2019 12:26:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861997; cv=none; d=google.com; s=arc-20160816; b=Oul5VNwrr5Km30WVYVxmmQhkm39aqghgTbcSlTZUJVUShFrzroVMXX1UuJHf13WIh8 kGM8ebjYBkjZEGReMLmxF3eNSgM7uAwSYT1VHAlEDFwHdPM+hGy8raAJdK2vC5+19jPk 7EI/vjj3AykbApwMOzPr62Pfvxvgp5JUzooChlbpWN5GJkbGbKbOdk+Z7sZkisySo0jc MwvOE8RqdMEatTMga2gcUclfMxMsQMPjG1dxemk9aCqHML6CKgyZkTButAlOJz0eokMU QD6WWpNl6bBdVrQ3kis9CtJNHtBL0gHwtnQwwDUWbbzHfWjm1/pWZwI3EHVGhtcJgAa0 /y2g== 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=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=s8yc16r4G7/iWgSicXmbxDAKsDLLma4QKEmy8Zz6iucVrxH7qNExNthvhMULk1GMsp NiCM+BEgOtIRwCM2rBxalrkT0Tx4ezTri8hSpdrOuPre4sr2VlmMVkeBgiSXOi2MvUzG Ii6nuDyM2KxoWNTN0aQylzlW3YAYDmDITxoe+xb5asks359Xr2zBsGm+M0pL+suF5ZNX v/OtAtUhYZ/Rp49UvnpMViaPm1tceghwXE93XLl5a+zIeKoYtpD+TL0zwgHPlS1l7TVM JJkyrRkNWOdn/jZ8+3wMKGd7VGTUpPuF5/+CgfZjo72x2Ca5zo5gGd+hHOBjkWdMCkN1 nIJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jEtx2Jdf; 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 f47si13041722edd.144.2019.05.14.12.26.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:26: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=jEtx2Jdf; 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]:53046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd4O-00028e-B8 for patch@linaro.org; Tue, 14 May 2019 15:26:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvH-0002Uj-FS for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvG-0006r4-BV for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:11 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:42779) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvG-0006qd-53 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:10 -0400 Received: by mail-pg1-x544.google.com with SMTP id 145so38402pgg.9 for ; Tue, 14 May 2019 12:17:10 -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=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=jEtx2JdfSEnx9wg7IUoABEvgcTiDkClNISLTjxkFd1xs3ygY/erYGhuPNuKzbok7wY 9zg1++DiysYh58F6krddQ06B7PN/nODTb0wihz5dV5XmVMzW5yePW70gCx7sySeES1AJ e0PEmUzBuai1f62E6AtPzQSVx5TFy4C5iRATdKryKLJkuI2W7Vwq55Pd0O79qxxAl1CA wDWbrMGI3IjAfhJ6Nm6f3YGU5vLsOimPN7kvGn881rk7x+fGwcR42lqtK7LH2eTBE4Cj MTMSjMOtOZQpRClbC4MHR5zcESZpfKuA55f1avXEFCKf4y4mfs83rdpTg8AAkgUokhSw KX0A== 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=CCvph4F0+gsWZSKZYyRUd00rEVqCU0cysWzx7Ki8dAo=; b=n59hbWQNVm/VOsLTyvZFr6u1bNQyuI6YB3/OKag09BvtuNiVsQpyv2X5VfUcN2aBji mzG5NoIZ2CBafDjsyzmLc8I1OhS//RrGze2OKfWYHEwfIzUnxsSdvfI13epGxA97QIkX XXF6LLUEuU6/pgCD6/lEXRufQfu7YkibZe4J8duGBkBNPAiLp168ZyXyjTv3n3g3dqCA jtwZpl9HBrOQilb2xP+bEZvVeUQrIklmp7CyuODDXgXjXAZ3dvO/QFAhCa071CFRuQyZ +W982rMi6VLzrQHoCQTGJqIhoFswDDIxLiVCzvdHqejIMgZPJNDsq9lO3EIHmcVnYbrz gw/g== X-Gm-Message-State: APjAAAWcGQJ7xDTzzt4aIA9l6V/11FFP9bqwnBUStpKfbeF+F0y2KCVd aL2nC+jYY+I0N9lVw2Kxy2B7I8ARioQ= X-Received: by 2002:a63:5cb:: with SMTP id 194mr40132251pgf.294.1557861428923; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:39 -0700 Message-Id: <20190514191653.31488-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 10/24] cpus: Initialize pseudo-random seeds for all guest cpus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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 Tue May 14 19:16: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: 164235 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3005818ili; Tue, 14 May 2019 12:23:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSpqXIL/X5BVTBM2VWg9r/JnS/eo2Kv8S0SJimox2vPfBaf4AqbkjojoDLRM6q4AHpvPEM X-Received: by 2002:a17:906:7709:: with SMTP id q9mr29580667ejm.288.1557861807472; Tue, 14 May 2019 12:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861807; cv=none; d=google.com; s=arc-20160816; b=OXLIqTgfL5vEB9OUWwy2KkW/oIeqVP6QOERfU3jkBZQRxmW5MhB3vui9nVFRsH/iPr +5wr6iQdvViITrJRX8PT2cbGaCK862yCtrWqeBnWSW8kHeaYi0WCLQwVRzl5QjxlH4OU MPZMQ0jTtwy5uYVyX+lII0KzvEeAKPMtDSkzW1GM5ZXkFq4q+f7dFSmtSKr8HM6NESzm 1nj1uEn0TiLz9Vc4jej6klCOX8D8gCf7nhX9cwdAL2KAQWllazFwA79BZ2JF4KwBaHiX OsVJMLsVuj/kLqAVKd85eqMzdYJlgz7fdH56iSFx0aTSH7zI+pdsxcU2mS1WXP8elt0h hE6Q== 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=xy1OktLeK7/mJWPw/JMSGUFtW6+kUG05ru+wLl6Tmjo=; b=Ho7zvZrhd4OFln9CQ4QheBxynBgZqnFAHOSh9ZZPq0Ig0cmpi0YANDQM0uehGskUEH Ns0IqB4f7jYCAYSoYi4JfynP4bQlpsDSzSW9hQcZLlRrobN6vi1QJauJinDd7GK11NcT Nsiv1yz3q/89EZ7RX3IY8Mt/PRtUXKnKqFNawdCJ7k0X961ly1ScAIUMgOUW2eTShKJr U0vRdwGqEIVle3qQ69iss9QDoJqNLv/esmcVsRhrf9pUP6xzXfiJF9sjPiFv0puX7NvP Slm115YSGA9sLKLq4TI+7nORuLYAqmys11C8XI3w27aUQKFq06AEDNxNVCbdo/9Ge9SU eCDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=llixhV8s; 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 cw9si6240372ejb.381.2019.05.14.12.23.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:23: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=llixhV8s; 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]:52988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd1K-0007lo-8s for patch@linaro.org; Tue, 14 May 2019 15:23:26 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvI-0002W8-TC for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvH-0006sg-Pm for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:12 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:38184) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvH-0006rT-JI for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:11 -0400 Received: by mail-pf1-x442.google.com with SMTP id b76so5329pfb.5 for ; Tue, 14 May 2019 12:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xy1OktLeK7/mJWPw/JMSGUFtW6+kUG05ru+wLl6Tmjo=; b=llixhV8s2IXNRYJyRFtKp14FjEtBz7C44GLPCmGS70qLY5BIDc0Pgwhek+5l0GJD2b GZD4F76T6qPe3RKOFELuf5+aWqIaZzgfke9bXCHJxNcr8bmZu2FqzSg6h2es1eDtBGxz PNV0JNX+o8nhp7y5y3vPiglzXelbBQSxJCY9847n2iykzuD8RK/LRDjvZ2P57wU7wzrV xQ/A4lvbGszCGWwMi8kganW0l0VDm7ARww5rr9l4quubcar4IsF35ZpEHk16zKOCjOFw MUPuKxZy5HsbMSVgaAtQBvoWDAjH8jKH5BPswX4Ge6d1r2wOnrT+OuIrA4pmNE2PCeD8 EsNQ== 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=xy1OktLeK7/mJWPw/JMSGUFtW6+kUG05ru+wLl6Tmjo=; b=mkyRK7kb3nCBUf/IyAFI4LasQWR7FME23wcsoywcq7qG/puMtOLjwnCdwUMtD/dUaD O4j7tUoW22nVXTwBBmodaAO8wocVO9EgCpJkQiIjljk2Hb0Lo/CwpuLux8iDfwuRZKTi RmajtfBpArnG8H3J7t4JhbF3IGgUEYsvWBJlzysbnPxkYfIyvoLgTWeedTa9FQqlVIn9 3IJrTaRzgiSCKuC3RBugovVWNYUj2v5tnIvb7PKqCUfQJCx6yebfiEi5IkjO6PLPY6xo gjmNc2zBSeMQ1CA1cDKpwzrV4YJ4AuY/UsjoaWnauPHMCTEyuJjfqe/I5FUwiWFsnzb7 e6Tg== X-Gm-Message-State: APjAAAV6tiaRzbiY9ug3ser9GgYZs+EYdH7WVnEZuqhYgDd2m6K/CZ7X 85kPi82QkibohI85P5UIVuyJb5qvTrc= X-Received: by 2002:a62:1b85:: with SMTP id b127mr14346929pfb.165.1557861430208; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:40 -0700 Message-Id: <20190514191653.31488-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 11/24] linux-user: Initialize pseudo-random seeds for all guest cpus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" When the -seed option is given, call qemu_guest_random_seed_main, putting the subsystem into deterministic mode. Pass derived seeds to each cpu created during clone; which is a no-op unless the subsystem is in deterministic mode. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 30 +++++++++++++++++++----------- linux-user/syscall.c | 3 +++ 2 files changed, 22 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index 3d2230320b..7e704845c0 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -34,6 +34,7 @@ #include "tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h" +#include "qemu/guest-random.h" #include "elf.h" #include "trace/control.h" #include "target_elf.h" @@ -48,6 +49,7 @@ static int gdbstub_port; static envlist_t *envlist; static const char *cpu_model; static const char *cpu_type; +static const char *seed_optarg; unsigned long mmap_min_addr; unsigned long guest_base; int have_guest_base; @@ -290,15 +292,9 @@ static void handle_arg_pagesize(const char *arg) } } -static void handle_arg_randseed(const char *arg) +static void handle_arg_seed(const char *arg) { - unsigned long long seed; - - if (parse_uint_full(arg, &seed, 0) != 0 || seed > UINT_MAX) { - fprintf(stderr, "Invalid seed number: %s\n", arg); - exit(EXIT_FAILURE); - } - srand(seed); + seed_optarg = arg; } static void handle_arg_gdb(const char *arg) @@ -433,7 +429,7 @@ static const struct qemu_argument arg_table[] = { "", "run in singlestep mode"}, {"strace", "QEMU_STRACE", false, handle_arg_strace, "", "log system calls"}, - {"seed", "QEMU_RAND_SEED", true, handle_arg_randseed, + {"seed", "QEMU_RAND_SEED", true, handle_arg_seed, "", "Seed for pseudo-random number generator"}, {"trace", "QEMU_TRACE", true, handle_arg_trace, "", "[[enable=]][,events=][,file=]"}, @@ -689,8 +685,20 @@ int main(int argc, char **argv, char **envp) do_strace = 1; } - if (getenv("QEMU_RAND_SEED")) { - handle_arg_randseed(getenv("QEMU_RAND_SEED")); + if (seed_optarg == NULL) { + seed_optarg = getenv("QEMU_RAND_SEED"); + } + if (seed_optarg != NULL) { + unsigned long long seed; + + /* This will go away with the last user of rand(). */ + if (parse_uint_full(seed_optarg, &seed, 0) != 0) { + fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); + exit(EXIT_FAILURE); + } + srand(seed); + + qemu_guest_random_seed_main(seed_optarg, &error_fatal); } target_environ = envlist_to_environ(envlist, NULL); diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 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 Tue May 14 19:16: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: 164239 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3007989ili; Tue, 14 May 2019 12:26:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEm+J9o/z76DHMXmC1AZ9ghNkYaiUAlGK3pXJprhAcoIAhhhmo2znoK+SypSi0kGJxrb3Y X-Received: by 2002:a50:e707:: with SMTP id a7mr32637295edn.68.1557861972855; Tue, 14 May 2019 12:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861972; cv=none; d=google.com; s=arc-20160816; b=vejrRufTW7ROOu3RSCfCyiQbobi9/SEfCG3U+qTS+r6zUBPBaoC5eM7yq3slYP0UcT FPztjkzGGjsfBDc9aqN9KlkzE/+SmU2MhjPsDFlGRMUl6nizgs7UaVzDhr7h6LBtpol/ y1CnDq80uFm5ff3boxEmDfTe4gaEXLzCE8bm3j7YC02NzfW3dh6NR+86R9SixPXm8rcK pWwLO0nVGvuxG/GRrj+JEPwN87y5TajNbu9vVDhf+W5aoxaPmPO1BCWcIQwFd/ZDdvAY +Bp8XuYTtbhDmK5nrIzKWzCh89aOMNjOLQI3Zks2qt33NC6hmfqbdW9jqQIAi+nwcqjJ /zNA== 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=bfHw/AF++9CIdfuqFxIkDwoY841o6ilZtdRCC2o4SUw=; b=J0R2KOu/EhNav8Kl4oqLPzxmWDKae62S3Th/y438jhrz+idIO2dRakWesOu0JuhU+Y fkOCtVfDtEflBvr+S0rNeKhSEQangm9tL+XIv2n1vBhNTj+Ai2TT5IUNRSgFyEhbKngm /XJ4qlws9FXtfjXL+1coXOnf1OzGgMy3hcv1CuqLstTz3scqTGDovWdEEe0TrMQu+WDL 2sxf/281gKWx2MOdyebFb9I3aQIkLjxykT+6uyh9CydQMoqiwEUun42MPfYPn2YsZBaG ZyQeRtjGqMBjKoL0RUuhLr0iylRxZw+M+mtEvSxF7z6QP41VQqfarNPovHbGQkhZBwA1 rPCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IlFGJF3S; 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 h8si7240453eda.177.2019.05.14.12.26.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:26:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IlFGJF3S; 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]:53042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd3z-000260-Lw for patch@linaro.org; Tue, 14 May 2019 15:26:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvJ-0002Wz-Lw for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvI-0006tu-Oz for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:13 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:46218) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvI-0006t6-JG for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:12 -0400 Received: by mail-pl1-x643.google.com with SMTP id r18so59356pls.13 for ; Tue, 14 May 2019 12:17:12 -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=bfHw/AF++9CIdfuqFxIkDwoY841o6ilZtdRCC2o4SUw=; b=IlFGJF3SuvPZpd2kbuEV+UtXwl1IWbTNWyUv62+k/g3kkbM8ML1HEH2MD+7xuqElPH oNsASmfjTCPtVn+MXD1Iy+HDwUmhX5L2KY45qXgpgIob+HXKTyU9vIpao1LUWWrPwBTQ M6TFz63lEed/f5qop86lfiU+7H9azglnYhguYOknSS7LuOSWKUZnEK61dkRhCK/ZY/XF AB11SKS8UhSA4HMAl9bZyTb3hS/P2AJBEWW4cdOSaMMvj6bneq/NyThIVoDnPipUv7rq xwUrfsMoFEBaFFourdIXkw6vdGFk8/NNQmIgqtsDEX9s4RXKJoHkrEDGiZjz/eWCZRGB 4tTw== 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=bfHw/AF++9CIdfuqFxIkDwoY841o6ilZtdRCC2o4SUw=; b=VYmOCn+dvu4AqYEbvEwf1+FSWcRM+0uVoc1qjJOmGQVMCXmPNBiA7bD6ze1HjGE8bi IbtL/jjxCME2qnE27J+QZ2apk7zxLQCLxCWbXYr2CxFCTo9kRuMchjWVdBdbOTh1cEqz dpl4TODq0QjdS6/MFsa6G7ysDpKuB218pzI/noqJdb4nkxendP0KKlTBNMyBso1mm/gE iUoKoeDTfMvViFym4WYpBSWYqkuvi5faVDEkiCqUJPMRDDs/Qncs6Q9E2ESwvUfWGoDQ 1FEakH434qeiitdO5xGS8Y1FiCqaFbn5ivUukCgA0c+iWERVxSjDc3dulWPi6nvWsSRI XguQ== X-Gm-Message-State: APjAAAU5zCyA0oIgYAOHdl1XNNPa/pII5g+dzwB1+4rgIL1v86XmHWup /APU2UcFCgn/YY3aIB6UacAJX4pKnWg= X-Received: by 2002:a17:902:1ea:: with SMTP id b97mr13615843plb.317.1557861431367; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:41 -0700 Message-Id: <20190514191653.31488-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 12/24] linux-user: Call qcrypto_random_init if not using -seed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" When not using -seed, we will use the random part of the crypto subsystem. For softmmu, we initialize the full qcrypto_init, because we use crypto for reasons other than random numbers. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/main.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index 7e704845c0..4c72f07555 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/random.h" char *exec_path; @@ -688,17 +689,26 @@ int main(int argc, char **argv, char **envp) if (seed_optarg == NULL) { seed_optarg = getenv("QEMU_RAND_SEED"); } - if (seed_optarg != NULL) { - unsigned long long seed; + { + Error *err = NULL; + if (seed_optarg != NULL) { + unsigned long long seed; - /* This will go away with the last user of rand(). */ - if (parse_uint_full(seed_optarg, &seed, 0) != 0) { - fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); - exit(EXIT_FAILURE); + /* This will go away with the last user of rand(). */ + if (parse_uint_full(seed_optarg, &seed, 0) != 0) { + fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); + exit(EXIT_FAILURE); + } + srand(seed); + + qemu_guest_random_seed_main(seed_optarg, &err); + } else { + qcrypto_random_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 Tue May 14 19:16:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164245 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3010863ili; Tue, 14 May 2019 12:29:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyggiMvHQ6Nm1eNeBG2TYqhZJWzEloPgTigWdQNq5zSzMyRYGnE8FZfRWg/Bvj+YqEyDzmF X-Received: by 2002:a17:906:164e:: with SMTP id n14mr29883083ejd.72.1557862191611; Tue, 14 May 2019 12:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862191; cv=none; d=google.com; s=arc-20160816; b=hk9JhGeh0y8Ke8kThr4nJzAqAkJiXsR8m51LuSCslisdOCSuykFP3U/UWlZZziAM2S TFdUtkdzNs4Org3TmFHe9F2Yg7V5IyK6qsnsY92ScHxBwutEdF4VdCRwCyIMxo7YKc7S 2REkI9vD5A066JvSRGIiaaQ5bA8x5R6SEgv3FUmyufO5IMVgdzSGFmVkq2ID9msGgFpx r4beJ6T2TdezE4O2nmEyY9Q4LC+2vK2agv6EtbYfYagi3vUdhkienrg1/izc8G6w4XKc DDDGl3wa4HFMs0fP7dnrys5IShEMaCxS/vIQXrTLIw9uR9OXtcy3lMdrp444ACQzDGq2 RJDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=LA1zmsYxmzBAEiSSaTbYsFeqnklh9uk6Ygv0EHqOLtQ=; b=SlrIxocf04jCIjkI53x0BlQja1oz8f4Lt2q/D23spATGZAUknyLkY+9bkjdseIaKBK OJFFzJr5IQJEF1/GfvFxkgjIOUzX0AtVqxWSVa/2C6XcsYytw4WGgULJwuXnOmscoKg+ 2ysK6EVqXzeScvHUyQa3Bk+B51pi4Pa9m1hl35M+sG2mcWtea6OzmSy6EuIbBAip5C85 AJKHwMOWfZ39Bik89SMv94Ck+okTi3i4JhJUsk/TeFpoz+MKzPv2UgKBwe4zzW+8PFMB 5dbYfidi7SZgbZf2ZaERUSaFu+ngrfVn9RIXpwnA1WAQpjqcsma+gCcP/Cs9jpqlczol +hFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qXAl+exE; 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 se27si5992705ejb.2.2019.05.14.12.29.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:29:51 -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=qXAl+exE; 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]:53087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd7W-0005DZ-Fc for patch@linaro.org; Tue, 14 May 2019 15:29:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48878) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvL-0002Yo-1y for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvJ-0006vB-UF for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:15 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:40108) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvJ-0006ua-Ol for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:13 -0400 Received: by mail-pf1-x443.google.com with SMTP id u17so444pfn.7 for ; Tue, 14 May 2019 12:17: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=LA1zmsYxmzBAEiSSaTbYsFeqnklh9uk6Ygv0EHqOLtQ=; b=qXAl+exEkgjEqmClYfwO7vrFkayBfeQkBVu+IovbupV24zdHx8PFEg1hT2Eq5cGx2M sUcF4i1VsdHpd2MzpdaspluHu7CUuetHJXEiMafVf+Vr0qMcBT6aogQNhLqgpHSnKZab VG0F3d08mvQD+GhvQDyZ6rlMt9KQLCYrc+eDTGecT5badY3bA7ys0ksH+dxn/BOdTt0f nbb9yWAfSTIzcWJCwZC5o6MTkt4dbYCj2C/iFZqXp9JJugPvq9bgeeYoJxTKokDscs9O Q7YoSEn7UXpbVpaTpT9DY0WcUXrdUTAddAtNQkVRaVtcoVT3UWngoWeNb4FR+JCR//i3 QpcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LA1zmsYxmzBAEiSSaTbYsFeqnklh9uk6Ygv0EHqOLtQ=; b=fw3UgFgw7W41UIa+c31Ms73RmZJN9j36pKcao10SgI2az9jxJhSA72XD847aM3ba6R ZT7a2MlrEzpuk9s7MTfBXZmLTPGMCwao2Rg8aOY/AO0XNzMmofhc4J96CglIY2H/G/wg qkNsp746aK7iYdqcE2cGUB6yGLyyqhjPg7pwOAdkY7r8yVovytv5y0QrrxaROKEd+q8K kuTSA2uVrPiiifSomVt6wUORGDWRHUpN3PAY4FlyCfKokeD2OqEoOFzp7g4LmbwSMntJ mcKWIsLsnQkeXSvBaNFhfWD8o/bR9qETGv4vfcOSEQ2xeQ9QHomQzF0aHdts4aopajSS KenQ== X-Gm-Message-State: APjAAAUCx4hqNBfKYO+Ge+zJeBo5JABHJVhyKQ+uAc1rghQwS1BQPdo+ VyCleKXCn5CwP6F2f8BBotEiyhKH3uo= X-Received: by 2002:a62:3605:: with SMTP id d5mr21638851pfa.28.1557861432600; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:42 -0700 Message-Id: <20190514191653.31488-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 13/24] linux-user: Use qemu_guest_getrandom_nofail for AT_RANDOM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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 Tue May 14 19:16: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: 164242 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3010413ili; Tue, 14 May 2019 12:29:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjp2loDehF0fvLBoYQeJeY3r2iBGlNftr+E2dL54WFVWYIkN9JE0KNV0Ve7w/+yGIYNQNK X-Received: by 2002:a50:9025:: with SMTP id b34mr38608387eda.145.1557862155477; Tue, 14 May 2019 12:29:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862155; cv=none; d=google.com; s=arc-20160816; b=lWxPc4QshCBf0kd4PfMFXHOvA3vqfYYiBsE3wWAWyQIjWyPDyvpZq0HvG0uDK2Im2g cawUGk+45U/SYXV/qrisDEydw8s0jrSkueK9ic81nXEJQSQTuGSi1AdBbOPUP0fRcN8b fWzWLU6Cj938/KkBR6D72+LQLrfuXxbqnIwWCPmpY0YTglOJ3SAMnZUloVYsEIxbGV5n GP5nGEfDJiCDHkQmPXTjDaRiMk48tJL1h1+EMp61ngm569Jwrkiq3rR19vGcDt9+Akdl eSwRLh3ZR7vMeilBOlPgS1W3Ghe8WXMhXgmUoPfn2ad6gJ8Gf6eh59J7ZhibiGF2dFC5 9QSg== 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=yE70JIuqrA6MJdI0/JWiVeD/16stq6LybzVtzKfjj1Q=; b=Wb1V42MgrxOwNVnT7mRjhbYZlSH8tho2DQF9CzGPGpU74KX2DYOxMzvA3B7JDYTytE iuh+Jg8XLLpt8EufHI9BQslz8sgfl/IBoTIIRAusMIfnergMit2IZuCS9JOFgQQLx3FC 7G89iAyr/Uiu9Ur2KFoWFgv/MZpnO8wBVWJ/rnUN5mCkZk14GCYQoOGtKlasnMMMtFlS sQc/8RXHUjymWqIpE/3u+LF5s1RLLXaJR//Oxi4Tm/Ib1kQifiseqIxEJtoyEZ7V45BZ Mm42VGMqqMUlBPdYH7Bss8mx1yAvKy5Mczlv03zT6rt62woshztIJeYa/acHumRF0LfG CoCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HAhj2AFc; 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 i41si2949815ede.444.2019.05.14.12.29.15 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:29:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HAhj2AFc; 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]:53072 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd6w-0004O2-8U for patch@linaro.org; Tue, 14 May 2019 15:29:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvM-0002aW-MR for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvL-0006wn-Iu for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:16 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:46460) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvL-0006w7-Cn for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:15 -0400 Received: by mail-pf1-x430.google.com with SMTP id y11so9608580pfm.13 for ; Tue, 14 May 2019 12:17: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=yE70JIuqrA6MJdI0/JWiVeD/16stq6LybzVtzKfjj1Q=; b=HAhj2AFcpUh4CzjBMsth/rz20YO6pgjhOkyg67ZMHAaUsCX/VlgNg8rJIOiRbwCdly DS5OZDF1vbWEvJQqapt4FwWTSXWok0p8b7K0qua9AryIAx932itK4y+oDQLspLb/5TVt stVUUWSKNufesu5j7h0fqTw4s7X/nguPDL3O9YqtVgGaqWi1ahmhO7lZyDPuqvi8cds9 38uqdrQJX1zgdlndtVHrlEegF5I0G0x3WHTt6MNXfWpLx1Yua55uXkvW+s7Pfe5hA0wE eM3V4rxguAL7vs9gdazmuPBu4qDqMNitb9NBT//PfpcJS4ygKC8pceHg2IJotdzSFVis PndQ== 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=yE70JIuqrA6MJdI0/JWiVeD/16stq6LybzVtzKfjj1Q=; b=CcFCfZkMhfopte756FvuEdTWcMfjW/V9IdKYx6UKc/FbAggqVEic3Keo9xu6AwvvOs oB739TxJ8hxxnOd/l7ogMPfObDaM6HOtWOjLdT1UYEFTCYNI/czrShrXAHyBy0/oDqN0 CR/10nit9vxQ8ekWIKO9xJA4ULNwfjdT24XE6KoSXlL1JoTdIU2xlAxrVJyMKjUbE7/d G8OpAozREARB9F05MbnXZ66fZslP4RVGHB1Jq9/OVDiMGMzcxSbyRxjdTAfXi4n3ImnX 55fD5/Hafrgq+RQxw6a6R31OScJq2Ish9IQf6CcZS0lS6k/HbBfJDYqj4zYoRi4J+3zb 1dug== X-Gm-Message-State: APjAAAVh9x4GFmfrTxvoQYc32ZLo1oVN0WCChFk7WHN+RoYsTFKPFUW+ DZUarAn5PF9BlnMqyZ+OuT+8ChAW7lc= X-Received: by 2002:a63:6b06:: with SMTP id g6mr28570506pgc.346.1557861434077; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:43 -0700 Message-Id: <20190514191653.31488-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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::430 Subject: [Qemu-devel] [PATCH v7 14/24] linux-user/aarch64: Use qemu_guest_getrandom for PAUTH keys X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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 Tue May 14 19:16: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: 164246 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3013235ili; Tue, 14 May 2019 12:32:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxID0Nz8FsVjoZqoyxnFyI8pf6ve4GAOJoh8FbAI1m5hg39yvEjTo9XQ8COhxPTbcLwAwth X-Received: by 2002:a50:89b0:: with SMTP id g45mr39090169edg.200.1557862347577; Tue, 14 May 2019 12:32:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862347; cv=none; d=google.com; s=arc-20160816; b=CGDpSxhgEv+ud6s0VzS6+cdPu5VaoW/Ae4MRvgdI363tR0Ulgez4+4MI2l+VZle0+b RRA3nOYgoyEQjHf0Gvwhvzy9T8iv/kcke0ZjvmE2Rf1FdZqxivD9NNnaOw5oJG77U6NQ 3lQbdrKO57CgaFRrXIjEVWYOZmmYRhY00M61sYc7t28y8l8UMRJPojR+TYe1XerXYnD+ WKD2rBy6o1JZ/qBvDc1iz1HGV1KaIvuTcnYjkOj1immak+tqjxXgW97NXM7itNuoZLSG 8q5kQtzO/b/C/4ttzMFLnVZNa12WvvQXrF78gMmxlA5I1LXRYNZLgI/lVFPy0SglLAH6 cGZQ== 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=snXBlb0VD87nnHn7Q6KPOfq6Oyu7S4mMYTFxn8359jU=; b=YIT+ZZL25/+mklVmvPT4k5xUDwDgNwU5os0jJck/doURT/Z/pACFGvtdQBtrOvKwvz vgANQlzU/KHkPAYfrdPe8XNhC7vLfwUfGgSYK/68ujV6LCvKvMuBo0JpF+uoIuz3607v iCKFTeyBoiud23dwtmIXE4C3Ve1ZY6OHBGb/EFG6U+RD6uKHtaf2/Z7SlsxgXZ9JyhoG Q+QSvJX3ZDh4ROtnXAbkINc/G6Cj4orx24L4uHpjy1sm0XZf8r9ioaM93bIcPBLEhmeb G9Jv4L1i0HCYLD4EB00UV9Mqyagc3Wmw0pNQ0zdwMNE00hZG2Wret5uS1RXPzMN6v9/a 6tBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cS6X8k+9; 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 u16si1434875ejx.27.2019.05.14.12.32.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:32: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=cS6X8k+9; 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]:53136 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQdA2-0007Vg-GJ for patch@linaro.org; Tue, 14 May 2019 15:32:26 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvO-0002bJ-3q for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvN-0006yT-4p for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:18 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:44123) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvM-0006xT-Sv for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:17 -0400 Received: by mail-pg1-x52b.google.com with SMTP id z16so34193pgv.11 for ; Tue, 14 May 2019 12:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=snXBlb0VD87nnHn7Q6KPOfq6Oyu7S4mMYTFxn8359jU=; b=cS6X8k+9x3u+9JC1Vv7LBt4ObMwsyt+ocIB02CPrAa8lIfW1gFx31NoNe073nSOMkk lDKTF0GO9O40go6+yOrPeq6IF4owyojh8z30sH3PL7OkbR6mt4A1jJjbFOZ3o/0AfGZu fhSo2B/6SzEHTpzp8vGlgJyxhwYBq0uSDVhAhzj8xQekDxnoABXILS7NPXE2Chs0vLLh j4ZnmGvM7cvxZG3rAd0/yg9sjB4bn5Ao+NSODB5bCf/6VVvuA4pxytazfbZJg+k8CLua VXFMN16gHDSLWcISHyFY/Qvjlfq+vKS8AN0EwJ13KteoQlsVZM8bc2u9dxY36hoc0uVA 4gCg== 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=snXBlb0VD87nnHn7Q6KPOfq6Oyu7S4mMYTFxn8359jU=; b=U/mfU7pqCgeWpsqWybxnyMyIyDUXLn5SxLR+KGy/hzHzdej44HSGHCnpIoH61akRBX PWseKd+On9AbuwFCjRYnNFf4n3BOmgjIccs4DdEKUswQ5JPPyTGk0ItCnlX74nV8cyT2 MftUrlVR03RbRLXuuLoz7z/RcvBc7mGhBWggRFrFTIoLo4QBvTjzk9BTsqhd6CNIjs7N FYSXR31BJnmCayjuc0khDqh0bTE3Tmcao7QGemT6riS15xXR4eJGhUrwYARG03+lE3WV evZfVR1vgxWR6DN/G+VzxK0q/j7MGBaD//e52zWAHB5XufpfvBTkhyied26axMurPz8s 80KQ== X-Gm-Message-State: APjAAAVHb5iSCejfIl2PZ/t40OEHz4teqEZWR5b8tpIojL+L6Rat+Bxy n9jfS1gN+w3SJGJoDBWTAOtVugXNERg= X-Received: by 2002:a63:3ece:: with SMTP id l197mr1249541pga.268.1557861435565; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:44 -0700 Message-Id: <20190514191653.31488-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::52b Subject: [Qemu-devel] [PATCH v7 15/24] linux-user: Remove srand call X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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 4c72f07555..5792c40ace 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -623,8 +623,6 @@ int main(int argc, char **argv, char **envp) cpu_model = NULL; - srand(time(NULL)); - qemu_add_opts(&qemu_trace_opts); optind = parse_args(argc, argv); @@ -692,15 +690,6 @@ int main(int argc, char **argv, char **envp) { Error *err = NULL; if (seed_optarg != NULL) { - unsigned long long seed; - - /* This will go away with the last user of rand(). */ - if (parse_uint_full(seed_optarg, &seed, 0) != 0) { - fprintf(stderr, "Invalid seed number: %s\n", seed_optarg); - exit(EXIT_FAILURE); - } - srand(seed); - qemu_guest_random_seed_main(seed_optarg, &err); } else { qcrypto_random_init(&err); From patchwork Tue May 14 19:16: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: 164247 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3014606ili; Tue, 14 May 2019 12:34:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyzYFDEULA5eXhU4fi97MMcyCX69ItnlmdDZJDXiz5ogEX+apt/BAYykMWEGI/Sf6I9IszC X-Received: by 2002:a50:d791:: with SMTP id w17mr38000441edi.223.1557862441993; Tue, 14 May 2019 12:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862441; cv=none; d=google.com; s=arc-20160816; b=aIKJj1m41YsPMhmz+RMMSvmNeOz6MGBl1GL/3b/1hnPpItUdLk/rfKpRnzfnwGAb2R ctvzrLz6pgqGcxHcOQSXSboTBZ5DrfdKrFaROboR+IGwiE9M2LaX8lVk3UJLC8th4AII yfDqg/bzEcBpdRqumsdG/iCSyK7+IEsTw6IcBQbysS6bK+EwIkAZc6fBJ3aOHwi3m5sT aCxmogZd/zcNKY15laDK3SjWYW9xlm2xBbp3eIcVNs+uoq/JWz+P/1+rDu7IsQspj7wm Cvf+/S0NrzBRDPfgfdv6GvqSpdJK925rD83emNzoE/jvWPCHIL2MOQcZuOyR1ziPEcNI c3Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=gZNiNYQQXuA93bC9AkQ3RkBuv003My9kgUQccuqjr10=; b=ec+pFPButEl6hPZWH2/Qk9ENvB/5Nx94nRXar4WjM/YyI450W/9Dhx7AXAt33l6Wc/ HWI6MMma4vEocL3mSohzHITgkfHAaiXjvlkMJmtH4MTe9/fXX23zCRYhXXdG/+gOIlFa 2U7iBfiADnjN/ysodoOKy0jiWp5XRB7MAUL0kLiN39EXIwQs8b+gMdeUjKB/3HGW0hMD 1FRO4vgswwX59aE0TBGMeR5vhzCAqpKsb9wc+K1IkBIZSFvlBo+xXWA8a606wSKQny2k TFFrVXm3ArT4Srb+QlJ3XeUVeO1JDNaBd04GYt5egP8cszZ/0cFQQFDQvalMhx8zvIbN X6Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="wdyp/cs6"; 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 s19si3755373edx.375.2019.05.14.12.34.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:34: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="wdyp/cs6"; 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]:53147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQdBY-00008T-SV for patch@linaro.org; Tue, 14 May 2019 15:34:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvR-0002d6-Hn for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvO-00070o-IO for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:20 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:33544) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvO-0006zM-9X for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:18 -0400 Received: by mail-pf1-x443.google.com with SMTP id z28so18290pfk.0 for ; Tue, 14 May 2019 12:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gZNiNYQQXuA93bC9AkQ3RkBuv003My9kgUQccuqjr10=; b=wdyp/cs6Zycjdm7r/zoV+/gINfmq+a87JqC8wqYy9g4QWWQ2Ih3wvoSqi38BS4y10N dBE7kInnbygibVpGV8xlAgCow7QXo4s9KsjQa3+SDIN9jIrpJxW1L/NLb/K7OVhsXYcd yicu/NxBEdishimKpwxf1daCezCJ/0zeg4j+TWzwDbHgyEj2IHma/RuSqUOWco3Nyw6N QOvdRFNIp2TJB7Bh4CXiZbtN2LOWTyyoAJsDNkpJ/BVF8sFmFCNVn1+apMaCuwJqhDEc 9YIsOXH91TlsOQnIxu+X2jyQXCo3V7IXSNj1x0ro83Cgv1GhS2LDFXqvSeFYXlCS9tFp 9ZRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gZNiNYQQXuA93bC9AkQ3RkBuv003My9kgUQccuqjr10=; b=R6uqOhYsU/VAhwmiPX2vnkKooMdQN5PuAAlOKYeT7lVIWpag+hHmOFiJWawppB+Tc9 25+srYrRrqRLp/SZbs2Ac/lBtDEpX0sZQXlWmVs9d/GztcKxCR1m5baXLAwl1ZcTAE7p 22/ev/9VEJXCoa926fDbrsyagYucrk3W3y2L/jFU5sHY0YkEoBlijFY7+0pDtDM33Zks nSsLaE+2+fWUHUMJee8am0ki2UPCDqAoYNzdLJO63VK5oVC+RyVhSvZGwbwoqKIXDH1E 67XO4irGJtPqcg3sHwnvO9PQach67E5BjFPfh+JgxszzNs0cb/kkna2ujXu6vPidEPsl F78Q== X-Gm-Message-State: APjAAAVXd6wgWqa6EFOPuRkUVRIOo9XqH9ePrDv3Iug98OOSm8GPyVcD dMntiEeqbpmA1KmkApmBcr8AYFKKJGA= X-Received: by 2002:a63:b901:: with SMTP id z1mr29239919pge.102.1557861436949; Tue, 14 May 2019 12:17:16 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.17.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:45 -0700 Message-Id: <20190514191653.31488-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 16/24] aspeed/scu: Use qemu_guest_getrandom_nofail X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Use the *_nofail routine instead of rolling our own error handling locally. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Reviewed-by: Joel Stanley Signed-off-by: Richard Henderson --- hw/misc/aspeed_scu.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c index c8217740ef..ab1e18ed4b 100644 --- a/hw/misc/aspeed_scu.c +++ b/hw/misc/aspeed_scu.c @@ -16,7 +16,7 @@ #include "qapi/visitor.h" #include "qemu/bitops.h" #include "qemu/log.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "trace.h" #define TO_REG(offset) ((offset) >> 2) @@ -157,14 +157,8 @@ static const uint32_t ast2500_a1_resets[ASPEED_SCU_NR_REGS] = { static uint32_t aspeed_scu_get_random(void) { - Error *err = NULL; uint32_t num; - - if (qcrypto_random_bytes((uint8_t *)&num, sizeof(num), &err)) { - error_report_err(err); - exit(1); - } - + qemu_guest_getrandom_nofail(&num, sizeof(num)); return num; } From patchwork Tue May 14 19:16: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: 164244 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3010856ili; Tue, 14 May 2019 12:29:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyI7iis234j+gVz71Gfo75BQIVHTCZUIMkQs3DLZkAn0MIMtMcX3xtmjfR+VQOu6/Q0uIti X-Received: by 2002:a17:906:3955:: with SMTP id g21mr28859809eje.61.1557862191292; Tue, 14 May 2019 12:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862191; cv=none; d=google.com; s=arc-20160816; b=SYK83abq1g14kwiniUHMnEas2RH5UnsUf4JPyuu02PLXO6vAcNmX6uGa79ecg80WXM n0HoQbacED+bxOdT9jpZuIvfPR82C7S1PobqyFZ4qonNMkMMkJIJbVA6ISgBdruP/kjG abKATHOsPnqs+dR9cufBCYh5PCQyL84xixlRpnYG4XEZIwzgCwcRF6jAUg4uote23d9V PkRnBUnjtaqnpCyWLIadSJmWjrc3vDgHKP+ewyi9DbH9gG6UB/0Kbvx8qBttzqLX761d d8cPwdKsk7+xJRw/ecpny6kU3XASYktu++iNpnhz3jQSpX3WZVBPvdHiPsaLL/UKbQoV Jqrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=zHL5/dOLNq3cxnvhnBPOBazkJM0pmZq+fc+P6w38V4s=; b=Img1ouF1TSpTJAsrzXlg2NkLKH6mTpQQKC51Or1JiKbc+At1THHkqe0FV7uMrWe2CE StNldh64v4MsCMeMin07m2jXE3a1qsUO1n6Zt4qqg5Rp8Y3couviIhhb7U43FIoOp7HT 5N/WohC/dea8omAh13OOeK07tyW+WtsZhQ9k9rAau9CnJzc17o1LYtHIjQ7DfICTTSRS eUW3qQqYHrorg94YNhPkIRQXN9gK08oKxSieHiapof3uPlHLIkHfiQrf/b6cBz2gQ9YT X3rkp7r8oVizun24/vLTFBeYoL+dYRWs1se+H2baKgx2Zg46eKyj2kWuDNvE1MXcCWaj LYEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=M6gR4U3L; 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 o14si2852149ejz.221.2019.05.14.12.29.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:29:51 -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=M6gR4U3L; 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]:53084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd7W-0004uq-5w for patch@linaro.org; Tue, 14 May 2019 15:29:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvR-0002d7-I8 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvP-00072z-Mp for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:21 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:40109) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvP-00071g-As for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:19 -0400 Received: by mail-pf1-x442.google.com with SMTP id u17so592pfn.7 for ; Tue, 14 May 2019 12:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zHL5/dOLNq3cxnvhnBPOBazkJM0pmZq+fc+P6w38V4s=; b=M6gR4U3L/bgTDtPmpFWXLWvD77Vm4fCPpE7DYCo4iDjA4pftInBaJ9WEh2MI/25bku ERxLzyDm4lvi0GcKiUPCXMLQnc+msFjEVCLWSy5RW5QFa7f8SmPHpzEUeBHBp96Ls3tw gUr43liDbX5lUAucADct9Mv8bF/+cpbzcrFyfVbRkwo1AtWMbwjdeARv0kXoZCPErki5 /oINr0aj5sBZumLjuLXKv87Fc8gD+C5ouLDi11xpglqafsqkL11OvjaiQFU4EYYbSy5X uSHJWUrk7SVDgs23zT153m9/kEZKys0Hot+jZ2EoK3BqYtliP4dq8Wy3XadpqiZD7M8n MEvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zHL5/dOLNq3cxnvhnBPOBazkJM0pmZq+fc+P6w38V4s=; b=kZnUhRbssnc2IfNq2pqtYy/fMePsYFoinetWZwMcU72xmRIBUvcwLjYn1SK05xpFGv UPjxTrWzeWqHk+Gc5hjR11JcckEa5dxEcMKc2WEglIU/rravrLkWS5d5+D9Rt1twwmLe Y1mxWynUCLClno3E5aggmZmiwEEwMTGwFhstiRmtqEI5nADJ9l8pAgqh8SmpzCYkgZir 0yPkjVbtJRsFfT97iCLLulh79k4JtqsOQxgcXRramzQupL17KYLIY1kxVPD4I0kesPI3 pXFpAJzPMRHj+4UCeXeunHpvIfmQMxcDLvcCuHKOoVKM8AcGBy/NuPO19r9GZXbVNzqm Bx3A== X-Gm-Message-State: APjAAAVxqQWBjj/Y7wY7FaiK94GXq0FC+HCacD7kCua+4XFgt7FLjzvW oUL+ZNQ6wB6GP5ixUHmfz5Ukznd8xRU= X-Received: by 2002:a63:541d:: with SMTP id i29mr39416547pgb.174.1557861438129; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:46 -0700 Message-Id: <20190514191653.31488-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 17/24] hw/misc/nrf51_rng: Use qemu_guest_getrandom_nofail X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Use the *_nofail routine instead of error_abort directly. Reviewed-by: Laurent Vivier Reviewed-by: Joel Stanley Signed-off-by: Richard Henderson --- hw/misc/nrf51_rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/hw/misc/nrf51_rng.c b/hw/misc/nrf51_rng.c index d188f044f4..3400e90a9b 100644 --- a/hw/misc/nrf51_rng.c +++ b/hw/misc/nrf51_rng.c @@ -14,7 +14,7 @@ #include "qapi/error.h" #include "hw/arm/nrf51.h" #include "hw/misc/nrf51_rng.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" static void update_irq(NRF51RNGState *s) { @@ -145,7 +145,7 @@ static void nrf51_rng_timer_expire(void *opaque) { NRF51RNGState *s = NRF51_RNG(opaque); - qcrypto_random_bytes(&s->value, 1, &error_abort); + qemu_guest_getrandom_nofail(&s->value, 1); s->event_valrdy = 1; qemu_set_irq(s->eep_valrdy, 1); From patchwork Tue May 14 19:16:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164249 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3015592ili; Tue, 14 May 2019 12:35:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaeW3Gt9ZWK1M6AYvmtEyBdvoa250rxhGOXG3Cgwza4sIubER92i6Hu6IHJoLganKXCvnP X-Received: by 2002:a17:906:61c3:: with SMTP id t3mr10850559ejl.273.1557862513696; Tue, 14 May 2019 12:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862513; cv=none; d=google.com; s=arc-20160816; b=r+3X50iz5/VKM5NA9VYTMSf0yRruVZ244jwTJ76ozt09TDRPbrGJRbCWkRZp9kUbQI nS6zJbgYnFxNoUwUHjttubaYIwcODnwyNcOzSYoDi4z0LQahyihVMWVMAN1fsZVs0qTb ZG5jOkJpjl5ccr9Zu9OKfn+LTOAKSxZque0wXzbYi5ypqGxMF1qHvZXfFRaTfLsQtkUU AosXy01JzeCAX99P3tFjt9JELzjy6bNcfX92k3JkCvirMvl9m4cdaD+Di0It48vFn+jz e8MIFDENS4UMUr9U/nVxacYZ5Jx5gws5FbeCDsmTvN4hD4iWZw+L0I0pBx9mvUwoKnDG mqfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=wKy5ep5gzBeVJvdgqxMAwC/EHW/NEI1i+sUaPM2vsGg=; b=jjvD3nVxz05/7YcYZcpK9INpvxl291HItJGAmwhF9qEGRwMynTF/QYcxrgv4wVopt7 2Xayb0pHMj2Jjt61DbDIuyS/Hq+Cv6sA8TVKDx5ZT2/QMeTkYURTvd+on32ISTRhq/JZ wJKTrPjcv97MLzrk827Irz9nNAbzATiqQk9OpObbWhsVBm53H3ffHcHnkgBeBJctPz50 +KEMS2C4+/wLUGrKKZUbIqGqFXXlg93VZe/FoUCWjLicLBNcNOj7cc1BATDjzL8Pjb8G uvsCW+Z64Erc97qhvAS1nflxLWsOCMPqJGhlC1OVhTjRejGCa/ZjLmOKs3YAVO3ae1Z0 2c2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HUMjL7Yb; 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 e41si328132edd.236.2019.05.14.12.35.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:35: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=HUMjL7Yb; 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]:53179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQdCi-0000zd-KI for patch@linaro.org; Tue, 14 May 2019 15:35:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvV-0002hM-Bs for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvT-00076f-3A for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:25 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:44350) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvR-00073d-IH for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:21 -0400 Received: by mail-pg1-x541.google.com with SMTP id z16so34264pgv.11 for ; Tue, 14 May 2019 12:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wKy5ep5gzBeVJvdgqxMAwC/EHW/NEI1i+sUaPM2vsGg=; b=HUMjL7YbNsLvockZ2JWS36HhF7Fu+KVAC98o3BcIpBR1mnssHseBVExELZPJO3y24P iskIXmWNnsyrl+hwNmr4KCejZOOjzsP/Bf7Qv+5S9v9qi6/qm4/aTfquomhrUckKf6TB 2rk/3ex0QtBwMEhVD4/V4xfT8i9e42C7Aq9vC7ECEnTvgYOLntqzayUSyuzn0h2cys/4 EsmGJvTBQL68MEA7vMzt05MiZQXMciYXywLfPT7UO+A4hQdFa/ccCcVw5xI33uvg93x6 r0liswMq8iDa0jInLwEnBl4LjuQPX8bXg6vJUWNdrCxXYxyavQAXrvKwb4m6D+zG4NIu pBCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wKy5ep5gzBeVJvdgqxMAwC/EHW/NEI1i+sUaPM2vsGg=; b=jLJZBC7JEQ/oR/gH65Oky6faO/J4RGcXyy1112/eMMZDlStsv6ZPHNTLXn4J1OYFPX FQPS7iOPHAnbFIf8LH/zoaz4SQsoPqDQqdTQv97jOvYDMvAzJTL1YkYLBOJ28s5jg7W6 MoO4FT8fYkvOSwwY54aBrPAmNUX1B83AMLnnMmtFPuaUTP6I8WL21tOipPUOnATIVHxL x2z12Q77Ld0/PM6DubIlYiTfwehu+1yXE6QIewmZ4mJhS7Gvo8l0fiRZQ8aoYrFSY++Y v3JA8wy0fajc5E7VshoKFIP0HtBhBUHc8EKzkFdlNs7bnj/vPqOpx47al+oweg68HPTI zOFA== X-Gm-Message-State: APjAAAWGNIjkqi9vzc/dg/6Uh/SgeHeoU3ddP/ocNZ6e4dyCDnZY7FXl QH0MvKsMpkuQvugfrm0u2iLCQG9eFNA= X-Received: by 2002:aa7:8d81:: with SMTP id i1mr14308617pfr.244.1557861439629; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:47 -0700 Message-Id: <20190514191653.31488-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH v7 18/24] hw/misc/bcm2835_rng: Use qemu_guest_getrandom_nofail X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Use the *_nofail routine instead of rolling our own error handling locally. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- hw/misc/bcm2835_rng.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) -- 2.17.1 diff --git a/hw/misc/bcm2835_rng.c b/hw/misc/bcm2835_rng.c index 4d62143b24..fe59c868f5 100644 --- a/hw/misc/bcm2835_rng.c +++ b/hw/misc/bcm2835_rng.c @@ -9,30 +9,26 @@ #include "qemu/osdep.h" #include "qemu/log.h" -#include "qapi/error.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "hw/misc/bcm2835_rng.h" static uint32_t get_random_bytes(void) { uint32_t res; - Error *err = NULL; - if (qcrypto_random_bytes((uint8_t *)&res, sizeof(res), &err) < 0) { - /* On failure we don't want to return the guest a non-random - * value in case they're really using it for cryptographic - * purposes, so the best we can do is die here. - * This shouldn't happen unless something's broken. - * In theory we could implement this device's full FIFO - * and interrupt semantics and then just stop filling the - * FIFO. That's a lot of work, though, so we assume any - * errors are systematic problems and trust that if we didn't - * fail as the guest inited then we won't fail later on - * mid-run. - */ - error_report_err(err); - exit(1); - } + /* + * On failure we don't want to return the guest a non-random + * value in case they're really using it for cryptographic + * purposes, so the best we can do is die here. + * This shouldn't happen unless something's broken. + * In theory we could implement this device's full FIFO + * and interrupt semantics and then just stop filling the + * FIFO. That's a lot of work, though, so we assume any + * errors are systematic problems and trust that if we didn't + * fail as the guest inited then we won't fail later on + * mid-run. + */ + qemu_guest_getrandom_nofail(&res, sizeof(res)); return res; } From patchwork Tue May 14 19:16:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164251 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3018009ili; Tue, 14 May 2019 12:37:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzojbiWBIItivMG4WhFgSNKQm/oXdtW/NlncUA+Jmx0p/n5CQ432HAdvaHTpldhhBDI6zon X-Received: by 2002:a17:906:2518:: with SMTP id i24mr17662505ejb.169.1557862674857; Tue, 14 May 2019 12:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862674; cv=none; d=google.com; s=arc-20160816; b=BYu/FMVkGxC9M3IGAzw8wZxygkaBaHZLD5vN0scdWZIlyhdaXFPXVYIwsVSJ3I1Jmz k97ByEhd+wlrqYB4qPfi+/Gcw0azqhUKSKchmlw4roTtYO710WOZF++EPtHV5DTOs7qq uAZaBxMNPz4iltuIII7cnkaeCniwheBqKm+Azh6Y0mwr64fDAgIvT56DPaEeCvy1lSYZ 5ZBBwZyrPXsh5YpY09hEqvaKP9eQEnRdrvqfqpd+hoEYaaxPi1g3f+6QN1MJAYdGOTyj RLuzHn5sD/twfzX516S3NqoQKOw+FBBaBMzo2goOp+bRgxNaKjLRzBKq19EFifLicMpV BoYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=/VWGaUBQJcHRh8ZCol9Bt7n9p31zv9AWS8bL9WKxKYs=; b=reaS3bVbCpHYOvsHFM6YB8TYfi2poSIUM6n+S6omLTxuRGP7QMgfyDdZ8jkzPNHMv4 p410KOxKDGxzwT8qs/xbACsrHlBH6IgPS8YBmHSYZtA2kW/77OCNDZWaj+Zfvx5B1cKS ch4/91dxO6pLpo2BIc+z2KBLH0OzB39LxkiEtJpakUHyc4WT/WdurKs2OQ95DXksQ2T3 XpxplK9SJw485P4zYI65o2lc62j1bqdwbt4CnoY6iaxp68LjiyTUrA4TN50fHfq+nMvN 8Jwz1f8lsTd0AEo/vnYLVqfY4jCL6gq4CDJvByBYwSVT/2rGDS1w4TNMJ3czOUH1sx/i 4K/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ry6QEhMe; 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 d4si6257717ejb.324.2019.05.14.12.37.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12: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=ry6QEhMe; 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]:53225 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQdFJ-0003B6-Ol for patch@linaro.org; Tue, 14 May 2019 15:37:53 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvV-0002hK-BM for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvT-00077L-GS for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:25 -0400 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:40051) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvT-00075U-2N for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:23 -0400 Received: by mail-pl1-x643.google.com with SMTP id g69so73586plb.7 for ; Tue, 14 May 2019 12:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/VWGaUBQJcHRh8ZCol9Bt7n9p31zv9AWS8bL9WKxKYs=; b=ry6QEhMeXE+0og9mw97zNWAEloNKkbE7ODLUz0iLgJwFzeY9WxkiukGjsbexWRwrto NGmnfgcOedsNVxI5363MkVUJOsLhTHN0dFpJg6tZGwL3Wv7QdZ/CY8/WRCvjTxwXhL/4 Qv8X8QngWVyFPouabU56oeHedFPDQaAEujSZAbcSGhMkXltt9tmjWU13N9g91OalpwvW FqmVFAxc9iphkhv9DsIrK74utN9okF3A8jbDU+son2vluXc2YQIdhIzr8m0OWOrwUGDO rb9fsGlXAcNjL+QYhiw2jgsu5+TWQUtbmWMdTridweG+dOaUaGl1PtRFbY0mX1gd8Zxz 0iiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/VWGaUBQJcHRh8ZCol9Bt7n9p31zv9AWS8bL9WKxKYs=; b=cnZhoB0qXn7vvQ3liI0xpoZL63bjdBOji35uBG1SE/VGkXnzSxfQPAmFqK1EyUHb4g zDSmDxVfvzXV08md5ZcaWEixla0wFiIzDNzlzbd9ZoGYn/i9CPf+MS3qFsx851l8iX6z eVSzL4ROv7hTdYPeYi+O4jzscPF/0U06KcY6zy+C7ZZ7MHtPMR2cho0UQn3Qy9FUbn35 r0D3B9+idi+vk5Gk4y0/CKhHgFXYDNG5UD1u4ePD6Ibr2DL9SMQutkw0U4t3kpOO0Np5 nGV0VFG8rhusDhJeg6o86ar3NLTa/JrCU/tQxkZ+Qq3TZtmOjHBPa3RTNekNsk41rNVD F2aA== X-Gm-Message-State: APjAAAVkezsSZIsHkBoO6yzzBG2JJXT7Wg3vjbhFeRjQfZpEfD5K8rhm WMqZWmLq/G2V+uI9Qkgb/B6Q3ly+xuQ= X-Received: by 2002:a17:902:b606:: with SMTP id b6mr40343627pls.100.1557861440862; Tue, 14 May 2019 12:17: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 o6sm18682982pfa.88.2019.05.14.12.17.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:48 -0700 Message-Id: <20190514191653.31488-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 19/24] hw/misc/exynos4210_rng: Use qemu_guest_getrandom X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- hw/misc/exynos4210_rng.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) -- 2.17.1 diff --git a/hw/misc/exynos4210_rng.c b/hw/misc/exynos4210_rng.c index 4ecbebd2d7..0e70ffb404 100644 --- a/hw/misc/exynos4210_rng.c +++ b/hw/misc/exynos4210_rng.c @@ -18,10 +18,10 @@ */ #include "qemu/osdep.h" -#include "crypto/random.h" #include "hw/sysbus.h" #include "qapi/error.h" #include "qemu/log.h" +#include "qemu/guest-random.h" #define DEBUG_EXYNOS_RNG 0 @@ -109,7 +109,6 @@ static void exynos4210_rng_set_seed(Exynos4210RngState *s, unsigned int i, static void exynos4210_rng_run_engine(Exynos4210RngState *s) { Error *err = NULL; - int ret; /* Seed set? */ if ((s->reg_status & EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE) == 0) { @@ -127,13 +126,11 @@ static void exynos4210_rng_run_engine(Exynos4210RngState *s) } /* Get randoms */ - ret = qcrypto_random_bytes((uint8_t *)s->randr_value, - sizeof(s->randr_value), &err); - if (!ret) { + if (qemu_guest_getrandom(s->randr_value, sizeof(s->randr_value), &err)) { + error_report_err(err); + } else { /* Notify that PRNG is ready */ s->reg_status |= EXYNOS4210_RNG_STATUS_PRNG_DONE; - } else { - error_report_err(err); } out: From patchwork Tue May 14 19:16:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164252 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3019744ili; Tue, 14 May 2019 12:40:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJDtyQEr75E0I/ru6BlIrVR7w/VognWG9hA6U6N/XmWzpVamJpduLBA8R9VTGhCxSRs0i6 X-Received: by 2002:a05:6402:745:: with SMTP id p5mr2325015edy.62.1557862810202; Tue, 14 May 2019 12:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862810; cv=none; d=google.com; s=arc-20160816; b=wECn1jvVwAJXsvA2ACaa9RAS1f//EFIRZPsKMfCzMrFg9Uo5nzJ4/eVfwgLYXEBv+1 ek1AppMEartlmaJGZYlvRFLAkM92ftVApLeSV+fpDsNioet/VstK3k0v+pX9Fcf/sOlY XzHKz0KrrovoE6I+i1J4UKQ4dtjrGEbOgyACeWB66cYEZFB6SVocG91gsALFUyeALdEq moUk7KWQnMDqbW+7qKcxMukDlrNhf/DwqGyqYTt2Zq4avUf8T5+74IZWuDFxXoSabE3H QISY3Pr1lcKSG0z1QnspuKrsE+4V/+zjSQtJjPHzqap0LUEQqoxB3wrw/eXme4/N1Xp8 6Eog== 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=O5zIN7a5YhWG7ErE5cL09/UzOmkeLwtbGoogr/y9loY=; b=Zv/4A8TH6u5Q10jOFA5c296xB8naWxe87BYmeAHJuHgXGADbdWpd+zZlGLvtCAY2H7 iiTkRIJuNZux3oFXadrhoBXGrgH813BVmecQK3DLQ+oXnnPKgYbNhiFFK6tpKURRgFL7 dvAlWWzIOrByj1YyfYkos7EMYA/beue9dk84k1Pyfd0Yc6tmy0cVlnzndewZupbX3p9V wGkOKvPwlqxCzq0zBTw1Ybok/sHVdbybj07ePoxgv4Mdh8lz6635+uPZ7diQSsOgP+LO 3Xjxu6lJR0MXlOp/ECB6iUVvjHmsLRBAfFQNZ2dXJMn458oMa29YkKuFJpCHhuG1OW8r y6Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=zBIqfv+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 j9si7113975ede.372.2019.05.14.12.40.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:40: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=zBIqfv+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]:53271 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQdHV-0004ud-4Y for patch@linaro.org; Tue, 14 May 2019 15:40:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvX-0002jG-B3 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvV-00078u-Dx for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:27 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:33830) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvT-00076S-FJ for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:25 -0400 Received: by mail-pl1-x642.google.com with SMTP id w7so87626plz.1 for ; Tue, 14 May 2019 12:17: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 :mime-version:content-transfer-encoding; bh=O5zIN7a5YhWG7ErE5cL09/UzOmkeLwtbGoogr/y9loY=; b=zBIqfv+Rf+wqMW0YWwon2IO/Kg9oYoaROJ0trx/hb6LtxsvULmwzesApZOkhtpX3oB etsJIXaRkEYkgKQmzwKTh4eT5ncHWZskSLelX74X13NTa1PPQujLeG79oJ8ow2ABrg+5 yvy00zYkGuPxnackbeOD4bb/LOEs0VXvDJV7R0IkpnKNcGQnu2ItRBPQgFS6PuYNYFq0 EdXNLID3Ya7OlWIULRPLXtj63n9M/+vMO0r//kLjIYxeeIoNcV5WawNY7LIqlrJihR5x Yr3+95XjxGEn5kmWUp/mBK7QWS/9OOWE+C2LVg6HIa+SqrOj6+BNRmLARzqrP0YJWsRm kd0A== 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=O5zIN7a5YhWG7ErE5cL09/UzOmkeLwtbGoogr/y9loY=; b=VHTwiR85d/a7MX0xyUGMPKaI1d79S9+v3Qfo+5oVXG57rhaRNJ/4ap4K7yQKDc14DT uOs98DCygj+XJ2eM9efW4t99ydznEicmbj2euDfKpL9JxUIo3ZktNa/FqeCXIwLOJO80 O63nl2yweMM/r3Juf68XdYqFiwQRW6dI4Rs6j0oJoSFquhVRBhCp90GMzoWsTVGa1liu KB1+n4/1wUbzeHsit/eXM3wmTrwbIutmGKQjRBWPABDxoWxTifheYGi1ooEev2zURUpF NaV+U+dOdFP6X/MiRVh2lzxuRaesOzGlvhO5Z1yP5kMaLmoXVBgmep/yg3lMEl5nY4h8 0Dzg== X-Gm-Message-State: APjAAAWii5L6+0MpsG2KAuT6FMsSEatkgj9ry4WfltVW5+dOLV3Yo1Wa R3mSUMW13ouf7DrAG8KxUXO4uYhXUX0= X-Received: by 2002:a17:902:a510:: with SMTP id s16mr39273364plq.334.1557861442042; Tue, 14 May 2019 12:17:22 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.17.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:49 -0700 Message-Id: <20190514191653.31488-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 20/24] target/arm: Put all PAC keys into a structure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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 Tue May 14 19:16:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164248 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3015130ili; Tue, 14 May 2019 12:34:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxt0v/QwXzoZglpiimOcAgcDcjdasK0nJR1QvhGQbP6xme7AqR6BDHun/hY2EPwnT3Tg/RQ X-Received: by 2002:a50:9705:: with SMTP id c5mr39593522edb.258.1557862480451; Tue, 14 May 2019 12:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862480; cv=none; d=google.com; s=arc-20160816; b=WV9DxeW+z8SjHl8Sw8WZcq12SabX1FyGWckhbCO3bZprNnTf7CkGRaCsgcpFlaDECZ SjM1DV//zdKw3vK026UFqfJPMsiVIsWGMqR4nQT9tviaMU1mORzgOpmbFxr4hl08VOKs 6joMPAviR+KUssFNZpBmjUTcqm9GcKqs0ppFitcmD1ygOGdYSmPYWBJOyxEs122q2HNs wGOyo+vbFGoQ2B3/ZYFesX1GIW6yYszwx1U8sa4GzlJ1BLQIbNiIpLxtSe+e/r+RW5Qe URAUXlQs9WKKIo3lYGHJ3Guykq1HNfL6ekLAZlF7ajzImvsooJx/95pU/ZjYFZUVlf0C sXRg== 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=ztXvGPgxsfNQ6iDCN/IIJ1leMuVNwtZhgkaITTqSNbM=; b=iiFBw5oHBqdTdVQDCFQ7vo+Otavhw9WQT3EkpTQxcVHMRUA9cZi6CrRe6EuG5uvxDB jCDCLQFoJznb5G8rzG0/MBHSKwoLTB9pFcmSfziPDUAT9FsLKoMHz+/obnf8K9ahLoOF JkXQpsLghgnyqhVoQyLUZE7OpHKELHYbOeq4o8xF2YVTV8yGfdYEDmJp1vTmUV7J4ee2 2JvtlDv52q8z1ys9+YXNndSKJ2x0fRfquhsBDTusOVlyqB0x1WE/1/ZYhj+BVzEVx+a9 wh1fpp6ozhG2kIHpt+HU3uWJQf+g/l1Fxuqj1IluXwAIbNSH+TO0AF16SGBtLA1kV+OZ LWAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NmvaCxP8; 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 z16si691809edb.381.2019.05.14.12.34.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:34:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NmvaCxP8; 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]:53153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQdCB-0000Yp-8b for patch@linaro.org; Tue, 14 May 2019 15:34:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvZ-0002kz-92 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvX-0007BA-Cy for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:29 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:32870) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvV-00077v-Cq for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:27 -0400 Received: by mail-pg1-x544.google.com with SMTP id h17so59151pgv.0 for ; Tue, 14 May 2019 12:17:24 -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=ztXvGPgxsfNQ6iDCN/IIJ1leMuVNwtZhgkaITTqSNbM=; b=NmvaCxP8/NUxTJKhpruWGlr0tMYYMFV7E7HC63sZmEEcWQ5JGtCxZreUnu9lYonhW7 /K7oFc6yW/a9VEBSpMdrmJAX24RhNvvE8fv571LcPkSoGrBt6X8Og/+k+fZ41aeceObD 7oezAV1fuN9v/LA7twFpZMwhYmu5ZEr3vSp4kXROofKFKPITjvrR+mE8R9CksiqIrASw ZZWeLt90GsGZfQScLtBs9gZfNwnaU5g6i//jfa3+f2AZo29kQs57paMLs7Ap083MsesS Beng3oXl1G+NxMd49SQLb2+vJN3zgdNH2/WF5tJ52jyF3vCSVl/h+3c8gleQLrld+ime PHFw== 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=ztXvGPgxsfNQ6iDCN/IIJ1leMuVNwtZhgkaITTqSNbM=; b=lklb3/H3FX4Wn0P+LzSMhzAfFkzn34sbvgg+AIXdxtBBLv7G7u5BVwV9o9k8gbyD5g feUIXXx1X9jnJNaWLRaV/8kf49APaJqidO2AUNWys3MnM4RNaXv2ITQJ2NBwr5f6Q+1X fpQMDEQo3taKhfl40OcEnmBc6pZipvMuKkIj7l5WfVW5R076oNPmJd8hCDjESjPZ9WHw WbaQI13jGZFUWgj0ycdGpuytQEyhogqpe3Gu5oBB81hRqqbT8GyI7uxPcpU0xOSWOR6r L+fwMIj/WPa1rSgKdHCs7/GSG8XHpeonSloL0VaawkiqF2dIKOG+6mZupwtNmQRhbKAT tmNA== X-Gm-Message-State: APjAAAW1bPCJ/OlxMbExLvoVk1K46ErAhbDLYZ2MOc2R2FevgX021cJf 05QClEVyRLV7BSeC8D8Iadox1OWgcKs= X-Received: by 2002:a63:6fcf:: with SMTP id k198mr39296225pgc.158.1557861443281; Tue, 14 May 2019 12:17:23 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.17.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:50 -0700 Message-Id: <20190514191653.31488-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH v7 21/24] target/arm: Implement ARMv8.5-RNG X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use the newly introduced infrastructure for guest random numbers. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 5 +++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) -- 2.17.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 892f9a4ad2..c34207611b 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3521,6 +3521,11 @@ static inline bool isar_feature_aa64_condm_5(const ARMISARegisters *id) return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TS) >= 2; } +static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RNDR) != 0; +} + static inline bool isar_feature_aa64_jscvt(const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, JSCVT) != 0; diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 228906f267..835f73cceb 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -310,6 +310,7 @@ static void aarch64_max_initfn(Object *obj) t = FIELD_DP64(t, ID_AA64ISAR0, DP, 1); t = FIELD_DP64(t, ID_AA64ISAR0, FHM, 1); t = FIELD_DP64(t, ID_AA64ISAR0, TS, 2); /* v8.5-CondM */ + t = FIELD_DP64(t, ID_AA64ISAR0, RNDR, 1); cpu->isar.id_aa64isar0 = t; t = cpu->isar.id_aa64isar1; diff --git a/target/arm/helper.c b/target/arm/helper.c index 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 Tue May 14 19:16:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164253 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3019989ili; Tue, 14 May 2019 12:40:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKXk44jIe92KQv/NoAmSn7fl4+8BPK0IHYfovOrg1UEwH/V9h8JfIZZstDELfw61O4JwjC X-Received: by 2002:a17:906:2518:: with SMTP id i24mr17670714ejb.169.1557862832437; Tue, 14 May 2019 12:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862832; cv=none; d=google.com; s=arc-20160816; b=S+pQI7xiWM7hTUpdIC9SAn+EKg8qlO1uEUNkskXCHMt6bWfgh+PdEeRxW8wa00U/AV kW79kzwKGsA4t/lzJ/byASjk5F3lnnCjFLVBWMSDAf6g2ZImAiXcBeuqkwsNHFYloU34 RhlPLVPSQXOC2BR/mK7XASHTYxSJjBzk5n8WIQhuz0CJIm5IbS3UhOboFC0W5EP5Dk7e MotJut7aYD31XKNFO+1PUveBYRwGuxuF2ec8UJ8dacEvwb/fOYlIHhMHedujJwhD3vzd YmOkaFLjeczS0ut97NeynwsraWhRjE8G0FNOM5Sk/FfJweTe+DhQV5Vi60EKiN/90TUM KJ2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=bpjcbv60JSWpD1TbbxFv9kSVFeLonJbRE1N/VVDdCYY=; b=tgWFVxARhNKw4onJzy9dcL+hIovraVNuTtaRs2aRgOUrgO6orL8IrnpO2I3x4fYDN0 WxFkNV/NarMDB6Rzj2hWTeX+egZmMhVAKpmbDNA3oViDS3w8pM8EKn6i/kJogVLkDcu8 1mvkriZauE8sA4SPMPYf9PLYHszxste2LLVsZxJuWwqtZU6TNC5SvkbshvLeVBOt7G73 SVxiNAIQ6J4mYwlBcuyJjsbzzWfzASY6tcpgBhjTkznG59wNnNBm87jb+66hqTFwuyf5 4i/3sjR/9rOOWqRj334lwaGT/4SreJr/dohXpkiWH81KdSGsocEGD11S2Ei7bDBEqpaF nBIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PlxewZmj; 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 c9si1165354ejr.142.2019.05.14.12.40.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:40:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PlxewZmj; 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]:53286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQdHr-0004z6-DP for patch@linaro.org; Tue, 14 May 2019 15:40:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvd-0002o9-25 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvZ-0007Cx-8Q for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:31 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:41159) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvX-00078h-Ah for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:27 -0400 Received: by mail-pf1-x442.google.com with SMTP id q17so1141636pfq.8 for ; Tue, 14 May 2019 12:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bpjcbv60JSWpD1TbbxFv9kSVFeLonJbRE1N/VVDdCYY=; b=PlxewZmjyDw1MRMeUJq5NHFmH8hnskUokgZSO9xNh1AbLmV6hnE0Mn4KI/rIai48Iv hxBBfjK55wezLBn1LuyPqmYy5226oZhqeMfzAc5igpSsKrNRja+lg8xstqn3vDwAYyWS DVboJI3YJGV1aHZMxtpt5AiF2qQKJGKoUKKJR2fo41bh5ApjZ4yUJTJ2Y2tP+k5TOjUr Si368T13i4bNNK9DjsCs0Zz7rJI9DoLHHgNc2qp2MEjjJUwPakxCt/qKKp61KwxoT9l+ YNWD8zWKFJzmY7RxjZepLkB5l5CJUsANyh9TUbwep7GqigsT8ttd4C96CGhc9HOP7+rQ Iepg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bpjcbv60JSWpD1TbbxFv9kSVFeLonJbRE1N/VVDdCYY=; b=Hbw9beNr9Gj/NrwHN5/36WMA3nb9OYqIOyveDJxel0gmonwpZvNDpdZ6ajthHRJEAk KJAoivtURKeLe6WEADJENZJ27f8zSJaE1KwTad9hJGZo+EfthV2gyy/S1ypYnLkNZsPJ 1QJf0Dv6S44d2j1Mt7T1gwD3MD9W3qxWQ/mcSHTP1BM7W/FlZs5vCMJ5KYAZICgSXMbS b47250VPZFeZ1cxXSOtcP1jHXcfjVeSHjwjdSKL73QLMuxH5gx22knmyAbMmEdJKMN7C Khwm+f7ZqqsMgbGP8uqS1DX9A+CB2JjrXsbtSg16uNpC+mwJ7OHW9Vf7zXpoYKAhw/e5 rwWA== X-Gm-Message-State: APjAAAWCnQIADO9hHlwPIGP76HfBYFcATMjM8Z6GhmysNOlEfJlMMp47 E+jbEsu6GF6BrEYtWzSspVFTY3tvUWs= X-Received: by 2002:a63:3e41:: with SMTP id l62mr1294578pga.383.1557861444603; Tue, 14 May 2019 12:17:24 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.17.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:51 -0700 Message-Id: <20190514191653.31488-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 22/24] target/ppc: Use qemu_guest_getrandom for DARN X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We now have an interface for guest visible random numbers. Acked-by: David Gibson Reviewed-by: Laurent Vivier Signed-off-by: Richard Henderson --- target/ppc/int_helper.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index f6a088ac08..9af779ad38 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -23,6 +23,8 @@ #include "exec/helper-proto.h" #include "crypto/aes.h" #include "fpu/softfloat.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" #include "helper_regs.h" /*****************************************************************************/ @@ -158,25 +160,38 @@ uint32_t helper_cmpeqb(target_ulong ra, target_ulong rb) #undef hasvalue /* - * Return invalid random number. - * - * FIXME: Add rng backend or other mechanism to get cryptographically suitable - * random number + * Return a random number. */ -target_ulong helper_darn32(void) +uint64_t helper_darn32(void) { - return -1; + Error *err = NULL; + uint32_t ret; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + + return ret; } -target_ulong helper_darn64(void) +uint64_t helper_darn64(void) { - return -1; + Error *err = NULL; + uint64_t ret; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + + return ret; } -#endif - -#if defined(TARGET_PPC64) - uint64_t helper_bpermd(uint64_t rs, uint64_t rb) { int i; From patchwork Tue May 14 19:16:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164240 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3008006ili; Tue, 14 May 2019 12:26:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqx9aRoRDfgZymNZZ7Hw2AlVeiVDbqWDt82eviEJjKN179wU0PSIxSvzK1bC9Ha1yygbI+4A X-Received: by 2002:a05:6402:180b:: with SMTP id g11mr38716396edy.268.1557861974251; Tue, 14 May 2019 12:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557861974; cv=none; d=google.com; s=arc-20160816; b=asTiLbvdFslR2sU49UJXRMn7+vZsOXo7u8fII0jf1e9xiB68iWGE5PEzwjUzGlWa8A m1De1xyPlBqRH8xWFu4tCZN2nCDjBoCH8YeZ2lQ4k2M3IkxIhSL8m3ABdnPpDH9WKmLT flj2xRoOPYiXjwZuq5TpGK7F8ep1CWMEj5p0jeosaqR7jkve67ZsqptTJNfXCF5zzwFD umGzjIg3IBrzikrjEt766qwy9P74YA1VStqAK5KW6j7CElXhs/RtSDKrrSd+GpXkJG37 xCc11hVc5VMMAd+iI+P8bSPzN0U9+V2gxgOqT5H9vnhV5/SD1x1EdidCfaSPoU1Npk+B oI7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=jubgcMuTGNSY5TtGEwh0c6OxeP3qp5DidyhAq6jVSSw=; b=E4RqOtrfBi4dwDBvglV3MWdUYBLFf4p2IDsZQTBnsLvcZQnbkZw/RxUExydw2Q013L 2UMwuDPzd26e+r2EUVYelCnA/oE7IMVwDhjvO3ConsNo7p1U6MHANUnOq03ccauKpUS/ zUfwdY9yteWxPXtbXsiyXZGnUHbcmJ9e1dANSrgP8GWSF24agEzDFoeNAdGFqKa/PebS Yz80bvuTjg0rZHFZ/S42p2tlP7Z8q+QWmnkCoHl4Eok9e9TktqAOWhSS1xCzC5P+1jSN 6u305URgpczeL9RvrbfVjtp1tzO75ECCPXfoM3ScG/vyRjZT8gEG4zXym+u86KnkNCtq x7Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=USq6jzxM; 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 w15si2627086edv.270.2019.05.14.12.26.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:26: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=USq6jzxM; 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]:53044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQd41-000273-4I for patch@linaro.org; Tue, 14 May 2019 15:26:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvd-0002o8-1y for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvZ-0007D5-AD for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:31 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:45597) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvX-0007A2-CC for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:28 -0400 Received: by mail-pf1-x443.google.com with SMTP id s11so9613058pfm.12 for ; Tue, 14 May 2019 12:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jubgcMuTGNSY5TtGEwh0c6OxeP3qp5DidyhAq6jVSSw=; b=USq6jzxMgaDUaG3WM5mv/86HAk8ydS51FPFNqcritjxxEKAosVlp5suwP9i/dIjTav g3btabJUyGGeeUvdNCD2n006RMXNCr8HJhUowRVkirYEJYCPKg9lQ6o4cngo6OfoIX4v MT7Re2niSRdtLT1amhr69tPvfXiDoIUR0uPMDi/lK8ct3Vt82XMHRyaBCSkVHLb/deF4 e/j4j/qLRCHr011Kwqi9WQI7UJuNQ+CpBx19x8Wxum7R+BRTWJashGP4hr+8/fzKityc Q/ZJVDSyAo8B5Gc+6BO30SzXT6Bb9PFKi2dyPOIHU8YVho64enIFGigrCDePbVICpiej xFeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jubgcMuTGNSY5TtGEwh0c6OxeP3qp5DidyhAq6jVSSw=; b=AgmFE9o9fkqVZ2cgrp1acYf60mAfhAFXXw/HDQvzawl7bLVzQIpEj/hbJVawZz8odU slrGFrIYuGsK73BB1I3HvHhsQPsFtK+Ga91GRyH7a0R5yjy3vlEIB/h5NKveEbYX4pD3 RGeLCBcW9Q2GKWdUZvHn3GH4yVm++2niC81pjyh9IQ9uZK/jkjw7zRH+JscfBlba/ykG AcscsychIByBnQZbBIQzXwoZCIS2AXalFo738TlGdNO0Cc6BAmhpdp2EERLSI9QiIcBg OjgLH4gNwEXld3AKBwiy4VfpmUkYvr8+T2n747felCFvt5UQu9QAGIqI0D/DDysgWFbv XxdQ== X-Gm-Message-State: APjAAAUY+//co7YGcBLJkAzvAXf7B3/Q12aKNJwPNzd3lkY3SqXaZ8js q/5eT2pP7iGJQ9QC9bxejAYgTmSHSKQ= X-Received: by 2002:a62:2687:: with SMTP id m129mr43682012pfm.204.1557861445759; Tue, 14 May 2019 12:17:25 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.17.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:52 -0700 Message-Id: <20190514191653.31488-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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 v7 23/24] 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: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Generating a random number counts as I/O, as it cannot be replayed and produce the same results. Acked-by: David Gibson Reviewed-by: Laurent Vivier Suggested-by: Peter Maydell Signed-off-by: Richard Henderson --- target/ppc/translate.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/target/ppc/translate.c b/target/ppc/translate.c index b5217f632f..4a5de28036 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -1847,13 +1847,22 @@ static void gen_darn(DisasContext *ctx) { int l = L(ctx->opcode); - if (l == 0) { - gen_helper_darn32(cpu_gpr[rD(ctx->opcode)]); - } else if (l <= 2) { - /* Return 64-bit random for both CRN and RRN */ - gen_helper_darn64(cpu_gpr[rD(ctx->opcode)]); - } else { + if (l > 2) { tcg_gen_movi_i64(cpu_gpr[rD(ctx->opcode)], -1); + } else { + if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { + gen_io_start(); + } + if (l == 0) { + gen_helper_darn32(cpu_gpr[rD(ctx->opcode)]); + } else { + /* Return 64-bit random for both CRN and RRN */ + gen_helper_darn64(cpu_gpr[rD(ctx->opcode)]); + } + if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { + gen_io_end(); + gen_stop_exception(ctx); + } } } #endif From patchwork Tue May 14 19:16:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164250 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3017090ili; Tue, 14 May 2019 12:36:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwN7Y4lHSHMyPDAOb9Pparq23bYDpOZXnz0dJP6nv6+QOXlOyHzmNvFmyERuI8xf238MWCe X-Received: by 2002:a17:906:9a9:: with SMTP id q9mr29419302eje.171.1557862607839; Tue, 14 May 2019 12:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862607; cv=none; d=google.com; s=arc-20160816; b=NSFGQxKAxmmRoX1Kc5nfgyyHK0IwLVkIJfi6ec0w21pUq5gm79xg6kvQiB+xnXp749 sVgB0B7x9TtPjAZbUBG/ssszb9c5lETOe0JLztlScGb30oUJsFq67Xc8ZQra9IU63Gp7 13Qm5Q+JuCTncAVhpkppzW2pbT5HGG8LdDkMArsSl9dSQCA43zaf2qUrLGVn4lqDwZ1S 26dN+QgKFKGBXvwKmWDSoe7LusTPtRmWFvftoSMp0FdYkYOqRi5GvuO9ugsaONiyse5y eFW+fckLDtKvbE3MAMgrdvAJj+C0Hl7XPFKWtsCk//5ijiLOdajtC2XP9mZaGNZlqjmJ Olng== 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=HYIlEI5x7dSKPn06Te85N+SIxFZI2TsRzdSqKh133IE=; b=YBev+xo5fTzXgtCmkBn3ot+Ex7qTvilYTToLNl50d/GWyaZnlD3JJ/ezVMDoaYAoEh fmrAEmlJ901oKKEdnk1gnqy9/D04FjObiWj+V18SSMqHTYDK6blVYyMQ2uyWveoW9QPj vTnFbvFNqTRX7O12Om/TvQpEj52AqkTHQP61j/H/TlbTCtPMf3K3yJaBNTnc2ncvu9gZ ueYy5dlY8qsWRNWxC6ubvaTb3qfGxwFhJIzqZ8pLSloJrDtT6tOHpplNHqdjA99VLlui HQmXlggXDUvt6od6LgHx1//HSNqYu+DkGwgz6RoNNTBu8ZvWfcDNPfjUPp21Lj+jhsFf OfhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rKeBW048; 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 l24si1996438edb.217.2019.05.14.12.36.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:36:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rKeBW048; 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]:53210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQdEE-0002I9-I8 for patch@linaro.org; Tue, 14 May 2019 15:36:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49032) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcve-0002q5-W9 for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvd-0007Fb-3Q for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:34 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:39626) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvZ-0007BT-8w for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:30 -0400 Received: by mail-pf1-x435.google.com with SMTP id z26so3276pfg.6 for ; Tue, 14 May 2019 12:17:28 -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=HYIlEI5x7dSKPn06Te85N+SIxFZI2TsRzdSqKh133IE=; b=rKeBW048rbZAKp/CQy6+FJuXXCdeRR2f6Ts45gVcCljIN/N82Tov1OXogSF2BQ+nu3 p0ml1kairTTI5Kw2R4tprTPkM7ahsLng3NDQUT/uioO6RD/roEgxHZP2AbtnIbRBA2Vu wpdBU+9T9w5wDR2qnEVofHe7b6c1do+3v+3Wwz5h5hyY7m/k4/p/cZocV/s4wd4ogRff 58ixcZmQLoKiOYT1X9E4HZauwsPaQoLvQ7fQckvGP5dtAhbi4tf03nKMhGCTAXwcjpAZ 15HzfXCpEhfKd07SyuJmbbIDTcj1c+AwtztkwLURq3UH+G8RCO+w1fUNhXDSnhqcA8FM Q19g== 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=HYIlEI5x7dSKPn06Te85N+SIxFZI2TsRzdSqKh133IE=; b=ajgOl51aP9gMhmVuRAlCE249MLQLjI8LiLuWKoz834Hx/PfYAz0scOfy5E92gRR24D 2T3X6KuivZ8dRkaxIsGNMrzcvL+3OF87xCKjhxtzNvA9qeiZ1YW9deGOnfxHAV3LZDnt dtetgaleUnS4hCO8dnmxg78y2P+jg9uwPC+U/OAupFGOyxpDGeRgzdHQuUPce4EFfyfA gihGwRzhxxLEBl6MksDjHLuTWQLoVRjCqW+YCpSwaQKCSCR2Qjbvn89wfqG0p0Szzmyh GxuneRkE8tT0pBpX/1gkh13HQ09sXDEA7w3PYLqgXpEwha15w//0Gg807wN7pVfgnd7p R1Aw== X-Gm-Message-State: APjAAAVwtI7Y3/zkeOYJI7IJC09Cfy75ff0sTNj17hkZ3t3OkmOx2VM/ SbOFAGfMW6JDbWfvZ/x2XiJUmUWCFZ4= X-Received: by 2002:a62:6d47:: with SMTP id i68mr42667690pfc.189.1557861446957; Tue, 14 May 2019 12:17:26 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.17.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:53 -0700 Message-Id: <20190514191653.31488-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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::435 Subject: [Qemu-devel] [PATCH v7 24/24] target/i386: Implement CPUID_EXT_RDRAND X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We now have an interface for guest visible random numbers. Reviewed-by: Eduardo Habkost Signed-off-by: Richard Henderson --- target/i386/helper.h | 2 ++ target/i386/cpu.c | 5 ++-- target/i386/int_helper.c | 21 ++++++++++++++ target/i386/translate.c | 62 ++++++++++++++++++++++++++++++---------- 4 files changed, 73 insertions(+), 17 deletions(-) -- 2.17.1 diff --git a/target/i386/helper.h b/target/i386/helper.h index 6fb8fb9b74..8f9e1905c3 100644 --- a/target/i386/helper.h +++ b/target/i386/helper.h @@ -226,3 +226,5 @@ DEF_HELPER_3(rcrl, tl, env, tl, tl) DEF_HELPER_3(rclq, tl, env, tl, tl) DEF_HELPER_3(rcrq, tl, env, tl, tl) #endif + +DEF_HELPER_1(rdrand, tl, env) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 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; /**************************/