From patchwork Fri Mar 15 03:26:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1056808 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="N1+YCvWS"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44LB8F1jkrz9s4Y for ; Fri, 15 Mar 2019 14:36:45 +1100 (AEDT) Received: from localhost ([127.0.0.1]:48706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4deF-0006Dz-3b for incoming@patchwork.ozlabs.org; Thu, 14 Mar 2019 23:36:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h4dcI-00059H-QB for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:34:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h4dUn-00035j-0j for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:57 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:34603) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h4dUm-00034r-R0 for qemu-devel@nongnu.org; Thu, 14 Mar 2019 23:26:56 -0400 Received: by mail-pg1-x52c.google.com with SMTP id v12so5434042pgq.1 for ; Thu, 14 Mar 2019 20:26:56 -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=etLbcy1a7zqlIhvc39R877L+TQ7d/3g/A8LNCCGc1X0=; b=N1+YCvWSZOazdw53D7FI4pwwRuL6fG0KC9IfI14M03A9rlUsT4yiUnU8KTBtH4zMG6 ONdH/EHITdbj2n4vy+lTQgkNcNNDsm88ZSFRFjcpsjEkQd2h1+6U8sQLkR1jRP/65AF6 5LZOte7687WnlGApjBrbv4iwMZ2406I/qkkL66dCtrI62E5dZBZlnHGDllqyNQsYOsBN xXk8ZqZZAK82CZboonh3pLOXGermxgW7h0v18CCTi42iWQoRcDjoqt9v8c+I7FFPxOjd 3FHqqQjhD7/5p6IR9g6seCgAjw2MVd1GYuO04B8CR2rSO1MlXK/GIIMZUQKJrhjn5f9C QgwQ== 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=etLbcy1a7zqlIhvc39R877L+TQ7d/3g/A8LNCCGc1X0=; b=D5KfEr2q48R3ZceAxMeQsr/jzOcY6D7WVXGpKtRu+RGEG2/BH3cl50VidE0AOA/VkX EEd01nIf7dyfaO6t24rwe9PBX8fIXf17ZjBqYvyncX9OLgDTJJlgE+AX3RwToSDs+CZC lGBQetLPcWUhnNhcSeW3gxgrmtrs5DEmw2MvGPJqY+3YaEjTu4NefJomon8SPFBMJAWq LSTMdz6r6o41ENxZizw1yU6Hn222zwpIVqaQOXgGxkFl8+ojswAwlscyLHQ+ISCU2a/r S9EAAmDv0rYKF0QCpzybcaUaFqRYOJZWIU3dT64UVueVQAwYllmOPZyEl5uKyN+Rf9NU DqHQ== X-Gm-Message-State: APjAAAVvEV1H4QgUEgNTDLxvM7xhErbcC0bwbnjRYZYSw+en6ORJQ6tm zzdfR4yCDHapLeFgABrTjZihWjjBrYA= X-Google-Smtp-Source: APXvYqxPRra1UbvHOvIIu/bNEFNOkSPM+QhRyBp5Di/7ZVHI81czU+kTLg9RQT0YsE7bq2J6N2rdzQ== X-Received: by 2002:a17:902:1002:: with SMTP id b2mr1788447pla.248.1552620415419; Thu, 14 Mar 2019 20:26:55 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id d26sm690816pfn.86.2019.03.14.20.26.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Mar 2019 20:26:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 14 Mar 2019 20:26:24 -0700 Message-Id: <20190315032629.21234-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190315032629.21234-1-richard.henderson@linaro.org> References: <20190315032629.21234-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::52c Subject: [Qemu-devel] [PATCH v3 18/23] 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: qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Andrew Baumann Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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. Cc: qemu-arm@nongnu.org Cc: Andrew Baumann Cc: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- hw/misc/bcm2835_rng.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) 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; }