From patchwork Wed Mar 13 06:26:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160204 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13955900jad; Tue, 12 Mar 2019 23:33:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuMVnI06tiiJJWQwxORkd9aCp354pwlNH39HFCcW2KHY30iBOCbBaXVHUV9SdwlM9vMhNQ X-Received: by 2002:a81:7092:: with SMTP id l140mr14742714ywc.85.1552458829828; Tue, 12 Mar 2019 23:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552458829; cv=none; d=google.com; s=arc-20160816; b=Uf20N/pka5DnzG81IbU/tW07o3PMdvM4s4MBw3nuz0WUaDut9n26JxVB17WChiGTV5 /z6XyJM+AQ2OXuysWo7FLTTV8T6cDFj+Fj7ip1VgZb1Z05vy1MJJiM6x0HXRbiAU53wP fUxFAIwx0CcklC/spuoElatucjGBAFnYfdzlhtiqoSwkO1AiI+WBfMutYROCRa1fxJUO NMYprXIcXLp+jcjyK/AwU6HYgy5SemFXDGlyNcMq2xO8uqk7q+SIu8+ke1F+Hm+JRhyX erY2CgOq0mhpaMIzQbT+kajrgpIcFfYMUbFDQ9nXdKiZwHISh84cG+TsSsR2QVpBlzWI tM7w== 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=H1kR7KejSOEAo4SO3V5tbV5T3KpzO83g+NoqvRJ2QWw=; b=Zk0/aLBclav/K7K15fdX/8We865HTOvDWCReq7lip89GfEb3MjtoU/IBZP5iU/1VtK aTp8EsLfYzsopemZQCaezcaHDQyEsbF9gubxpyVV9Zf/GK7HsdDv9+UBi7b0yUKriqir OchiODGN3OeUjn51s2iLWr14/i70QUXtX+4nixtb3to4ekoW3L1Y0caS6N17jDIDvCnA sETVSEXbpfpOHXb5LEohpMWy3mx841n9IWbxGWgIJBRTcZRTIJbVG/L8cfjOgqkgn1ap MmzG0abBJi3f76u5aW5XZ34b05hz2eqgKRuV4fxz1IbLZu2cnme6SG/sS0YoHTYynD/2 4B2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=S0zDuzdK; 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 p184si3533346ybb.328.2019.03.12.23.33.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:33:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=S0zDuzdK; 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]:39238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xSX-0004vr-Dg for patch@linaro.org; Wed, 13 Mar 2019 02:33:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xLg-0000f2-Ur for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3xLd-00020W-QL for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:44 -0400 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:44559) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3xLb-0001z8-JO for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:40 -0400 Received: by mail-pf1-x441.google.com with SMTP id a3so646105pff.11 for ; Tue, 12 Mar 2019 23:26:35 -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=H1kR7KejSOEAo4SO3V5tbV5T3KpzO83g+NoqvRJ2QWw=; b=S0zDuzdK22q4q3mWgO+5DpUFb8pbei00ekirao9yNGHgtTi/50t373vCGn7hvtUuTd tqf1qD2xPcy503eH0svjOd/oO8SeIFS9zqsz7cdmuO7uTliLPvGXZGpHntxwh+9615NS RMrItAUW4abDGgVs1Oi9fdnlcBsolNYBsNxy8IG4YKOSdEnQVQuxnfoOxmamy9e/Mxdq kGGPEAVjxTyYce/lxx0XgUqRl5PQGhMBUHeQLbnaIJW+sposFufHdAODdRmSG7D81dfi JuwTDPWxNtWIodhsveVdQ2FywUQnyx73xUBzM4EjDYnAoNyXuWw3PyAHIis5Y+qbpSaT okBQ== 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=H1kR7KejSOEAo4SO3V5tbV5T3KpzO83g+NoqvRJ2QWw=; b=M4CGVyPsf66dE3ATNWxnQHB06h0M8EyMVq1oZ6G/DdxuyL0/Kiu8g9c+laM/RC6dYg LzOpLQ5LbLxIOWL8WFPFFHe0MWobbYOB8Xfmmat4NGgyEiJ2CnyWa7OvWzyVeTHqD0fh yiRUN1RSbntHo2MwOcYQin7Ztt4+v03MB6PY9HewyvNxufx/c3FoaJeICpWNnk+8i6yf uojfogL1sIdnGmsIW8LtSI2q6SUKuK1fMYedn+I/YZvZ+clDWqcZb8EXhhAhb/AVV2mK ealQrPsk4T9z/mTTmr8cUva/6swC5noAR1/U3bW/emkwNEFXk/EWgR5BYIFtx64fFwrP LBnQ== X-Gm-Message-State: APjAAAXzYyIBpIaQBLjVQ2jynIhsQi0WJ5Gz9ZZRZRz4/o/wtzq4ZH0P VYMiPRi3f3Te/fZePloRwHn1nvMU09M= X-Received: by 2002:a17:902:b416:: with SMTP id x22mr44336735plr.285.1552458393888; Tue, 12 Mar 2019 23:26:33 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id m64sm25593889pfi.149.2019.03.12.23.26.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:26:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 23:26:24 -0700 Message-Id: <20190313062630.30568-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190313062630.30568-1-richard.henderson@linaro.org> References: <20190313062630.30568-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::441 Subject: [Qemu-devel] [PATCH for-4.1 1/7] util: Add qemu_getrandom and support functions 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: peter.maydell@linaro.org, david@redhat.com, laurent@vivier.eu, armbru@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Initialize the system from system and linux-user arguments. Propagate deterministic seeds when creating new cpu threads. Signed-off-by: Richard Henderson --- include/qemu/random.h | 58 +++++++++++++++++++++++++++++++++ include/qom/cpu.h | 1 + cpus.c | 9 +++++ linux-user/main.c | 9 ++--- linux-user/syscall.c | 3 ++ util/random.c | 76 +++++++++++++++++++++++++++++++++++++++++++ vl.c | 4 +++ qemu-options.hx | 10 ++++++ util/Makefile.objs | 1 + 9 files changed, 164 insertions(+), 7 deletions(-) create mode 100644 include/qemu/random.h create mode 100644 util/random.c -- 2.17.1 diff --git a/include/qemu/random.h b/include/qemu/random.h new file mode 100644 index 0000000000..9d88008288 --- /dev/null +++ b/include/qemu/random.h @@ -0,0 +1,58 @@ +/* + * QEMU 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_RANDOM_H +#define QEMU_RANDOM_H + +/** + * qemu_seedrandom_main(const char *optarg, Error **errp) + * @optarg: a non-NULL pointer to a C string + * @errp: an Error handler + * + * The @optarg value is that which accompanies the -seed argument. + * This forces qemu_getrandom into deterministic mode. + */ +void qemu_seedrandom_main(const char *optarg, Error **errp); + +/** + * qemu_seedrandom_thread_part1(void) + * + * If qemu_getrandom is in deterministic mode, returns an + * independant seed for the new thread. Otherwise returns 0. + */ +uint64_t qemu_seedrandom_thread_part1(void); + +/** + * qemu_seedrandom_thread_part2(uint64_t seed) + * @seed: a value for the new thread. + * + * If qemu_getrandom is in deterministic mode, this stores an + * independant seed for the new thread. Otherwise a no-op. + */ +void qemu_seedrandom_thread_part2(uint64_t seed); + +/** + * qemu_getrandom(void *buf, size_t len, bool nonblock) + * @buf: a buffer of bytes to be written + * @len: the number of bytes in @buf + * @nonblock: do not delay if the entropy pool is low + * + * Fills len bytes in buf with random data. If nonblock is false, + * this may require a delay while the entropy pool fills. Returns + * true if the call is successful, but the only non-successful case + * is when nonblock is true. + * + * The value of len must be <= 256, so that the BSD getentropy(3) + * function can be used to implement this. + */ +bool qemu_getrandom(void *buf, size_t len, bool nonblock); + +#endif /* QEMU_RANDOM_H */ diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 1d6099e5d4..343cc6d51e 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -372,6 +372,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 e83f72b48b..b5d3f46220 100644 --- a/cpus.c +++ b/cpus.c @@ -49,6 +49,7 @@ #include "qemu/option.h" #include "qemu/bitmap.h" #include "qemu/seqlock.h" +#include "qemu/random.h" #include "tcg.h" #include "hw/nmi.h" #include "sysemu/replay.h" @@ -1275,6 +1276,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_seedrandom_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1318,6 +1320,7 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_seedrandom_thread_part2(cpu->random_seed); do { qemu_mutex_unlock_iothread(); @@ -1477,6 +1480,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_seedrandom_thread_part2(cpu->random_seed); /* wait for initial kick-off after machine start */ while (first_cpu->stopped) { @@ -1591,6 +1595,7 @@ static void *qemu_hax_cpu_thread_fn(void *arg) hax_init_vcpu(cpu); qemu_cond_signal(&qemu_cpu_cond); + qemu_seedrandom_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1630,6 +1635,7 @@ static void *qemu_hvf_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_seedrandom_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1670,6 +1676,7 @@ static void *qemu_whpx_cpu_thread_fn(void *arg) /* signal CPU creation */ cpu->created = true; qemu_cond_signal(&qemu_cpu_cond); + qemu_seedrandom_thread_part2(cpu->random_seed); do { if (cpu_can_run(cpu)) { @@ -1723,6 +1730,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_seedrandom_thread_part2(cpu->random_seed); /* process any pending work */ cpu->exit_request = 1; @@ -2070,6 +2078,7 @@ void qemu_init_vcpu(CPUState *cpu) cpu->nr_cores = smp_cores; cpu->nr_threads = smp_threads; cpu->stopped = true; + cpu->random_seed = qemu_seedrandom_thread_part1(); if (!cpu->as) { /* If the target cpu hasn't set up any address spaces itself, diff --git a/linux-user/main.c b/linux-user/main.c index a0aba9cb1e..37300230f5 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -33,6 +33,7 @@ #include "tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h" +#include "qemu/random.h" #include "elf.h" #include "trace/control.h" #include "target_elf.h" @@ -291,13 +292,7 @@ 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(EXIT_FAILURE); - } - srand(seed); + qemu_seedrandom_main(arg, &error_fatal); } static void handle_arg_gdb(const char *arg) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 208fd1813d..18d98f5a08 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -110,6 +110,7 @@ #include "uname.h" #include "qemu.h" +#include "qemu/random.h" #include "fd-trans.h" #ifndef CLONE_IO @@ -5448,6 +5449,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_seedrandom_thread_part2(cpu->random_seed); /* Enable signals. */ sigprocmask(SIG_SETMASK, &info->sigmask, NULL); /* Signal to the parent that we're ready. */ @@ -5534,6 +5536,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_seedrandom_thread_part1(); /* If this is our first additional thread, we need to ensure we * generate code for parallel execution and flush old translations. diff --git a/util/random.c b/util/random.c new file mode 100644 index 0000000000..ded8725a3b --- /dev/null +++ b/util/random.c @@ -0,0 +1,76 @@ +/* + * QEMU 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/random.h" + + +/* + * While jrand48 is not technically thread safe, jrand48_r is glibc specific. + * However, the only other global state are the A and C values, which are + * otherwise constant. The only way to muck with those is with lcong48(3). + * So if we don't do that, jrand48 *is* thread-safe. + */ +static __thread uint16_t xsubi[3]; + +/* Deterministic implementation using libc functions. */ +bool qemu_getrandom(void *buf, size_t len, bool nonblock) +{ + size_t i; + uint32_t val; + + g_assert_cmpuint(len, <=, 256); + + for (i = 0; i + 4 <= len; i += 4) { + val = jrand48(xsubi); + __builtin_memcpy(buf + i, &val, 4); + } + if (i < len) { + val = jrand48(xsubi); + __builtin_memcpy(buf + i, &val, len - i); + } + + return true; +} + +uint64_t qemu_seedrandom_thread_part1(void) +{ + uint64_t ret; + qemu_getrandom(&ret, sizeof(ret), false); + return ret; +} + +void qemu_seedrandom_thread_part2(uint64_t seed) +{ + xsubi[0] = seed; + xsubi[1] = seed >> 16; + xsubi[2] = seed >> 32; +} + +void qemu_seedrandom_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); + } else { + qemu_seedrandom_thread_part2(seed); + } +} + +static void __attribute__((constructor)) initialize(void) +{ + /* Make sure A and C parameters are initialized. */ + srand48(0); + qemu_seedrandom_thread_part2(time(NULL) + getpid() * 1500450271ull); +} diff --git a/vl.c b/vl.c index 027b853d92..5daf12f74a 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/random.h" #define MAX_VIRTIO_CONSOLES 1 @@ -3330,6 +3331,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_seedrandom_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 8693f5fa3c..a45ae70d33 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3598,6 +3598,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 psudorandom number generator\n", + QEMU_ARCH_ALL) +STEXI +@item -seed @var{number} +@findex -seed +Force qemu to use a deterministic pseudo random number generator, +seeded with @var{number}. +ETEXI + DEF("L", HAS_ARG, QEMU_OPTION_L, \ "-L path set the directory for the BIOS, VGA BIOS and keymaps\n", QEMU_ARCH_ALL) diff --git a/util/Makefile.objs b/util/Makefile.objs index 835fcd69e2..bc7405c535 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -53,5 +53,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 += random.o stub-obj-y += filemonitor-stub.o From patchwork Wed Mar 13 06:26:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160198 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13951158jad; Tue, 12 Mar 2019 23:27:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxE+HxZGqfVa2mYJaMfPuxj8aJr4soSMS6Hwwty5FQeiKIUSNeWt66J/UN377wvI5bq5681 X-Received: by 2002:a81:3657:: with SMTP id d84mr32877836ywa.53.1552458425103; Tue, 12 Mar 2019 23:27:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552458425; cv=none; d=google.com; s=arc-20160816; b=sjSGVnFSzuQXYTgHijdCOiG0VKkbIDgcwPDSYIJfcKXf5jOQCA4gaOBY5gVVe25mVH eDJHnrnfu2f81c+UuGdM/X/GY0RzML7ckdjxw5gIhvVnE9RCm4Ht/N4FxmQpvG8c0T/f reuYp93BVv5NV4Vf3et5QB2aQW+jm6R9nYiXUqcV8n8xgA4lHN1goKgY+PsHlrLhUHxj kydJxY9N0Oag0LKhi+TiMVQjwKa49Guup5rMhtNVwMQkg7OhUV1cepDBs2o3vceoJLYl DA3Gqk8n6AsX9NgyCCu/c7uyYRK/AQ5WxYSbgmGSVUVCYF72hXS7pQviYqi2LTsCsVzm jidw== 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=2Mo+uQeJOvkzulvZHsMg8FatmP4cFOzNXezUkMKmYfY=; b=RHpoAFZtd8mOiQIBz7yDh1sbZRQu6oxlDmvwDw+ZqfdUygF8xC2Bcj5B3o04HCKRwn t31m7FIexX7if8TqYFWU4NTT4/GnwGttXJYAr0KVnB3w+Y4S6mqOxHTwM2/PEsEJdRbh wegRNkYaBIlkVHsEHRdyYrDSiLyKPy/KsgXhcHVQ9LQYdmdl1LxcxboLcoigE0CwvZ1f 7/p6hin8G/EpMkL29mZlfGChmLzqZKKTNHDKIIZNiil2sQX1JtxQqBRxgL6uv6FZoPzb KBuWMT7i7Sx5TTK9KLuHDDOob3MfQxus2WuunjmI/XmoWDJAO96VpCVvrLxf5y3W9YJX URxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=OSCXIJy6; 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 l124si6087042ywb.40.2019.03.12.23.27.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:27:05 -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=OSCXIJy6; 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]:39164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xM0-0000gc-LY for patch@linaro.org; Wed, 13 Mar 2019 02:27:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xLg-0000f0-U4 for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3xLd-00020I-PD for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:44 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:34005) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3xLb-0001zJ-2x for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:39 -0400 Received: by mail-pf1-x443.google.com with SMTP id v64so678760pfb.1 for ; Tue, 12 Mar 2019 23:26:36 -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=2Mo+uQeJOvkzulvZHsMg8FatmP4cFOzNXezUkMKmYfY=; b=OSCXIJy6l0sZwBOpnRart2TJQvO2bTZbcqyYKZjcfbnQA1qFURevryu5JAdIjxNE/7 PCZeUzDKdg7dCCXcsajcanTFN3X6lzv6ZrHFgWDn+b4se8OmwmWYy8+qAl2c9HWvtuHb XvFTsTD/U+c4CJmNO+LdlGBqfDvAFMcS0vYEiwfwKRK1CUtkDJSb7eW941cBlOAeDqYx 3I8KsdSFHF+/sa5s153XgU46pdMGNohAwFVkz4lXQKNOwYlcLb2q/wF/WeieZlOeU0tR UQnL6SjaudAARg1aX+LxvvJn2zB2np/2Mvjt+Rj9pAFAbDsNriMZJkHERQUJ0QlDe8K+ Fsig== 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=2Mo+uQeJOvkzulvZHsMg8FatmP4cFOzNXezUkMKmYfY=; b=luvxV+8dd6jQOvTR+WdMlr1OBvA1Px6wSfljSF2XI9NkG/REQwl0HfBSPsmILddICG XEOaqOZgzCkY/6bpVd75evVyCznwH5zF7fr5WKr0vzeo7jidHYTj4OTp6wnOJ4e1m/MU KYkdf4+h0XchCg+xy6Q4+i3N3GyFKzJC1Y9gf9WvSD9kSZsbz+DkpsqBckFhGiM7YKn6 vbXBvmJPBgeNTxz9DNVjZc1eG0V++8DdQ11xJy9uBGjLPxjp9xD1x8gRq3tQCl0EN9E6 QdMvxVxJ07O5v2b3eI2H/5IC5Fjs+L4pkzyXjfij+OrxBV4q/lCgUMzT8pT1P8o533aX R5wQ== X-Gm-Message-State: APjAAAX3o09JuF+1vZrw3ElBZWiLncghZmbemaLMe852FCI3rrHLZGn/ SNT/+csDJNtX4/MTDk/BoT9r7izBqBo= X-Received: by 2002:a17:902:8d89:: with SMTP id v9mr44599962plo.254.1552458395122; Tue, 12 Mar 2019 23:26:35 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id m64sm25593889pfi.149.2019.03.12.23.26.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:26:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 23:26:25 -0700 Message-Id: <20190313062630.30568-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190313062630.30568-1-richard.henderson@linaro.org> References: <20190313062630.30568-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 for-4.1 2/7] util: Use getrandom for qemu_getrandom if available 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: peter.maydell@linaro.org, david@redhat.com, laurent@vivier.eu, armbru@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We only allow access to the "urandom" side of the interface, and using -seed forces the use of the deterministic algorithm. Signed-off-by: Richard Henderson --- util/random.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++----- configure | 18 +++++++++++- 2 files changed, 88 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/util/random.c b/util/random.c index ded8725a3b..833169fad5 100644 --- a/util/random.c +++ b/util/random.c @@ -15,6 +15,13 @@ #include "qapi/error.h" #include "qemu/random.h" +#ifdef CONFIG_GETRANDOM +# include +static bool deterministic; +#else +#define deterministic true +#endif + /* * While jrand48 is not technically thread safe, jrand48_r is glibc specific. @@ -25,13 +32,11 @@ static __thread uint16_t xsubi[3]; /* Deterministic implementation using libc functions. */ -bool qemu_getrandom(void *buf, size_t len, bool nonblock) +static bool do_jrand48(void *buf, size_t len, bool nonblock) { size_t i; uint32_t val; - g_assert_cmpuint(len, <=, 256); - for (i = 0; i + 4 <= len; i += 4) { val = jrand48(xsubi); __builtin_memcpy(buf + i, &val, 4); @@ -44,18 +49,63 @@ bool qemu_getrandom(void *buf, size_t len, bool nonblock) return true; } +#ifdef CONFIG_GETRANDOM +static bool do_getrandom(void *buf, size_t len, bool nonblock) +{ + while (len != 0) { + ssize_t ret = getrandom(buf, len, nonblock ? GRND_NONBLOCK : 0); + if (unlikely(ret < 0)) { + switch (errno) { + case EAGAIN: + /* Only returned for GRND_NONBLOCK. */ + return false; + case EINTR: + /* Signal. Just try again. */ + break; + default: + /* EFAULT or EINVAL; either a bug in the user or here. */ + g_assert_not_reached(); + } + } else { + len -= ret; + buf += ret; + } + } + return true; +} +#endif + +bool qemu_getrandom(void *buf, size_t len, bool nonblock) +{ + /* Assert the interface contract is honored. */ + g_assert_cmpuint(len, <=, 256); + + if (!deterministic) { +#ifdef CONFIG_GETRANDOM + return do_getrandom(buf, len, nonblock); +#endif + } + return do_jrand48(buf, len, nonblock); +} + uint64_t qemu_seedrandom_thread_part1(void) { uint64_t ret; - qemu_getrandom(&ret, sizeof(ret), false); + if (deterministic) { + qemu_getrandom(&ret, sizeof(ret), false); + } else { + ret = 0; + } return ret; } void qemu_seedrandom_thread_part2(uint64_t seed) { - xsubi[0] = seed; - xsubi[1] = seed >> 16; - xsubi[2] = seed >> 32; + if (deterministic) { + xsubi[0] = seed; + xsubi[1] = seed >> 16; + xsubi[2] = seed >> 32; + } } void qemu_seedrandom_main(const char *optarg, Error **errp) @@ -64,6 +114,9 @@ void qemu_seedrandom_main(const char *optarg, Error **errp) if (parse_uint_full(optarg, &seed, 0)) { error_setg(errp, "Invalid seed number: %s", optarg); } else { +#ifndef deterministic + deterministic = true; +#endif qemu_seedrandom_thread_part2(seed); } } @@ -72,5 +125,16 @@ static void __attribute__((constructor)) initialize(void) { /* Make sure A and C parameters are initialized. */ srand48(0); + +#ifdef CONFIG_GETRANDOM + /* Make sure support exists within the running kernel. */ + errno = 0; + if (getrandom(NULL, 0, 0) == 0) { + return; + } + g_assert_cmpint(errno, ==, ENOSYS); + deterministic = true; +#endif + qemu_seedrandom_thread_part2(time(NULL) + getpid() * 1500450271ull); } diff --git a/configure b/configure index cab830a4c9..22c7944e38 100755 --- a/configure +++ b/configure @@ -5700,6 +5700,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 @@ -7073,7 +7087,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 Wed Mar 13 06:26:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160202 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13954802jad; Tue, 12 Mar 2019 23:32:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTbce7OKO5a2EuD5bULC25XOWjupI4vp2PajnKLlfR5vGt8hn99+LoA0ifSD3gELbEH2Ln X-Received: by 2002:a81:a342:: with SMTP id a63mr33725733ywh.362.1552458737187; Tue, 12 Mar 2019 23:32:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552458737; cv=none; d=google.com; s=arc-20160816; b=jDSVy/BmOyTSdd92kzucqY5mT0bzxEIMGgFWEux4iJ13ckFFO4lcLnidKgflaes2cj igbNEDpQSAEbyFvFkxyAENABem/2Qzp94VlN656KJVOQxkCcgULBK83fdcPpPcizxRT1 XVkjg0YFB+ogTyn+OBRGEiKOqBE0j36DL9/3UHQ2KEYY38W5p7eTr+Ypzf/MPQgY0x4V pjvLxYGpp5h9uwRjG/GtrVMzWIKnPxO8pSRV867Qrn60yHlvnVk799DX+IwT70WJBEy2 LIzWIbhq0OTBSK41pjAoB9dOSQXxDffuYGHPOE07HAm0NcAhJvVbuBpkuyFo2APQPRl2 +KtA== 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=CRrzqIjVEmnH35vuK6IV8EUSMF7zJvww1HBvBe97Ku4=; b=dCLFAOLJjjbsccHFBBCf3cn0viY6lk56v06kCZ1O+nCnBfju+az4PSM5Nkj0tAEsa/ mnRy8pfr3+nXKKgWZ+N6f6XLdsJMLxuBfrv2OefYgcBm2npjqkaACkBpcCf4UFnSHGfX 5Bet4Tx+Tlui3Dyepovo219RIq69aHip0jqywzG34j6RXmf5+URD678xK22skaIIcFME SqD0OE3sGqPHCwIpNd/EvI0RZYL2UD+dZjaK8gipjMYXu2Euzt2x5ksGmupNjHlnGtRN UmxdHVmMVu5uvAqbJyD8wJnaJErcpnss2cF0kefO/z1yayricQUBHMltlYlhtznrPRK7 M8lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=rcLdNjoV; 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 i1si6071267ybk.389.2019.03.12.23.32.17 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:32:17 -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=rcLdNjoV; 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]:39230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xR2-00047s-O2 for patch@linaro.org; Wed, 13 Mar 2019 02:32:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xLi-0000fi-2b for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3xLg-000211-UR for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:45 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:41148) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3xLd-0001zV-Qk for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:42 -0400 Received: by mail-pf1-x442.google.com with SMTP id d25so655910pfn.8 for ; Tue, 12 Mar 2019 23:26:37 -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=CRrzqIjVEmnH35vuK6IV8EUSMF7zJvww1HBvBe97Ku4=; b=rcLdNjoVIFH1g8WiIkvbj+zNp7Ux9iXWfNyq8aL69cL517Jr/hTLmCz3e9GEbxQps9 a/V9dDc2mMt5Mw727KPVM8ZUcgKcFG3vr4Ng3VrsOyaqZcky6Vqt9yS7bgpuPFrgX6hn Jweauj+3uY4V3Aa28hp8yEW6WsKXSRBllCskxIDmg9tSEprXKBwj26rgbzpYKiJjFjSB xZy2JI4pfCWIxp3j4hNqXhtxCM7S8RFQW3bd08buctR3zxO6iP8ftaPHSDMMSpelTKd/ Kan4nOMwszEbNtXePbliuHECm+iaEryKGa5BoAGTJQIOtoLY2OZwlyVq8pgn87I5DySc DRfA== 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=CRrzqIjVEmnH35vuK6IV8EUSMF7zJvww1HBvBe97Ku4=; b=RG7l3IsLoHtlPL+huEijJ6PoXA1P/NmpFaUGhTloS3Jvg55U30H3sXfR7Lz1mrwfkA y7WE5f+n3W8D9qRNsFHPsTKC2YIiLHnLoTY0oE0GxgX07XKXvSK/0TFpBxxOsVPqai54 DnlpC4x/SrXHIbJX5DXh4i1eWrQMDRVqBAkRmTMuk9DJOKnHsnUlNvBcp7zNoperUog4 WamMfM9uPTmmuhjeMEddU7H3QVCP7Ls43n/oO9kdBfp9vKg/ksA+u/4KanefVIxmb9Ye 1QkOr+2LLA5EW7rLfEBq8ueg3V/nn2fVlsITO8wNW9uStOyPm1OpinDAzhy3d3pyv4zP gkVg== X-Gm-Message-State: APjAAAXULbYuSOVsY+XWzcno+dyoemhcIahfGdtQu+PiLriaaGyZN/j5 b1j5QSQRA97T3c+KVKJ6Tf+1eJYuGto= X-Received: by 2002:a63:6605:: with SMTP id a5mr38836091pgc.372.1552458396294; Tue, 12 Mar 2019 23:26:36 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id m64sm25593889pfi.149.2019.03.12.23.26.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:26:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 23:26:26 -0700 Message-Id: <20190313062630.30568-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190313062630.30568-1-richard.henderson@linaro.org> References: <20190313062630.30568-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 for-4.1 3/7] linux-user: Use qemu_getrandom 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: peter.maydell@linaro.org, david@redhat.com, laurent@vivier.eu, armbru@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand * 16. 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 c1a26021f8..f33bf4fb85 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/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_getrandom(k_rand_bytes, sizeof(k_rand_bytes), false); if (STACK_GROWS_DOWN) { sp -= 16; u_rand_bytes = sp; From patchwork Wed Mar 13 06:26:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160200 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13953111jad; Tue, 12 Mar 2019 23:30:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCBZdCewDM7+geXG5Ewu7v7+pO2xTWY/QaKIHWg2zAoIOziw0n9j6EVQIYcJKfyJ7CHyqj X-Received: by 2002:a81:5c56:: with SMTP id q83mr32692ywb.497.1552458599766; Tue, 12 Mar 2019 23:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552458599; cv=none; d=google.com; s=arc-20160816; b=KM7MpmmHsnMUNMlYtC0xyFJ5wGuULSMR9o2J51bLO1c4UoPDGeQBh755vjrKTqPgCi K3AsFRSJTK2gTwYVXPtVTqBE9i8FXCqWMrGm2F8SaYkpb4fsfbZ+XOQDAJheQqj3PpFt S+qBRLbKB4xib/39oZNFGkUTd35M1TWwcJ7BnQAnFsWIGOKGc1ekixTX95kSi0qnoM0n TnW7X+TxPz2xK4IDIiv7izhu6+gbjAXbkz6QJ6fElRp2YZ/px4aP7v84vSYxjxTw0rYr Rnrhsc4CfmfAz3eXnClXCxUonZQObmZR2+As0eNH22rT7yGl/YHZCYx9q1wSY5M33WZE 2Yfg== 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=gpelhTrFHIRILhcge+m6UkRTeSiVlbqBCdoqAwCZgvk=; b=nGr+oIX/sQjYQRqSGgLS7r7ms5523t7VHOeE5OIfbSoYl6vtlMq8biDmuV2abPNp+E zqFRV9hdvgFVxhGpGAympFAxjdUIUYspSIjdVIhd9DU7KUrQV9rDRbyMskyUlw9TMvxt DqLsyNkIqxj0R6XG9fJm3ZVflwfw9wSUvqIfxqsEOwoiW9Cp4YySkR77pQv+WeNVTHdi eY1LajmMo8TV5AofJruSssHkTbrXdVKSIlYEEBDBsI1kegpOiTrOUH7s/ijGc08/4UJu gs6T9kxQdDnxsEAwfzMRaceouH5T+utJFpM+JLjvrKSqjdc52xO1WbjdUR1+uTG4vt16 Pxig== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=UJUiu3Mj; 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 204si6190058ybs.210.2019.03.12.23.29.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:29: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=UJUiu3Mj; 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]:39180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xOp-00029p-Aq for patch@linaro.org; Wed, 13 Mar 2019 02:29:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xLg-0000f1-UD for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3xLd-00020O-Ph for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:44 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:45424) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3xLb-0001zb-2y for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:40 -0400 Received: by mail-pg1-x543.google.com with SMTP id 125so770710pgc.12 for ; Tue, 12 Mar 2019 23:26:38 -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=gpelhTrFHIRILhcge+m6UkRTeSiVlbqBCdoqAwCZgvk=; b=UJUiu3MjA//pbGAQqYY3Hhn1Bj/L3YPaBdYg1kaOQqB9hF7OvaeUgTFTDByKdPNcxL bc6Q1dE6z+u2xsUCtFNFMTtQpH07pYyc8KcSTImqAU0QoUPX2zFcqEVnQqJksF6QJo38 SDEUsA/ds6UuEj8sHx15IN2dZsFmM0qTce8flhmWb2KzsoaW350EgUgt9rPgg0J4/Zv+ 3AGV5TgYKLJhAN/CUj4HUrrDU5oC73lqLxVW1gy0I0CUPpqlqH801l4/NmB2HTU09l9J lxl+X7JbvERkQcnfjBrnbP6ht3BJg9D+R8+T3uA2+fuT365eX6YhS1r/hHbgJi36NcFZ E9gA== 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=gpelhTrFHIRILhcge+m6UkRTeSiVlbqBCdoqAwCZgvk=; b=LhZkFjg8OIvra2faMLDlgEyr8y725ArJQnkenA+VlmHvpOFpHp9/Bn5Ut/0fV1Sjx5 aDCwu+bsUN4xWRM4l53RxZ305sJTtuh/n9QRIPQ8SJk/cJdJUTvhK2vHPtdh5OnV/Jgb xB9HqIoTXug9fYnsYHBsfRnJgEMQpjrwcSoyUbfhiR5EQKR3WdiIdhZ4KETk9uVFvpFD 702QeDKSIZx+9XFZ9gAXGhzmL//naKGN0y7nKsyzmsq0X58VrWaGgaUcMMjm/Ma1pmaM 6fNeT+pqYzzb7kDyWD6ZENMP2I0w1/rMK4rgwJcr6xjJGFJarNI+gv3KKojj/QyjTpp7 3BXg== X-Gm-Message-State: APjAAAWSRs+oxG0on6aHTqVLVHMrLHFfrevPjreotrW9buODKJHSO5Yf PDACO3B/zCyZ8rqaG3oDdOh0n5iuPF4= X-Received: by 2002:a17:902:8203:: with SMTP id x3mr43823533pln.159.1552458397416; Tue, 12 Mar 2019 23:26:37 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id m64sm25593889pfi.149.2019.03.12.23.26.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:26:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 23:26:27 -0700 Message-Id: <20190313062630.30568-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190313062630.30568-1-richard.henderson@linaro.org> References: <20190313062630.30568-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::543 Subject: [Qemu-devel] [PATCH for-4.1 4/7] linux-user/aarch64: Use qemu_getrandom for arm_init_pauth_key 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: peter.maydell@linaro.org, david@redhat.com, laurent@vivier.eu, armbru@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand * 3. Signed-off-by: Richard Henderson --- linux-user/aarch64/cpu_loop.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) -- 2.17.1 diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index d75fd9d3e2..ad30cab52d 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/random.h" #define get_user_code_u32(x, gaddr, env) \ ({ abi_long __r = get_user_u32((x), (gaddr)); \ @@ -147,22 +148,9 @@ 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(); + qemu_getrandom(key, sizeof(*key), false); } void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs) From patchwork Wed Mar 13 06:26:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160201 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13954556jad; Tue, 12 Mar 2019 23:31:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqweMGgkyRJn8qF6pgd6JXfF4ghdw6ew2Ch43NZuaJF9piDNk/0PExSq6+6VK3JMPKM4iPrK X-Received: by 2002:a81:6f8a:: with SMTP id k132mr32933010ywc.469.1552458716586; Tue, 12 Mar 2019 23:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552458716; cv=none; d=google.com; s=arc-20160816; b=BUs4ZOxLa8vVmKlFFyaaQVZPyaf75latIqGytQ0vx37h9DSRqPg5t7Uq8W2+AfgYrQ XQcb5UCSN3kmXxX6Oc9n/JAt3ZQBTZKO/0ppxZpMJAnXSS1ZjfZ1KFE4+0+LA3xQzytc MkVhDSJnHNUPYYvIl23csYvp+jHPlCFx7w1NYgU2JPWQX398JoHs2gV4cfPDSupQqZzf jSXcO76S/eSLbGgjw5jMGu9+y4HQSNxq2nHuOZShAtKe9H1BTAbeWCzPvz6cH9G1jsry N7d3Ni0bMb0kgKSzuJ289uQ5mSlMX7EOIK2KZyD3lQRKH0ci2roCJb6kEWXY2qlRNFDA nUcQ== 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=6eyH2FF7eLIJ4cGxJdoLLGwUA9HamRNHz//ATv6/MHk=; b=ObHU9NuNlZZtuZJ/eAl7YXyPSgIEMSUmU8vLp/JkTsjrwNRPbjfUPQGOcQ/LA1sFo0 NF++yVACkTgIdswgtfDNgRXT76kAazyFlc9qwLK6+FwTxAnRustj0ESMw6xKxuLd5LJ6 jzuRGUb0ZYkz6DS5Vc+VXz86He6jhZMp9IP6/N88C7Sc0gX6LyBwe3pfgxubFHP66ybE X2H9tqqqY1S5z7OVpwYg1T4iEsBXt7Z+X0yzBsw8k0XJmxhJf/6O2YGoAV0XborzhfVG W6aVDUHn4cEu2DW2b2ojEkWkjkW0kQ0l595vOCeDiAGS71hj0ZCo3nhLp4uhjL2Rj5Ry 4iQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WB20gWP0; 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 o81si6398683ywc.424.2019.03.12.23.31.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:31:56 -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=WB20gWP0; 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]:39224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xQi-0003VO-3Y for patch@linaro.org; Wed, 13 Mar 2019 02:31:56 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xLi-0000fh-2I for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3xLg-000218-VD for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:45 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:43183) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3xLd-0001zt-RD for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:44 -0400 Received: by mail-pg1-x536.google.com with SMTP id l11so776692pgq.10 for ; Tue, 12 Mar 2019 23:26:39 -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=6eyH2FF7eLIJ4cGxJdoLLGwUA9HamRNHz//ATv6/MHk=; b=WB20gWP0BAwNJzVgLNB2AJ+TD98XeL01dvXwWFvVD6LnmbnRcU6Db0WkCVeTxx+j11 Efjz3IQNVAh39Gp/wBS/42zVzUBZhKcsqfRofYsa3V3xZQks/ejHMjFF43QxNaBlU5eU 3bDfnjIdj3HiQ/912VRIFjs3D7cVf7EXOBUkhqjN5uqhadsaJQot0t3kQPbXA5El1fjG TwSKMIeLHNBkkr/acxp74wQvB04Svym93hJpfUwOxuN6hiUX4eSrfvzTGIQxx9JMBrqA JcHcUpT/h2tF46v3V+PYIUFPfLhI7IzmMZobPzh3ny6oL1GofKGFKmQuh2e5wu0f9q84 ItkA== 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=6eyH2FF7eLIJ4cGxJdoLLGwUA9HamRNHz//ATv6/MHk=; b=OavbbvA8ZmdBbcpCI89+7k323Z8mjqlc5/ssX9hnxYdwmWmX5aV8HGBJaPUKlRP7iZ O1O1sfhMzbGZlaR6EXMmnXrEpoizvz6hfZt1kt8qpfpCQG7StkzowAUAjdJmR/ZaAuXV 9R9reJ6/K+mJ2ueW5UcOUZPgTHVZX4H58NKDl/9XxpAl7+L1/fEx+RMnWgSUW7OL6aS9 SiuOqiVQuVH76+5kcvN4sVf3prb+GR7sGcRLgs+keopj3K8w0vjSS/R2J3Q6WaxRcdlq A0NTAZQzXzzLY3EPhctsH40O7LKteRAlIjWbpjgdt/+xye/ISovOVKszhwiRMlOGf3uo B7Gw== X-Gm-Message-State: APjAAAXP6PHjHHXlXugGTfhNwT6DSM0w28VfCf1Vf7xFkJteCMsgFBev 82ZsUhGfPXKZtTUkYdTO/h0ZkgOaw7c= X-Received: by 2002:a17:902:361:: with SMTP id 88mr44235425pld.78.1552458398515; Tue, 12 Mar 2019 23:26:38 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id m64sm25593889pfi.149.2019.03.12.23.26.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:26:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 23:26:28 -0700 Message-Id: <20190313062630.30568-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190313062630.30568-1-richard.henderson@linaro.org> References: <20190313062630.30568-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::536 Subject: [Qemu-devel] [PATCH for-4.1 5/7] 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: peter.maydell@linaro.org, david@redhat.com, laurent@vivier.eu, armbru@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We no longer use rand() within linux-user. Signed-off-by: Richard Henderson --- linux-user/main.c | 2 -- 1 file changed, 2 deletions(-) -- 2.17.1 diff --git a/linux-user/main.c b/linux-user/main.c index 37300230f5..7a40a14c6a 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -619,8 +619,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); From patchwork Wed Mar 13 06:26:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160205 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13956778jad; Tue, 12 Mar 2019 23:35:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxK2WVsuX70mvDHHkntb+cl9h5UpJpLr73EzWSZrcqQHKvnC4ayA+bkE/vWXlaJrhFaMgke X-Received: by 2002:a81:7a04:: with SMTP id v4mr33475691ywc.410.1552458905155; Tue, 12 Mar 2019 23:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552458905; cv=none; d=google.com; s=arc-20160816; b=t1bIqd+lo0OByK6J9gMGzSUkOcJXSy9Th+vumqPMsw2tcnByWTcY3GiRZj7UKdZM/E Q/VDTZzUsnAKylocW95u6YrX9iGYfVi5e4fBVzKY2UHK6W/m8XiF5R9DZtOnNRiW/vsq 6UTJCUQVFaHjaDwnuCAGBzOLhthR8RMj7qHTJMNp/cS4D+FLPUpsE7Fx1zB6ngnyFmje 6DWbibapsjU8K/B8rg8P1AeCejAz+M1oburxltyqyVzTVJbipa7PKI/jDeSPEtsIGYDw oMBhu7UluJKVv3lMQutr9T1fg93MT/IxfMl2D+ACbrUmLwiiHAJoVpxCbRZ8UHU9C9tA oR5w== 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=URg26ke8pptD4/rvcTYVkJk/irN25dGRogOZ9l3dOw0=; b=QXjxP6nv9wPytWUMG3N9+5JneavTXG3O8iKFRbp2DIqkaWN0heb+qwuKAaDV1YG8G2 GI4OuwHsjQAYNt7XAHX8213Z3jeXdWe12oA/su6plB8YXhurYma3n2fiMt3wumhRO7Al 8ufA2uHRY8THZVIiOmpEO85+rJ1Ss2BEeDi2uLHq5fGsR22ojEP/e3m9hbaf2VVpJ+dQ 356XRpShvtf9GuPEupQH/INCCnIxu79AvCm3/e/GMJZrCq7IThck6WVXRTwX34OeTttF nS+np23td5fXkN/PWflTx2k8+Fka+L0HvIdcnGQgYA6FH4PzcBibLISlDR4ampsKQzKo AjxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dS3FAoHE; 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 i6si5918994ybk.165.2019.03.12.23.35.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:35:05 -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=dS3FAoHE; 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]:39244 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xTk-0005fJ-Og for patch@linaro.org; Wed, 13 Mar 2019 02:35:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xLm-0000hp-GM for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3xLk-00022F-Lk for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:50 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:41151) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3xLi-000201-5M for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:46 -0400 Received: by mail-pf1-x444.google.com with SMTP id d25so656017pfn.8 for ; Tue, 12 Mar 2019 23:26:41 -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=URg26ke8pptD4/rvcTYVkJk/irN25dGRogOZ9l3dOw0=; b=dS3FAoHELYL2MV7G8GTDTECXtKyskTPhm7ft1GWJOmlWOIQDNn6jJSCfiRbMslmTLC M78c5niYkIWlgclhWl8FwbIvdKSJIAU54Q9YQoNO+z+K0qQYqmDlknryBn/FyRGKyrUH Ep1C9cZ98DAjndiJ/HumttR/4BZZnUqQyWJR5OTkfzmk8aYvP5Vo0nRS042feD7/yGD7 PDYls+zQTRyYq1/nBhsQ+AtQby9R3N0AyHJuvxnQ3zYrNwlRFO7ID2iaPit5cEq5AG9n e9wP7XL8KSLwrn6G3cR5tZ3hBQHnkCp1JFfK5NdjWinruCBacnDcB9n+wpAeDOzdaxSd qBXw== 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=URg26ke8pptD4/rvcTYVkJk/irN25dGRogOZ9l3dOw0=; b=eMdKg0p99fdmhp19GphDs+fjOblTjqDT3jYE4pZdQxj/y+roAbucpIygUs8fdtEkm/ OOMP1r8mYgC+Z6GOjiZJ/o0itvg7AgAAfY/Nnd0udojxCACAwft79A71ABUChxiipM3U RKnXsG/pS8jPjnVRZNY6+zOX6OmphHBtjG1JYBhb1TfnZDNXr3Xle3bqqXe6suF2oepx qShOxxYqowA6GrzGl+bfJgQU5FTduUEt3NPrBnHFiJpAIq5Eka6dPs5piobQ4bVCkubm QN9Ck8H/3s2AryiABYT/MlxS/gFNQccZQPvksuaoPX6Q2dZtqEeyJl754cAmfFAM/KX1 mv8g== X-Gm-Message-State: APjAAAUb4MAqfhZnSME+Uo/Y6yt8EPZq6icCZ1ewYFaUXyGoTawnuQI4 RwCdECdkMaN10eGcUzcVaaZ4kJYw/5k= X-Received: by 2002:a63:fd03:: with SMTP id d3mr38012133pgh.359.1552458399765; Tue, 12 Mar 2019 23:26:39 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id m64sm25593889pfi.149.2019.03.12.23.26.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:26:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 23:26:29 -0700 Message-Id: <20190313062630.30568-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190313062630.30568-1-richard.henderson@linaro.org> References: <20190313062630.30568-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::444 Subject: [Qemu-devel] [PATCH for-4.1 6/7] ui/vnc: Use qemu_getrandom for make_challenge 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: peter.maydell@linaro.org, david@redhat.com, laurent@vivier.eu, armbru@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use a better interface for random numbers than rand, plus some useless floating point arithmetic. Signed-off-by: Richard Henderson --- ui/vnc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) -- 2.17.1 Reviewed-by: Gerd Hoffmann diff --git a/ui/vnc.c b/ui/vnc.c index 1871422e1d..cbdfa37c52 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -46,6 +46,7 @@ #include "qom/object_interfaces.h" #include "qemu/cutils.h" #include "io/dns-resolver.h" +#include "qemu/random.h" #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT #define VNC_REFRESH_INTERVAL_INC 50 @@ -2537,12 +2538,7 @@ void start_client_init(VncState *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)); + qemu_getrandom(vs->challenge, sizeof(vs->challenge), false); } static int protocol_client_auth_vnc(VncState *vs, uint8_t *data, size_t len) From patchwork Wed Mar 13 06:26: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: 160203 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13955075jad; Tue, 12 Mar 2019 23:32:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwE8r3Qqu27S3QhXrSGMJQZ6/mI1vebFTiN4N3ffVmPqdpQI7WFyP3ylbDFvR0cEoa9Hnxs X-Received: by 2002:a25:750b:: with SMTP id q11mr34070949ybc.195.1552458756712; Tue, 12 Mar 2019 23:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552458756; cv=none; d=google.com; s=arc-20160816; b=OYTimzRIg3JhkzEEyG4wveq59fEl+HmmMNO8KKO7GNdHMO8o294TFA0yOYre6Q3RUM LRlBf01/v/UFWNjeLPuC+emrFAcUy5sF0Jnd4j283nxJzaRwagMB3LgsYvEVV+zzPOwF ikpZL2/NotCI9AkKXxlH+wSSdYXbDQhguJGiS8bCykthVX8baxk8h169ZrH8dEXWMEK4 TzwArbfBlivKzjH6zXxn5VasyHk+KYomRVs70v/qOrh+6m45mPPNTXHQrMv0oiGhn58T 7+zdzGq3Lu7aDktDdEkBuouk5Qk6HaMN+6GWD2KTreZ9A3MioHU0fNgm4Mn2MCgyQeen 4hJw== 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=8ejONeoCzadNPUYlAxbfn+jA7CyP4F1IWrm2q1c5QP0=; b=j4vcGCKZRNxDkM6xQnOnC+M6fW6HAs5ACbSDbcryuJxJuYCyrwHz7fjlfr7JI63INr F3+wMN8sCrIdAvOJcKjorclRqqep8gfJNsU+TfIeM/WkhGdTnfN9IN1cA0XnmIAQNoUL USQIyFZcGK1n0S0cTYERwFlNuYPIMIPVtOre/a0ndBHXUTRc9PKgtFaNqj8LrNvdYkkL mxENMmh4y9EUnGW69gLWyJM9ATXRGtxf2JIn1Ewu3nknsHYSAqn+yudVYUPsbuxJ3c8H HuCLb3VNNDbQhBftWVuW6b8fbZsQ+msuZWiwV8ZqiLHd3Uxp3gPC56IJAJRpC2i+ClGE vyYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oN5wkKZq; 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 e82si6155319ybe.132.2019.03.12.23.32.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:32:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oN5wkKZq; 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]:39226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xRM-0003sG-92 for patch@linaro.org; Wed, 13 Mar 2019 02:32:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xLk-0000hT-LI for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3xLi-00021p-4v for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:47 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:43162) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3xLg-00020S-TW for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:45 -0400 Received: by mail-pg1-x542.google.com with SMTP id l11so776770pgq.10 for ; Tue, 12 Mar 2019 23:26:42 -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=8ejONeoCzadNPUYlAxbfn+jA7CyP4F1IWrm2q1c5QP0=; b=oN5wkKZqD0fvF9x65sX6QPI+B7vDpOFru4ra3fiMqAAehA+8tZmzEwYnh25dAFFBa3 I5UhXUprlSaRE0hfLpNNm+ycev2GgFsBDWObqbZ40CiaIuefqSVq+1p7PJ+/glVi21D5 tWelcGYPLEeUE2PyuxECJYWQ62XmFMcDs0aaAOgP1GxyrnSBriKZeEQnc12qyuwKXSC7 t9Qyl5SWDFE5HnZ3IB1A7My/giE5DmPHVuS2HD/cstKNajmPfXgsx6WDtl/y8sFQbwOl RWyjzJg4WpTGIvCVa7knqA/rQf75VDtidioRKK5rPBR/Rbx1R4RVVXB06Zv7xYSl48c+ AY0w== 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=8ejONeoCzadNPUYlAxbfn+jA7CyP4F1IWrm2q1c5QP0=; b=Ns2pRukoGrLXLhEc9/2yeM9fTfzplvDgBnGFU6Qsxmi7l+ciThI7GcFVnc0V2YG4rf ZHMu9eQTEte8OsLop5Cp/OmDykRp3QzfDS1oQwbJNsyjyVcSsDn8RS7tgy6qOz7zFheK HFlX4zAizeVhEfLSAjqW/LoZarhogZCE1xEjq+K+dfs0CqkaY0NJ0WfzBJEj/mqi61EZ onJtg264WFef4c7DDulMGZnEzE2AM7GhRTGTVLuMitEed4Mh84ztKClJsyAIHeE9nnEJ u8wOylaYow0mIHHr+JEq0VSpUcQJ3j8Lqy0nfXAUA0pX7trWqtX2aaxrkWrOM8pFYlbz ITvA== X-Gm-Message-State: APjAAAXBnwtj//2+PlSIdEVaEry3o6F2c7ZQIXlFTdSo9oR1Dx7mLn8Z CfSYWVyBC8c62KVaRJy1iRkSYBp3voY= X-Received: by 2002:aa7:8c13:: with SMTP id c19mr6053062pfd.247.1552458400890; Tue, 12 Mar 2019 23:26:40 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id m64sm25593889pfi.149.2019.03.12.23.26.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:26:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 23:26:30 -0700 Message-Id: <20190313062630.30568-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190313062630.30568-1-richard.henderson@linaro.org> References: <20190313062630.30568-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::542 Subject: [Qemu-devel] [PATCH for-4.1 7/7] 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: peter.maydell@linaro.org, david@redhat.com, laurent@vivier.eu, armbru@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- target/arm/cpu.h | 5 +++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) -- 2.17.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 5f23c62132..aaa9e02e78 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3441,6 +3441,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 2607d39ad1..3fe7dc8719 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -20,6 +20,7 @@ #include "fpu/softfloat.h" #include "qemu/range.h" #include "qapi/qapi-commands-target.h" +#include "qemu/random.h" #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ @@ -5717,6 +5718,34 @@ static const ARMCPRegInfo pauth_reginfo[] = { .fieldoffset = offsetof(CPUARMState, apib_key.hi) }, REGINFO_SENTINEL }; + +static uint64_t rndr_readfn(CPUARMState *env, const ARMCPRegInfo *ri) +{ + uint64_t ret; + + /* Success sets NZCV = 0000. */ + env->NF = env->CF = env->VF = 0, env->ZF = 1; + if (likely(qemu_getrandom(&ret, sizeof(ret), true))) { + return ret; + } + + /* Failure sets Z = 1 and returns 0. */ + env->ZF = 0; + return 0; +} + +/* 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, + .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, + .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, @@ -6661,6 +6690,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 /*