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);