From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF190C32792 for ; Thu, 3 Oct 2019 16:53:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B692320862 for ; Thu, 3 Oct 2019 16:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570121595; bh=UGqMufujAPeYf8XfJuRbDlboz+r/vDuLTwr5F1tDuSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=VYKrJn5UndkU6+CeOxBefMLo0snaZIW4ddcMOq6A6NGAUmXlNAt+Z8IkDeXVbDSc/ Rm0d0xeQu/mBxpEVYvzYUJMe1HZgv0x4kmCQnL5yB19k/7Xkh9ktrljtsWqU61ks4r 3319gYOLI2Kcv1BhD/51Fv/FpdDFyGL8nLvJNgQE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406317AbfJCQxO (ORCPT ); Thu, 3 Oct 2019 12:53:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:41054 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406266AbfJCQxI (ORCPT ); Thu, 3 Oct 2019 12:53:08 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AFDA020862; Thu, 3 Oct 2019 16:53:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570121588; bh=UGqMufujAPeYf8XfJuRbDlboz+r/vDuLTwr5F1tDuSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yorl1VqcjhFXp3xhEbMeqjD2fNYnzrk7ss6cDuOmvI/Ko97mvP34d4YE3dIMxUwC3 ai749Uxrm8ctj5IeR8dU/kLdBsG8JDvSF4zCQN4RLd1I108bLV1pkv1lEtaXC0MYcR crzf3+V93zpHHJx9NFKBspc1SI5cFf6UOpTqvaAQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Laurent Vivier , Theodore Tso , Herbert Xu Subject: [PATCH 5.3 333/344] hwrng: core - dont wait on add_early_randomness() Date: Thu, 3 Oct 2019 17:54:58 +0200 Message-Id: <20191003154611.544359173@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154540.062170222@linuxfoundation.org> References: <20191003154540.062170222@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Laurent Vivier commit 78887832e76541f77169a24ac238fccb51059b63 upstream. add_early_randomness() is called by hwrng_register() when the hardware is added. If this hardware and its module are present at boot, and if there is no data available the boot hangs until data are available and can't be interrupted. For instance, in the case of virtio-rng, in some cases the host can be not able to provide enough entropy for all the guests. We can have two easy ways to reproduce the problem but they rely on misconfiguration of the hypervisor or the egd daemon: - if virtio-rng device is configured to connect to the egd daemon of the host but when the virtio-rng driver asks for data the daemon is not connected, - if virtio-rng device is configured to connect to the egd daemon of the host but the egd daemon doesn't provide data. The guest kernel will hang at boot until the virtio-rng driver provides enough data. To avoid that, call rng_get_data() in non-blocking mode (wait=0) from add_early_randomness(). Signed-off-by: Laurent Vivier Fixes: d9e797261933 ("hwrng: add randomness to system from rng...") Cc: Reviewed-by: Theodore Ts'o Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/char/hw_random/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c @@ -67,7 +67,7 @@ static void add_early_randomness(struct size_t size = min_t(size_t, 16, rng_buffer_size()); mutex_lock(&reading_mutex); - bytes_read = rng_get_data(rng, rng_buffer, size, 1); + bytes_read = rng_get_data(rng, rng_buffer, size, 0); mutex_unlock(&reading_mutex); if (bytes_read > 0) add_device_randomness(rng_buffer, bytes_read);