Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6144374iog; Thu, 23 Jun 2022 12:15:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s1sutmB0m+LQAjIJ7UVJERD88W7lcmAgH+gyyBCwPdeQQsTPvn/Q16gB/XIo8S6BErs5zO X-Received: by 2002:a05:6402:43cd:b0:435:d76d:f9a7 with SMTP id p13-20020a05640243cd00b00435d76df9a7mr4932919edc.119.1656011754544; Thu, 23 Jun 2022 12:15:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011754; cv=none; d=google.com; s=arc-20160816; b=bvSEXHEHx+6ONdfG2jDHk+wzIjTaLc64joOpkkjcgMCl3YIHaRimEnMSNaUJIvGDmi k5nX/afpfEWPbstMJ6/K14Zmr55KbRuMtWf5pDZvqYTNcWeADOAV0jpEmRFanfdS+r7F UEB2sP0FEkhnly7aDNl1ECUbeRdmIc2jXFkyKluLlSzWiJQ27WuLSCA2/dCt4YFAkg+8 FpupD6lxIDZR+rUqzjsrRN6d4UNVVdufmPBZ0+OmF6a0zFhz9YwzQ3z7nZI02sa+QQWB 9aEysz3/3U95GSeOh7/ST1WXoyG2Y107aXf4zC38gf0UMTaWPgtoKveMFv9JPj75XKZO TdqA== 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=Vfg30UgoAi1xFkFuAd2EVa19iwUJ61y5sOjaKeBjeO4=; b=0zOQxGFbueslAxhSfgWmsifidnd/0q/1rgrjIYmY3/QZZMgECpTv8nGMWPdMu+e0Bq eaCn1qCTuJXplxSd0XrVCOoDlvD2kjcU/vD14x+m7xNGI0hz/w8WqmdMLpKEOwy2XNNS c0MiOrAp44IZwYycI1ydARzvCn2BLN7OgYoBL1/UWc94CDlS2VL64b7G9iwV/w3A078t 0oi/voFSpGLJD97P52HKF2ERoWZkXdZvqwxsrLmU7+hcZt9hmwizSUPbTGdGIk1GpGR+ rLHL4Hzbq2acyMcT2u8Y18lOHiVVjlmzHyw2jsBInhBA0xXodLRFiccAtanm/R+wvBfl 5jgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=r3tqG1rN; 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 hz5-20020a1709072ce500b006fedcc0e599si7519991ejc.118.2022.06.23.12.15.28; Thu, 23 Jun 2022 12:15:54 -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=r3tqG1rN; 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 S232420AbiFWROH (ORCPT + 99 others); Thu, 23 Jun 2022 13:14:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231772AbiFWRLn (ORCPT ); Thu, 23 Jun 2022 13:11:43 -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 D33801B7B1; Thu, 23 Jun 2022 09:51:30 -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 95BACB82490; Thu, 23 Jun 2022 16:51:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F00AAC3411B; Thu, 23 Jun 2022 16:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003088; bh=EfDHez6bplTEEaL8HZ+uQVhkOVviWmPlixb/w9592Jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r3tqG1rNIxjx8JLuEx0kgbUjE3AQJDfbuOV8fl15J+ooX9ocvJIDh7vEePsuqjSAw mRfsWUZuhfpVXsJScnMoHym2z5KYUJfOfBxVcitnyXiuGNLaKNDznOEvHuC2EhbXIX llfDPEqW/bkxKBVFTueb3nCUnMaOJU17rOl6vk2k= 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.9 124/264] random: remove outdated INT_MAX >> 6 check in urandom_read() Date: Thu, 23 Jun 2022 18:41:57 +0200 Message-Id: <20220623164347.575405243@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: "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 @@ -1336,9 +1336,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;