Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2439529ioo; Sat, 28 May 2022 13:45:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhsYbzDEoU3SctuPU3AiOrDFvkPNYjMIOFYI+osRlNjYA3XHt+RJqKiKjI43YpmDfrniRB X-Received: by 2002:a17:90b:4a03:b0:1e2:92f2:3167 with SMTP id kk3-20020a17090b4a0300b001e292f23167mr6832043pjb.1.1653770722031; Sat, 28 May 2022 13:45:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770722; cv=none; d=google.com; s=arc-20160816; b=yJMf+FC52zJQWOccLghqiBRr1JFmq86txIRqesbcb7ESrOM19UEU3z8QaMBgW12MwZ xTdGnvdscYMhNahugUZwPsMOO1UmR52kM23HGMxuzBb//7Rf5ZkcKIlOe9b0/a0q1Ymm de/W+CzMrk5SebOnF76uPrh71LKmspEFrBSHSsRofAmYITA+I7wtnz4PYWfARMxVh6aD D9fZHr7gH0IXc+eQHjAZJAOVuvRaDnwYoys4ieqRiLS92CEwm7m94Y4mSUSky5BZ555N lmFjpJfXnsD27pkJ2c+HAqw52DTkatH/4+QG7wsJs+Km4vdYNEDMTpP6t3jcXvzuG0U0 WBhw== 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=GRqhhclhUXSO3MRykluI1VFDI0vxPc2ll1K9i4y/hys=; b=KXPDn2dz5iUtoI8cj3KNYoOBUDUsiI1wzC2nabeW4dqIZBJDPKCuw3AZcAW5qeZc2H kAvPxhXOWqjiq0xr7RhaI16CMuGRmjJQ6mV2I116yVBMYYeCDZShgVTKMsEwUU8UUek2 HfziCJDvKwJ0LK9OGIzRw9rQjrSiA7wktMXg9hsyafBcH7MJwkYMU+xGhR1B4+kBZE8q nKw9+EM0kfivLCzVp7oTPnvGT3DRha3FfylkO5i5ArfkP4EGHh92sz2F32mlHcHWFQdf xQLc4P7mPg1reGGt3CwuQariWaI/5gGvVQBMGdfwLlH8PYcAlOvG6NyFBqY7w+472nsl F14A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZY4FmL6y; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y15-20020a056a00180f00b005191e2b27a5si10693600pfa.58.2022.05.28.13.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:45:22 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZY4FmL6y; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B91552B254; Sat, 28 May 2022 12:44:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350341AbiE0JE2 (ORCPT + 99 others); Fri, 27 May 2022 05:04:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350461AbiE0I77 (ORCPT ); Fri, 27 May 2022 04:59:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E04795D5C0; Fri, 27 May 2022 01:55:57 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 6CC4361CB7; Fri, 27 May 2022 08:55:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47306C385B8; Fri, 27 May 2022 08:55:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653641756; bh=Ve6NfPpdS1r05uyDwxztOFOgYNEeL5kzJRoMP9JvtMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZY4FmL6y8TdecJTQaoJNhliuhozPzUuSd40UHPGC28C4TsmiizEgo11eqf7ax32j+ eVbASixqPL/JkzOB0FM+2zO01u+a8MckK2qpqMAe9CrBX+aO+8UIBXGeeTDaMSdvQq b/rNhxOlG5SdrKzhawc8ywIgbmu3Yyylv/7TVc1w= 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 5.17 020/111] random: remove outdated INT_MAX >> 6 check in urandom_read() Date: Fri, 27 May 2022 10:48:52 +0200 Message-Id: <20220527084822.188475049@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220527084819.133490171@linuxfoundation.org> References: <20220527084819.133490171@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=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 @@ -1286,9 +1286,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;