* [Qemu-devel] [PATCH v5] linux-user: Let user specify random seed
@ 2014-10-14 15:18 Magnus Reftel
2014-10-14 15:18 ` [Qemu-devel] [PATCH] " Magnus Reftel
0 siblings, 1 reply; 5+ messages in thread
From: Magnus Reftel @ 2014-10-14 15:18 UTC (permalink / raw)
To: qemu-devel, riku.voipio
linux-user uses the rand function for generating the value of the AT_RANDOM elf
aux vector entry, and explicitly seeds the random number generator with the
current time. This makes it impossible to reproduce runs that use the AT_RANDOM
bytes.
This patch adds a command line option and a matching environment variable for
setting the random seed, so that the AT_RANDOM values can be predictable when
the user chooses. The default is still to seed the random number generator
with the current time.
The difference from version 4 of the patch is only the addition of the line
Reviewed-by: Eric Blake <eblake@redhat.com>
to the commit message.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH] linux-user: Let user specify random seed
2014-10-14 15:18 [Qemu-devel] [PATCH v5] linux-user: Let user specify random seed Magnus Reftel
@ 2014-10-14 15:18 ` Magnus Reftel
0 siblings, 0 replies; 5+ messages in thread
From: Magnus Reftel @ 2014-10-14 15:18 UTC (permalink / raw)
To: qemu-devel, riku.voipio; +Cc: 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 <reftel@spotify.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
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);
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v5] linux-user: Let user specify random seed
@ 2014-10-22 13:17 Magnus Reftel
2014-10-23 10:03 ` Riku Voipio
0 siblings, 1 reply; 5+ messages in thread
From: Magnus Reftel @ 2014-10-22 13:17 UTC (permalink / raw)
To: qemu-devel; +Cc: riku.voipio
On Tue, Oct 14, 2014 at 5:18 PM, Magnus Reftel <reftel@spotify.com> wrote:
> linux-user uses the rand function for generating the value of the AT_RANDOM elf
> aux vector entry, and explicitly seeds the random number generator with the
> current time. This makes it impossible to reproduce runs that use the AT_RANDOM
> bytes.
>
> This patch adds a command line option and a matching environment variable for
> setting the random seed, so that the AT_RANDOM values can be predictable when
> the user chooses. The default is still to seed the random number generator
> with the current time.
>
> The difference from version 4 of the patch is only the addition of the line
> Reviewed-by: Eric Blake <eblake@redhat.com>
> to the commit message.
Ping.
http://patchwork.ozlabs.org/patch/399483/
BR
Magnus Reftel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v5] linux-user: Let user specify random seed
2014-10-22 13:17 [Qemu-devel] [PATCH v5] " Magnus Reftel
@ 2014-10-23 10:03 ` Riku Voipio
2014-10-28 14:40 ` Magnus Reftel
0 siblings, 1 reply; 5+ messages in thread
From: Riku Voipio @ 2014-10-23 10:03 UTC (permalink / raw)
To: Magnus Reftel; +Cc: qemu-devel
On Wed, Oct 22, 2014 at 03:17:33PM +0200, Magnus Reftel wrote:
> On Tue, Oct 14, 2014 at 5:18 PM, Magnus Reftel <reftel@spotify.com> wrote:
> > linux-user uses the rand function for generating the value of the AT_RANDOM elf
> > aux vector entry, and explicitly seeds the random number generator with the
> > current time. This makes it impossible to reproduce runs that use the AT_RANDOM
> > bytes.
> >
> > This patch adds a command line option and a matching environment variable for
> > setting the random seed, so that the AT_RANDOM values can be predictable when
> > the user chooses. The default is still to seed the random number generator
> > with the current time.
> >
> > The difference from version 4 of the patch is only the addition of the line
> > Reviewed-by: Eric Blake <eblake@redhat.com>
> > to the commit message.
> Ping.
> http://patchwork.ozlabs.org/patch/399483/
Applied to linux-user que, thanks
Riku
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH v5] linux-user: Let user specify random seed
2014-10-23 10:03 ` Riku Voipio
@ 2014-10-28 14:40 ` Magnus Reftel
0 siblings, 0 replies; 5+ messages in thread
From: Magnus Reftel @ 2014-10-28 14:40 UTC (permalink / raw)
To: Riku Voipio; +Cc: qemu-devel
On Thu, Oct 23, 2014 at 12:03 PM, Riku Voipio <riku.voipio@iki.fi> wrote:
> On Wed, Oct 22, 2014 at 03:17:33PM +0200, Magnus Reftel wrote:
>> Ping.
>> http://patchwork.ozlabs.org/patch/399483/
>
> Applied to linux-user que, thanks
Thanks!
BR
Magnus Reftel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-10-28 14:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-14 15:18 [Qemu-devel] [PATCH v5] linux-user: Let user specify random seed Magnus Reftel
2014-10-14 15:18 ` [Qemu-devel] [PATCH] " Magnus Reftel
-- strict thread matches above, loose matches on Subject: below --
2014-10-22 13:17 [Qemu-devel] [PATCH v5] " Magnus Reftel
2014-10-23 10:03 ` Riku Voipio
2014-10-28 14:40 ` Magnus Reftel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).