Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6145422iog; Thu, 23 Jun 2022 12:16:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s8ozqFGHdVa1rzHBBxhDSCTk4nKR7ExT14Ldzq7VGXv6++hbhuKN/7WgNRfc2UUHZTKlHd X-Received: by 2002:a05:6402:274a:b0:435:9807:7752 with SMTP id z10-20020a056402274a00b0043598077752mr12842628edd.63.1656011816500; Thu, 23 Jun 2022 12:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011816; cv=none; d=google.com; s=arc-20160816; b=RzkCXo+2h8t3A6RILJGiXlHe+byTOk/YnKe507Rqxl+VxG6L61dOobYzcY0fxKsA36 ZUQyR2PwCfQfMGk17tzHY7g7a2Op4UdDU5VV/+dwk/qyyiN//n9z/hJOUBMBtBcDNX2E cvY6oAs9QHL6SegJK4CsGX2Fstj/ExddfIbPMbQ16bjpRWCDNrZvk26JsqopMl+08aZC k1A9Hetulj1nSpu9FGsNL3myrbwL3NnMQuC/yFd+WdBXkDxXr5Yr8BfWpdQSdit+2MT7 nBzKNCYXTjNJjZA8X0c2UBh/a6SleVXTwkegRq/UYfkbdjgzk9NNvnRvN8URpqlPRo8s ljKw== 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=Ndg93KQ8+RxWrEt33NMOYYskrDl2QdOUicfSreNC0n8=; b=aoKNl4Am2dfv14/87HlZf4ftJdJ6KBTbA3aAB5w1WY1jemC3agYyat1z6A4ITUMb3W t/rdtigRQcB3fGoakZnfh4ZFgbGjaXdQgxy6D1ryO4cv29C8pDYcxTUFFlH/zG6FOKdG T3jhF5lnGL7naqN7QQAyR4A0klR9wASRj6hsuG6iDUWcPqnC3RBu0lUQKmwO8dTNn6ri mRyCpIUhilehpT6vsOBATaUnYjGjFmsEGE/uw09fHMjPzqAc1hHmTmP4yanzx55d7U2W twMGHZ51l2QKhdoMuLB+835DE/EY/uus3HiPEeGhHn73LsiYnvjZc+F9/4T162sgzk0v w7eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tNPHRMI0; 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 eb9-20020a0564020d0900b00435bbe82254si495708edb.143.2022.06.23.12.16.31; Thu, 23 Jun 2022 12:16:56 -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=tNPHRMI0; 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 S232402AbiFWSDi (ORCPT + 99 others); Thu, 23 Jun 2022 14:03:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235765AbiFWSBQ (ORCPT ); Thu, 23 Jun 2022 14:01:16 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F4FAB3D05; Thu, 23 Jun 2022 10:16:40 -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 B572FB824C0; Thu, 23 Jun 2022 17:16:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C4E4C3411B; Thu, 23 Jun 2022 17:16:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004596; bh=iOUN+SJWtArXuCdDvQf/Yj0CiUG/LST6tsaQIxZiZN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tNPHRMI0fnZi4cc3BN4QVP7JzbX3W39XyuS4BkqTchCOhXOVwH5GZGpqY+QozgGv1 21MRhIVXPjXJRKcwGj4plWMuMOWSwLZ5U4jFgiAKLO3LKPRU7QG8loZtaUuC/VSDX0 kOVA9qmVwuTF8/K32bQHx6MIgLPfC6XMvxsav93s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Dominik Brodowski , Jann Horn , Eric Biggers , "Jason A. Donenfeld" Subject: [PATCH 4.19 089/234] random: remove outdated INT_MAX >> 6 check in urandom_read() Date: Thu, 23 Jun 2022 18:42:36 +0200 Message-Id: <20220623164345.577438270@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: "Jason A. Donenfeld" commit 434537ae54ad37e93555de21b6ac8133d6d773a9 upstream. In 79a8468747c5 ("random: check for increase of entropy_count because of signed conversion"), a number of checks were added around what values were passed to account(), because account() was doing fancy fixed point fractional arithmetic, and a user had some ability to pass large values directly into it. One of things in that commit was limiting those values to INT_MAX >> 6. The first >> 3 was for bytes to bits, and the next >> 3 was for bits to 1/8 fractional bits. However, for several years now, urandom reads no longer touch entropy accounting, and so this check serves no purpose. The current flow is: urandom_read_nowarn()-->get_random_bytes_user()-->chacha20_block() Of course, we don't want that size_t to be truncated when adding it into the ssize_t. But we arrive at urandom_read_nowarn() in the first place either via ordinary fops, which limits reads to MAX_RW_COUNT, or via getrandom() which limits reads to INT_MAX. Cc: Theodore Ts'o Reviewed-by: Dominik Brodowski Reviewed-by: Jann Horn Reviewed-by: Eric Biggers Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1284,9 +1284,8 @@ void rand_initialize_disk(struct gendisk static ssize_t urandom_read_nowarn(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) { - int ret; + ssize_t ret; - nbytes = min_t(size_t, nbytes, INT_MAX >> 6); ret = get_random_bytes_user(buf, nbytes); trace_urandom_read(nbytes, input_pool.entropy_count); return ret;