From patchwork Mon Nov 3 12:02:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 40022 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4C8E321894 for ; Mon, 3 Nov 2014 12:30:14 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id ge10sf6199860lab.5 for ; Mon, 03 Nov 2014 04:30:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=4ZMxzSXR+AuiA5xcH9kAS46dxYGRWLiMUTA40Xxzpv4=; b=bFXJyfM490woSITkfg3fdbeRyU5MI0pib6wqguvjT9dfq1WFR6k1na7DBf3r0OJW4R ChDeHjmpwykbsRO1CSrmp3VsKAPen3g4n3m0isl8aWStPNxNiy4lnimtKLiOQC4AGZvQ VVYg4dqM/Ie0/m7vcyo0ZbRqM05ABAKDTHs3ZQmsv5utbeVQ8ZCB/ezr4SW7PMfIHdhv s1W8N70PvXK9Qk4mt1sta45IFal69sMSiBEtg11ZEv23/ZSPHloBkZRH/cfDVig35TbH jzK1NpEu9PMOARS/aOQXMJXE7b2v67V5QQla28P+5UXZ6LZ1ZuL0g8DazA+sfFsFSh4u FCiw== X-Gm-Message-State: ALoCoQnoGZEKjCQ7LX9kH8xn7dwDhKqTywt6JVsdJcAmsqWEkgL+BDZabl8Gjd+1v44S3yXHItjP X-Received: by 10.112.77.9 with SMTP id o9mr3836650lbw.6.1415017812525; Mon, 03 Nov 2014 04:30:12 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.133 with SMTP id r5ls676154laa.65.gmail; Mon, 03 Nov 2014 04:30:12 -0800 (PST) X-Received: by 10.112.85.106 with SMTP id g10mr50006519lbz.38.1415017812380; Mon, 03 Nov 2014 04:30:12 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id k10si32214808lbp.126.2014.11.03.04.30.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Nov 2014 04:30:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id hs14so9563544lab.33 for ; Mon, 03 Nov 2014 04:30:12 -0800 (PST) X-Received: by 10.112.12.35 with SMTP id v3mr50387763lbb.80.1415017812003; Mon, 03 Nov 2014 04:30:12 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp225996lbz; Mon, 3 Nov 2014 04:30:10 -0800 (PST) X-Received: by 10.140.32.136 with SMTP id h8mr21282938qgh.13.1415017810026; Mon, 03 Nov 2014 04:30:10 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e6si29340664qar.66.2014.11.03.04.30.09 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 03 Nov 2014 04:30:10 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:34111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGlt-0000fB-7Q for patch@linaro.org; Mon, 03 Nov 2014 07:30:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGLV-0007Mm-3G for qemu-devel@nongnu.org; Mon, 03 Nov 2014 07:02:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlGLL-00046h-UF for qemu-devel@nongnu.org; Mon, 03 Nov 2014 07:02:53 -0500 Received: from afflict.kos.to ([92.243.29.197]:59744) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGLL-00046M-Ny for qemu-devel@nongnu.org; Mon, 03 Nov 2014 07:02:43 -0500 Received: from afflict.kos.to (afflict [92.243.29.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 779BD264DA; Mon, 3 Nov 2014 13:02:42 +0100 (CET) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 3 Nov 2014 14:02:39 +0200 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 92.243.29.197 Cc: Peter Maydell , Magnus Reftel Subject: [Qemu-devel] [PULL 1/3] linux-user: Let user specify random seed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Magnus Reftel This patch introduces the -seed command line option and the QEMU_RAND_SEED environment variable for setting the random seed, which is used for the AT_RANDOM ELF aux entry. Signed-off-by: Magnus Reftel Reviewed-by: Eric Blake Signed-off-by: Riku Voipio --- linux-user/elfload.c | 1 - linux-user/main.c | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 1c04fcf..f2e2197 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1539,7 +1539,6 @@ 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). */ - srand((unsigned int) time(NULL)); for (i = 0; i < 16; i++) { k_rand_bytes[i] = rand(); } diff --git a/linux-user/main.c b/linux-user/main.c index 483eb3f..5887022 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -3546,6 +3546,17 @@ static void handle_arg_pagesize(const char *arg) } } +static void handle_arg_randseed(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(1); + } + srand(seed); +} + static void handle_arg_gdb(const char *arg) { gdbstub_port = atoi(arg); @@ -3674,6 +3685,8 @@ 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 for pseudo-random number generator"}, {"version", "QEMU_VERSION", false, handle_arg_version, "", "display version information and exit"}, {NULL, NULL, false, NULL, NULL, NULL} @@ -3856,6 +3869,8 @@ int main(int argc, char **argv, char **envp) cpudef_setup(); /* parse cpu definitions in target config file (TBD) */ #endif + srand(time(NULL)); + optind = parse_args(argc, argv); /* Zero out regs */ @@ -3926,6 +3941,10 @@ int main(int argc, char **argv, char **envp) do_strace = 1; } + if (getenv("QEMU_RAND_SEED")) { + handle_arg_randseed(getenv("QEMU_RAND_SEED")); + } + target_environ = envlist_to_environ(envlist, NULL); envlist_free(envlist);