Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6031550iog; Thu, 23 Jun 2022 09:56:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1trALMtMRdJN0qJ8rwnykMacEqKpDFE4naz9lLXHtyZD8ou4n8XnYZ4t9AYog10EhEVSCNi X-Received: by 2002:aa7:c14f:0:b0:435:7b75:fd06 with SMTP id r15-20020aa7c14f000000b004357b75fd06mr11977665edp.352.1656003401180; Thu, 23 Jun 2022 09:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656003401; cv=none; d=google.com; s=arc-20160816; b=klG5lA8UdjtCBcYu35Xxlfbzm33hXjk0vtzpfszvtH6c3NyPnUkxtnPhM/+ZwoCTCn L7aF+8L1ygFqUX8KKhZJt17YP5ocPHYFBTLw625fk+3IIblbZyShoFQlCL+sMh5FZx9G +cuT3wqy0O3STgMRQVdgtAnCfv1q62lol6e0BLO7NKlHusePZDwLz7IFYsBZnKr9w7T8 6aOneQHXYwlrf0/fr0WfMDYyLhTYisfARcurlp7pELAeDuvb2k4zGH83AR6uCMqJcCh2 0Lpqx3EDEFLUnLoG8QaRt7tfk2gKR6Yb6uikjl/RnYXy9sRg2IUYy3K5B0lgGI0w2SAe OGHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jXkfvhx22WvvAQSMzqo1f1JOue4FfPQGANZOA9O0blY=; b=tD0iC+M0HWKjN5uCA+W/ZpFtrYEMWX6QOJga4oVcx1ViNgLApXHBEvAaV1Zab2o8Pr +eMAfMV8gSsj6xxE94PMzUU53BTqhO2d6z7l01vvI5wufSChTPL8eptdDAu1kS18jVqH BGcfDJXn8lv2BX4p1xotwToSYBBwJNrz5BfknIooV4ZN1UGryN2PCaFlIVpQw/+KfhNw GkQHaYBGtynLCmeUBrF6baBLhwSqt9Mhvixv99+M2NhWKT4e7Ds4hKxCyjWJ8m9d764d phr7qFYPNK/aSxX6AjD8uNA2MSH6aorq45tqlSBQb+9Oa8L12iz7T82wFQykP43GNWTk nhCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fkuSR+Ht; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q20-20020a50cc94000000b004358144aaf6si46711edi.428.2022.06.23.09.56.12; Thu, 23 Jun 2022 09:56:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fkuSR+Ht; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232619AbiFWQri (ORCPT + 99 others); Thu, 23 Jun 2022 12:47:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232556AbiFWQqx (ORCPT ); Thu, 23 Jun 2022 12:46:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 458A949C9F; Thu, 23 Jun 2022 09:46:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C6190B82491; Thu, 23 Jun 2022 16:46:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 220A1C3411B; Thu, 23 Jun 2022 16:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656002807; bh=QCWuFJbSl4FhgUQAJaPiaZVjAiaAZAjuslsFkYmNtDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fkuSR+Htn5yiLMVbbPanII0xoHL3iLXqgQjtp0+or4uodhTKzml6kYX53VLd2Mz/k dYONmMnVvhcD4Jsat3UPcXMdOfdqn14tC5cQWNme4Cdhr1JE1X+4qHXdWzhuDxBiIG bjPzzskK1LgzymUUiwXeP7V5VHCKrfTY/XaQg46s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , "Steven Rostedt (VMware)" , "Tobin C. Harding" , "Jason A. Donenfeld" Subject: [PATCH 4.9 031/264] random: Return nbytes filled from hw RNG Date: Thu, 23 Jun 2022 18:40:24 +0200 Message-Id: <20220623164344.949637835@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Tobin C. Harding" commit 753d433b586d1d43c487e3d660f5778c7c8d58ea upstream. Currently the function get_random_bytes_arch() has return value 'void'. If the hw RNG fails we currently fall back to using get_random_bytes(). This defeats the purpose of requesting random material from the hw RNG in the first place. There are currently no intree users of get_random_bytes_arch(). Only get random bytes from the hw RNG, make function return the number of bytes retrieved from the hw RNG. Acked-by: Theodore Ts'o Reviewed-by: Steven Rostedt (VMware) Signed-off-by: Tobin C. Harding Signed-off-by: Theodore Ts'o Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 16 +++++++++------- include/linux/random.h | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1783,26 +1783,28 @@ EXPORT_SYMBOL(del_random_ready_callback) * key known by the NSA). So it's useful if we need the speed, but * only if we're willing to trust the hardware manufacturer not to * have put in a back door. + * + * Return number of bytes filled in. */ -void get_random_bytes_arch(void *buf, int nbytes) +int __must_check get_random_bytes_arch(void *buf, int nbytes) { + int left = nbytes; char *p = buf; - trace_get_random_bytes_arch(nbytes, _RET_IP_); - while (nbytes) { + trace_get_random_bytes_arch(left, _RET_IP_); + while (left) { unsigned long v; - int chunk = min(nbytes, (int)sizeof(unsigned long)); + int chunk = min_t(int, left, sizeof(unsigned long)); if (!arch_get_random_long(&v)) break; memcpy(p, &v, chunk); p += chunk; - nbytes -= chunk; + left -= chunk; } - if (nbytes) - get_random_bytes(p, nbytes); + return nbytes - left; } EXPORT_SYMBOL(get_random_bytes_arch); --- a/include/linux/random.h +++ b/include/linux/random.h @@ -37,7 +37,7 @@ extern void get_random_bytes(void *buf, extern int wait_for_random_bytes(void); extern int add_random_ready_callback(struct random_ready_callback *rdy); extern void del_random_ready_callback(struct random_ready_callback *rdy); -extern void get_random_bytes_arch(void *buf, int nbytes); +extern int __must_check get_random_bytes_arch(void *buf, int nbytes); #ifndef MODULE extern const struct file_operations random_fops, urandom_fops;