Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6158605iog; Thu, 23 Jun 2022 12:34:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vJj3JGLn+SbLvlALrC5t6QpyB8Fs60C1zbmxh6FMMYce0Xd7uUnJw45Fmck6kmT6bgCX5X X-Received: by 2002:a17:90b:3a89:b0:1ec:93d2:f47d with SMTP id om9-20020a17090b3a8900b001ec93d2f47dmr5578604pjb.139.1656012875478; Thu, 23 Jun 2022 12:34:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656012875; cv=none; d=google.com; s=arc-20160816; b=Ume0QeH18YOMyWg3AKdNCsNE606UmKOU0g7jJE6GRLEpst2HUzMOclUxBcRFR3v2fk dtpCvdR5s7EBDas+6ni1tfNTCiA8K2GeKvdRrauZGOVxIQGcaCpTDeYoe1E19e6Re4RD 99njk6JVK7fOBXgx6DHea8f1FX2nwYVeRf8LQsFpQzDsEXEEhtCHsMBTO1vBqpMevXv5 YBElfP2/K2rFTFikd2/MI8Z8VozBHdI4ar07Yut5O1t8ZSA+oglL5ExKNdhv3gpQubKR evei/EgZTDMbXu2yPw73YbrJS6WznyqbttZT1bm5PUhWiV/3JCYvKVITI3vol7iAF+sB glzg== 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=/M0AkOsWaTuTg6LEerXfb3jsUcXX+l5FL3HQTGPpnOA=; b=wUE1VABDSHYJsQIEbgZjKTvMmnQb0sbR8Vke4duog/SdXa+yyLsdh5XA/YqJDFBOJR HNEZvV35XSHW207QwTASLDViArmod1Mq77CAfiRND1mptIGAXkZYrLEtTfwo47PBSRaD UhOt2K0j+BDN67tQIiXZvjqHWyM4h5MPrBD2YxYJxOvFaNNj4A3M+CzCKrn3GIQ1Ig9A a6pGNpqvJGWg6aTlPOAR1eg8lFryxHX2QUdo1aV7hnyj2LygrgdOdd+ow+V7zIM0E4jd 2RxLBbe4cirARW0r6GLWn/eJmPBghfCoZUYYYTtOVelXcaxJtH+ukX8cU9d6wMcn0MFn 9oCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Hk1XiS/P"; 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 b6-20020a17090a800600b001e0552f722asi3680550pjn.87.2022.06.23.12.34.21; Thu, 23 Jun 2022 12:34:35 -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="Hk1XiS/P"; 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 S235493AbiFWRy6 (ORCPT + 99 others); Thu, 23 Jun 2022 13:54:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235387AbiFWRw2 (ORCPT ); Thu, 23 Jun 2022 13:52:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D79FE31904; Thu, 23 Jun 2022 10:12:59 -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 8F9FAB82490; Thu, 23 Jun 2022 17:12:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1BC9C3411B; Thu, 23 Jun 2022 17:12:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004377; bh=LiwC49+x7F1HNzQPralqy684JqA/sOexS0k4kd4ZTjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hk1XiS/Pki/1hS8UfPvqdosj6JIRQHBTCyvy1AgZYTYYi8o9hya7lIgttu5H0w7gP ug/lLlYiORd1+zTkhUfOq3NU5nnS4NxG3BUbwEuhqs23QazS7JPbkgxwskggzyo1Cd o1m6C3s+lIL+vjeQSva1PMirgcmk+g4k7N+uo0/M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Theodore Tso , "Jason A. Donenfeld" Subject: [PATCH 4.19 019/234] random: Add a urandom_read_nowait() for random APIs that dont warn Date: Thu, 23 Jun 2022 18:41:26 +0200 Message-Id: <20220623164343.605934035@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@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: Andy Lutomirski commit c6f1deb158789abba02a7eba600747843eeb3a57 upstream. /dev/random and getrandom() never warn. Split the meat of urandom_read() into urandom_read_nowarn() and leave the warning code in urandom_read(). This has no effect on kernel behavior, but it makes subsequent patches more straightforward. It also makes the fact that getrandom() never warns more obvious. Signed-off-by: Andy Lutomirski Link: https://lore.kernel.org/r/c87ab200588de746431d9f916501ef11e5242b13.1577088521.git.luto@kernel.org Signed-off-by: Theodore Ts'o Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -2025,11 +2025,22 @@ random_read(struct file *file, char __us } static ssize_t +urandom_read_nowarn(struct file *file, char __user *buf, size_t nbytes, + loff_t *ppos) +{ + int ret; + + nbytes = min_t(size_t, nbytes, INT_MAX >> (ENTROPY_SHIFT + 3)); + ret = extract_crng_user(buf, nbytes); + trace_urandom_read(8 * nbytes, 0, ENTROPY_BITS(&input_pool)); + return ret; +} + +static ssize_t urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) { unsigned long flags; static int maxwarn = 10; - int ret; if (!crng_ready() && maxwarn > 0) { maxwarn--; @@ -2041,10 +2052,8 @@ urandom_read(struct file *file, char __u crng_init_cnt = 0; spin_unlock_irqrestore(&primary_crng.lock, flags); } - nbytes = min_t(size_t, nbytes, INT_MAX >> (ENTROPY_SHIFT + 3)); - ret = extract_crng_user(buf, nbytes); - trace_urandom_read(8 * nbytes, 0, ENTROPY_BITS(&input_pool)); - return ret; + + return urandom_read_nowarn(file, buf, nbytes, ppos); } static __poll_t @@ -2204,7 +2213,7 @@ SYSCALL_DEFINE3(getrandom, char __user * if (unlikely(ret)) return ret; } - return urandom_read(NULL, buf, count, NULL); + return urandom_read_nowarn(NULL, buf, count, NULL); } /********************************************************************